Skip to content

Commit

Permalink
refactor: Convert ParseObject to TypeScript (#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis committed May 16, 2024
1 parent 3cc0aed commit 81b6944
Show file tree
Hide file tree
Showing 12 changed files with 733 additions and 709 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ jobs:
with:
version: 2
check-types:
name: Check types
name: Check Types
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci
- name: Check types
- name: Build Types
run: npm run build:types
- name: Lint Types
run: npm run lint:types
- name: Test Types
run: npm run test:types
check-docs:
name: Check Docs
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"posttest:mongodb": "mongodb-runner stop --all",
"lint": "eslint --cache src/ integration/",
"lint:fix": "eslint --fix --cache src/ integration/",
"lint:types": "dtslint types",
"watch": "cross-env PARSE_BUILD=${PARSE_BUILD} gulp watch",
"watch:browser": "cross-env PARSE_BUILD=browser npm run watch",
"watch:node": "cross-env PARSE_BUILD=node npm run watch",
Expand Down
18 changes: 9 additions & 9 deletions src/CoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type ObjectController = {
object: ParseObject | Array<ParseObject>,
forceFetch: boolean,
options: RequestOptions
) => Promise<any>,
) => Promise<Array<ParseObject | undefined> | ParseObject | undefined>,
save: (object: ParseObject | Array<ParseObject | ParseFile> | null, options: RequestOptions) => Promise<ParseObject | Array<ParseObject> | ParseFile>,
destroy: (object: ParseObject | Array<ParseObject>, options: RequestOptions) => Promise<ParseObject | Array<ParseObject>>,
};
Expand Down Expand Up @@ -86,7 +86,7 @@ type QueryController = {
type EventuallyQueue = {
save: (object: ParseObject, serverOptions: SaveOptions) => Promise<any>,
destroy: (object: ParseObject, serverOptions: RequestOptions) => Promise<any>,
poll: (ms: number) => void
poll: (ms?: number) => void
};
type RESTController = {
request: (method: string, path: string, data?: any, options?: RequestOptions) => Promise<any>,
Expand Down Expand Up @@ -598,39 +598,39 @@ const CoreManager = {
return config['HooksController']!;
},

setParseOp(op: ParseOp) {
setParseOp(op: typeof ParseOp) {
config['ParseOp'] = op;
},

getParseOp() {
return config['ParseOp']!;
},

setParseObject(object: ParseObject) {
setParseObject(object: typeof ParseObject) {
config['ParseObject'] = object;
},

getParseObject(): ParseObject {
return config['ParseObject']!;
},

setParseQuery(query: ParseQuery) {
setParseQuery(query: typeof ParseQuery) {
config['ParseQuery'] = query;
},

getParseQuery() {
return config['ParseQuery']!
getParseQuery(): ParseQuery {
return config['ParseQuery']!;
},

setParseRole(role: ParseRole) {
setParseRole(role: typeof ParseRole) {
config['ParseRole'] = role;
},

getParseRole(): ParseRole {
return config['ParseRole']!;
},

setParseUser(user: ParseUser) {
setParseUser(user: typeof ParseUser) {
config['ParseUser'] = user;
},

Expand Down
2 changes: 1 addition & 1 deletion src/EventuallyQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ const EventuallyQueue = {
* @param [ms] Milliseconds to ping the server. Default 2000ms
* @static
*/
poll(ms: number = 2000) {
poll(ms?: number = 2000) {
if (polling) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/InstallationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const InstallationController = {
installationData.className = '_Installation';
const current = ParseInstallation.fromJSON(installationData);
currentInstallationCache = current;
return current;
return current as ParseInstallation;
}
const installationId = await this.currentInstallationId();
const installation = new ParseInstallation();
Expand Down
2 changes: 1 addition & 1 deletion src/Parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ interface ParseType {
_initialize(applicationId: string, javaScriptKey: string, masterKey?: string): void,
setAsyncStorage(storage: any): void,
setLocalDatastoreController(controller: any): void,
getServerHealth(): Promise<any>
getServerHealth(): Promise<any>,

applicationId: string,
javaScriptKey: string,
Expand Down
4 changes: 2 additions & 2 deletions src/ParseInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ParseInstallation extends ParseObject {
* Parse.Installation.DEVICE_TYPES.WEB
* </pre
*
* @property {Object} DEVICE_TYPES
* @property {object} DEVICE_TYPES
* @static
*/
static get DEVICE_TYPES(): DeviceInterface {
Expand All @@ -202,7 +202,7 @@ class ParseInstallation extends ParseObject {
* @param {...any} args
* @returns {Promise}
*/
async save(...args: Array<any>): Promise<ParseInstallation> {
async save(...args: Array<any>): Promise<this> {
await super.save.apply(this, args);
await CoreManager.getInstallationController().updateInstallationOnDisk(this);
return this;
Expand Down

0 comments on commit 81b6944

Please sign in to comment.