Skip to content

Commit f673df6

Browse files
authored
refactor: Convert helper functions to TypeScript (#2132)
1 parent 1ac1890 commit f673df6

25 files changed

+60
-98
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
- run: npm ci
2626
- name: Build Types
2727
run: npm run build:types
28-
- name: Lint Types
29-
run: npm run lint:types
3028
- name: Test Types
3129
run: npm run test:types
30+
- name: Lint Types
31+
run: npm run lint:types
3232
check-docs:
3333
name: Check Docs
3434
timeout-minutes: 5

src/CoreManager.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import type ParseConfig from './ParseConfig';
1515
import type LiveQueryClient from './LiveQueryClient';
1616
import type ParseSchema from './ParseSchema';
1717
import type ParseInstallation from './ParseInstallation';
18-
import type ParseQuery from './ParseQuery';
19-
import type * as ParseOp from './ParseOp';
20-
import type ParseRole from './ParseRole';
2118

2219
type AnalyticsController = {
2320
track: (name: string, dimensions: { [key: string]: string }) => Promise<any>,
@@ -598,43 +595,43 @@ const CoreManager = {
598595
return config['HooksController']!;
599596
},
600597

601-
setParseOp(op: typeof ParseOp) {
598+
setParseOp(op: any) {
602599
config['ParseOp'] = op;
603600
},
604601

605602
getParseOp() {
606603
return config['ParseOp']!;
607604
},
608605

609-
setParseObject(object: typeof ParseObject) {
606+
setParseObject(object: any) {
610607
config['ParseObject'] = object;
611608
},
612609

613-
getParseObject(): ParseObject {
610+
getParseObject() {
614611
return config['ParseObject']!;
615612
},
616613

617-
setParseQuery(query: typeof ParseQuery) {
614+
setParseQuery(query: any) {
618615
config['ParseQuery'] = query;
619616
},
620617

621-
getParseQuery(): ParseQuery {
618+
getParseQuery() {
622619
return config['ParseQuery']!;
623620
},
624621

625-
setParseRole(role: typeof ParseRole) {
622+
setParseRole(role: any) {
626623
config['ParseRole'] = role;
627624
},
628625

629-
getParseRole(): ParseRole {
626+
getParseRole() {
630627
return config['ParseRole']!;
631628
},
632629

633-
setParseUser(user: typeof ParseUser) {
630+
setParseUser(user: any) {
634631
config['ParseUser'] = user;
635632
},
636633

637-
getParseUser(): ParseUser {
634+
getParseUser() {
638635
return config['ParseUser']!;
639636
},
640637
};

src/ParseObject.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,7 @@ const DefaultController = {
23852385
return Promise.resolve(target);
23862386
},
23872387

2388-
save(target: ParseObject | Array<ParseObject | ParseFile>, options: RequestOptions): Promise<ParseObject | Array<ParseObject> | ParseFile> {
2388+
save(target: ParseObject | null | Array<ParseObject | ParseFile>, options: RequestOptions): Promise<ParseObject | Array<ParseObject> | ParseFile> {
23892389
const batchSize =
23902390
options && options.batchSize ? options.batchSize : CoreManager.get('REQUEST_BATCH_SIZE');
23912391
const localDatastore = CoreManager.getLocalDatastore();
@@ -2452,11 +2452,11 @@ const DefaultController = {
24522452

24532453
// Queue up tasks for each object in the batch.
24542454
// When every task is ready, the API request will execute
2455-
const batchReturned = new resolvingPromise();
2456-
const batchReady = [];
2457-
const batchTasks = [];
2455+
const batchReturned = resolvingPromise();
2456+
const batchReady: ReturnType<typeof resolvingPromise<void>>[] = [];
2457+
const batchTasks: Promise<void>[] = [];
24582458
batch.forEach((obj, index) => {
2459-
const ready = new resolvingPromise();
2459+
const ready = resolvingPromise<void>();
24602460
batchReady.push(ready);
24612461
const task = function () {
24622462
ready.resolve();

src/__tests__/escape-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
jest.autoMockOff();
22

3-
const escape = require('../escape.js').default;
3+
const escape = require('../escape').default;
44

55
describe('escape', () => {
66
it('escapes special HTML characters', () => {

src/arrayContainsObject.js renamed to src/arrayContainsObject.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @flow
3-
*/
4-
51
import CoreManager from './CoreManager';
62
import type ParseObject from './ParseObject';
73

src/canBeSerialized.js renamed to src/canBeSerialized.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @flow
3-
*/
4-
51
import CoreManager from './CoreManager';
62
import ParseFile from './ParseFile';
73
import type ParseObject from './ParseObject';

src/decode.js renamed to src/decode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/**
2-
* @flow
3-
*/
41
import CoreManager from './CoreManager';
5-
import ParseACL from './ParseACL'; // eslint-disable-line no-unused-vars
62
import ParseFile from './ParseFile';
73
import ParseGeoPoint from './ParseGeoPoint';
84
import ParsePolygon from './ParsePolygon';

src/encode.js renamed to src/encode.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @flow
3-
*/
4-
51
import CoreManager from './CoreManager';
62
import ParseACL from './ParseACL';
73
import ParseFile from './ParseFile';
@@ -10,10 +6,10 @@ import ParsePolygon from './ParsePolygon';
106
import ParseRelation from './ParseRelation';
117

128
function encode(
13-
value: mixed,
9+
value: any,
1410
disallowObjects: boolean,
1511
forcePointers: boolean,
16-
seen: Array<mixed>,
12+
seen: Array<any>,
1713
offline: boolean
1814
): any {
1915
const ParseObject = CoreManager.getParseObject();
@@ -57,7 +53,7 @@ function encode(
5753
if (isNaN(value)) {
5854
throw new Error('Tried to encode an invalid date.');
5955
}
60-
return { __type: 'Date', iso: (value: any).toJSON() };
56+
return { __type: 'Date', iso: (value as Date).toJSON() };
6157
}
6258
if (
6359
Object.prototype.toString.call(value) === '[object RegExp]' &&
@@ -84,10 +80,10 @@ function encode(
8480
}
8581

8682
export default function (
87-
value: mixed,
83+
value: any,
8884
disallowObjects?: boolean,
8985
forcePointers?: boolean,
90-
seen?: Array<mixed>,
86+
seen?: Array<any>,
9187
offline?: boolean
9288
): any {
9389
return encode(value, !!disallowObjects, !!forcePointers, seen || [], offline);

src/equals.js renamed to src/equals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ParseACL from './ParseACL';
33
import ParseFile from './ParseFile';
44
import ParseGeoPoint from './ParseGeoPoint';
55

6-
export default function equals(a, b) {
6+
export default function equals(a: any, b: any): boolean {
77
const toString = Object.prototype.toString;
88
if (toString.call(a) === '[object Date]' || toString.call(b) === '[object Date]') {
99
const dateA = new Date(a);

src/escape.js renamed to src/escape.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/*
2-
* @flow
3-
*/
4-
51
const encoded = {
62
'&': '&amp;',
73
'<': '&lt;',

0 commit comments

Comments
 (0)