Skip to content

⚡ Release v2.0.1 #624

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

Merged
merged 6 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions 2.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Upgrading Parse SDK to version 2.0.0

With Parse SDK 2.0.0, gone are the backbone style callbacks and Parse.Promises.

Instead, the Parse SDK 2.0.0 uses native promises in the browser, node and react native that allows for a more standard API.

Migrating to native Promises should be straightforward, we'll recap the different changes:

## `.done()` and `.fail()` continuations

With native promises, `.done` and `.fail` don't exist and are replaces by `.then` and `.catch`

```js
// before
const query = new Parse.Query();
query.find()
.done((results) => {

})
.fail((error) => {

});

// after
query.find()
.then((results) => {

})
.catch((error) => {

});
```

## `.always()` is replaced by `.finally()`

```js
// before
const query = new Parse.Query();
query.find()
.always((result) => {

});

// after
query.find()
.finally((result) => {

});
```

## `new Parse.Promise()`

With native promises, the constructor is different, you will need to update to the native constructor which requires moving the code around.

```js
// before
const promise = new Promise();
doSomethingAsync((error, success) => {
if (error) { promise.reject(error); }
else { promise.resolve(success); }
});
return promise;

// after
return new Promise((resolve, reject) => {
doSomethingAsync((error, success) => {
if (error) { reject(error); }
else { resolve(success); }
});
});
```

## Static methods

- `Parse.Promise.as` is replaced by `Promise.resolve`
- `Parse.Promise.error` is replaced by `Promise.reject`
- `Parse.Promise.when` is replaced by `Promise.all`

:warning: `Promise.all` only takes an array or an iterable promises.

```js
// before
Parse.Promise.when(promise1, promise2, promise3)
.then((result1, result2, result3) => {

});

// after
Promise.all([promise1, promise2, promise3])
.then(([result1, result2, result3]) => {

});
```
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Parse-SDK-JS

## 2.0.1

- Ensure we only read the job status id header if present.

## 2.0.0

- Parse.Promise has been replaced by native Promises
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ var AsyncStorage = require('react-native').AsyncStorage;
Parse.setAsyncStorage(AsyncStorage);
```

## Upgrading to Parse SDK 2.0.0

With Parse SDK 2.0.0, gone are the backbone style callbacks and Parse.Promises.

We have curated a [migration guide](2.0.0.md) that should help you migrate your code.

## License

```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parse",
"version": "2.0.0",
"version": "2.0.1",
"description": "The Parse JavaScript SDK",
"homepage": "https://www.parse.com",
"keywords": [
Expand Down
54 changes: 16 additions & 38 deletions src/CloudCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
* Defines a Cloud Function.
*
* **Available in Cloud Code only.**
* **Starting parse-server 3.0.0, all cloud hooks and functions are asynchronous**
* **All response objects are removed and replaced by promises / async/await based resolution**
*
* @method define
* @name Parse.Cloud.define
* @param {String} name The name of the Cloud Function
* @param {Function} data The Cloud Function to register. This function should take two parameters a {@link Parse.Cloud.FunctionRequest} and a {@link Parse.Cloud.FunctionResponse}
* @param {Function} data The Cloud Function to register. This function can be an async function and should take one parameter a {@link Parse.Cloud.FunctionRequest}.
*/

/**
Expand All @@ -16,19 +18,19 @@
*
* If you want to use afterDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1.
* ```
* Parse.Cloud.afterDelete('MyCustomClass', (request) => {
* Parse.Cloud.afterDelete('MyCustomClass', async (request) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

i just curios about this CloudCode. Is it work in browser now? or is your long-team plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's in the server, but that's easier to have the whole cloud code API documentation with the rest of the JS SDK, we may move it at a later point if we generate a bigger API docs for parse-server.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, i see i just confused :)

* // code here
* })
*
* Parse.Cloud.afterDelete(Parse.User, (request) => {
* Parse.Cloud.afterDelete(Parse.User, async (request) => {
* // code here
* })
*```
*
* @method afterDelete
* @name Parse.Cloud.afterDelete
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the after delete function for. This can instead be a String that is the className of the subclass.
* @param {Function} func The function to run after a delete. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
* @param {Function} func The function to run after a delete. This function can be async and should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
*/

/**
Expand All @@ -40,19 +42,19 @@
* If you want to use afterSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1.
*
* ```
* Parse.Cloud.afterSave('MyCustomClass', function(request) {
* Parse.Cloud.afterSave('MyCustomClass', async function(request) {
* // code here
* })
*
* Parse.Cloud.afterSave(Parse.User, function(request) {
* Parse.Cloud.afterSave(Parse.User, async function(request) {
* // code here
* })
* ```
*
* @method afterSave
* @name Parse.Cloud.afterSave
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the after save function for. This can instead be a String that is the className of the subclass.
* @param {Function} func The function to run after a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
* @param {Function} func The function to run after a save. This function can be an async function and should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
*/

/**
Expand All @@ -62,19 +64,19 @@
*
* If you want to use beforeDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1.
* ```
* Parse.Cloud.beforeDelete('MyCustomClass', (request, response) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it remove response in beforeDelete?
i was used it before like this:

Parse.Cloud.beforeDelete('RedBookNote', async function (request, response) {
    response.success();
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In parse-server 3.0 (the the docs update is for parse-server 3.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand this leads to a lot of confusion, I'll bring in the CLoud Code docs in parse-server instead. And just add the link here. I'll revert cloud code docs for now :)

Copy link
Contributor

Choose a reason for hiding this comment

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

goood :)

* Parse.Cloud.beforeDelete('MyCustomClass', (request) => {
* // code here
* })
*
* Parse.Cloud.beforeDelete(Parse.User, (request, response) => {
* Parse.Cloud.beforeDelete(Parse.User, (request) => {
* // code here
* })
*```
*
* @method beforeDelete
* @name Parse.Cloud.beforeDelete
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the before delete function for. This can instead be a String that is the className of the subclass.
* @param {Function} func The function to run before a delete. This function should take two parameters a {@link Parse.Cloud.TriggerRequest} and a {@link Parse.Cloud.BeforeDeleteResponse}.
* @param {Function} func The function to run before a delete. This function can be async and should take one parameter, a {@link Parse.Cloud.TriggerRequest}.
*/

/**
Expand All @@ -86,19 +88,19 @@
* If you want to use beforeSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1.
*
* ```
* Parse.Cloud.beforeSave('MyCustomClass', (request, response) => {
* Parse.Cloud.beforeSave('MyCustomClass', (request) => {
* // code here
* })
*
* Parse.Cloud.beforeSave(Parse.User, (request, response) => {
* Parse.Cloud.beforeSave(Parse.User, (request) => {
* // code here
* })
* ```
*
* @method beforeSave
* @name Parse.Cloud.beforeSave
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the after save function for. This can instead be a String that is the className of the subclass.
* @param {Function} func The function to run before a save. This function should take two parameters a {@link Parse.Cloud.TriggerRequest} and a {@link Parse.Cloud.BeforeSaveResponse}.
* @param {Function} func The function to run before a save. This function can be async and should take one parameter a {@link Parse.Cloud.TriggerRequest};
*/

/**
Expand Down Expand Up @@ -135,7 +137,7 @@
* @method job
* @name Parse.Cloud.job
* @param {String} name The name of the Background Job
* @param {Function} func The Background Job to register. This function should take two parameters a {@link Parse.Cloud.JobRequest} and a {@link Parse.Cloud.JobStatus}
* @param {Function} func The Background Job to register. This function can be async should take a single parameters a {@link Parse.Cloud.JobRequest}
*
*/

Expand Down Expand Up @@ -163,31 +165,7 @@
/**
* @typedef Parse.Cloud.JobRequest
* @property {Object} params The params passed to the background job.
*/

/**
* @typedef Parse.Cloud.JobStatus
* @property {function} error If error is called, will end the job unsuccessfully with an optional completion message to be stored in the job status.
* @property {function} message If message is called with a string argument, will update the current message to be stored in the job status.
* @property {function} success If success is called, will end the job successfullly with the optional completion message to be stored in the job status.
*/

/**
* @typedef Parse.Cloud.BeforeSaveResponse
* @property {function} success If called, will allow the save to happen. If a Parse.Object is passed in, then the passed in object will be saved instead.
* @property {function} error If called, will reject the save. An optional error message may be passed in.
*/

/**
* @typedef Parse.Cloud.BeforeDeleteResponse
* @property {function} success If called, will allow the delete to happen.
* @property {function} error If called, will reject the save. An optional error message may be passed in.
*/

/**
* @typedef Parse.Cloud.FunctionResponse
* @property {function} success If success is called, will return a successful response with the optional argument to the caller.
* @property {function} error If error is called, will return an error response with an optionally passed message.
*/

/**
Expand Down