Skip to content
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ All notable changes to this project will be documented in this file.

---

### [4.0.5] - 2024-11-28

### Fix

- update rich-domain lib to check nullish type: now 'create' return a possibly null value in Result instance.

---

### [4.0.4] - 2024-09-26

### Fix
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export default class Money extends ValueObject<Props> {
}

// factory method to create an instance and validate value.
public static create(amount: number): Result<Money> {
public static create(amount: number): Result<Money | null> {

const isValid = this.isValidProps({ amount });
if(!isValid) return Fail("Invalid amount for money");
Expand All @@ -286,7 +286,7 @@ console.log(resA.isOk());


// money instance
const moneyA = resA.value();
const moneyA = resA.value() as Money;

moneyA.get("amount");

Expand All @@ -297,7 +297,7 @@ moneyA.isGt(Money.zero());

// > true

const moneyB = Money.create(100).value();
const moneyB = Money.create(100).value() as Money;

const moneyC = moneyA.sum(moneyB);

Expand Down Expand Up @@ -364,12 +364,12 @@ How to use entity instance
```ts

// operation result
const total = Money.create(500).value();
const total = Money.create(500).value() as Money;
const discount = Money.zero();
const fees = Money.zero();

// create a payment
const payment = Payment.create({ total, discount, fees }).value();
const payment = Payment.create({ total, discount, fees }).value() as Payment;

// create fee and discount
const fee = Money.create(17.50).value();
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "type-ddd",
"version": "4.0.4",
"version": "4.0.5",
"description": "This package provide utils file and interfaces to assistant build a complex application with domain driving design",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -53,7 +53,7 @@
},
"homepage": "https://github.com/4lessandrodev/type-ddd/tree/main",
"peerDependencies": {
"rich-domain": "^1.23.4"
"rich-domain": "^1.24.0"
},
"devDependencies": {
"@types/jest": "^27.0.1",
Expand All @@ -65,7 +65,7 @@
"lint-staged": "^15.0.1",
"madge": "^8.0.0",
"prettier": "^3.0.0",
"rich-domain": "^1.23.4",
"rich-domain": "^1.24.0",
"rimraf": "^5.0.5",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/cnpj/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ All notable changes to this project will be documented in this file.

## Released

---

### [0.0.3] - 2024-11-28

### Fix

- update rich-domain lib to check nullish type: now 'create' return a possibly null value in Result instance.

### [0.0.2] - 2024-05-31

### Docs
Expand Down
24 changes: 12 additions & 12 deletions packages/cnpj/__tests__/cnpj.value-object.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ describe('CNPJ Value Object', () => {
it('should create a valid CNPJ with special characters removed', () => {
const valueObject = CNPJValueObject.create('43.909.299/0001-04');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('43909299000104');
expect(valueObject.value()?.value()).toBe('43909299000104');
});

it('should create a valid CNPJ with numbers only', () => {
const valueObject = CNPJValueObject.create('60105617000101');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('60105617000101');
expect(valueObject.value()?.value()).toBe('60105617000101');
});

it('should initialize an instance without error', () => {
Expand Down Expand Up @@ -61,25 +61,25 @@ describe('CNPJ Value Object', () => {
it('should format a CNPJ with special characters', () => {
const valueObject =
CNPJValueObject.create('20.798.751/0001-02').value();
expect(valueObject.toPattern()).toBe('20.798.751/0001-02');
expect(valueObject?.toPattern()).toBe('20.798.751/0001-02');
});

it('should format a CNPJ with special characters', () => {
const valueObject =
CNPJValueObject.create('65.389.009/0001-81').value();
expect(valueObject.toPattern()).toBe('65.389.009/0001-81');
expect(valueObject?.toPattern()).toBe('65.389.009/0001-81');
});

it('should format a CNPJ with special characters', () => {
const valueObject =
CNPJValueObject.create('02.470.431/0001-47').value();
expect(valueObject.toPattern()).toBe('02.470.431/0001-47');
expect(valueObject?.toPattern()).toBe('02.470.431/0001-47');
});

it('should format a CNPJ with special characters and remove them later', () => {
const valueObject =
CNPJValueObject.create('62.412.404/0001-40').value();
expect(valueObject.toPattern()).toBe('62.412.404/0001-40');
expect(valueObject?.toPattern()).toBe('62.412.404/0001-40');
});
});

Expand All @@ -89,27 +89,27 @@ describe('CNPJ Value Object', () => {
const valueObject = CNPJValueObject.create(validCNPJ).value();

// Compare with invalid CNPJ
let isEqual = valueObject.compare('invalid');
let isEqual = valueObject?.compare('invalid');
expect(isEqual).toBeFalsy();

// Compare with different valid CNPJ
isEqual = valueObject.compare('22.606.062/0001-20');
isEqual = valueObject?.compare('22.606.062/0001-20');
expect(isEqual).toBeFalsy();

// Compare with the same valid CNPJ
isEqual = valueObject.compare(validCNPJ);
isEqual = valueObject?.compare(validCNPJ);
expect(isEqual).toBeTruthy();

// Compare with a valid CNPJ with different format
isEqual = valueObject.compare('22606062000155');
isEqual = valueObject?.compare('22606062000155');
expect(isEqual).toBeFalsy();

// Compare with a valid CNPJ with the same value but different format
isEqual = valueObject.compare('22606062000184');
isEqual = valueObject?.compare('22606062000184');
expect(isEqual).toBeTruthy();

// Compare with the same valid CNPJ
isEqual = valueObject.compare('22.606.062/0001-84');
isEqual = valueObject?.compare('22.606.062/0001-84');
expect(isEqual).toBeTruthy();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cnpj/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class CNPJ extends ValueObject<string> {
* @example "22398345000188"
* @summary fails if provide an invalid pattern or a cnpj with invalid digit sum
*/
public static create(value: string): Result<CNPJ> {
public static create(value: string): Result<CNPJ | null> {
const isValidValue = CNPJ.isValidProps(value);

if (!isValidValue) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cnpj/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@type-ddd/cnpj",
"description": "Library that provides TypeScript type definitions for handling CNPJ (Cadastro Nacional da Pessoa Jurídica) in Domain-Driven Design contexts. It facilitates the validation and manipulation of CNPJ numbers, ensuring they adhere to the Brazilian legal standards.",
"version": "0.0.2",
"version": "0.0.3",
"main": "index.js",
"types": "index.d.ts",
"author": "Alessandro Dev",
Expand Down Expand Up @@ -33,7 +33,7 @@
"build": "tsc"
},
"peerDependencies": {
"rich-domain": "^1.23.4"
"rich-domain": "^1.24.0"
},
"files": [
"index.js",
Expand Down
8 changes: 8 additions & 0 deletions packages/cpf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ All notable changes to this project will be documented in this file.

## Released

---

### [0.0.3] - 2024-11-28

### Fix

- update rich-domain lib to check nullish type: now 'create' return a possibly null value in Result instance.

### [0.0.2] - 2024-05-31

### Docs
Expand Down
44 changes: 22 additions & 22 deletions packages/cpf/__tests__/cpf.value-object.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,94 +9,94 @@ describe('cpf.value-object', () => {
it('should create a valid cpf with special chars and remove special chars on get value', () => {
const valueObject = CPFValueObject.create('667.324.914-58');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('66732491458');
expect(valueObject.value()?.value()).toBe('66732491458');
});

it('should create a valid cpf with special chars and remove special chars on get value', () => {
const valueObject = CPFValueObject.create('934.665.143-12');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('93466514312');
expect(valueObject.value()?.value()).toBe('93466514312');
});

it('should create a valid cpf with special chars and remove special chars on get value', () => {
const valueObject = CPFValueObject.create('690.574.738-60');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('69057473860');
expect(valueObject.value()?.value()).toBe('69057473860');
});

it('should create a valid cpf with special chars and remove special chars on get value', () => {
const valueObject = CPFValueObject.create('324.123.359-66');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('32412335966');
expect(valueObject.value()?.value()).toBe('32412335966');
});

it('should create a valid cpf with special chars and remove special chars on get value', () => {
const valueObject = CPFValueObject.create('673.761.543-02');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('67376154302');
expect(valueObject.value()?.value()).toBe('67376154302');
});

it('should create a valid cpf with special chars and remove special chars on get value', () => {
const valueObject = CPFValueObject.create('024.815.901-12');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('02481590112');
expect(valueObject.value()?.value()).toBe('02481590112');
});

it('should create a valid cpf with special chars and remove special chars on get value', () => {
const valueObject = CPFValueObject.create('754.179.880-06');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('75417988006');
expect(valueObject.value()?.value()).toBe('75417988006');
});

it('should format a cpf to add special chars', () => {
const valueObject = CPFValueObject.create('667.324.914-58').value();
expect(valueObject.toPattern()).toBe('667.324.914-58');
expect(valueObject?.toPattern()).toBe('667.324.914-58');
});

it('should format a cpf to add special chars', () => {
const valueObject = CPFValueObject.create('578.363.883-87').value();
expect(valueObject.toPattern()).toBe('578.363.883-87');
expect(valueObject?.toPattern()).toBe('578.363.883-87');
});

it('should format a cpf to add special chars', () => {
const valueObject = CPFValueObject.create('844.676.543-80').value();
expect(valueObject.toPattern()).toBe('844.676.543-80');
expect(valueObject?.toPattern()).toBe('844.676.543-80');
});

it('should format a cpf to add special chars and remove it later', () => {
const valueObject = CPFValueObject.create('667.324.914-58').value();
expect(valueObject.toPattern()).toBe('667.324.914-58');
expect(valueObject.value()).toBe('66732491458');
expect(valueObject?.toPattern()).toBe('667.324.914-58');
expect(valueObject?.value()).toBe('66732491458');
});

it('should compare value on instance and provided value', () => {
const valueObject = CPFValueObject.create('549.777.281-14').value();
let isEqual = valueObject.compare('invalid');
let isEqual = valueObject?.compare('invalid');
expect(isEqual).toBeFalsy();

isEqual = valueObject.compare('549.777.281-15');
isEqual = valueObject?.compare('549.777.281-15');
expect(isEqual).toBeFalsy();

isEqual = valueObject.compare('549.777.281-14');
isEqual = valueObject?.compare('549.777.281-14');
expect(isEqual).toBeTruthy();

isEqual = valueObject.compare('54977728314');
isEqual = valueObject?.compare('54977728314');
expect(isEqual).toBeFalsy();

isEqual = valueObject.compare('54977728114');
isEqual = valueObject?.compare('54977728114');
expect(isEqual).toBeTruthy();

isEqual = valueObject.compare('54977728114');
isEqual = valueObject?.compare('54977728114');
expect(isEqual).toBeTruthy();

isEqual = valueObject.compare('549.777.281-14');
isEqual = valueObject?.compare('549.777.281-14');
expect(isEqual).toBeTruthy();
});

it('should create a valid cpf only numbers', () => {
const valueObject = CPFValueObject.create('53534317661');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('53534317661');
expect(valueObject.value()?.value()).toBe('53534317661');
expect(CPFValueObject.isValid('53534317661')).toBeTruthy();
});

Expand All @@ -118,13 +118,13 @@ describe('cpf.value-object', () => {
it('should create a valid cpf only numbers', () => {
const valueObject = CPFValueObject.create('53534317661');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('53534317661');
expect(valueObject.value()?.value()).toBe('53534317661');
});

it('should create a valid cpf only numbers', () => {
const valueObject = CPFValueObject.create('98614591039');
expect(valueObject.isOk()).toBeTruthy();
expect(valueObject.value().value()).toBe('98614591039');
expect(valueObject.value()?.value()).toBe('98614591039');
});

it('should init an instance with success', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cpf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class CPF extends ValueObject<string> {
* @example "72725477824"
* @summary fails if provide an invalid pattern or a cpf with invalid digit sum
*/
public static create(value: string): Result<CPF> {
public static create(value: string): Result<CPF | null> {
const isValidValue = CPF.isValidProps(value);

if (!isValidValue) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cpf/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@type-ddd/cpf",
"description": "This package provides TypeScript type definitions for handling CPF (Cadastro de Pessoa Física) in Domain-Driven Design contexts",
"version": "0.0.2",
"version": "0.0.3",
"main": "index.js",
"types": "index.d.ts",
"author": "Alessandro Dev",
Expand Down Expand Up @@ -30,7 +30,7 @@
"build": "tsc"
},
"peerDependencies": {
"rich-domain": "^1.23.4"
"rich-domain": "^1.24.0"
},
"files": [
"index.js",
Expand Down
8 changes: 8 additions & 0 deletions packages/date/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ All notable changes to this project will be documented in this file.

## Released

---

### [0.0.3] - 2024-11-28

### Fix

- update rich-domain lib to check nullish type: now 'create' return a possibly null value in Result instance.

### [0.0.2] - 2024-05-31

### Docs
Expand Down
Loading