Skip to content

Commit 7d93f0f

Browse files
Merge pull request #468 from 4lessandrodev/release/v3.10.0
chore: update rich-domain core to v1.24
2 parents a3e8eb3 + 945f755 commit 7d93f0f

File tree

51 files changed

+806
-716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+806
-716
lines changed

lib/patterns/proxy/proxy.pattern.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,18 @@ export abstract class TSProxy<Data, Payload, Error = string> {
9494
private readonly context: IProxyContext<Data, Payload, Error>,
9595
) {}
9696

97-
private async canExecute(data: Data): Promise<Result<boolean, Error>> {
97+
private async canExecute(
98+
data: Data,
99+
): Promise<Result<boolean | null, Error>> {
98100
if (!this.context.canExecute) {
99101
return Result.Ok(true);
100102
}
101103
return this.context.canExecute.execute(data);
102104
}
103105

104-
private async beforeExecute(data: Data): Promise<Result<Data, Error>> {
106+
private async beforeExecute(
107+
data: Data,
108+
): Promise<Result<Data | null, Error>> {
105109
if (!this.context.beforeExecute) {
106110
return Result.Ok(data);
107111
}
@@ -118,7 +122,7 @@ export abstract class TSProxy<Data, Payload, Error = string> {
118122
return this.context.afterExecute.execute(Result.Ok(data.value()));
119123
}
120124

121-
async execute(data: Data): Promise<Result<Payload, Error>> {
125+
async execute(data: Data): Promise<Result<Payload | null, Error>> {
122126
const beforePayload = await this.beforeExecute(data);
123127

124128
if (beforePayload.isFail()) {
@@ -142,7 +146,7 @@ export abstract class TSProxy<Data, Payload, Error = string> {
142146

143147
const param = beforePayload?.value() ? beforePayload?.value() : data;
144148

145-
const executeResult = await this.context.execute.execute(param);
149+
const executeResult = await this.context.execute.execute(param as Data);
146150

147151
if (executeResult.isFail()) {
148152
const error = executeResult?.error() ?? 'error on execute proxy';

lib/types/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export interface CloneProps {
4545
*/
4646
export type ICanExecuteProxy<Data, Error> = IUseCase<
4747
Data,
48-
Result<boolean, Error>
48+
Result<boolean | null, Error>
4949
>;
5050
/**
5151
* @description Method responsible for do something you want after run `execute` method
@@ -84,7 +84,10 @@ export type IAfterHookProxy<Payload, Error> = IUseCase<
8484
* // ...
8585
*
8686
*/
87-
export type IBeforeHookProxy<Data, Error> = IUseCase<Data, Result<Data, Error>>;
87+
export type IBeforeHookProxy<Data, Error> = IUseCase<
88+
Data,
89+
Result<Data | null, Error>
90+
>;
8891

8992
/**
9093
* @description Context parameters for a proxy class instance.

lib/utils/birthday.value-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class BirthdayValueObject extends ValueObject<Prop> {
6666
return isBeforeToday && hasLessThan121YearsOld;
6767
}
6868

69-
public static create(value: Date): Result<BirthdayValueObject> {
69+
public static create(value: Date): Result<BirthdayValueObject | null> {
7070
if (!BirthdayValueObject.isValidValue(value)) {
7171
return Result.fail(BirthdayValueObject.MESSAGE);
7272
}

lib/utils/cnpj.value-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class CNPJValueObject extends ValueObject<Prop> {
9393
* @example "22398345000188"
9494
* @summary fails if provide an invalid pattern or a cnpj with invalid digit sum
9595
*/
96-
public static create(value: string): Result<CNPJValueObject> {
96+
public static create(value: string): Result<CNPJValueObject | null> {
9797
const isValidValue = CNPJValueObject.isValidProps(value);
9898

9999
if (!isValidValue) {

lib/utils/cpf.value-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class CPFValueObject extends ValueObject<Prop> {
9696
* @example "72725477824"
9797
* @summary fails if provide an invalid pattern or a cpf with invalid digit sum
9898
*/
99-
public static create(value: string): Result<CPFValueObject> {
99+
public static create(value: string): Result<CPFValueObject | null> {
100100
const isValidValue = CPFValueObject.isValidProps(value);
101101

102102
if (!isValidValue) {

lib/utils/currency.value-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class CurrencyValueObject extends ValueObject<Prop> {
228228
* @param props object currency and value
229229
* @returns Result with instance of CurrencyValueObject
230230
*/
231-
public static create(props: Prop): Result<CurrencyValueObject> {
231+
public static create(props: Prop): Result<CurrencyValueObject | null> {
232232
const isValidCurrency = Object.keys(currency).includes(props.currency);
233233
if (!isValidCurrency) {
234234
return Result.fail(`${props.currency} is an invalid currency`);

lib/utils/custom-number.value-object.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ export class CustomNumberValueObject extends ValueObject<Prop> {
9595
);
9696
}
9797

98-
public static create(value: number): Result<CustomNumberValueObject> {
98+
public static create(
99+
value: number,
100+
): Result<CustomNumberValueObject | null> {
99101
const isValidValue = CustomNumberValueObject.isValidValue(value);
100102

101103
if (!isValidValue) {

lib/utils/custom-string.value-object.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ export class CustomStringValueObject extends ValueObject<Prop> {
102102
return VALIDATOR(value) && value.length >= MIN && value.length <= MAX;
103103
}
104104

105-
public static create(value: string): Result<CustomStringValueObject> {
105+
public static create(
106+
value: string,
107+
): Result<CustomStringValueObject | null> {
106108
const isValidValue = CustomStringValueObject.isValidProps(value);
107109

108110
if (!isValidValue) {

lib/utils/date-value-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export class DateValueObject extends ValueObject<Prop> {
443443
return instanceTime === time;
444444
}
445445

446-
public static create(date?: Date): Result<DateValueObject> {
446+
public static create(date?: Date): Result<DateValueObject | null> {
447447
const value = date ?? new Date();
448448
const isValid = DateValueObject.isValidProps(value);
449449
if (!isValid) return Result.fail('Invalid Date Value');

lib/utils/dimension.value-object.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export class DimensionValueObject extends ValueObject<DimensionValueObjectProps>
5757
unit: UnitOfMeasure,
5858
): DimensionValueObject {
5959
const float = (value = parseFloat(value.toFixed(3)));
60-
this.props.dimension = CustomNumberValueObject.create(float).value();
60+
this.props.dimension = CustomNumberValueObject.create(
61+
float,
62+
).value() as CustomNumberValueObject;
6163
this.changeDimensionUnit(unit);
6264
return this;
6365
}
@@ -230,7 +232,10 @@ export class DimensionValueObject extends ValueObject<DimensionValueObjectProps>
230232
return this;
231233
}
232234

233-
public static create({ unit, value }: Props): Result<DimensionValueObject> {
235+
public static create({
236+
unit,
237+
value,
238+
}: Props): Result<DimensionValueObject | null> {
234239
const isValidUnit = unit in UnitsOfMeasure;
235240

236241
if (!isValidUnit) {
@@ -247,7 +252,7 @@ export class DimensionValueObject extends ValueObject<DimensionValueObjectProps>
247252
return Result.Ok(
248253
new DimensionValueObject({
249254
unit,
250-
dimension: customNumber.value(),
255+
dimension: customNumber.value() as CustomNumberValueObject,
251256
}),
252257
);
253258
}

0 commit comments

Comments
 (0)