Skip to content

Commit c2af191

Browse files
authored
Merge branch 'alpha' into totp-adapter
2 parents f6f3e85 + 3ec3e40 commit c2af191

File tree

7 files changed

+40
-7
lines changed

7 files changed

+40
-7
lines changed

DEPRECATIONS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
1313
| DEPPS7 | Remove file trigger syntax `Parse.Cloud.beforeSaveFile((request) => {})` | [#7966](https://github.com/parse-community/parse-server/pull/7966) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - |
1414
| DEPPS8 | Login with expired 3rd party authentication token defaults to `false` | [#7079](https://github.com/parse-community/parse-server/pull/7079) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - |
1515
| DEPPS9 | Rename LiveQuery `fields` option to `keys` | [#8389](https://github.com/parse-community/parse-server/issues/8389) | 6.0.0 (2023) | 7.0.0 (2024) | deprecated | - |
16+
| DEPPS10 | Config option `encodeParseObjectInCloudFunction` defaults to `true` | [#8634](https://github.com/parse-community/parse-server/issues/8634) | 6.2.0 (2023) | 8.0.0 (2025) | deprecated | - |
1617

1718
[i_deprecation]: ## "The version and date of the deprecation."
1819
[i_removal]: ## "The version and date of the planned removal."

spec/CloudCode.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,27 @@ describe('Cloud Code', () => {
13531353
});
13541354
});
13551355

1356+
it('should not encode Parse Objects', async () => {
1357+
const user = new Parse.User();
1358+
user.setUsername('username');
1359+
user.setPassword('password');
1360+
user.set('deleted', false);
1361+
await user.signUp();
1362+
Parse.Cloud.define(
1363+
'deleteAccount',
1364+
async req => {
1365+
expect(req.params.object instanceof Parse.Object).not.toBeTrue();
1366+
return 'Object deleted';
1367+
},
1368+
{
1369+
requireMaster: true,
1370+
}
1371+
);
1372+
await Parse.Cloud.run('deleteAccount', { object: user.toPointer() }, { useMasterKey: true });
1373+
});
1374+
13561375
it('allow cloud to encode Parse Objects', async () => {
1376+
await reconfigureServer({ encodeParseObjectInCloudFunction: true });
13571377
const user = new Parse.User();
13581378
user.setUsername('username');
13591379
user.setPassword('password');

src/Deprecator/Deprecations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
module.exports = [
1919
{ optionKey: 'allowClientClassCreation', changeNewDefault: 'false' },
2020
{ optionKey: 'allowExpiredAuthDataToken', changeNewDefault: 'false' },
21+
{ optionKey: 'encodeParseObjectInCloudFunction', changeNewDefault: 'true' },
2122
];

src/Options/Definitions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ module.exports.ParseServerOptions = {
210210
action: parsers.booleanParser,
211211
default: false,
212212
},
213+
encodeParseObjectInCloudFunction: {
214+
env: 'PARSE_SERVER_ENCODE_PARSE_OBJECT_IN_CLOUD_FUNCTION',
215+
help:
216+
'If set to `true`, a `Parse.Object` that is in the payload when calling a Cloud Function will be converted to an instance of `Parse.Object`. If `false`, the object will not be converted and instead be a plain JavaScript object, which contains the raw data of a `Parse.Object` but is not an actual instance of `Parse.Object`. Default is `false`. <br><br>\u2139\uFE0F The expected behavior would be that the object is converted to an instance of `Parse.Object`, so you would normally set this option to `true`. The default is `false` because this is a temporary option that has been introduced to avoid a breaking change when fixing a bug where JavaScript objects are not converted to actual instances of `Parse.Object`.',
217+
action: parsers.booleanParser,
218+
default: false,
219+
},
213220
encryptionKey: {
214221
env: 'PARSE_SERVER_ENCRYPTION_KEY',
215222
help: 'Key for encrypting your files',

src/Options/docs.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ export interface ParseServerOptions {
202202
cacheAdapter: ?Adapter<CacheAdapter>;
203203
/* Adapter module for email sending */
204204
emailAdapter: ?Adapter<MailAdapter>;
205+
/* If set to `true`, a `Parse.Object` that is in the payload when calling a Cloud Function will be converted to an instance of `Parse.Object`. If `false`, the object will not be converted and instead be a plain JavaScript object, which contains the raw data of a `Parse.Object` but is not an actual instance of `Parse.Object`. Default is `false`. <br><br>ℹ️ The expected behavior would be that the object is converted to an instance of `Parse.Object`, so you would normally set this option to `true`. The default is `false` because this is a temporary option that has been introduced to avoid a breaking change when fixing a bug where JavaScript objects are not converted to actual instances of `Parse.Object`.
206+
:DEFAULT: false */
207+
encodeParseObjectInCloudFunction: ?boolean;
205208
/* Public URL to your parse server with http:// or https://.
206209
:ENV: PARSE_PUBLIC_SERVER_URL */
207210
publicServerURL: ?string;

src/Routers/FunctionsRouter.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { jobStatusHandler } from '../StatusHandler';
99
import _ from 'lodash';
1010
import { logger } from '../logger';
1111

12-
function parseObject(obj) {
12+
function parseObject(obj, config) {
1313
if (Array.isArray(obj)) {
1414
return obj.map(item => {
1515
return parseObject(item);
@@ -18,21 +18,21 @@ function parseObject(obj) {
1818
return Object.assign(new Date(obj.iso), obj);
1919
} else if (obj && obj.__type == 'File') {
2020
return Parse.File.fromJSON(obj);
21-
} else if (obj && obj.__type == 'Pointer') {
21+
} else if (obj && obj.__type == 'Pointer' && config.encodeParseObjectInCloudFunction) {
2222
return Parse.Object.fromJSON({
2323
__type: 'Pointer',
2424
className: obj.className,
2525
objectId: obj.objectId,
2626
});
2727
} else if (obj && typeof obj === 'object') {
28-
return parseParams(obj);
28+
return parseParams(obj, config);
2929
} else {
3030
return obj;
3131
}
3232
}
3333

34-
function parseParams(params) {
35-
return _.mapValues(params, parseObject);
34+
function parseParams(params, config) {
35+
return _.mapValues(params, item => parseObject(item, config));
3636
}
3737

3838
export class FunctionsRouter extends PromiseRouter {
@@ -66,7 +66,7 @@ export class FunctionsRouter extends PromiseRouter {
6666
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Invalid job.');
6767
}
6868
let params = Object.assign({}, req.body, req.query);
69-
params = parseParams(params);
69+
params = parseParams(params, req.config);
7070
const request = {
7171
params: params,
7272
log: req.config.loggerController,
@@ -126,7 +126,7 @@ export class FunctionsRouter extends PromiseRouter {
126126
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, `Invalid function: "${functionName}"`);
127127
}
128128
let params = Object.assign({}, req.body, req.query);
129-
params = parseParams(params);
129+
params = parseParams(params, req.config);
130130
const request = {
131131
params: params,
132132
master: req.auth && req.auth.isMaster,

0 commit comments

Comments
 (0)