Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Add typescript definition file #1

Open
JaneJeon opened this issue Aug 27, 2019 · 9 comments
Open

Add typescript definition file #1

JaneJeon opened this issue Aug 27, 2019 · 9 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Milestone

Comments

@JaneJeon
Copy link
Owner

No description provided.

@JaneJeon JaneJeon self-assigned this Aug 27, 2019
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.91. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@JaneJeon JaneJeon removed their assignment Sep 6, 2019
@JaneJeon JaneJeon added enhancement New feature or request good first issue Good for newcomers and removed feature_request labels Sep 11, 2019
@JaneJeon JaneJeon added this to To do in Maintenance Dec 26, 2019
@geopic
Copy link

geopic commented Jan 19, 2020

Hello, I'm looking to contribute to open-source projects by writing type declaration files, can I work on this issue?

@JaneJeon
Copy link
Owner Author

@geopic please! You're a lifesaver!

@JaneJeon JaneJeon added the help wanted Extra attention is needed label Jan 21, 2020
@geopic
Copy link

geopic commented Jan 22, 2020

Hello! I have a few queries from the Readme:

  1. Under the '@casl/ability' subheading, you have a function named acl with a number of parameters. What kind of arguments are expected from those parameters?

  2. Under the 'Options' heading, you have the options object for the objectionAuthorize function. What data type is role supposed to be for user?

Cheers, George

@geopic
Copy link

geopic commented Jan 22, 2020

Also in the options object, is undefined in the resourceAugments object always the undefined type?

@JaneJeon
Copy link
Owner Author

JaneJeon commented Jan 22, 2020

Ooh, you decided to go with the hard one? @geopic

So whereas the ACL is an instance of a class in case of role-acl, for casl, for @casl/ability, it needs to be a function taking (user, resource, action, body, opts) (and in that order as well) that returns an instance of Ability.

As for question number 2, did you mean roleFromUser? In case of role-acl it needs to take an instance of Objection Model and return a string.

As for the resourceAugments, the true/false/undefined are meant to be "constants" in the ACL namespace, so yes, they're always going to be the javascript true/false/undefined types.

And finally, perhaps the most important thing is making sure that when you call SomeModel.query(), the type points to an instance of our custom query builder (which in itself is a subclass of the base Model's QueryBuilder). It is the most important thing that led me to even create this issue in the first place, because when you're working with the ORM, you're always going to be calling SomeModel.query().blah()... and when the .query() doesn't correctly point to the model's QueryBuilder, everything that is chained to the .query() loses types which leads to a horrible development experience D:

Thankfully, the author of the main ORM managed to put in completely new typings to help with that: http://vincit.github.io/objection.js/recipes/custom-query-builder.html#extending-the-query-builder-in-typescript 🎉

@JaneJeon JaneJeon added this to the v4 milestone Jan 22, 2020
@geopic
Copy link

geopic commented Jan 22, 2020

Thanks for the info Jane, I'll ask again if I have any further questions.

Ooh, you decided to go with the hard one?

I've decided to go with both, this one first. 😉

@geopic
Copy link

geopic commented Jan 23, 2020

So whereas the ACL is an instance of a class in case of role-acl, for casl, for @casl/ability, it needs to be a function taking (user, resource, action, body, opts) (and in that order as well) that returns an instance of Ability.

What data types are those arguments?

@JaneJeon
Copy link
Owner Author

So the thing about this is that user and resource are based on whatever model classes you're using. But at a high level, I guess both are instances of a subclass of the Model class: https://github.com/Vincit/objection.js/blob/master/typings/objection/index.d.ts#L1370

action: string, body: object, and opts is an object that can technically have any argument BUT it's based on defaultOpts (https://github.com/JaneJeon/objection-authorize/blob/master/index.js#L14) and is Object.assign'd with any option you pass per query. @geopic

@JaneJeon JaneJeon moved this from To do to In progress in Maintenance Feb 4, 2020
@JaneJeon JaneJeon removed the good first issue Good for newcomers label Apr 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
No open projects
Maintenance
  
In progress
Development

Successfully merging a pull request may close this issue.

2 participants