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(pinia-orm)!: Add casts for attributes & strict types #101

Merged
merged 7 commits into from
Jul 20, 2022
Merged

Conversation

CodeDredd
Copy link
Owner

@CodeDredd CodeDredd commented Jul 19, 2022

Thoughts

It's over with auto casting ;-) .... after reading and thinking i decided to introduce strict types. So for now if you have defined a string field it will throw a console warning if the type is not correct (I will also make an option i think to throw an error instead of an warning.

But the good news....casting is coming back in form of standard and custom casts:
examples:

    class User extends Model {
      static entity = 'users'

      @Str('') name!: string

      static casts() {
        return {
          name: 'string',
        }
      }

or with decorator

    class User extends Model {
      static entity = 'users'

      @Cast('string')
      @Str('test')
        name!: string
    }

ToDos:

  • String Cast & Test
  • Boolean Cast & Test
  • Number Cast & Test
  • Array Cast & Test
  • Cast Decorator
  • Custom Casts & Test
  • Docs

Related issues: vuex-orm/vuex-orm-next#95


BREAKING CHANGES: No more auto casting. if still want to have the same behaviour you have to use casts

@CodeDredd CodeDredd self-assigned this Jul 19, 2022
@CodeDredd CodeDredd added the enhancement New feature or request label Jul 19, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #101 (ebf1321) into master (d6016ad) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head ebf1321 differs from pull request most recent head bd6e231. Consider uploading reports for the commit bd6e231 to get more accurate results

@@            Coverage Diff             @@
##           master     #101      +/-   ##
==========================================
+ Coverage   99.51%   99.52%   +0.01%     
==========================================
  Files          51       54       +3     
  Lines        4338     4456     +118     
  Branches      338      350      +12     
==========================================
+ Hits         4317     4435     +118     
  Misses         21       21              
Impacted Files Coverage Δ
packages/pinia-orm/src/model/Model.ts 100.00% <100.00%> (ø)
...ges/pinia-orm/src/model/attributes/types/String.ts 100.00% <100.00%> (ø)
...kages/pinia-orm/src/model/attributes/types/Type.ts 100.00% <100.00%> (ø)
...ackages/pinia-orm/src/model/casts/CastAttribute.ts 100.00% <100.00%> (ø)
packages/pinia-orm/src/model/casts/StringCast.ts 100.00% <100.00%> (ø)
packages/pinia-orm/src/model/decorators/Cast.ts 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 d6016ad...bd6e231. Read the comment docs.

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.

2 participants