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

Cloud functions and Typescript No argument for validationHandler in beforeSave trigger #7016

Closed
4 tasks done
alljinx opened this issue Nov 18, 2020 · 10 comments
Closed
4 tasks done
Labels
type:question Support or code-level question

Comments

@alljinx
Copy link
Contributor

alljinx commented Nov 18, 2020

New Issue Checklist

Issue Description

Hello,

I'm using Parse Server 4.4.0 and @types/parse 2.12.7 with TypeScript.
All is working as expected, thanks for your work :)

But, I'm trying to add a validation handler on a before save trigger, as described on the documentaion :
Parse.Cloud.beforeSave("Review", (request) => { // do any additional beforeSave logic here },{ fields: { stars : { required:true, options: stars => { return stars >= 1 && stars =< 5; }, error: 'Your review must be between one and five stars' } } });

But, in the index.d.ts used by Typescript, here is the declaration :
function beforeSave(arg1: any, func?: (request: BeforeSaveRequest) => Promise<void> | void): void;

And here is the JS code from your GitHub sources :
ParseCloud.beforeSave = function (parseClass, handler, validationHandler) {

As you can see, the "validationHandler" arguments for the method ParseCloud.beforeSave is missing in the declaration of the index.d.ts file. So, in Typescript, I can't add field validation like it's done in the documentation.

Am I missing somthing or is it really an issue ?

Thanks for help.

Steps to reproduce

Just install parse-server and @types/parse and use it with typescript.

Actual Outcome

In the index.d.ts :
function beforeSave(arg1: any, func?: (request: BeforeSaveRequest) => Promise<void> | void): void;

Expected Outcome

In the index.d.ts :
function beforeSave(arg1: any, func?: (request: BeforeSaveRequest) => Promise<void> | void, func?: (any) => Promise<void> | void): void;

Environment

Server

  • Parse Server version: 4.4.0
  • Parse Server @types version: 2.12.7
  • Operating system: Windows 10
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 4.2
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): JavaScriot
  • SDK version: 2.18.0

Logs

@mtrezza
Copy link
Member

mtrezza commented Nov 18, 2020

Thanks for reporting. To report an issue, please use the issue template provided when you create an issue. The template asks for essential information which helps us to investigate the issue.

@alljinx
Copy link
Contributor Author

alljinx commented Nov 18, 2020

Sorry, updated !

@dblythy
Copy link
Member

dblythy commented Nov 19, 2020

I can confidently say I have no idea how typescript works, but it seems as the issue is here, in the typescript library.

I might be wrong, but I don't know if this is an issue with Parse Server, or if the typescript definitions need to be updated in that repo.

@dblythy
Copy link
Member

dblythy commented Nov 19, 2020

See this discussion

@alljinx
Copy link
Contributor Author

alljinx commented Nov 19, 2020

OK so I will wait for the merge...
Thx !

@dblythy
Copy link
Member

dblythy commented Nov 19, 2020

I would imagine the fastest way of getting this feature on Typescript would be to submit a PR to the typescript library.

@fastrde
Copy link
Contributor

fastrde commented Nov 20, 2020

Quicktip:

(Parse.Cloud as any).beforeSave("Review", 
  (request) => { // do any additional beforeSave logic here }, { 
    fields: { 
      stars : { 
        required:true, options: stars => { return stars >= 1 && stars =< 5; }, 
        error: 'Your review must be between one and five stars' 
      } 
    } 
});

should do it. It's hacky, but works till the definition is up to date.

@alljinx
Copy link
Contributor Author

alljinx commented Nov 20, 2020

Thank you fastrde, that's exactly what I did :D

@fastrde
Copy link
Contributor

fastrde commented Nov 23, 2020

The problem is clearly an outdated definition file in the DefinitelyTyped Repository. I think this issue can be closed here. Maybe, at some point in the future, the definitions should be maintained here.

@mtrezza
Copy link
Member

mtrezza commented Nov 23, 2020

I'm closing this as it does not seem to be a Parse Server issue.

The solution seems to be to raise this issue in a 3rd part library.

Feel free to comment if you have any questions and we can re-open this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

4 participants