Skip to content

Commit

Permalink
default exports, and partial reordering to alleviate require cycles, …
Browse files Browse the repository at this point in the history
…but still have major issue with ParseObject and its require cycles
  • Loading branch information
swittk committed Oct 30, 2023
1 parent d1b2dde commit b17194c
Show file tree
Hide file tree
Showing 69 changed files with 617 additions and 562 deletions.
850 changes: 421 additions & 429 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/AnonymousUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ const AnonymousUtils = {
},
};

module.exports = AnonymousUtils;
export default AnonymousUtils;
2 changes: 1 addition & 1 deletion src/CoreManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type ParseObject from './ParseObject';
import type { AttributeMap, ObjectCache, OpsMap, State } from './ObjectStateMutations';
import type ParseFile from './ParseFile';
import type { FileSaveOptions, FileSource } from './ParseFile';
import type { Op } from './ParseOp';
import type ParseObject from './ParseObject';
import type { QueryJSON } from './ParseQuery';
import type ParseUser from './ParseUser';
import type { AuthData } from './ParseUser';
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,5 @@ const FacebookUtils = {
return provider;
},
};

module.exports = FacebookUtils;
export default FacebookUtils;
1 change: 1 addition & 0 deletions src/IndexedDBStorageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ if (typeof window !== 'undefined' && window.indexedDB) {
// IndexedDB not supported
module.exports = undefined;
}
module.exports = IndexedDBStorageController;
export default IndexedDBStorageController;
4 changes: 2 additions & 2 deletions src/LiveQueryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class LiveQueryClient {
*/
subscribe(query: ParseQuery, sessionToken?: string): LiveQuerySubscription {
if (!query) {
throw new ParseError(ParseError.INCORRECT_TYPE, 'Subscribe requires a query.')
return undefined;
}
const className = query.className;
const queryJSON = query.toJSON();
Expand Down Expand Up @@ -522,5 +522,5 @@ if (process.env.PARSE_BUILD === 'node') {
} else if (process.env.PARSE_BUILD === 'react-native') {
CoreManager.setWebSocketController(WebSocket as any);
}

module.exports = LiveQueryClient;
export default LiveQueryClient;
2 changes: 1 addition & 1 deletion src/LiveQuerySubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ class Subscription {
});
}
}

module.exports = Subscription;
export default Subscription;
13 changes: 7 additions & 6 deletions src/Parse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import decode from './decode';
import encode from './encode';
import CryptoController from './CryptoController';
import EventuallyQueue from './EventuallyQueue';
import IndexedDBStorageController from './IndexedDBStorageController';
import InstallationController from './InstallationController';
import * as ParseOp from './ParseOp';
import RESTController from './RESTController';
import ACL from './ParseACL';
import * as Analytics from './Analytics'
Expand All @@ -21,7 +18,7 @@ import GeoPoint from './ParseGeoPoint'
import Polygon from './ParsePolygon'
import Installation from './ParseInstallation'
import LocalDatastore from './LocalDatastore'
import Object from './ParseObject'
import ParseObject from './ParseObject'
import * as Push from './Push'
import Query from './ParseQuery'
import Relation from './ParseRelation'
Expand All @@ -32,6 +29,10 @@ import Storage from './Storage'
import User from './ParseUser'
import LiveQuery from './ParseLiveQuery'
import LiveQueryClient from './LiveQueryClient'
// Need to reorder these last due to them requiring ParseObject/ParseRole, etc to be defined first
import * as ParseOp from './ParseOp';
import decode from './decode';
import encode from './encode';

/**
* Contains all Parse API classes and functions.
Expand Down Expand Up @@ -63,7 +64,7 @@ interface ParseType {
Polygon: typeof Polygon,
Installation: typeof Installation,
LocalDatastore: typeof LocalDatastore,
Object: typeof Object,
Object: typeof ParseObject,
Op: {
Set: typeof ParseOp.SetOp,
Unset: typeof ParseOp.UnsetOp,
Expand Down Expand Up @@ -130,7 +131,7 @@ const Parse: ParseType = {
Polygon: Polygon,
Installation: Installation,
LocalDatastore: LocalDatastore,
Object: Object,
Object: ParseObject,
Op: {
Set: ParseOp.SetOp,
Unset: ParseOp.UnsetOp,
Expand Down
2 changes: 1 addition & 1 deletion src/ParseACL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,5 @@ class ParseACL {
this.setWriteAccess('role:' + role, allowed);
}
}

module.exports = ParseACL;
export default ParseACL;
2 changes: 1 addition & 1 deletion src/ParseCLP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,5 +603,5 @@ class ParseCLP {
this.setProtectedFields(this._getRoleName(role), fields);
}
}

module.exports = ParseCLP;
export default ParseCLP;
2 changes: 1 addition & 1 deletion src/ParseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ const DefaultController = {
};

CoreManager.setConfigController(DefaultController);

module.exports = ParseConfig;
export default ParseConfig;
1 change: 1 addition & 0 deletions src/ParseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,5 @@ class ParseError extends Error {
static X_DOMAIN_REQUEST = 602;
}

module.exports = ParseError;
export default ParseError;
3 changes: 2 additions & 1 deletion src/ParseFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,5 @@ const DefaultController = {
CoreManager.setFileController(DefaultController);

export default ParseFile;
exports.b64Digit = b64Digit;
module.exports = ParseFile;
module.exports.b64Digit = b64Digit;
1 change: 1 addition & 0 deletions src/ParseGeoPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@ class ParseGeoPoint {
}
}

module.exports = ParseGeoPoint;
export default ParseGeoPoint;
2 changes: 1 addition & 1 deletion src/ParseInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export default class Installation extends ParseObject {
}
}
}

module.exports = Installation;
ParseObject.registerSubclass('_Installation', Installation);
1 change: 1 addition & 0 deletions src/ParseLiveQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class LiveQuery {
}
}

module.exports = LiveQuery;
export default LiveQuery;

let defaultLiveQueryClient;
Expand Down
63 changes: 54 additions & 9 deletions src/ParseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import CoreManager from './CoreManager';
import canBeSerialized from './canBeSerialized';
// import canBeSerialized from './canBeSerialized';
import decode from './decode';
import encode from './encode';
import escape from './escape';
Expand Down Expand Up @@ -38,6 +38,51 @@ import type { RequestOptions, FullOptions } from './RESTController';

import uuidv4 from './uuid';

export function canBeSerialized(obj: ParseObject): boolean {
if (!(obj instanceof ParseObject)) {
return true;
}
const attributes = obj.attributes;
for (const attr in attributes) {
const val = attributes[attr];
if (!canBeSerializedHelper(val)) {
return false;
}
}
return true;
}
function canBeSerializedHelper(value: any): boolean {
if (typeof value !== 'object') {
return true;
}
if (value instanceof ParseRelation) {
return true;
}
if (value instanceof ParseObject) {
return !!value.id;
}
if (value instanceof ParseFile) {
if (value.url()) {
return true;
}
return false;
}
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
if (!canBeSerializedHelper(value[i])) {
return false;
}
}
return true;
}
for (const k in value) {
if (!canBeSerializedHelper(value[k])) {
return false;
}
}
return true;
}

export type Pointer = {
__type: string,
className: string,
Expand Down Expand Up @@ -707,15 +752,15 @@ class ParseObject {
* The only supported option is <code>error</code>.
* @returns {(ParseObject|boolean)} true if the set succeeded.
*/
set(keyOrAttributes: string | AttributeMap, valueOrOptions?: any, options?: any): ParseObject | boolean {
let changes: AttributeMap = {};
set(key: any, value?: any, options?: any): ParseObject | boolean {
// TODO: Improve types here without breaking stuff.
let changes = {};
const newOps = {};
let key: string | undefined;
if (keyOrAttributes && typeof keyOrAttributes === 'object') {
changes = keyOrAttributes;
options = valueOrOptions;
if (key && typeof key === 'object') {
changes = key;
options = value;
} else if (typeof key === 'string') {
changes[key] = valueOrOptions;
changes[key] = value;
} else {
// Key is weird; just return ourself
return this;
Expand Down Expand Up @@ -2578,5 +2623,5 @@ const DefaultController = {
};

CoreManager.setObjectController(DefaultController);

module.exports = ParseObject;
export default ParseObject;
2 changes: 1 addition & 1 deletion src/ParsePolygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@ class ParsePolygon {
return points;
}
}

module.exports = ParsePolygon;
export default ParsePolygon;
1 change: 1 addition & 0 deletions src/ParseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2162,4 +2162,5 @@ const DefaultController = {

CoreManager.setQueryController(DefaultController);

module.exports = ParseQuery;
export default ParseQuery;
4 changes: 2 additions & 2 deletions src/ParseRelation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { RelationOp } from './ParseOp';
import ParseObject from './ParseObject';
import type ParseObject from './ParseObject';
import ParseQuery from './ParseQuery';

/**
Expand Down Expand Up @@ -147,5 +147,5 @@ class ParseRelation {
return query;
}
}

module.exports = ParseRelation;
export default ParseRelation;
4 changes: 2 additions & 2 deletions src/ParseRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* @flow
*/

import ParseObject from './ParseObject';
import ParseACL from './ParseACL';
import ParseError from './ParseError';
import ParseObject from './ParseObject';

import type { AttributeMap } from './ObjectStateMutations';
import type ParseRelation from './ParseRelation';
Expand Down Expand Up @@ -142,5 +142,5 @@ class ParseRole extends ParseObject {
}

ParseObject.registerSubclass('_Role', ParseRole);

module.exports = ParseRole;
export default ParseRole;
2 changes: 1 addition & 1 deletion src/ParseSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,5 +503,5 @@ const DefaultController = {
};

CoreManager.setSchemaController(DefaultController);

module.exports = ParseSchema;
export default ParseSchema;
2 changes: 1 addition & 1 deletion src/ParseSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ const DefaultController = {
};

CoreManager.setSessionController(DefaultController);

module.exports = ParseSession;
export default ParseSession;
2 changes: 1 addition & 1 deletion src/ParseUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,5 +1291,5 @@ const DefaultController = {
};

CoreManager.setUserController(DefaultController);

module.exports = ParseUser;
export default ParseUser;
2 changes: 1 addition & 1 deletion src/__tests__/AnonymousUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const mockProvider = {
},
};

const AnonymousUtils = require('../AnonymousUtils').default;
const AnonymousUtils = require('../AnonymousUtils');

describe('AnonymousUtils', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/EventuallyQueue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jest.mock('../ParseQuery', () => {
const mockRNStorageInterface = require('./test_helpers/mockRNStorage');
const CoreManager = require('../CoreManager');
const EventuallyQueue = require('../EventuallyQueue');
const ParseError = require('../ParseError').default;
const ParseError = require('../ParseError');
const ParseObject = require('../ParseObject');
const RESTController = require('../RESTController');
const Storage = require('../Storage');
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/FacebookUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MockUser {

jest.setMock('../ParseUser', MockUser);

const FacebookUtils = require('../FacebookUtils').default;
const FacebookUtils = require('../FacebookUtils');

describe('FacebookUtils', () => {
beforeEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/LiveQueryClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jest.setMock('../LocalDatastore', mockLocalDatastore);

const CoreManager = require('../CoreManager');
const EventEmitter = require('../EventEmitter');
const LiveQueryClient = require('../LiveQueryClient').default;
const ParseObject = require('../ParseObject').default;
const ParseQuery = require('../ParseQuery').default;
const LiveQueryClient = require('../LiveQueryClient');
const ParseObject = require('../ParseObject');
const ParseQuery = require('../ParseQuery');
const { resolvingPromise } = require('../promiseUtils');
const events = require('events');

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/LocalDatastore-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
jest.autoMockOff();
jest.unmock('../LocalDatastoreUtils');

const encode = require('../encode').default;
const encode = require('../encode');

let objectCount = 0;

Expand Down Expand Up @@ -91,7 +91,7 @@ const CoreManager = require('../CoreManager');
const LocalDatastore = require('../LocalDatastore');
const ParseObject = require('../ParseObject');
const ParseQuery = require('../ParseQuery');
const ParseUser = require('../ParseUser').default;
const ParseUser = require('../ParseUser');
const LocalDatastoreController = require('../LocalDatastoreController');
const RNDatastoreController = require('../LocalDatastoreController.react-native');
const BrowserStorageController = require('../StorageController.browser');
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/OfflineQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ jest.autoMockOff();

const matchesQuery = require('../OfflineQuery').matchesQuery;
const validateQuery = require('../OfflineQuery').validateQuery;
const ParseError = require('../ParseError').default;
const ParseObject = require('../ParseObject').default;
const ParseQuery = require('../ParseQuery').default;
const ParseGeoPoint = require('../ParseGeoPoint').default;
const ParsePolygon = require('../ParsePolygon').default;
const ParseUser = require('../ParseUser').default;
const ParseError = require('../ParseError');
const ParseObject = require('../ParseObject');
const ParseQuery = require('../ParseQuery');
const ParseGeoPoint = require('../ParseGeoPoint');
const ParsePolygon = require('../ParsePolygon');
const ParseUser = require('../ParseUser');

describe('OfflineQuery', () => {
it('matches blank queries', () => {
Expand Down
Loading

0 comments on commit b17194c

Please sign in to comment.