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

Parse.Cloud.define third parameter issues (Validation Handler) #6965

Closed
4 tasks done
dblythy opened this issue Oct 23, 2020 · 1 comment · Fixed by #6968
Closed
4 tasks done

Parse.Cloud.define third parameter issues (Validation Handler) #6965

dblythy opened this issue Oct 23, 2020 · 1 comment · Fixed by #6968
Labels
type:feature New feature or improvement of existing feature

Comments

@dblythy
Copy link
Member

dblythy commented Oct 23, 2020

New Issue Checklist

As discussed in the community forum, Parse.Cloud.define has a third undocumented parameter available that is a "validation" handler. A couple of issues:

-Throwing in this block returns error code 1:

it('Throw from validator', async done => {
    Parse.Cloud.define('myFunction', req => {
// cloud function
    }, req => {
// validator function
      throw 'error'
    });
    try {
      await Parse.Cloud.run('myFunction');
    } catch (e) {
      expect(e.code).toBe(Parse.Error.VALIDATION_ERROR);
// is error code 1
      done()
    }
});

-Validation functions must return 'true'

it('complete validator', async done => {
    Parse.Cloud.define('myFunction', req => {
      return 'myFunc'
    }, req => {

    });
    try {
      const result = await Parse.Cloud.run('myFunction',{});
      expect(result).toBe('myFunc');
      done()
    } catch (e) {
      // e.code: 1, e.message: undefined
      fail('should not have thrown error');
    }
  });

-Validation functions don't work with async

it('async validator', async done => {
    Parse.Cloud.define('myFunction', req => {
      return 'myFunc'
    }, async req => {
      throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'It should fail');
    });
    try {
      await Parse.Cloud.run('myFunction');
// doesn't throw an error
      fail('should have validation error')
    } catch (e) {
      expect(e.code).toBe(Parse.Error.SCRIPT_FAILED);
      expect(e.message).toBe('It should fail');
      done();
    }
});

-Validator functions are not documented, and there only seems to be one spec.

Considering these have seemingly been around since the beginning of Parse Server:

-how likely are they to be in production? (my guess is most people aren't using them, due to being undocumented)
-should we continue to support them?
-should I work on a PR for fixing the problems with them?
-should I work on a PR to the docs / SDK?

Thanks all!

@dplewis
Copy link
Member

dplewis commented Oct 23, 2020

I’m fine with add all the enhancements. We can document the breaking changes if any. I assume not a lot of users are using this feature since it’s undocumented

@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants