Skip to content

Commit 0347f50

Browse files
authored
Merge branch 'alpha' into ts-docs
2 parents c789c08 + e6dc1b5 commit 0347f50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+7269
-7411
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Type Definition Check
3131
run: npm run ci:typecheck
3232
- name: Test Types
33-
run: npm run test:types 2>&1 | tee silent.txt;
33+
run: npm run test:types
3434
check-docs:
3535
name: Check Docs
3636
timeout-minutes: 10

eslint.config.test.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ export default tseslint.config({
1414
'@typescript-eslint': tseslint.plugin,
1515
},
1616
rules: {
17-
'no-empty': 'off',
1817
'@typescript-eslint/no-unused-vars': 'off',
1918
'@typescript-eslint/no-unused-expressions': 'off',
20-
'@typescript-eslint/no-empty-object-type': 'off',
21-
'@typescript-eslint/ban-ts-comment': 'off',
2219
'@typescript-eslint/no-unsafe-call': 'off',
23-
'@typescript-eslint/no-unsafe-member-access': 'off',
24-
'@typescript-eslint/no-unsafe-argument': 'off',
25-
'@typescript-eslint/no-unsafe-assignment': 'off',
20+
"@typescript-eslint/no-explicit-any": "off",
21+
"@typescript-eslint/no-unsafe-return": "off",
2622
},
2723
languageOptions: {
2824
parser: tseslint.parser,

package-lock.json

Lines changed: 103 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@
8989
"puppeteer": "24.2.1",
9090
"regenerator-runtime": "0.14.1",
9191
"semantic-release": "24.2.3",
92-
"typescript-eslint": "8.25.0",
92+
"typescript-eslint": "8.26.0",
9393
"vinyl-source-stream": "2.0.0"
9494
},
9595
"optionalDependencies": {
9696
"crypto-js": "4.2.0"
9797
},
9898
"scripts": {
9999
"build": "node build_releases.js",
100-
"build:types": "tsc && prettier --write 'types/{**/*,*}.ts'",
100+
"build:types": "tsc",
101101
"ci:typecheck": "node ./ci/typecheck.js",
102102
"release": "node build_releases.js && npm publish",
103103
"test": "cross-env PARSE_BUILD=node jest",
@@ -106,11 +106,12 @@
106106
"posttest:mongodb": "mongodb-runner stop --all",
107107
"lint": "eslint --cache src/ integration/",
108108
"lint:fix": "eslint --fix --cache src/ integration/",
109-
"test:types": "eslint --cache types/tests.ts -c eslint.config.test.mjs",
109+
"test:types": "eslint types/tests.ts -c eslint.config.test.mjs",
110110
"watch": "cross-env PARSE_BUILD=${PARSE_BUILD} gulp watch",
111111
"watch:browser": "cross-env PARSE_BUILD=browser npm run watch",
112112
"watch:node": "cross-env PARSE_BUILD=node npm run watch",
113113
"watch:react-native": "cross-env PARSE_BUILD=react-native npm run watch",
114+
"watch:ts": "tsc --watch",
114115
"integration": "cross-env TESTING=1 jasmine --config=jasmine.json",
115116
"docs": "jsdoc -c ./jsdoc-conf.json ./src",
116117
"madge:circular": "madge ./src --extensions js,ts --circular",

src/AnonymousUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const AnonymousUtils = {
4444
* linked to an anonymous user.
4545
* @static
4646
*/
47-
isLinked(user: ParseUser) {
47+
isLinked(user: ParseUser): boolean {
4848
const provider = this._getAuthProvider();
4949
return user._isLinked(provider.getAuthType());
5050
},

src/Cloud.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ import type { RequestOptions } from './RESTController';
3737
* @returns {Promise} A promise that will be resolved with the result
3838
* of the function.
3939
*/
40-
export function run(name: string, data: any, options: RequestOptions): Promise<any> {
40+
export function run<T extends () => any>(
41+
name: string,
42+
data?: null,
43+
options?: RequestOptions
44+
): Promise<ReturnType<T>>;
45+
export function run<
46+
T extends (param: { [P in keyof Parameters<T>[0]]: Parameters<T>[0][P] }) => any,
47+
>(name: string, data: Parameters<T>[0], options?: RequestOptions): Promise<ReturnType<T>>;
48+
export function run(name: string, data?: any, options?: RequestOptions): Promise<any> {
4149
if (typeof name !== 'string' || name.length === 0) {
4250
throw new TypeError('Cloud function name must be a string.');
4351
}
@@ -88,7 +96,7 @@ export function getJobStatus(jobStatusId: string): Promise<ParseObject> {
8896
}
8997

9098
const DefaultController = {
91-
run(name: string, data: any, options: RequestOptions) {
99+
run(name: string, data: any, options?: RequestOptions): Promise<any> {
92100
const RESTController = CoreManager.getRESTController();
93101
const payload = encode(data, true);
94102

@@ -105,12 +113,12 @@ const DefaultController = {
105113
});
106114
},
107115

108-
getJobsData(options: RequestOptions) {
116+
getJobsData(options?: RequestOptions): Promise<any> {
109117
const RESTController = CoreManager.getRESTController();
110118
return RESTController.request('GET', 'cloud_code/jobs/data', null, options);
111119
},
112120

113-
async startJob(name: string, data: any, options: RequestOptions) {
121+
async startJob(name: string, data: any, options?: RequestOptions): Promise<string> {
114122
const RESTController = CoreManager.getRESTController();
115123

116124
const payload = encode(data, true);

src/CoreManager.ts

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ import type ParseSession from './ParseSession';
1313
import type { HookDeclaration, HookDeleteArg } from './ParseHooks';
1414
import type ParseConfig from './ParseConfig';
1515
import type LiveQueryClient from './LiveQueryClient';
16-
import type ParseSchema from './ParseSchema';
1716
import type ParseInstallation from './ParseInstallation';
1817

1918
type AnalyticsController = {
2019
track: (name: string, dimensions: { [key: string]: string }) => Promise<any>;
2120
};
2221
type CloudController = {
23-
run: (name: string, data: any, options: RequestOptions) => Promise<any>;
24-
getJobsData: (options: RequestOptions) => Promise<any>;
22+
run: (name: string, data: any, options?: RequestOptions) => Promise<any>;
23+
getJobsData: (options?: RequestOptions) => Promise<any>;
2524
/** Returns promise which resolves with JobStatusId of the job */
26-
startJob: (name: string, data: any, options: RequestOptions) => Promise<string>;
25+
startJob: (name: string, data: any, options?: RequestOptions) => Promise<string>;
2726
};
2827
type ConfigController = {
2928
current: () => Promise<ParseConfig> | ParseConfig;
@@ -56,15 +55,15 @@ type ObjectController = {
5655
fetch: (
5756
object: ParseObject | Array<ParseObject>,
5857
forceFetch: boolean,
59-
options: RequestOptions
58+
options?: RequestOptions
6059
) => Promise<Array<ParseObject | undefined> | ParseObject | undefined>;
6160
save: (
6261
object: ParseObject | Array<ParseObject | ParseFile> | null,
63-
options: RequestOptions
62+
options?: RequestOptions
6463
) => Promise<ParseObject | Array<ParseObject> | ParseFile | undefined>;
6564
destroy: (
6665
object: ParseObject | Array<ParseObject>,
67-
options: RequestOptions
66+
options?: RequestOptions
6867
) => Promise<ParseObject | Array<ParseObject>>;
6968
};
7069
type ObjectStateController = {
@@ -93,18 +92,52 @@ type QueryController = {
9392
find(
9493
className: string,
9594
params: QueryJSON,
96-
options: RequestOptions
95+
options?: RequestOptions
9796
): Promise<{ results?: Array<ParseObject>; className?: string; count?: number }>;
9897
aggregate(
9998
className: string,
10099
params: any,
101-
options: RequestOptions
100+
options?: RequestOptions
102101
): Promise<{ results?: Array<any> }>;
103102
};
104-
type EventuallyQueue = {
105-
save: (object: ParseObject, serverOptions: SaveOptions) => Promise<any>;
106-
destroy: (object: ParseObject, serverOptions: RequestOptions) => Promise<any>;
107-
poll: (ms?: number) => void;
103+
export type QueueObject = {
104+
queueId: string;
105+
action: string;
106+
object: ParseObject;
107+
serverOptions: SaveOptions | RequestOptions;
108+
id: string;
109+
className: string;
110+
hash: string;
111+
createdAt: Date;
112+
};
113+
export type Queue = Array<QueueObject>;
114+
export type EventuallyQueue = {
115+
save: (object: ParseObject, serverOptions?: SaveOptions) => Promise<void>;
116+
destroy: (object: ParseObject, serverOptions?: RequestOptions) => Promise<void>;
117+
generateQueueId: (action: string, object: ParseObject) => string;
118+
enqueue(
119+
action: string,
120+
object: ParseObject,
121+
serverOptions?: SaveOptions | RequestOptions
122+
): Promise<void>;
123+
store(data: Queue): Promise<void>;
124+
load(): Promise<string | null>;
125+
getQueue(): Promise<Queue>;
126+
setQueue(queue: Queue): Promise<void>;
127+
remove(queueId: string): Promise<void>;
128+
clear(): Promise<void>;
129+
queueItemExists(queue: Queue, queueId: string): number;
130+
length(): Promise<number>;
131+
sendQueue(): Promise<boolean>;
132+
sendQueueCallback(object: ParseObject, queueObject: QueueObject): Promise<void>;
133+
poll(ms?: number): void;
134+
stopPoll(): void;
135+
isPolling(): boolean;
136+
process: {
137+
create(ObjectType: any, queueObject: any): Promise<void>;
138+
byId(ObjectType: any, queueObject: any): Promise<void>;
139+
byHash(ObjectType: any, queueObject: any): Promise<void>;
140+
};
108141
};
109142
type RESTController = {
110143
request: (method: string, path: string, data?: any, options?: RequestOptions) => Promise<any>;
@@ -119,14 +152,14 @@ type RESTController = {
119152
};
120153
type SchemaController = {
121154
purge: (className: string) => Promise<any>;
122-
get: (className: string, options?: RequestOptions) => Promise<{ results: ParseSchema[] }>;
155+
get: (className: string, options?: RequestOptions) => Promise<any>;
123156
delete: (className: string, options?: RequestOptions) => Promise<void>;
124157
create: (className: string, params: any, options?: RequestOptions) => Promise<any>;
125158
update: (className: string, params: any, options?: RequestOptions) => Promise<any>;
126-
send(className: string, method: string, params: any, options: RequestOptions): Promise<any>;
159+
send(className: string, method: string, params: any, options?: RequestOptions): Promise<any>;
127160
};
128161
type SessionController = {
129-
getSession: (token: RequestOptions) => Promise<ParseSession>;
162+
getSession: (options?: RequestOptions) => Promise<ParseSession>;
130163
};
131164
type StorageController =
132165
| {
@@ -166,24 +199,24 @@ type UserController = {
166199
setCurrentUser: (user: ParseUser) => Promise<void>;
167200
currentUser: () => ParseUser | null;
168201
currentUserAsync: () => Promise<ParseUser | null>;
169-
signUp: (user: ParseUser, attrs: AttributeMap, options: RequestOptions) => Promise<ParseUser>;
170-
logIn: (user: ParseUser, options: RequestOptions) => Promise<ParseUser>;
202+
signUp: (user: ParseUser, attrs: AttributeMap, options?: RequestOptions) => Promise<ParseUser>;
203+
logIn: (user: ParseUser, options?: RequestOptions) => Promise<ParseUser>;
171204
loginAs: (user: ParseUser, userId: string) => Promise<ParseUser>;
172-
become: (user: ParseUser, options: RequestOptions) => Promise<ParseUser>;
205+
become: (user: ParseUser, options?: RequestOptions) => Promise<ParseUser>;
173206
hydrate: (user: ParseUser, userJSON: AttributeMap) => Promise<ParseUser>;
174-
logOut: (options: RequestOptions) => Promise<void>;
175-
me: (user: ParseUser, options: RequestOptions) => Promise<ParseUser>;
176-
requestPasswordReset: (email: string, options: RequestOptions) => Promise<void>;
207+
logOut: (options?: RequestOptions) => Promise<void>;
208+
me: (user: ParseUser, options?: RequestOptions) => Promise<ParseUser>;
209+
requestPasswordReset: (email: string, options?: RequestOptions) => Promise<void>;
177210
updateUserOnDisk: (user: ParseUser) => Promise<ParseUser>;
178-
upgradeToRevocableSession: (user: ParseUser, options: RequestOptions) => Promise<void>;
211+
upgradeToRevocableSession: (user: ParseUser, options?: RequestOptions) => Promise<void>;
179212
linkWith: (user: ParseUser, authData: AuthData, options?: FullOptions) => Promise<ParseUser>;
180213
removeUserFromDisk: () => Promise<ParseUser | void>;
181214
verifyPassword: (
182215
username: string,
183216
password: string,
184-
options: RequestOptions
217+
options?: RequestOptions
185218
) => Promise<ParseUser>;
186-
requestEmailVerification: (email: string, options: RequestOptions) => Promise<void>;
219+
requestEmailVerification: (email: string, options?: RequestOptions) => Promise<void>;
187220
};
188221
type HooksController = {
189222
get: (type: string, functionName?: string, triggerName?: string) => Promise<any>;

src/EventuallyQueue.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,12 @@ import ParseObject from './ParseObject';
44
import ParseQuery from './ParseQuery';
55
import Storage from './Storage';
66

7+
import type { Queue, QueueObject } from './CoreManager';
78
import type { SaveOptions } from './ParseObject';
89
import type { RequestOptions } from './RESTController';
910

10-
type QueueObject = {
11-
queueId: string;
12-
action: string;
13-
object: ParseObject;
14-
serverOptions: SaveOptions | RequestOptions;
15-
id: string;
16-
className: string;
17-
hash: string;
18-
createdAt: Date;
19-
};
20-
21-
type Queue = Array<QueueObject>;
22-
2311
const QUEUE_KEY = 'Parse/Eventually/Queue';
24-
let queueCache: QueueObject[] = [];
12+
let queueCache: Queue = [];
2513
let dirtyCache = true;
2614
let polling: ReturnType<typeof setInterval> | undefined = undefined;
2715

@@ -44,7 +32,7 @@ const EventuallyQueue = {
4432
* @static
4533
* @see Parse.Object#saveEventually
4634
*/
47-
save(object: ParseObject, serverOptions: SaveOptions = {}): Promise<void> {
35+
save(object: ParseObject, serverOptions?: SaveOptions): Promise<void> {
4836
return this.enqueue('save', object, serverOptions);
4937
},
5038

@@ -59,7 +47,7 @@ const EventuallyQueue = {
5947
* @static
6048
* @see Parse.Object#destroyEventually
6149
*/
62-
destroy(object: ParseObject, serverOptions: RequestOptions = {}): Promise<void> {
50+
destroy(object: ParseObject, serverOptions?: RequestOptions): Promise<void> {
6351
return this.enqueue('destroy', object, serverOptions);
6452
},
6553

@@ -92,7 +80,7 @@ const EventuallyQueue = {
9280
async enqueue(
9381
action: string,
9482
object: ParseObject,
95-
serverOptions: SaveOptions | RequestOptions
83+
serverOptions?: SaveOptions | RequestOptions
9684
): Promise<void> {
9785
const queueData = await this.getQueue();
9886
const queueId = this.generateQueueId(action, object);
@@ -112,7 +100,7 @@ const EventuallyQueue = {
112100
queueId,
113101
action,
114102
object: object.toJSON(),
115-
serverOptions,
103+
serverOptions: serverOptions || {},
116104
id: object.id,
117105
className: object.className,
118106
hash: object.get('hash'),
@@ -121,11 +109,11 @@ const EventuallyQueue = {
121109
return this.setQueue(queueData);
122110
},
123111

124-
store(data: QueueObject[]) {
112+
store(data: Queue): Promise<void> {
125113
return Storage.setItemAsync(QUEUE_KEY, JSON.stringify(data));
126114
},
127115

128-
load() {
116+
load(): Promise<string | null> {
129117
return Storage.getItemAsync(QUEUE_KEY);
130118
},
131119

@@ -134,10 +122,10 @@ const EventuallyQueue = {
134122
*
135123
* @function getQueue
136124
* @name Parse.EventuallyQueue.getQueue
137-
* @returns {Promise<QueueObject[]>}
125+
* @returns {Promise<Queue>}
138126
* @static
139127
*/
140-
async getQueue(): Promise<QueueObject[]> {
128+
async getQueue(): Promise<Queue> {
141129
if (dirtyCache) {
142130
queueCache = JSON.parse((await this.load()) || '[]');
143131
dirtyCache = false;
@@ -297,7 +285,7 @@ const EventuallyQueue = {
297285
* @param [ms] Milliseconds to ping the server. Default 2000ms
298286
* @static
299287
*/
300-
poll(ms = 2000) {
288+
poll(ms?: number): void {
301289
if (polling) {
302290
return;
303291
}
@@ -311,7 +299,7 @@ const EventuallyQueue = {
311299
}
312300
})
313301
.catch(e => e);
314-
}, ms);
302+
}, ms || 2000);
315303
},
316304

317305
/**
@@ -321,7 +309,7 @@ const EventuallyQueue = {
321309
* @name Parse.EventuallyQueue.stopPoll
322310
* @static
323311
*/
324-
stopPoll() {
312+
stopPoll(): void {
325313
clearInterval(polling);
326314
polling = undefined;
327315
},

src/FacebookUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* global FB */
22
import ParseUser from './ParseUser';
3-
import type { AuthProviderType } from './ParseUser';
3+
import type { AuthProvider } from './ParseUser';
44

55
let initialized = false;
66
let requestedPermissions;
77
let initOptions;
8-
const provider: AuthProviderType = {
8+
const provider: AuthProvider = {
99
authenticate(options) {
1010
if (typeof FB === 'undefined') {
1111
options.error(this, 'Facebook SDK not found.');
@@ -227,7 +227,7 @@ const FacebookUtils = {
227227
},
228228

229229
// Used for testing purposes
230-
_getAuthProvider() {
230+
_getAuthProvider(): AuthProvider {
231231
return provider;
232232
},
233233
};

0 commit comments

Comments
 (0)