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

feat(field): add id field type #52

Merged
merged 6 commits into from
Dec 12, 2021
Merged

Conversation

jhomarolo
Copy link
Contributor

@jhomarolo jhomarolo commented Dec 8, 2021

Adding ID field option on metadata.

Took the liberty to add a type validation for ID fields (only Number and String), if the wrong type is sent, gotu will ignore the isID option. Hope it's consensus among all that we need something like that, but I did not implemented nothing fancy for now.

finishing pr #48

Fixes #46

Proposed Changes

  1. Adding ID field option on metadata.

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • Remember to check if code coverage decrease, if so, please implement the necessary tests

Reviewing Maintainer

  • Label as breaking if this is a large fundamental change
  • Label as either automation, bug, documentation, enhancement, infrastructure, or performance

Adding ID field option on metadata.

herbsjs#46
@codecov
Copy link

codecov bot commented Dec 8, 2021

Codecov Report

Merging #52 (d48db19) into master (91c62d1) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #52   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         4    +1     
  Lines          103       108    +5     
=========================================
+ Hits           103       108    +5     
Impacted Files Coverage Δ
src/baseEntity.js 100.00% <100.00%> (ø)
src/customTypes/id.js 100.00% <100.00%> (ø)
src/field.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91c62d1...d48db19. Read the comment docs.

@jhomarolo jhomarolo added the enhancement New feature or request label Dec 8, 2021
@jhomarolo jhomarolo requested a review from dalssoft December 8, 2021 13:11
README.md Outdated
})
```

ID Fields only accepts ```Number``` or ```String``` type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How a id typed as Date is a problem? It might not look right, but I can't see why we should constraint the type. It is a developer decision that won't impact in any way Herbs architecture.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove this in the documentation.

const { field } = require('../field')

const id = (type, options) => {
return field(type, { ...options, isId: true })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const Plan =
    entity('Plan', {
        ...
        myId: id(Number, { validation: { length: { is: 10 }  }),

Is it possible to have the above code with this implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should work fine. I've added tests with this scenario

src/field.js Outdated
this.type = type
this.options = options
this.isId = !!options.isId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be replicated?
if options.isID is true the object will have meta.options.isID and meta.isID fields. Is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should.
Because validation method inside baseEntity.js access the meta.schema not the options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to have:

if (options && options.exceptIDs && definition.options.isId) continue

?

src/field.js Outdated
this.type = type
this.options = options
this.isId = !!options.isId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to have:

if (options && options.exceptIDs && definition.options.isId) continue

?

README.md Outdated

```javascript

const instance = User()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const instance = User() should be const instance = new User()?

is this a new instance or a entity type (class)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I fixed the docs

@@ -131,5 +136,67 @@ describe('An entity', () => {
})
})

it('should set a field as ID using id module', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'should set a field as ID using id module'
what is the 'id module'?
should it be 'should set a field as ID and have valid entity'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, it was inside the old PR, but module isn't the best message for this.

@dalssoft
Copy link
Member

I think this PR is ready to merge. However, it should be merged only if the documentation on the web site is ready to merge as well.

@jhomarolo
Copy link
Contributor Author

@dalssoft ok, I'll do it

@jhomarolo jhomarolo merged commit 02e1796 into herbsjs:master Dec 12, 2021
@jhomarolo
Copy link
Contributor Author

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

jhomarolo added a commit to herbsjs/herbs that referenced this pull request Dec 12, 2021
fix buchu bug in audittrail (herbsjs/buchu#52). Add ID field feature in
gotu (herbsjs/gotu#52). Add checker isIterable in suma
(herbsjs/suma#36). Add javascriptIdentifier in suma
(herbsjs/suma#38)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ID field
2 participants