Repository: parse-community/Parse-SDK-JS
Pull request #1539 (2022-09-02 17:52:57)

feat: add `json` option to `Parse.Query.each()`
### New Pull Request Checklist
<!--
    Check every following box [x] before submitting your PR.
    Click the "Preview" tab for better readability.
    Thanks for contributing to Parse Platform!
-->

- [x] I am not disclosing a [vulnerability](https://github.com/parse-community/parse-server/blob/master/SECURITY.md).
- [ ] I am creating this PR in reference to an [issue](https://github.com/parse-community/Parse-SDK-JS/issues?q=is%3Aissue).

### Issue Description
<!-- Add a brief description of the issue this PR solves. -->

Building upon features added in https://github.com/parse-community/Parse-SDK-JS/pull/1294

Related issue: #`FILL_THIS_OUT`

### Approach
<!-- Add a description of the approach in this PR. -->

### TODOs before merging
<!--
    Add TODOs that need to be completed before merging this PR.
    Delete TODOs that do not apply to this PR.
-->

- [x] Add tests
- [x] Add changes to documentation (guides, repository pages, in-code descriptions)


Patch:
diff --git a/src/ParseQuery.js b/src/ParseQuery.js
index fe5c6f0..9ec6a65 100644
--- a/src/ParseQuery.js
+++ b/src/ParseQuery.js
@@ -990,6 +990,9 @@ class ParseQuery {
     if (options.hasOwnProperty('context') && typeof options.context === 'object') {
       findOptions.context = options.context;
     }
+    if (options.hasOwnProperty('json')) {
+      findOptions.json = options.json;
+    }
 
     let finished = false;
     let previousResults = [];
@@ -1030,6 +1033,7 @@ class ParseQuery {
    *     be used for this request.
    *   <li>sessionToken: A valid session token, used for making a request on
    *       behalf of a specific user.
+   *   <li>json: Return raw json without converting to Parse.Object
    * </ul>
    * @returns {Promise} A promise that will be fulfilled once the
    *     iteration has completed.


Test patch:
diff --git a/integration/test/ParseQueryTest.js b/integration/test/ParseQueryTest.js
index 90f8292..b159ab5 100644
--- a/integration/test/ParseQueryTest.js
+++ b/integration/test/ParseQueryTest.js
@@ -70,6 +70,13 @@ describe('Parse Query', () => {
     assert.strictEqual(result.foo, 'bar');
     assert.strictEqual(result.className, 'TestObject');
     assert.strictEqual(result.objectId, object.id);
+
+    await query.each((obj) => {
+      assert.strictEqual(obj instanceof Parse.Object, false);
+      assert.strictEqual(obj.foo, 'bar');
+      assert.strictEqual(obj.className, 'TestObject');
+      assert.strictEqual(obj.objectId, object.id);
+    }, { json: true });
   });
 
   it('can do query with count', async () => {
diff --git a/src/__tests__/ParseQuery-test.js b/src/__tests__/ParseQuery-test.js
index 89150dc..c3d9cf0 100644
--- a/src/__tests__/ParseQuery-test.js
+++ b/src/__tests__/ParseQuery-test.js
@@ -1376,6 +1376,13 @@ describe('ParseQuery', () => {
     expect(result.size).toBe('small');
     expect(result.name).toEqual('Product 3');
     expect(result.className).toEqual('Item');
+
+    await q.each((obj) => {
+      expect(obj.objectId).toBe('I1');
+      expect(obj.size).toBe('small');
+      expect(obj.name).toEqual('Product 3');
+      expect(obj.className).toEqual('Item');
+    }, { json: true });
   });
 
   it('will error when getting a nonexistent object', done => {