From 9f111158edf7fd57a65db0c4f9244b37e58cf293 Mon Sep 17 00:00:00 2001 From: dblythy Date: Sun, 30 Oct 2022 04:03:31 +1100 Subject: [PATCH] feat: add convenience access to Parse Server configuration in Cloud Code via `Parse.Server` (#8244) --- spec/CloudCode.spec.js | 10 ++++++++++ src/ParseServer.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index bf1a2c8c42..c522af0b5d 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -50,6 +50,16 @@ describe('Cloud Code', () => { }); }); + it('can get config', () => { + const config = Parse.Server; + let currentConfig = Config.get('test'); + expect(Object.keys(config)).toEqual(Object.keys(currentConfig)); + config.silent = false; + Parse.Server = config; + currentConfig = Config.get('test'); + expect(currentConfig.silent).toBeFalse(); + }); + it('show warning on duplicate cloud functions', done => { const logger = require('../lib/logger').logger; spyOn(logger, 'warn').and.callFake(() => {}); diff --git a/src/ParseServer.js b/src/ParseServer.js index e6b30d1918..df20020d6d 100644 --- a/src/ParseServer.js +++ b/src/ParseServer.js @@ -374,6 +374,16 @@ class ParseServer { function addParseCloud() { const ParseCloud = require('./cloud-code/Parse.Cloud'); + Object.defineProperty(Parse, 'Server', { + get() { + return Config.get(Parse.applicationId); + }, + set(newVal) { + newVal.appId = Parse.applicationId; + Config.put(newVal); + }, + configurable: true, + }); Object.assign(Parse.Cloud, ParseCloud); global.Parse = Parse; }