Skip to content

Commit

Permalink
Merge pull request #75 from herbsjs/beta
Browse files Browse the repository at this point in the history
Merge beta
  • Loading branch information
jhomarolo authored Nov 22, 2023
2 parents ae6be8e + 0d1e7d0 commit 968d5fb
Show file tree
Hide file tree
Showing 11 changed files with 14,242 additions and 1,670 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: CD Build

on:
push:
branches: [ master ]
branches: [ master, next, beta, alpha ]

jobs:
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

strategy:
matrix:
node-version: [14.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: CI build

on:
pull_request:
branches: [master]
branches: [ master, next, beta, alpha ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
Expand Down
15 changes: 14 additions & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"branches": "master",
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"master",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"repositoryUrl": "https://github.com/herbsjs/gotu",
"debug": "true",
"plugins": [
Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# [1.3.0-beta.5](https://github.com/herbsjs/gotu/compare/v1.3.0-beta.4...v1.3.0-beta.5) (2023-11-22)


### Bug Fixes

* 🐛 update eslint ([903f7da](https://github.com/herbsjs/gotu/commit/903f7daa6722d7166e49f99484702af90861e609))

# [1.3.0-beta.4](https://github.com/herbsjs/gotu/compare/v1.3.0-beta.3...v1.3.0-beta.4) (2023-11-22)


### Bug Fixes

* 🐛 update suma ([de458fd](https://github.com/herbsjs/gotu/commit/de458fdb4c73170469e1e5295f10789d27bff59e))

# [1.3.0-beta.3](https://github.com/herbsjs/gotu/compare/v1.3.0-beta.2...v1.3.0-beta.3) (2023-06-23)


### Bug Fixes

* **base entity:** fix bug on schema ids ([06b6f9b](https://github.com/herbsjs/gotu/commit/06b6f9b9069c26bc183eb89e392aed2e3f96ed6a))

# [1.3.0-beta.2](https://github.com/herbsjs/gotu/compare/v1.3.0-beta.1...v1.3.0-beta.2) (2023-05-07)


### Features

* **validation:** onlyIDs - validate only ID fields ([cc08622](https://github.com/herbsjs/gotu/commit/cc08622af5be87e0e643346d6e9b212352663979))
* **validation:** reference Validation - Validation option only for reference/entity types ([39faa00](https://github.com/herbsjs/gotu/commit/39faa00fceb1371dfd63cc54ce9df14304bc4bfa))

# [1.3.0-beta.1](https://github.com/herbsjs/gotu/compare/v1.2.0...v1.3.0-beta.1) (2023-03-29)


### Features

* **entity:** try Parse - a method to cast the data loaded to a entity to the correct type ([2efb440](https://github.com/herbsjs/gotu/commit/2efb44052136dd1ee6e73ef3453ccabdbf60bcd3)), closes [#29](https://github.com/herbsjs/gotu/issues/29)

# [1.2.0](https://github.com/herbsjs/gotu/compare/v1.1.3...v1.2.0) (2022-07-27)


Expand Down
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,79 @@ plan.plan.myId = '123'
plan.plan.monthlyCost = 500
plan.isValid({exceptIDs: true}) // true

plan.isValid() // false
plan.errors // { }

```


You can validate only id field validation using `isValid({onlyIDs: true})`. Example: Imagine that your entity you want to validate only the id because you should insert first the id.

```javascript

const Plan =
entity('Plan', {
...
myId: id(Number),
monthlyCost: field(Number),
})

const plan = new Plan()
plan.plan.myId = 123
plan.plan.monthlyCost = '500'
plan.isValid({onlyIDs: true}) // true

plan.isValid() // false
plan.errors // { myId: [ wrongType: 'Number' ] }

```

You can validate references too. Gotu will automatically validate subentities, however with the reference key, you can select whether you want to validate only the Ids or except the Ids

```javascript

const AnEntity1 = entity('A entity', {
id1: id(Number, { validation: { presence: true } }),
field1: field(String, { validation: { presence: true } })
})
const AnEntity2 = entity('A entity', {
id21: id(Number, { validation: { presence: true } }),
id22: id(String, { validation: { presence: true } }),
field2: field(String, { validation: { presence: true } }),
fieldEntity2: field(AnEntity1, { validation: { presence: true } }),
fieldEntities2: field([AnEntity1], { validation: { presence: true } })
})
const AnEntity3 = entity('A entity', {
id3: id(Number, { validation: { presence: true } }),
field3: field(String, { validation: { presence: true } }),
fieldEntity3: field(AnEntity2, { validation: { presence: true } })
})
const instance = AnEntity3.fromJSON({
id3: '3',
field3: undefined,
fieldEntity3: {
id21: '2',
id22: 2,
field2: 'value2',
fieldEntity2: { id1: undefined, field1: 'value1' },
fieldEntities2: [
{ id1: '1', field1: undefined },
{ id1: undefined, field1: 'value1' }]
}
})


instance.validate({ references: { onlyIDs: true } })

instance.errors /*
{ id3: [{ wrongType: 'Number' }],
field3: [{ cantBeEmpty: true }],
fieldEntity3: {
id21: [{ wrongType: 'Number' }],
id22: [{ wrongType: 'String' }],
}})}*/

```

### Custom Validation

Expand Down
Loading

0 comments on commit 968d5fb

Please sign in to comment.