Skip to content

Commit

Permalink
refactor: Convert CoreManager to TypeScript (#2118)
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis authored May 3, 2024
1 parent 8717ed6 commit 1c50c37
Show file tree
Hide file tree
Showing 9 changed files with 480 additions and 285 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Types are updated manually after every release. If a definition doesn't exist, p

#### Core Manager

The SDK has a [Core Manager](src/CoreManager.js) that handles all configurations and controllers. These modules can be swapped out for customization before you initialize the SDK. For full list of all available modules take a look at the [Core Manager Documentation](src/CoreManager.js).
The SDK has a [Core Manager](src/CoreManager.ts) that handles all configurations and controllers. These modules can be swapped out for customization before you initialize the SDK. For full list of all available modules take a look at the [Core Manager Documentation](src/CoreManager.ts).

```js
// Configuration example
Expand Down
324 changes: 203 additions & 121 deletions src/CoreManager.js → src/CoreManager.ts

Large diffs are not rendered by default.

79 changes: 41 additions & 38 deletions src/Parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 Down Expand Up @@ -50,7 +50,10 @@ interface ParseType {
Parse?: ParseType,
Analytics: typeof Analytics,
AnonymousUtils: typeof AnonymousUtils,
Cloud: typeof Cloud,
Cloud: typeof Cloud & {
/** only available in server environments */
useMasterKey?: () => void
},
CLP: typeof CLP,
CoreManager: typeof CoreManager,
Config: typeof Config,
Expand All @@ -63,7 +66,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 All @@ -81,7 +84,7 @@ interface ParseType {
Session: typeof Session,
Storage: typeof Storage,
User: typeof User,
LiveQuery: ParseLiveQuery,
LiveQuery: typeof ParseLiveQuery,
LiveQueryClient: typeof LiveQueryClient,

initialize(applicationId: string, javaScriptKey: string): void,
Expand All @@ -106,7 +109,7 @@ interface ParseType {
_ajax(...args: any[]): void,
_decode(...args: any[]): void,
_encode(...args: any[]): void,
_getInstallationId?(): string,
_getInstallationId?(): Promise<string>,
enableLocalDatastore(polling: boolean, ms: number): void,
isLocalDatastoreEnabled(): boolean,
dumpLocalDatastore(): void,
Expand All @@ -117,37 +120,37 @@ interface ParseType {
const Parse: ParseType = {
ACL: ACL,
Analytics: Analytics,
AnonymousUtils: AnonymousUtils,
AnonymousUtils: AnonymousUtils,
Cloud: Cloud,
CLP: CLP,
CoreManager: CoreManager,
Config: Config,
Error: ParseError,
CoreManager: CoreManager,
Config: Config,
Error: ParseError,
FacebookUtils: FacebookUtils,
File: File,
GeoPoint: GeoPoint,
Polygon: Polygon,
Installation: Installation,
LocalDatastore: LocalDatastore,
Object: Object,
File: File,
GeoPoint: GeoPoint,
Polygon: Polygon,
Installation: Installation,
LocalDatastore: LocalDatastore,
Object: ParseObject,
Op: {
Set: ParseOp.SetOp,
Unset: ParseOp.UnsetOp,
Increment: ParseOp.IncrementOp,
Add: ParseOp.AddOp,
Remove: ParseOp.RemoveOp,
AddUnique: ParseOp.AddUniqueOp,
Relation: ParseOp.RelationOp,
},
Push: Push,
Query: Query,
Relation: Relation,
Role: Role,
Schema: Schema,
Session: Session,
Storage: Storage,
User: User,
LiveQueryClient: LiveQueryClient,
Set: ParseOp.SetOp,
Unset: ParseOp.UnsetOp,
Increment: ParseOp.IncrementOp,
Add: ParseOp.AddOp,
Remove: ParseOp.RemoveOp,
AddUnique: ParseOp.AddUniqueOp,
Relation: ParseOp.RelationOp,
},
Push: Push,
Query: Query,
Relation: Relation,
Role: Role,
Schema: Schema,
Session: Session,
Storage: Storage,
User: User,
LiveQueryClient: LiveQueryClient,
IndexedDB: undefined,
Hooks: undefined,
Parse: undefined,
Expand Down Expand Up @@ -181,7 +184,7 @@ const Parse: ParseType = {
/* eslint-disable no-console */
console.log(
"It looks like you're using the browser version of the SDK in a " +
"node.js environment. You should require('parse/node') instead."
"node.js environment. You should require('parse/node') instead."
);
/* eslint-enable no-console */
}
Expand Down Expand Up @@ -389,7 +392,7 @@ const Parse: ParseType = {
return encode(value, disallowObjects);
},

_getInstallationId () {
_getInstallationId() {
return CoreManager.getInstallationController().currentInstallationId();
},
/**
Expand Down Expand Up @@ -418,7 +421,7 @@ const Parse: ParseType = {
* @static
* @returns {boolean}
*/
isLocalDatastoreEnabled () {
isLocalDatastoreEnabled() {
return this.LocalDatastore.isEnabled;
},
/**
Expand Down Expand Up @@ -446,7 +449,7 @@ const Parse: ParseType = {
*
* @static
*/
enableEncryptedUser () {
enableEncryptedUser() {
this.encryptedUser = true;
},

Expand All @@ -456,7 +459,7 @@ const Parse: ParseType = {
* @static
* @returns {boolean}
*/
isEncryptedUserEnabled () {
isEncryptedUserEnabled() {
return this.encryptedUser;
},
};
Expand All @@ -466,7 +469,7 @@ CoreManager.setRESTController(RESTController);

if (process.env.PARSE_BUILD === 'node') {
Parse.initialize = Parse._initialize;
Parse.Cloud = Parse.Cloud || {};
Parse.Cloud = Parse.Cloud || {} as any;
Parse.Cloud.useMasterKey = function () {
CoreManager.set('USE_MASTER_KEY', true);
};
Expand Down
4 changes: 4 additions & 0 deletions src/ParseFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ if (process.env.PARSE_BUILD === 'weapp') {
type Base64 = { base64: string };
type Uri = { uri: string };
type FileData = Array<number> | Base64 | Blob | Uri;
export type FileSaveOptions = FullOptions & {
metadata?: { [key: string]: any },
tags?: { [key: string]: any },
};
export type FileSource =
| {
format: 'file',
Expand Down
3 changes: 3 additions & 0 deletions src/ParseHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import CoreManager from './CoreManager';
import decode from './decode';
import ParseError from './ParseError';

export type HookDeclaration = { functionName: string, url: string } | { className: string, triggerName: string, url: string };
export type HookDeleteArg = { functionName: string } | { className: string, triggerName: string };

export function getFunctions() {
return CoreManager.getHooksController().get('functions');
}
Expand Down
2 changes: 1 addition & 1 deletion src/ParseSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ParseSession extends ParseObject {
options = options || {};
const controller = CoreManager.getSessionController();

const sessionOptions = {};
const sessionOptions: FullOptions = {};
if (options.hasOwnProperty('useMasterKey')) {
sessionOptions.useMasterKey = options.useMasterKey;
}
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"noImplicitAny": false,
"allowJs": false
},
"files": [
"src/Parse.ts",
"src/ParseSession.ts"
"include": [
"src/*.ts"
]
}
Loading

0 comments on commit 1c50c37

Please sign in to comment.