Skip to content

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

Closed

Description

@dblythy

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!

Activity

  1. dplewis commented on Oct 23, 2020

    @dplewis
    Member

    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

  2. added
    type:featureNew feature or improvement of existing feature
    and removed on Dec 6, 2021
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:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions