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

feat: Allow Parse.Object pointers in Cloud Code arguments #8490

Merged
merged 8 commits into from
May 25, 2023

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Mar 30, 2023

Pull Request

Issue

In order to merge in parse-community/parse-dashboard#2409, we need a way to pass Parse Objects into cloud code. This PR allows for a Pointer to be passed through via:

Parse.Cloud.run("function", { object: obj.toPointer });

And then the pointer is accessible directly in cloud code via req.params.object. The pointer is unfetched, it's up to the developer to decide what to thereafter.

Note: obj.toPointer() has to be added for now until the JS SDK is updated to support this.

Closes: n/a

Approach

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: allow pointers in cloud code feat: Allow pointers in cloud code Mar 30, 2023
@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 30, 2023

Thanks for opening this pull request!

  • ❌ Please link an issue that describes the reason for this pull request, otherwise your pull request will be closed. Make sure to write it as Closes: #123 in the PR description, so I can recognize it.

@codecov
Copy link

codecov bot commented Mar 30, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.54 ⚠️

Comparison is base (fd6a007) 94.33% compared to head (2e7cea3) 93.79%.

❗ Current head 2e7cea3 differs from pull request most recent head a178883. Consider uploading reports for the commit a178883 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #8490      +/-   ##
==========================================
- Coverage   94.33%   93.79%   -0.54%     
==========================================
  Files         183      183              
  Lines       14574    14576       +2     
==========================================
- Hits        13748    13672      -76     
- Misses        826      904      +78     
Impacted Files Coverage Δ
src/Routers/FunctionsRouter.js 94.36% <100.00%> (+0.16%) ⬆️

... and 9 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dblythy dblythy requested a review from a team April 10, 2023 03:24
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: obj.toPointer() has to be added for now until the JS SDK is updated to support this.

  • What would the SDK have to support and how difficult would it be to add that support?
  • Is there any other use for this PR other than being a workaround? I.e. would that be removed again once the SDK supports sending Parse Objects?

@mtrezza
Copy link
Member

mtrezza commented May 21, 2023

@dblythy parse-community/parse-dashboard#2409 is a almost ready for merging. What are the limitations of the feature if this PR here is not merged, i.e. pointers are unsupported? Would the passed object just not contain pointers, or would the whole feature not work for object that contain pointers?

@dblythy
Copy link
Member Author

dblythy commented May 22, 2023

Currently the JS SDK throws an error if trying to encode a Parse Object as a parameter in Parse.Cloud.run ("Parse Objects are not allowed here").

Once this feature is merged, the JS SDK will just need to convert Parse Objects to pointers instead of throwing.

The other thought is that the Parse Object is only a pointer in cloud code and will still need to be fetched - do you think this is the right approach? Or should it be prefetched (just like req.user)

@mtrezza
Copy link
Member

mtrezza commented May 22, 2023

Currently the JS SDK throws an error

So if only parse-community/parse-dashboard#2409 is merged, then if the obj has a pointer the script invocation will fail? It's basically a non-functional feature without these PRs.

Once this feature is merged, the JS SDK will just need to convert Parse Objects to pointers instead of throwing.

So this feature requires 3 PRs in total to work, in dashboard, server and js sdk?

Note: obj.toPointer() has to be added for now until the JS SDK is updated to support this.

I still don't get this, maybe it's just the phrasing. The "for now" sounds to me as if this PR was adding a temporary workaround that will be removed later. So my question is whether we can go straight for the proper solution so we don't need a temporary one.

Or should it be prefetched

I don't see any benefit in pre-fetching. If it's needed then the developer can fetch in code (same cost), and for those who don't need it it's an unnecessary cost.

@dblythy
Copy link
Member Author

dblythy commented May 25, 2023

All this PR does is transforms a JSON representation of a pointer to a Parse.Pointer, so it can be fetched in cloud code.

The JS SDK currently does not support sending Parse Objects to Parse.Cloud.run (it says Objects not allowed).

There will need to be a PR to the JS SDK to transform Parse.Objects to the JSON representation of a pointer when using Parse.Cloud.run

@mtrezza
Copy link
Member

mtrezza commented May 25, 2023

Did we already have a definition of a JSON representation for a Parse.Pointer, or is that something you needed to invent?

@dblythy
Copy link
Member Author

dblythy commented May 25, 2023

There is already a JSON representation of a pointer:

{
      __type: 'Pointer',
      className: ...,
      objectId: ...,
}

Just passing this to cloud code currently does nothing - it stays as JSON instead of being converted to a Parse.Pointer

@mtrezza
Copy link
Member

mtrezza commented May 25, 2023

Got it, so let's merge this once the CI passes.

@mtrezza mtrezza changed the title feat: Allow pointers in cloud code feat: Allow Parse.Object pointers in Cloud Code arguments May 25, 2023
@mtrezza mtrezza changed the title feat: Allow Parse.Object pointers in Cloud Code arguments feat: Allow Parse.Object pointers in Cloud Code arguments May 25, 2023
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good!

@mtrezza mtrezza merged commit 28aeda3 into parse-community:alpha May 25, 2023
parseplatformorg pushed a commit that referenced this pull request May 27, 2023
# [6.1.0-alpha.14](6.1.0-alpha.13...6.1.0-alpha.14) (2023-05-27)

### Bug Fixes

* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.1.0-alpha.14

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label May 27, 2023
parseplatformorg pushed a commit that referenced this pull request Jun 10, 2023
# [6.3.0-beta.1](6.2.0...6.3.0-beta.1) (2023-06-10)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Jun 10, 2023
@dblythy dblythy deleted the allow-pointers branch June 11, 2023 13:29
parseplatformorg pushed a commit that referenced this pull request Jun 18, 2023
# [6.3.0-alpha.1](6.2.0...6.3.0-alpha.1) (2023-06-18)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0-alpha.1

@oallouch
Copy link
Contributor

Is this new feature in the docs ?

@mtrezza
Copy link
Member

mtrezza commented Jun 18, 2023

This will be reverted / amended, it's a breaking change. You will then find it in the API docs once it's stable released. #8634

parseplatformorg pushed a commit that referenced this pull request Sep 16, 2023
# [6.3.0](6.2.2...6.3.0) (2023-09-16)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants