Skip to content

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

Closed

Description

@alljinx

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

Activity

  1. mtrezza commented on Nov 18, 2020

    @mtrezza
    Member

    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.

  2. alljinx commented on Nov 18, 2020

    @alljinx
    ContributorAuthor

    Sorry, updated !

  3. dblythy commented on Nov 19, 2020

    @dblythy
    Member

    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.

  4. dblythy commented on Nov 19, 2020

    @dblythy
    Member
  5. alljinx commented on Nov 19, 2020

    @alljinx
    ContributorAuthor

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

  6. dblythy commented on Nov 19, 2020

    @dblythy
    Member

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

  7. fastrde commented on Nov 20, 2020

    @fastrde
    Contributor

    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.

  8. alljinx commented on Nov 20, 2020

    @alljinx
    ContributorAuthor

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

  9. fastrde commented on Nov 23, 2020

    @fastrde
    Contributor

    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.

  10. mtrezza commented on Nov 23, 2020

    @mtrezza
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:questionSupport or code-level question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions