From d50284b9ecf2706d4d00e65cc631f691a11a64c9 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Mon, 6 Aug 2018 16:06:30 -0400 Subject: [PATCH 1/5] :zap: Release v2.0.1 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ea22af0d..c73589d4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index c1021854d..053e8d06a 100644 --- a/package.json +++ b/package.json @@ -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": [ From 09310b55d31d26a03e316af87aec334f4079e70e Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Mon, 6 Aug 2018 18:29:03 -0400 Subject: [PATCH 2/5] Adds documentation for async functions --- src/CloudCode.js | 54 ++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/src/CloudCode.js b/src/CloudCode.js index 4dde9026b..5e52a8cca 100644 --- a/src/CloudCode.js +++ b/src/CloudCode.js @@ -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}. */ /** @@ -16,11 +18,11 @@ * * 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) => { * // code here * }) * - * Parse.Cloud.afterDelete(Parse.User, (request) => { + * Parse.Cloud.afterDelete(Parse.User, async (request) => { * // code here * }) *``` @@ -28,7 +30,7 @@ * @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}. */ /** @@ -40,11 +42,11 @@ * 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 * }) * ``` @@ -52,7 +54,7 @@ * @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}. */ /** @@ -62,11 +64,11 @@ * * 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) => { + * Parse.Cloud.beforeDelete('MyCustomClass', (request) => { * // code here * }) * - * Parse.Cloud.beforeDelete(Parse.User, (request, response) => { + * Parse.Cloud.beforeDelete(Parse.User, (request) => { * // code here * }) *``` @@ -74,7 +76,7 @@ * @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}. */ /** @@ -86,11 +88,11 @@ * 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 * }) * ``` @@ -98,7 +100,7 @@ * @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}; */ /** @@ -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} * */ @@ -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. */ /** From a17fa615801f94b4f8449b01190c8770126d0f09 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 7 Aug 2018 12:07:30 -0400 Subject: [PATCH 3/5] Adds documentation about 2.0.0 --- 2.0.0.md | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 2.0.0.md diff --git a/2.0.0.md b/2.0.0.md new file mode 100644 index 000000000..93b773be6 --- /dev/null +++ b/2.0.0.md @@ -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]) => { + +}); +``` From c5d8d5613fc94a2818fdef54e63aa6b1ecd8ce52 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 7 Aug 2018 15:24:07 -0400 Subject: [PATCH 4/5] Adds upgrade guide --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 63ba094de..01071a03b 100644 --- a/README.md +++ b/README.md @@ -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 ``` From ea31d096b222e51eee40a0728b3c89224254191c Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Thu, 9 Aug 2018 11:46:53 -0400 Subject: [PATCH 5/5] Reverts CloudCode docs --- src/CloudCode.js | 54 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/src/CloudCode.js b/src/CloudCode.js index 5e52a8cca..4dde9026b 100644 --- a/src/CloudCode.js +++ b/src/CloudCode.js @@ -2,13 +2,11 @@ * 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 can be an async function and should take one parameter a {@link Parse.Cloud.FunctionRequest}. + * @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} */ /** @@ -18,11 +16,11 @@ * * 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', async (request) => { + * Parse.Cloud.afterDelete('MyCustomClass', (request) => { * // code here * }) * - * Parse.Cloud.afterDelete(Parse.User, async (request) => { + * Parse.Cloud.afterDelete(Parse.User, (request) => { * // code here * }) *``` @@ -30,7 +28,7 @@ * @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 can be async and should take just one parameter, {@link Parse.Cloud.TriggerRequest}. + * @param {Function} func The function to run after a delete. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}. */ /** @@ -42,11 +40,11 @@ * 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', async function(request) { + * Parse.Cloud.afterSave('MyCustomClass', function(request) { * // code here * }) * - * Parse.Cloud.afterSave(Parse.User, async function(request) { + * Parse.Cloud.afterSave(Parse.User, function(request) { * // code here * }) * ``` @@ -54,7 +52,7 @@ * @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 can be an async function and should take just one parameter, {@link Parse.Cloud.TriggerRequest}. + * @param {Function} func The function to run after a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}. */ /** @@ -64,11 +62,11 @@ * * 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) => { + * Parse.Cloud.beforeDelete('MyCustomClass', (request, response) => { * // code here * }) * - * Parse.Cloud.beforeDelete(Parse.User, (request) => { + * Parse.Cloud.beforeDelete(Parse.User, (request, response) => { * // code here * }) *``` @@ -76,7 +74,7 @@ * @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 can be async and should take one parameter, a {@link Parse.Cloud.TriggerRequest}. + * @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}. */ /** @@ -88,11 +86,11 @@ * 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) => { + * Parse.Cloud.beforeSave('MyCustomClass', (request, response) => { * // code here * }) * - * Parse.Cloud.beforeSave(Parse.User, (request) => { + * Parse.Cloud.beforeSave(Parse.User, (request, response) => { * // code here * }) * ``` @@ -100,7 +98,7 @@ * @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 can be async and should take one parameter a {@link Parse.Cloud.TriggerRequest}; + * @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}. */ /** @@ -137,7 +135,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 can be async should take a single parameters a {@link Parse.Cloud.JobRequest} + * @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} * */ @@ -165,7 +163,31 @@ /** * @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. */ /**