Skip to content

Commit 2c89746

Browse files
committed
Remove coremanager and _decode
1 parent b3ea550 commit 2c89746

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

src/Auth.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LRUCache as LRU } from 'lru-cache';
77
import RestQuery from './RestQuery';
88
import RestWrite from './RestWrite';
99
import { encodeDate } from './Utils';
10+
import { loadModule } from './Adapters/AdapterLoader';
1011

1112
// An Auth object tells you who is requesting something and whether
1213
// the master key was used.
@@ -520,6 +521,7 @@ const checkIfUserHasProvidedConfiguredProvidersForLogin = (
520521

521522
// Validate each authData step-by-step and return the provider responses
522523
const handleAuthDataValidation = async (authData, req, foundUser) => {
524+
const Parse = await loadModule('parse/node.js');
523525
let user;
524526
if (foundUser) {
525527
user = Parse.User.fromJSON({ className: '_User', ...foundUser });
@@ -535,8 +537,7 @@ const handleAuthDataValidation = async (authData, req, foundUser) => {
535537
user.id = req.auth.isMaster ? req.getUserId() : req.auth.user.id;
536538
await user.fetch({ useMasterKey: true });
537539
}
538-
539-
const { updatedObject } = req.buildParseObjects();
540+
const { updatedObject } = req.buildParseObjects(Parse);
540541
const requestObject = getRequestObject(undefined, req.auth, updatedObject, user, req.config);
541542
// Perform validation as step-by-step pipeline for better error consistency
542543
// and also to avoid to trigger a provider (like OTP SMS) if another one fails

src/ClientSDK.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ function fromString(version) {
3737

3838
module.exports = {
3939
applicationId: Parse.applicationId,
40-
_decode: Parse._decode,
41-
CoreManager: Parse.CoreManager,
4240
Object: Parse.Object,
4341
Query: Parse.Query,
4442
Schema: Parse.Schema,

src/LiveQuery/QueryTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var equalObjects = require('./equalObjects');
22
var Id = require('./Id');
3-
import * as Parse from '../ClientSDK';
3+
import Parse from 'parse/node';
44
import { containsPoint, radiansTo } from '../Utils';
55
/**
66
* Query Hashes are deterministic hashes for Parse Queries.

src/RestWrite.js

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const Auth = require('./Auth');
99
const { encodeDate, checkProhibitedKeywords } = require('./Utils');
1010
var cryptoUtils = require('./cryptoUtils');
1111
var passwordCrypto = require('./password');
12-
import Parse from 'parse/node';
1312
import ParseError from './ParseError';
1413
var triggers = require('./triggers');
1514
var ClientSDK = require('./ClientSDK');
@@ -18,6 +17,7 @@ import RestQuery from './RestQuery';
1817
import _ from 'lodash';
1918
import logger from './logger';
2019
import { requiredColumns } from './Controllers/SchemaController';
20+
import { loadModule } from './Adapters/AdapterLoader';
2121

2222
// query and data are both provided in REST API format. So data
2323
// types are encoded by plain old objects.
@@ -224,7 +224,7 @@ RestWrite.prototype.validateSchema = function () {
224224

225225
// Runs any beforeSave triggers against this operation.
226226
// Any change leads to our data being mutated.
227-
RestWrite.prototype.runBeforeSaveTrigger = function () {
227+
RestWrite.prototype.runBeforeSaveTrigger = async function () {
228228
if (this.response || this.runOptions.many) {
229229
return;
230230
}
@@ -235,8 +235,8 @@ RestWrite.prototype.runBeforeSaveTrigger = function () {
235235
) {
236236
return Promise.resolve();
237237
}
238-
239-
const { originalObject, updatedObject } = this.buildParseObjects();
238+
const Parse = await loadModule('parse/node.js');
239+
const { originalObject, updatedObject } = this.buildParseObjects(Parse);
240240
const identifier = updatedObject._getStateIdentifier();
241241
const stateController = Parse.CoreManager.getObjectStateController();
242242
const [pending] = stateController.getPendingOps(identifier);
@@ -801,7 +801,7 @@ RestWrite.prototype._validateEmail = function () {
801801
{},
802802
this.validSchemaController
803803
)
804-
.then(results => {
804+
.then(async (results) => {
805805
if (results.length > 0) {
806806
throw new ParseError(
807807
ParseError.EMAIL_TAKEN,
@@ -815,7 +815,8 @@ RestWrite.prototype._validateEmail = function () {
815815
Object.keys(this.data.authData)[0] === 'anonymous')
816816
) {
817817
// We updated the email, send a new validation
818-
const { originalObject, updatedObject } = this.buildParseObjects();
818+
const Parse = await loadModule('parse/node.js');
819+
const { originalObject, updatedObject } = this.buildParseObjects(Parse);
819820
const request = {
820821
original: originalObject,
821822
object: updatedObject,
@@ -950,7 +951,8 @@ RestWrite.prototype.createSessionTokenIfNeeded = async function () {
950951
// If sign-up call
951952
if (!this.storage.authProvider) {
952953
// Create request object for verification functions
953-
const { originalObject, updatedObject } = this.buildParseObjects();
954+
const Parse = await loadModule('parse/node.js');
955+
const { originalObject, updatedObject } = this.buildParseObjects(Parse);
954956
const request = {
955957
original: originalObject,
956958
object: updatedObject,
@@ -1540,9 +1542,9 @@ RestWrite.prototype.runDatabaseOperation = function () {
15401542
false,
15411543
this.validSchemaController
15421544
)
1543-
.then(response => {
1545+
.then(async (response) => {
15441546
response.updatedAt = this.updatedAt;
1545-
this._updateResponseWithData(response, this.data);
1547+
await this._updateResponseWithData(response, this.data);
15461548
this.response = { response };
15471549
});
15481550
});
@@ -1628,14 +1630,14 @@ RestWrite.prototype.runDatabaseOperation = function () {
16281630
);
16291631
});
16301632
})
1631-
.then(response => {
1633+
.then(async (response) => {
16321634
response.objectId = this.data.objectId;
16331635
response.createdAt = this.data.createdAt;
16341636

16351637
if (this.responseShouldHaveUsername) {
16361638
response.username = this.data.username;
16371639
}
1638-
this._updateResponseWithData(response, this.data);
1640+
await this._updateResponseWithData(response, this.data);
16391641
this.response = {
16401642
status: 201,
16411643
response,
@@ -1646,7 +1648,7 @@ RestWrite.prototype.runDatabaseOperation = function () {
16461648
};
16471649

16481650
// Returns nothing - doesn't wait for the trigger.
1649-
RestWrite.prototype.runAfterSaveTrigger = function () {
1651+
RestWrite.prototype.runAfterSaveTrigger = async function () {
16501652
if (!this.response || !this.response.response || this.runOptions.many) {
16511653
return;
16521654
}
@@ -1661,8 +1663,8 @@ RestWrite.prototype.runAfterSaveTrigger = function () {
16611663
if (!hasAfterSaveHook && !hasLiveQuery) {
16621664
return Promise.resolve();
16631665
}
1664-
1665-
const { originalObject, updatedObject } = this.buildParseObjects();
1666+
const Parse = await loadModule('parse/node.js');
1667+
const { originalObject, updatedObject } = this.buildParseObjects(Parse);
16661668
updatedObject._handleSaveResponse(this.response.response, this.response.status || 200);
16671669

16681670
if (hasLiveQuery) {
@@ -1690,13 +1692,13 @@ RestWrite.prototype.runAfterSaveTrigger = function () {
16901692
this.config,
16911693
this.context
16921694
)
1693-
.then(result => {
1695+
.then(async (result) => {
16941696
const jsonReturned = result && !result._toFullJSON;
16951697
if (jsonReturned) {
16961698
this.pendingOps.operations = {};
16971699
this.response.response = result;
16981700
} else {
1699-
this.response.response = this._updateResponseWithData(
1701+
this.response.response = await this._updateResponseWithData(
17001702
(result || updatedObject).toJSON(),
17011703
this.data
17021704
);
@@ -1721,7 +1723,7 @@ RestWrite.prototype.objectId = function () {
17211723
};
17221724

17231725
// Returns a copy of the data and delete bad keys (_auth_data, _hashed_password...)
1724-
RestWrite.prototype.sanitizedData = function () {
1726+
RestWrite.prototype.sanitizedData = function (Parse) {
17251727
const data = Object.keys(this.data).reduce((data, key) => {
17261728
// Regexp comes from Parse.Object.prototype.validate
17271729
if (!/^[A-Za-z][0-9A-Za-z_]*$/.test(key)) {
@@ -1733,7 +1735,7 @@ RestWrite.prototype.sanitizedData = function () {
17331735
};
17341736

17351737
// Returns an updated copy of the object
1736-
RestWrite.prototype.buildParseObjects = function () {
1738+
RestWrite.prototype.buildParseObjects = function (Parse) {
17371739
const extraData = { className: this.className, objectId: this.query?.objectId };
17381740
let originalObject;
17391741
if (this.query && this.query.objectId) {
@@ -1772,7 +1774,7 @@ RestWrite.prototype.buildParseObjects = function () {
17721774
return data;
17731775
}, deepcopy(this.data));
17741776

1775-
const sanitized = this.sanitizedData();
1777+
const sanitized = this.sanitizedData(Parse);
17761778
for (const attribute of readOnlyAttributes) {
17771779
delete sanitized[attribute];
17781780
}
@@ -1796,13 +1798,17 @@ RestWrite.prototype.cleanUserAuthData = function () {
17961798
}
17971799
};
17981800

1799-
RestWrite.prototype._updateResponseWithData = function (response, data) {
1800-
const stateController = Parse.CoreManager.getObjectStateController();
1801-
const [pending] = stateController.getPendingOps(this.pendingOps.identifier);
1802-
for (const key in this.pendingOps.operations) {
1803-
if (!pending[key]) {
1804-
data[key] = this.originalData ? this.originalData[key] : { __op: 'Delete' };
1805-
this.storage.fieldsChangedByTrigger.push(key);
1801+
RestWrite.prototype._updateResponseWithData = async function (response, data) {
1802+
// Operations are set if beforeSave trigger is used
1803+
if (this.pendingOps.operations) {
1804+
const Parse = await loadModule('parse/node.js');
1805+
const stateController = Parse.CoreManager.getObjectStateController();
1806+
const [pending] = stateController.getPendingOps(this.pendingOps.identifier);
1807+
for (const key in this.pendingOps.operations) {
1808+
if (!pending[key]) {
1809+
data[key] = this.originalData ? this.originalData[key] : { __op: 'Delete' };
1810+
this.storage.fieldsChangedByTrigger.push(key);
1811+
}
18061812
}
18071813
}
18081814
const skipKeys = [...(requiredColumns.read[this.className] || [])];

0 commit comments

Comments
 (0)