Skip to content

Commit 1c50c37

Browse files
authored
refactor: Convert CoreManager to TypeScript (#2118)
1 parent 8717ed6 commit 1c50c37

9 files changed

+480
-285
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Types are updated manually after every release. If a definition doesn't exist, p
9292

9393
#### Core Manager
9494

95-
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).
95+
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).
9696

9797
```js
9898
// Configuration example

src/CoreManager.js renamed to src/CoreManager.ts

Lines changed: 203 additions & 121 deletions
Large diffs are not rendered by default.

src/Parse.ts

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import GeoPoint from './ParseGeoPoint'
2121
import Polygon from './ParsePolygon'
2222
import Installation from './ParseInstallation'
2323
import LocalDatastore from './LocalDatastore'
24-
import Object from './ParseObject'
24+
import ParseObject from './ParseObject';
2525
import * as Push from './Push'
2626
import Query from './ParseQuery'
2727
import Relation from './ParseRelation'
@@ -50,7 +50,10 @@ interface ParseType {
5050
Parse?: ParseType,
5151
Analytics: typeof Analytics,
5252
AnonymousUtils: typeof AnonymousUtils,
53-
Cloud: typeof Cloud,
53+
Cloud: typeof Cloud & {
54+
/** only available in server environments */
55+
useMasterKey?: () => void
56+
},
5457
CLP: typeof CLP,
5558
CoreManager: typeof CoreManager,
5659
Config: typeof Config,
@@ -63,7 +66,7 @@ interface ParseType {
6366
Polygon: typeof Polygon,
6467
Installation: typeof Installation,
6568
LocalDatastore: typeof LocalDatastore,
66-
Object: typeof Object,
69+
Object: typeof ParseObject,
6770
Op: {
6871
Set: typeof ParseOp.SetOp,
6972
Unset: typeof ParseOp.UnsetOp,
@@ -81,7 +84,7 @@ interface ParseType {
8184
Session: typeof Session,
8285
Storage: typeof Storage,
8386
User: typeof User,
84-
LiveQuery: ParseLiveQuery,
87+
LiveQuery: typeof ParseLiveQuery,
8588
LiveQueryClient: typeof LiveQueryClient,
8689

8790
initialize(applicationId: string, javaScriptKey: string): void,
@@ -106,7 +109,7 @@ interface ParseType {
106109
_ajax(...args: any[]): void,
107110
_decode(...args: any[]): void,
108111
_encode(...args: any[]): void,
109-
_getInstallationId?(): string,
112+
_getInstallationId?(): Promise<string>,
110113
enableLocalDatastore(polling: boolean, ms: number): void,
111114
isLocalDatastoreEnabled(): boolean,
112115
dumpLocalDatastore(): void,
@@ -117,37 +120,37 @@ interface ParseType {
117120
const Parse: ParseType = {
118121
ACL: ACL,
119122
Analytics: Analytics,
120-
AnonymousUtils: AnonymousUtils,
123+
AnonymousUtils: AnonymousUtils,
121124
Cloud: Cloud,
122125
CLP: CLP,
123-
CoreManager: CoreManager,
124-
Config: Config,
125-
Error: ParseError,
126+
CoreManager: CoreManager,
127+
Config: Config,
128+
Error: ParseError,
126129
FacebookUtils: FacebookUtils,
127-
File: File,
128-
GeoPoint: GeoPoint,
129-
Polygon: Polygon,
130-
Installation: Installation,
131-
LocalDatastore: LocalDatastore,
132-
Object: Object,
130+
File: File,
131+
GeoPoint: GeoPoint,
132+
Polygon: Polygon,
133+
Installation: Installation,
134+
LocalDatastore: LocalDatastore,
135+
Object: ParseObject,
133136
Op: {
134-
Set: ParseOp.SetOp,
135-
Unset: ParseOp.UnsetOp,
136-
Increment: ParseOp.IncrementOp,
137-
Add: ParseOp.AddOp,
138-
Remove: ParseOp.RemoveOp,
139-
AddUnique: ParseOp.AddUniqueOp,
140-
Relation: ParseOp.RelationOp,
141-
},
142-
Push: Push,
143-
Query: Query,
144-
Relation: Relation,
145-
Role: Role,
146-
Schema: Schema,
147-
Session: Session,
148-
Storage: Storage,
149-
User: User,
150-
LiveQueryClient: LiveQueryClient,
137+
Set: ParseOp.SetOp,
138+
Unset: ParseOp.UnsetOp,
139+
Increment: ParseOp.IncrementOp,
140+
Add: ParseOp.AddOp,
141+
Remove: ParseOp.RemoveOp,
142+
AddUnique: ParseOp.AddUniqueOp,
143+
Relation: ParseOp.RelationOp,
144+
},
145+
Push: Push,
146+
Query: Query,
147+
Relation: Relation,
148+
Role: Role,
149+
Schema: Schema,
150+
Session: Session,
151+
Storage: Storage,
152+
User: User,
153+
LiveQueryClient: LiveQueryClient,
151154
IndexedDB: undefined,
152155
Hooks: undefined,
153156
Parse: undefined,
@@ -181,7 +184,7 @@ const Parse: ParseType = {
181184
/* eslint-disable no-console */
182185
console.log(
183186
"It looks like you're using the browser version of the SDK in a " +
184-
"node.js environment. You should require('parse/node') instead."
187+
"node.js environment. You should require('parse/node') instead."
185188
);
186189
/* eslint-enable no-console */
187190
}
@@ -389,7 +392,7 @@ const Parse: ParseType = {
389392
return encode(value, disallowObjects);
390393
},
391394

392-
_getInstallationId () {
395+
_getInstallationId() {
393396
return CoreManager.getInstallationController().currentInstallationId();
394397
},
395398
/**
@@ -418,7 +421,7 @@ const Parse: ParseType = {
418421
* @static
419422
* @returns {boolean}
420423
*/
421-
isLocalDatastoreEnabled () {
424+
isLocalDatastoreEnabled() {
422425
return this.LocalDatastore.isEnabled;
423426
},
424427
/**
@@ -446,7 +449,7 @@ const Parse: ParseType = {
446449
*
447450
* @static
448451
*/
449-
enableEncryptedUser () {
452+
enableEncryptedUser() {
450453
this.encryptedUser = true;
451454
},
452455

@@ -456,7 +459,7 @@ const Parse: ParseType = {
456459
* @static
457460
* @returns {boolean}
458461
*/
459-
isEncryptedUserEnabled () {
462+
isEncryptedUserEnabled() {
460463
return this.encryptedUser;
461464
},
462465
};
@@ -466,7 +469,7 @@ CoreManager.setRESTController(RESTController);
466469

467470
if (process.env.PARSE_BUILD === 'node') {
468471
Parse.initialize = Parse._initialize;
469-
Parse.Cloud = Parse.Cloud || {};
472+
Parse.Cloud = Parse.Cloud || {} as any;
470473
Parse.Cloud.useMasterKey = function () {
471474
CoreManager.set('USE_MASTER_KEY', true);
472475
};

src/ParseFile.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ if (process.env.PARSE_BUILD === 'weapp') {
1818
type Base64 = { base64: string };
1919
type Uri = { uri: string };
2020
type FileData = Array<number> | Base64 | Blob | Uri;
21+
export type FileSaveOptions = FullOptions & {
22+
metadata?: { [key: string]: any },
23+
tags?: { [key: string]: any },
24+
};
2125
export type FileSource =
2226
| {
2327
format: 'file',

src/ParseHooks.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import CoreManager from './CoreManager';
22
import decode from './decode';
33
import ParseError from './ParseError';
44

5+
export type HookDeclaration = { functionName: string, url: string } | { className: string, triggerName: string, url: string };
6+
export type HookDeleteArg = { functionName: string } | { className: string, triggerName: string };
7+
58
export function getFunctions() {
69
return CoreManager.getHooksController().get('functions');
710
}

src/ParseSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ParseSession extends ParseObject {
5757
options = options || {};
5858
const controller = CoreManager.getSessionController();
5959

60-
const sessionOptions = {};
60+
const sessionOptions: FullOptions = {};
6161
if (options.hasOwnProperty('useMasterKey')) {
6262
sessionOptions.useMasterKey = options.useMasterKey;
6363
}

tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"noImplicitAny": false,
99
"allowJs": false
1010
},
11-
"files": [
12-
"src/Parse.ts",
13-
"src/ParseSession.ts"
11+
"include": [
12+
"src/*.ts"
1413
]
1514
}

0 commit comments

Comments
 (0)