From fbd56102518eaf2ee04ddfca66277bd943962e8a Mon Sep 17 00:00:00 2001
From: Manuel <5673677+mtrezza@users.noreply.github.com>
Date: Sun, 2 Mar 2025 03:46:13 +0100
Subject: [PATCH 01/35] docs: Remove beta badge (#2473)
---
README.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/README.md b/README.md
index d104a89f6..ec6454279 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,6 @@
[](https://github.com/parse-community/parse-dashboard/releases)
[](https://www.npmjs.com/package/parse)
-[](https://www.npmjs.com/package/parse)
[](https://www.npmjs.com/package/parse)
[][open-collective-link]
From fef72e35e51d88223be051b88dc93a81cd12d6a2 Mon Sep 17 00:00:00 2001
From: Diamond Lewis
Date: Sun, 2 Mar 2025 18:27:23 -0600
Subject: [PATCH 02/35] ci: Add type definition check (#2462)
---
.github/workflows/ci.yml | 4 ++--
ci/typecheck.js | 35 +++++++++++++++++++++++++++++++++++
package.json | 3 ++-
3 files changed, 39 insertions(+), 3 deletions(-)
create mode 100644 ci/typecheck.js
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 81c922c3b..4034be1c5 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -27,8 +27,8 @@ jobs:
with:
cache: npm
- run: npm ci
- - name: Build Types
- run: npm run build:types
+ - name: Type Definition Check
+ run: npm run ci:typecheck
- name: Test Types
run: npm run test:types 2>&1 | tee silent.txt;
check-docs:
diff --git a/ci/typecheck.js b/ci/typecheck.js
new file mode 100644
index 000000000..50fe8877d
--- /dev/null
+++ b/ci/typecheck.js
@@ -0,0 +1,35 @@
+const fs = require('fs').promises;
+const { exec } = require('child_process');
+const util = require('util');
+
+async function getTypes(files) {
+ const types = {};
+ const promise = files.map((file) => {
+ if (file.includes('.d.ts')) {
+ return fs.readFile(`./types/${file}`, 'utf8').then((content) => {
+ types[file] = content;
+ });
+ }
+ });
+ await Promise.all(promise);
+ return types;
+}
+
+(async () => {
+ const execute = util.promisify(exec);
+ const currentFiles = await fs.readdir('./types');
+ const currentTypes = await getTypes(currentFiles);
+ await execute('npm run build:types');
+ const newFiles = await fs.readdir('./types');
+ const newTypes = await getTypes(newFiles);
+ for (const file of newFiles) {
+ if (currentTypes[file] !== newTypes[file]) {
+ console.error(
+ '\x1b[31m%s\x1b[0m',
+ 'Type definitions files cannot be updated manually. Use `npm run build:types` to generate type definitions.'
+ );
+ process.exit(1);
+ }
+ }
+ process.exit(0);
+})();
diff --git a/package.json b/package.json
index 63342724b..2e5362935 100644
--- a/package.json
+++ b/package.json
@@ -97,7 +97,8 @@
},
"scripts": {
"build": "node build_releases.js",
- "build:types": "tsc && prettier --write 'types/{**/*,*}.ts' && npm run lint:fix",
+ "build:types": "tsc && prettier --write 'types/{**/*,*}.ts'",
+ "ci:typecheck": "node ./ci/typecheck.js",
"release": "node build_releases.js && npm publish",
"test": "cross-env PARSE_BUILD=node jest",
"test:mongodb": "npm run test:mongodb:runnerstart && npm run integration",
From 60c8398a8a321210c6bdfc2a5b06728f2a12b18f Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 5 Mar 2025 07:42:45 +0100
Subject: [PATCH 03/35] refactor: Bump core-js from 3.40.0 to 3.41.0 (#2478)
---
package-lock.json | 15 ++++++++-------
package.json | 2 +-
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index cd13e5179..4c6ab546e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -39,7 +39,7 @@
"babel-plugin-transform-inline-environment-variables": "0.4.4",
"browserify": "17.0.0",
"codecov": "3.8.3",
- "core-js": "3.40.0",
+ "core-js": "3.41.0",
"cross-env": "7.0.2",
"eslint": "9.21.0",
"eslint-plugin-expect-type": "0.6.2",
@@ -10614,11 +10614,12 @@
}
},
"node_modules/core-js": {
- "version": "3.40.0",
- "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.40.0.tgz",
- "integrity": "sha512-7vsMc/Lty6AGnn7uFpYT56QesI5D2Y/UkgKounk87OP9Z2H9Z8kj6jzcSGAxFmUtDOS0ntK6lbQz+Nsa0Jj6mQ==",
+ "version": "3.41.0",
+ "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.41.0.tgz",
+ "integrity": "sha512-SJ4/EHwS36QMJd6h/Rg+GyR4A5xE0FSI3eZ+iBVpfqf1x0eTSg1smWLHrA+2jQThZSh97fmSgFSU8B61nxosxA==",
"dev": true,
"hasInstallScript": true,
+ "license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
@@ -39036,9 +39037,9 @@
}
},
"core-js": {
- "version": "3.40.0",
- "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.40.0.tgz",
- "integrity": "sha512-7vsMc/Lty6AGnn7uFpYT56QesI5D2Y/UkgKounk87OP9Z2H9Z8kj6jzcSGAxFmUtDOS0ntK6lbQz+Nsa0Jj6mQ==",
+ "version": "3.41.0",
+ "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.41.0.tgz",
+ "integrity": "sha512-SJ4/EHwS36QMJd6h/Rg+GyR4A5xE0FSI3eZ+iBVpfqf1x0eTSg1smWLHrA+2jQThZSh97fmSgFSU8B61nxosxA==",
"dev": true
},
"core-js-compat": {
diff --git a/package.json b/package.json
index 2e5362935..ad1d53bbc 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,7 @@
"babel-plugin-transform-inline-environment-variables": "0.4.4",
"browserify": "17.0.0",
"codecov": "3.8.3",
- "core-js": "3.40.0",
+ "core-js": "3.41.0",
"cross-env": "7.0.2",
"eslint": "9.21.0",
"eslint-plugin-expect-type": "0.6.2",
From 08e43ba86276096820f467d9f5819e624a286b22 Mon Sep 17 00:00:00 2001
From: Diamond Lewis
Date: Wed, 5 Mar 2025 11:45:20 -0600
Subject: [PATCH 04/35] feat: Allow `Parse.Object` field names to begin with
underscore `_` to access internal fields of Parse Server (#2475)
---
integration/test/ParseObjectTest.js | 4 ++--
src/ParseObject.ts | 4 ++--
src/__tests__/ParseObject-test.js | 6 ++++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/integration/test/ParseObjectTest.js b/integration/test/ParseObjectTest.js
index 05977687c..a58de1c65 100644
--- a/integration/test/ParseObjectTest.js
+++ b/integration/test/ParseObjectTest.js
@@ -547,7 +547,7 @@ describe('Parse Object', () => {
});
it('cannot create invalid key names', async () => {
- const error = new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: "foo^bar"`);
+ const error = new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid key name: foo^bar');
const item = new Parse.Object('Item');
expect(() => {
item.set({ 'foo^bar': 'baz' });
@@ -559,7 +559,7 @@ describe('Parse Object', () => {
const item = new Parse.Object('Item');
expect(() => {
item.set({ foobar: 'baz', 'foo^bar': 'baz' });
- }).toThrow(new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: "foo^bar"`));
+ }).toThrow(new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid key name: foo^bar'));
});
it('can unset fields', done => {
diff --git a/src/ParseObject.ts b/src/ParseObject.ts
index c53930757..208e503c7 100644
--- a/src/ParseObject.ts
+++ b/src/ParseObject.ts
@@ -1099,8 +1099,8 @@ class ParseObject {
return new ParseError(ParseError.OTHER_CAUSE, 'ACL must be a Parse ACL.');
}
for (const key in attrs) {
- if (!/^[A-Za-z][0-9A-Za-z_.]*$/.test(key)) {
- return new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: "${key}"`);
+ if (!/^[A-Za-z_][0-9A-Za-z_.]*$/.test(key)) {
+ return new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: ${key}`);
}
}
return false;
diff --git a/src/__tests__/ParseObject-test.js b/src/__tests__/ParseObject-test.js
index 565b57c96..127b7a053 100644
--- a/src/__tests__/ParseObject-test.js
+++ b/src/__tests__/ParseObject-test.js
@@ -965,7 +965,7 @@ describe('ParseObject', () => {
o.validate({
'invalid!key': 12,
})
- ).toEqual(new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: "invalid!key"`));
+ ).toEqual(new ParseError(ParseError.INVALID_KEY_NAME, 'Invalid key name: invalid!key'));
expect(
o.validate({
@@ -988,7 +988,7 @@ describe('ParseObject', () => {
expect(o.set('ACL', { '*': { read: true, write: false } })).toBe(o);
expect(() => {
o.set('$$$', 'o_O');
- }).toThrow(new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: "$$$"`));
+ }).toThrow(new ParseError(ParseError.INVALID_KEY_NAME, 'Invalid key name: $$$'));
});
it('ignores validation if ignoreValidation option is passed to set()', () => {
@@ -1003,6 +1003,8 @@ describe('ParseObject', () => {
expect(o.isValid()).toBe(true);
o.set('someKey', 'someValue');
expect(o.isValid()).toBe(true);
+ o.set('_internalField', 'allow_underscore');
+ expect(o.isValid()).toBe(true);
o._finishFetch({
objectId: 'O3',
'invalid!key': 'oops',
From 539342e186abdfcf85a4bff5075f064470d265ed Mon Sep 17 00:00:00 2001
From: semantic-release-bot
Date: Wed, 5 Mar 2025 17:46:22 +0000
Subject: [PATCH 05/35] chore(release): 6.1.0-alpha.1 [skip ci]
# [6.1.0-alpha.1](https://github.com/parse-community/Parse-SDK-JS/compare/6.0.0...6.1.0-alpha.1) (2025-03-05)
### Features
* Allow `Parse.Object` field names to begin with underscore `_` to access internal fields of Parse Server ([#2475](https://github.com/parse-community/Parse-SDK-JS/issues/2475)) ([08e43ba](https://github.com/parse-community/Parse-SDK-JS/commit/08e43ba86276096820f467d9f5819e624a286b22))
---
changelogs/CHANGELOG_alpha.md | 7 +++++++
package-lock.json | 4 ++--
package.json | 2 +-
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/changelogs/CHANGELOG_alpha.md b/changelogs/CHANGELOG_alpha.md
index ecb474315..75c2bc3e6 100644
--- a/changelogs/CHANGELOG_alpha.md
+++ b/changelogs/CHANGELOG_alpha.md
@@ -1,3 +1,10 @@
+# [6.1.0-alpha.1](https://github.com/parse-community/Parse-SDK-JS/compare/6.0.0...6.1.0-alpha.1) (2025-03-05)
+
+
+### Features
+
+* Allow `Parse.Object` field names to begin with underscore `_` to access internal fields of Parse Server ([#2475](https://github.com/parse-community/Parse-SDK-JS/issues/2475)) ([08e43ba](https://github.com/parse-community/Parse-SDK-JS/commit/08e43ba86276096820f467d9f5819e624a286b22))
+
# [6.0.0-alpha.2](https://github.com/parse-community/Parse-SDK-JS/compare/6.0.0-alpha.1...6.0.0-alpha.2) (2025-02-16)
diff --git a/package-lock.json b/package-lock.json
index 4c6ab546e..6fc9d4f9a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "parse",
- "version": "6.0.0",
+ "version": "6.1.0-alpha.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "parse",
- "version": "6.0.0",
+ "version": "6.1.0-alpha.1",
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime-corejs3": "7.26.9",
diff --git a/package.json b/package.json
index ad1d53bbc..16e0ea7c2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "parse",
- "version": "6.0.0",
+ "version": "6.1.0-alpha.1",
"description": "Parse JavaScript SDK",
"homepage": "https://parseplatform.org",
"keywords": [
From 6d33b191b8aff8f9b0dd4cac0c76f2f186844d61 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 5 Mar 2025 21:34:15 +0100
Subject: [PATCH 06/35] refactor: Bump @eslint/js from 9.18.0 to 9.21.0 (#2477)
---
package-lock.json | 31 ++++++++-----------------------
package.json | 2 +-
2 files changed, 9 insertions(+), 24 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 6fc9d4f9a..dd52a2229 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -23,7 +23,7 @@
"@babel/preset-env": "7.26.9",
"@babel/preset-react": "7.26.3",
"@babel/preset-typescript": "7.26.0",
- "@eslint/js": "9.18.0",
+ "@eslint/js": "9.21.0",
"@parse/minami": "git+https://github.com/parse-community/minami#main",
"@saithodev/semantic-release-backmerge": "4.0.1",
"@semantic-release/changelog": "6.0.3",
@@ -2744,10 +2744,11 @@
}
},
"node_modules/@eslint/js": {
- "version": "9.18.0",
- "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.18.0.tgz",
- "integrity": "sha512-fK6L7rxcq6/z+AaQMtiFTkvbHkBLNlwyRxHpKawP0x3u9+NC6MQTnFW+AdpwC6gfHTW0051cokQgtTN2FqlxQA==",
+ "version": "9.21.0",
+ "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.21.0.tgz",
+ "integrity": "sha512-BqStZ3HX8Yz6LvsF5ByXYrtigrV5AXADWLAGc7PH/1SxOb7/FIYYMszZZWiUou/GB9P2lXWk2SV4d+Z8h0nknw==",
"dev": true,
+ "license": "MIT",
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
@@ -12840,16 +12841,6 @@
"url": "https://opencollective.com/eslint"
}
},
- "node_modules/eslint/node_modules/@eslint/js": {
- "version": "9.21.0",
- "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.21.0.tgz",
- "integrity": "sha512-BqStZ3HX8Yz6LvsF5ByXYrtigrV5AXADWLAGc7PH/1SxOb7/FIYYMszZZWiUou/GB9P2lXWk2SV4d+Z8h0nknw==",
- "dev": true,
- "license": "MIT",
- "engines": {
- "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
- }
- },
"node_modules/eslint/node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
@@ -33065,9 +33056,9 @@
}
},
"@eslint/js": {
- "version": "9.18.0",
- "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.18.0.tgz",
- "integrity": "sha512-fK6L7rxcq6/z+AaQMtiFTkvbHkBLNlwyRxHpKawP0x3u9+NC6MQTnFW+AdpwC6gfHTW0051cokQgtTN2FqlxQA==",
+ "version": "9.21.0",
+ "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.21.0.tgz",
+ "integrity": "sha512-BqStZ3HX8Yz6LvsF5ByXYrtigrV5AXADWLAGc7PH/1SxOb7/FIYYMszZZWiUou/GB9P2lXWk2SV4d+Z8h0nknw==",
"dev": true
},
"@eslint/object-schema": {
@@ -40693,12 +40684,6 @@
"optionator": "^0.9.3"
},
"dependencies": {
- "@eslint/js": {
- "version": "9.21.0",
- "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.21.0.tgz",
- "integrity": "sha512-BqStZ3HX8Yz6LvsF5ByXYrtigrV5AXADWLAGc7PH/1SxOb7/FIYYMszZZWiUou/GB9P2lXWk2SV4d+Z8h0nknw==",
- "dev": true
- },
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
diff --git a/package.json b/package.json
index 16e0ea7c2..6b1097145 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,7 @@
"@babel/preset-env": "7.26.9",
"@babel/preset-react": "7.26.3",
"@babel/preset-typescript": "7.26.0",
- "@eslint/js": "9.18.0",
+ "@eslint/js": "9.21.0",
"@parse/minami": "git+https://github.com/parse-community/minami#main",
"@saithodev/semantic-release-backmerge": "4.0.1",
"@semantic-release/changelog": "6.0.3",
From 539ba2a80e9b60efeb1b47501ea338f4db6a55b5 Mon Sep 17 00:00:00 2001
From: Diamond Lewis
Date: Fri, 7 Mar 2025 20:42:01 -0600
Subject: [PATCH 07/35] refactor: Add initial generic type definitions (#2485)
---
eslint.config.test.mjs | 4 +-
package.json | 2 +-
src/AnonymousUtils.ts | 2 +-
src/CoreManager.ts | 3 +-
src/FacebookUtils.ts | 6 +-
src/LiveQuerySubscription.ts | 4 +-
src/ParseACL.ts | 4 +-
src/ParseGeoPoint.ts | 2 +-
src/ParseInstallation.ts | 12 +-
src/ParseObject.ts | 129 +--
src/ParseQuery.ts | 157 ++--
src/ParseRelation.ts | 14 +-
src/ParseRole.ts | 17 +-
src/ParseSchema.ts | 43 +-
src/ParseSession.ts | 6 +-
src/ParseUser.ts | 53 +-
types/CoreManager.d.ts | 8 +-
types/FacebookUtils.d.ts | 6 +-
types/LiveQuerySubscription.d.ts | 4 +-
types/Parse.d.ts | 40 +-
types/ParseACL.d.ts | 4 +-
types/ParseGeoPoint.d.ts | 2 +-
types/ParseInstallation.d.ts | 9 +-
types/ParseObject.d.ts | 109 ++-
types/ParseQuery.d.ts | 141 ++--
types/ParseRelation.d.ts | 17 +-
types/ParseRole.d.ts | 13 +-
types/ParseSchema.d.ts | 42 +-
types/ParseSession.d.ts | 8 +-
types/ParseUser.d.ts | 55 +-
types/tests.ts | 1295 +++++++++++++++---------------
31 files changed, 1136 insertions(+), 1075 deletions(-)
diff --git a/eslint.config.test.mjs b/eslint.config.test.mjs
index 3d2977c3e..8622d69d4 100644
--- a/eslint.config.test.mjs
+++ b/eslint.config.test.mjs
@@ -14,15 +14,15 @@ export default tseslint.config({
'@typescript-eslint': tseslint.plugin,
},
rules: {
- 'no-empty': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
- '@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
+ "@typescript-eslint/no-explicit-any": "off",
+ "@typescript-eslint/no-unsafe-return": "off",
},
languageOptions: {
parser: tseslint.parser,
diff --git a/package.json b/package.json
index 6b1097145..aebffbbcd 100644
--- a/package.json
+++ b/package.json
@@ -106,7 +106,7 @@
"posttest:mongodb": "mongodb-runner stop --all",
"lint": "eslint --cache src/ integration/",
"lint:fix": "eslint --fix --cache src/ integration/",
- "test:types": "eslint --cache types/tests.ts -c eslint.config.test.mjs",
+ "test:types": "eslint types/tests.ts -c eslint.config.test.mjs",
"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",
diff --git a/src/AnonymousUtils.ts b/src/AnonymousUtils.ts
index 99584c43f..db5041e72 100644
--- a/src/AnonymousUtils.ts
+++ b/src/AnonymousUtils.ts
@@ -44,7 +44,7 @@ const AnonymousUtils = {
* linked to an anonymous user.
* @static
*/
- isLinked(user: ParseUser) {
+ isLinked(user: ParseUser): boolean {
const provider = this._getAuthProvider();
return user._isLinked(provider.getAuthType());
},
diff --git a/src/CoreManager.ts b/src/CoreManager.ts
index 4f9ccea13..c1a174248 100644
--- a/src/CoreManager.ts
+++ b/src/CoreManager.ts
@@ -13,7 +13,6 @@ import type ParseSession from './ParseSession';
import type { HookDeclaration, HookDeleteArg } from './ParseHooks';
import type ParseConfig from './ParseConfig';
import type LiveQueryClient from './LiveQueryClient';
-import type ParseSchema from './ParseSchema';
import type ParseInstallation from './ParseInstallation';
type AnalyticsController = {
@@ -119,7 +118,7 @@ type RESTController = {
};
type SchemaController = {
purge: (className: string) => Promise;
- get: (className: string, options?: RequestOptions) => Promise<{ results: ParseSchema[] }>;
+ get: (className: string, options?: RequestOptions) => Promise;
delete: (className: string, options?: RequestOptions) => Promise;
create: (className: string, params: any, options?: RequestOptions) => Promise;
update: (className: string, params: any, options?: RequestOptions) => Promise;
diff --git a/src/FacebookUtils.ts b/src/FacebookUtils.ts
index f789bd17d..b90c65b94 100644
--- a/src/FacebookUtils.ts
+++ b/src/FacebookUtils.ts
@@ -1,11 +1,11 @@
/* global FB */
import ParseUser from './ParseUser';
-import type { AuthProviderType } from './ParseUser';
+import type { AuthProvider } from './ParseUser';
let initialized = false;
let requestedPermissions;
let initOptions;
-const provider: AuthProviderType = {
+const provider: AuthProvider = {
authenticate(options) {
if (typeof FB === 'undefined') {
options.error(this, 'Facebook SDK not found.');
@@ -227,7 +227,7 @@ const FacebookUtils = {
},
// Used for testing purposes
- _getAuthProvider() {
+ _getAuthProvider(): AuthProvider {
return provider;
},
};
diff --git a/src/LiveQuerySubscription.ts b/src/LiveQuerySubscription.ts
index 6b4c8a0c1..c20232a30 100644
--- a/src/LiveQuerySubscription.ts
+++ b/src/LiveQuerySubscription.ts
@@ -84,7 +84,7 @@ import type ParseQuery from './ParseQuery';
*
* });
*/
-class Subscription {
+class LiveQuerySubscription {
id: string | number;
query: ParseQuery;
sessionToken?: string;
@@ -131,4 +131,4 @@ class Subscription {
}
}
-export default Subscription;
+export default LiveQuerySubscription;
diff --git a/src/ParseACL.ts b/src/ParseACL.ts
index aab488941..5e07772fa 100644
--- a/src/ParseACL.ts
+++ b/src/ParseACL.ts
@@ -25,9 +25,9 @@ class ParseACL {
permissionsById: ByIdMap;
/**
- * @param {(Parse.User | object)} arg1 The user to initialize the ACL for
+ * @param {(Parse.User | object | null)} arg1 The user to initialize the ACL for
*/
- constructor(arg1: ParseUser | ByIdMap) {
+ constructor(arg1?: ParseUser | ByIdMap | null) {
this.permissionsById = {};
if (arg1 && typeof arg1 === 'object') {
const ParseUser = CoreManager.getParseUser();
diff --git a/src/ParseGeoPoint.ts b/src/ParseGeoPoint.ts
index 979abb693..2b18b991a 100644
--- a/src/ParseGeoPoint.ts
+++ b/src/ParseGeoPoint.ts
@@ -31,7 +31,7 @@ class ParseGeoPoint {
* @param {number} arg2 The longitude of the GeoPoint
*/
constructor(
- arg1: Array | { latitude: number; longitude: number } | number,
+ arg1?: Array | { latitude: number; longitude: number } | number,
arg2?: number
) {
if (Array.isArray(arg1)) {
diff --git a/src/ParseInstallation.ts b/src/ParseInstallation.ts
index 465d59175..ef87e95f7 100644
--- a/src/ParseInstallation.ts
+++ b/src/ParseInstallation.ts
@@ -1,8 +1,6 @@
import CoreManager from './CoreManager';
import ParseError from './ParseError';
-import ParseObject from './ParseObject';
-
-import type { AttributeMap } from './ObjectStateMutations';
+import ParseObject, { Attributes } from './ParseObject';
type DeviceInterface = {
IOS: string;
@@ -33,11 +31,11 @@ const DEVICE_TYPES: DeviceInterface = {
*
* @alias Parse.Installation
*/
-class ParseInstallation extends ParseObject {
+class ParseInstallation extends ParseObject {
/**
* @param {object} attributes The initial set of data to store in the object.
*/
- constructor(attributes?: AttributeMap) {
+ constructor(attributes?: T) {
super('_Installation');
if (attributes && typeof attributes === 'object') {
try {
@@ -220,7 +218,7 @@ class ParseInstallation extends ParseObject {
* @param {...any} args
* @returns {Promise}
*/
- async fetch(...args: Array): Promise {
+ async fetch(...args: Array): Promise {
try {
await super.fetch.apply(this, args);
} catch (e) {
@@ -259,7 +257,7 @@ class ParseInstallation extends ParseObject {
this._markAllFieldsDirty();
await super.save.apply(this, args);
}
- await CoreManager.getInstallationController().updateInstallationOnDisk(this);
+ await CoreManager.getInstallationController().updateInstallationOnDisk(this as any);
return this;
}
diff --git a/src/ParseObject.ts b/src/ParseObject.ts
index 208e503c7..d0ab2932c 100644
--- a/src/ParseObject.ts
+++ b/src/ParseObject.ts
@@ -29,6 +29,8 @@ import unsavedChildren from './unsavedChildren';
import type { AttributeMap, OpsMap } from './ObjectStateMutations';
import type { RequestOptions, FullOptions } from './RESTController';
+import type ParseGeoPoint from './ParseGeoPoint';
+import type ParsePolygon from './ParsePolygon';
export type Pointer = {
__type: string;
@@ -57,6 +59,38 @@ type FetchOptions = {
context?: AttributeMap;
};
+export type SetOptions = {
+ ignoreValidation: boolean;
+};
+
+export interface Attributes {
+ [key: string]: any;
+}
+
+interface JSONBaseAttributes {
+ objectId: string;
+ createdAt: string;
+ updatedAt: string;
+}
+
+type Encode = T extends ParseObject
+ ? ReturnType | Pointer
+ : T extends ParseACL | ParseGeoPoint | ParsePolygon | ParseRelation | ParseFile
+ ? ReturnType
+ : T extends Date
+ ? { __type: 'Date'; iso: string }
+ : T extends RegExp
+ ? string
+ : T extends Array
+ ? Array>
+ : T extends object
+ ? ToJSON
+ : T;
+
+type ToJSON = {
+ [K in keyof T]: Encode;
+};
+
// Mapping of class names to constructors, so we can populate objects from the
// server with appropriate subclasses of ParseObject
const classMap: AttributeMap = {};
@@ -100,7 +134,7 @@ function getServerUrlPath() {
*
* @alias Parse.Object
*/
-class ParseObject {
+class ParseObject {
/**
* @param {string} className The class name for the object
* @param {object} attributes The initial set of data to store in the object.
@@ -109,8 +143,8 @@ class ParseObject {
*/
constructor(
className?: string | { className: string; [attr: string]: any },
- attributes?: { [attr: string]: any },
- options?: { ignoreValidation: boolean }
+ attributes?: T | Attributes,
+ options?: SetOptions
) {
// Enable legacy initializers
if (typeof this.initialize === 'function') {
@@ -157,9 +191,9 @@ class ParseObject {
/* Prototype getters / setters */
- get attributes(): AttributeMap {
+ get attributes(): T {
const stateController = CoreManager.getObjectStateController();
- return Object.freeze(stateController.estimateAttributes(this._getStateIdentifier()));
+ return Object.freeze(stateController.estimateAttributes(this._getStateIdentifier())) as T;
}
/**
@@ -213,7 +247,7 @@ class ParseObject {
id = this._getId();
}
return {
- id: id,
+ id,
className: this.className,
};
} else {
@@ -221,7 +255,7 @@ class ParseObject {
}
}
- _getServerData(): AttributeMap {
+ _getServerData(): Attributes {
const stateController = CoreManager.getObjectStateController();
return stateController.getServerData(this._getStateIdentifier());
}
@@ -254,13 +288,13 @@ class ParseObject {
});
}
- _getDirtyObjectAttributes(): AttributeMap {
+ _getDirtyObjectAttributes(): Attributes {
const attributes = this.attributes;
const stateController = CoreManager.getObjectStateController();
const objectCache = stateController.getObjectCache(this._getStateIdentifier());
- const dirty = {};
+ const dirty: Attributes = {};
for (const attr in attributes) {
- const val = attributes[attr];
+ const val: any = attributes[attr];
if (
val &&
typeof val === 'object' &&
@@ -286,14 +320,14 @@ class ParseObject {
return dirty;
}
- _toFullJSON(seen?: Array, offline?: boolean): AttributeMap {
- const json: { [key: string]: any } = this.toJSON(seen, offline);
+ _toFullJSON(seen?: Array, offline?: boolean): Attributes {
+ const json: Attributes = this.toJSON(seen, offline);
json.__type = 'Object';
json.className = this.className;
return json;
}
- _getSaveJSON(): AttributeMap {
+ _getSaveJSON(): Attributes {
const pending = this._getPendingOps();
const dirtyObjects = this._getDirtyObjectAttributes();
const json = {};
@@ -347,7 +381,7 @@ class ParseObject {
};
}
- _finishFetch(serverData: AttributeMap) {
+ _finishFetch(serverData: Attributes) {
if (!this.id && serverData.objectId) {
this.id = serverData.objectId;
}
@@ -406,7 +440,7 @@ class ParseObject {
}
}
- _handleSaveResponse(response: AttributeMap, status: number) {
+ _handleSaveResponse(response: Attributes, status: number) {
const changes: Partial<{
createdAt: string;
updatedAt: string;
@@ -508,10 +542,10 @@ class ParseObject {
* @param offline
* @returns {object}
*/
- toJSON(seen: Array | void, offline?: boolean): AttributeMap {
+ toJSON(seen: Array | void, offline?: boolean): ToJSON & JSONBaseAttributes {
const seenEntry = this.id ? this.className + ':' + this.id : this;
seen = seen || [seenEntry];
- const json: AttributeMap = {};
+ const json: any = {};
const attrs = this.attributes;
for (const attr in attrs) {
if ((attr === 'createdAt' || attr === 'updatedAt') && attrs[attr].toJSON) {
@@ -662,8 +696,10 @@ class ParseObject {
* @param {string} attr The attribute to get the relation for.
* @returns {Parse.Relation}
*/
- relation(attr: string): ParseRelation {
- const value = this.get(attr);
+ relation = Extract>(
+ attr: T[K] extends ParseRelation ? K : never
+ ): ParseRelation {
+ const value = this.get(attr) as any;
if (value) {
if (!(value instanceof ParseRelation)) {
throw new Error('Called relation() on non-relation field ' + attr);
@@ -982,7 +1018,7 @@ class ParseObject {
const readonly = (this.constructor as any).readOnlyAttributes() || [];
// Attributes are frozen, so we have to rebuild an object,
// rather than delete readonly keys
- const copy = {};
+ const copy: T = {} as T;
for (const a in attributes) {
if (readonly.indexOf(a) < 0) {
copy[a] = attributes[a];
@@ -1001,7 +1037,7 @@ class ParseObject {
*
* @returns {Parse.Object}
*/
- newInstance(): any {
+ newInstance(): this {
const clone = new (this.constructor as new (
...args: ConstructorParameters
) => this)(this.className);
@@ -1094,7 +1130,7 @@ class ParseObject {
* @returns {Parse.Error|boolean} False if the data is valid. An error object otherwise.
* @see Parse.Object#set
*/
- validate(attrs: AttributeMap): ParseError | boolean {
+ validate(attrs: Attributes): ParseError | boolean {
if (Object.hasOwn(attrs, 'ACL') && !(attrs.ACL instanceof ParseACL)) {
return new ParseError(ParseError.OTHER_CAUSE, 'ACL must be a Parse ACL.');
}
@@ -1159,7 +1195,7 @@ class ParseObject {
*/
clear(): this {
const attributes = this.attributes;
- const erasable = {};
+ const erasable: Attributes = {};
let readonly = ['createdAt', 'updatedAt'];
if (typeof (this.constructor as any).readOnlyAttributes === 'function') {
readonly = readonly.concat((this.constructor as any).readOnlyAttributes());
@@ -1189,10 +1225,10 @@ class ParseObject {
* @returns {Promise} A promise that is fulfilled when the fetch
* completes.
*/
- fetch(options: FetchOptions): Promise {
+ fetch(options: FetchOptions): Promise {
const fetchOptions = ParseObject._getRequestOptions(options);
const controller = CoreManager.getObjectController();
- return controller.fetch(this, true, fetchOptions);
+ return controller.fetch(this, true, fetchOptions) as Promise;
}
/**
@@ -1215,8 +1251,8 @@ class ParseObject {
*/
fetchWithInclude(
keys: string | Array>,
- options: RequestOptions
- ): Promise {
+ options?: RequestOptions
+ ): Promise {
options = options || {};
options.include = keys;
return this.fetch(options);
@@ -1322,8 +1358,8 @@ class ParseObject {
* completes.
*/
async save(
- arg1: undefined | string | { [attr: string]: any } | null,
- arg2: SaveOptions | any,
+ arg1?: undefined | string | { [attr: string]: any } | null,
+ arg2?: SaveOptions | any,
arg3?: SaveOptions
): Promise {
let attrs;
@@ -1367,9 +1403,8 @@ class ParseObject {
.then(() => controller.save(unsavedObjects, saveOptions))
.then((savedOjbects: this[]) => savedOjbects.pop());
}
- return controller.save(unsaved, saveOptions).then(() => {
- return controller.save(this, saveOptions);
- }) as Promise as Promise;
+ await controller.save(unsaved, saveOptions);
+ return controller.save(this, saveOptions) as Promise as Promise;
}
/**
@@ -1576,9 +1611,9 @@ class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static fetchAll(list: Array, options: RequestOptions = {}) {
+ static fetchAll(list: T[], options?: RequestOptions): Promise {
const fetchOptions = ParseObject._getRequestOptions(options);
- return CoreManager.getObjectController().fetch(list, true, fetchOptions);
+ return CoreManager.getObjectController().fetch(list, true, fetchOptions) as Promise;
}
/**
@@ -1610,11 +1645,11 @@ class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static fetchAllWithInclude(
- list: Array,
+ static fetchAllWithInclude(
+ list: T[],
keys: string | Array>,
- options: RequestOptions
- ) {
+ options?: RequestOptions
+ ): Promise {
options = options || {};
options.include = keys;
return ParseObject.fetchAll(list, options);
@@ -1650,11 +1685,11 @@ class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static fetchAllIfNeededWithInclude(
- list: Array,
+ static fetchAllIfNeededWithInclude(
+ list: T[],
keys: string | Array>,
- options: RequestOptions
- ) {
+ options?: RequestOptions
+ ): Promise {
options = options || {};
options.include = keys;
return ParseObject.fetchAllIfNeeded(list, options);
@@ -1687,9 +1722,9 @@ class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static fetchAllIfNeeded(list: Array, options: FetchOptions) {
+ static fetchAllIfNeeded(list: T[], options?: FetchOptions): Promise {
const fetchOptions = ParseObject._getRequestOptions(options);
- return CoreManager.getObjectController().fetch(list, false, fetchOptions);
+ return CoreManager.getObjectController().fetch(list, false, fetchOptions) as Promise;
}
static handleIncludeOptions(options: { include?: string | string[] }) {
@@ -1797,9 +1832,9 @@ class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static saveAll(list: Array, options: SaveOptions = {}) {
+ static saveAll(list: T, options?: SaveOptions): Promise {
const saveOptions = ParseObject._getRequestOptions(options);
- return CoreManager.getObjectController().save(list, saveOptions);
+ return CoreManager.getObjectController().save(list, saveOptions) as any;
}
/**
@@ -1838,7 +1873,7 @@ class ParseObject {
}
const constructor = classMap[json.className];
const o = constructor ? new constructor(json.className) : new ParseObject(json.className);
- const otherAttributes: AttributeMap = {};
+ const otherAttributes: Attributes = {};
for (const attr in json) {
if (attr !== 'className' && attr !== '__type') {
otherAttributes[attr] = json[attr];
diff --git a/src/ParseQuery.ts b/src/ParseQuery.ts
index 648060b9b..913e8b471 100644
--- a/src/ParseQuery.ts
+++ b/src/ParseQuery.ts
@@ -235,7 +235,7 @@ function handleOfflineSort(a, b, sorts) {
*
* @alias Parse.Query
*/
-class ParseQuery {
+class ParseQuery {
/**
* @property {string} className
*/
@@ -263,7 +263,7 @@ class ParseQuery {
/**
* @param {(string | Parse.Object)} objectClass An instance of a subclass of Parse.Object, or a Parse className string.
*/
- constructor(objectClass: string | ParseObject) {
+ constructor(objectClass: string | (new (...args: any[]) => T | ParseObject)) {
if (typeof objectClass === 'string') {
if (objectClass === 'User' && CoreManager.get('PERFORM_USER_REWRITE')) {
this.className = '_User';
@@ -310,7 +310,7 @@ class ParseQuery {
* @param {Array} queries
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- _orQuery(queries: Array): ParseQuery {
+ _orQuery(queries: Array): this {
const queryJSON = queries.map(q => {
return q.toJSON().where;
});
@@ -325,7 +325,7 @@ class ParseQuery {
* @param {Array} queries
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- _andQuery(queries: Array): ParseQuery {
+ _andQuery(queries: Array): this {
const queryJSON = queries.map(q => {
return q.toJSON().where;
});
@@ -340,7 +340,7 @@ class ParseQuery {
* @param {Array} queries
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- _norQuery(queries: Array): ParseQuery {
+ _norQuery(queries: Array): this {
const queryJSON = queries.map(q => {
return q.toJSON().where;
});
@@ -357,7 +357,7 @@ class ParseQuery {
* @param value
* @returns {Parse.Query}
*/
- _addCondition(key: string, condition: string, value: any): ParseQuery {
+ _addCondition(key: string, condition: string, value: any): this {
if (!this._where[key] || typeof this._where[key] === 'string') {
this._where[key] = {};
}
@@ -518,7 +518,7 @@ class ParseQuery {
* @param {QueryJSON} json from Parse.Query.toJSON() method
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withJSON(json: QueryJSON): ParseQuery {
+ withJSON(json: QueryJSON): this {
if (json.where) {
this._where = json.where;
}
@@ -636,7 +636,7 @@ class ParseQuery {
* @returns {Promise} A promise that is resolved with the result when
* the query completes.
*/
- get(objectId: string, options?: QueryOptions): Promise {
+ get(objectId: string, options?: QueryOptions): Promise {
this.equalTo('objectId', objectId);
const firstOptions = ParseObject._getRequestOptions(options);
@@ -665,7 +665,7 @@ class ParseQuery {
* @returns {Promise} A promise that is resolved with the results when
* the query completes.
*/
- find(options?: QueryOptions): Promise> {
+ find(options?: QueryOptions): Promise {
const findOptions = ParseObject._getRequestOptions(options);
this._setRequestTask(findOptions);
@@ -726,9 +726,9 @@ class ParseQuery {
* @returns {Promise} A promise that is resolved with the results when
* the query completes.
*/
- async findAll(options?: BatchOptions): Promise> {
- let result: ParseObject[] = [];
- await this.eachBatch((objects: ParseObject[]) => {
+ async findAll(options?: BatchOptions): Promise {
+ let result: T[] = [];
+ await this.eachBatch((objects: T[]) => {
result = [...result, ...objects];
}, options);
return result;
@@ -853,7 +853,7 @@ class ParseQuery {
* @returns {Promise} A promise that is resolved with the object when
* the query completes.
*/
- first(options: QueryOptions = {}): Promise {
+ first(options: QueryOptions = {}): Promise {
const findOptions = ParseObject._getRequestOptions(options);
this._setRequestTask(findOptions);
@@ -889,9 +889,9 @@ class ParseQuery {
handleSelectResult(objects[0], select);
}
if (findOptions.json) {
- return objects[0];
+ return objects[0] as T;
} else {
- return ParseObject.fromJSON(objects[0], !select);
+ return ParseObject.fromJSON(objects[0], !select) as T;
}
});
}
@@ -917,7 +917,10 @@ class ParseQuery {
* @returns {Promise} A promise that will be fulfilled once the
* iteration has completed.
*/
- eachBatch(callback: (objs: Array) => void, options?: BatchOptions): Promise {
+ eachBatch(
+ callback: (objs: T[]) => PromiseLike | void,
+ options?: BatchOptions
+ ): Promise {
options = options || {};
if (this._order || this._skip || this._limit >= 0) {
@@ -931,7 +934,7 @@ class ParseQuery {
const findOptions = ParseObject._getRequestOptions(options);
let finished = false;
- let previousResults: ParseObject[] = [];
+ let previousResults: T[] = [];
return continueWhile(
() => {
return !finished;
@@ -947,9 +950,9 @@ class ParseQuery {
} else {
query.greaterThan('objectId', results[results.length - 1].id);
}
- previousResults = results;
+ previousResults = results as T[];
} else if (results.length > 0) {
- await Promise.resolve(callback(results));
+ await Promise.resolve(callback(results as T[]));
finished = true;
} else {
finished = true;
@@ -978,10 +981,10 @@ class ParseQuery {
* @returns {Promise} A promise that will be fulfilled once the
* iteration has completed.
*/
- each(callback: (obj: ParseObject) => any, options?: BatchOptions): Promise {
+ each(callback: (obj: T) => PromiseLike | void, options?: BatchOptions): Promise {
return this.eachBatch(results => {
let callbacksDone = Promise.resolve();
- results.forEach(result => {
+ results.forEach((result: T) => {
callbacksDone = callbacksDone.then(() => {
return callback(result);
});
@@ -996,7 +999,7 @@ class ParseQuery {
* @param {(string|object)} value String or Object of index that should be used when executing query
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- hint(value: any): ParseQuery {
+ hint(value: any): this {
if (typeof value === 'undefined') {
delete this._hint;
}
@@ -1010,7 +1013,7 @@ class ParseQuery {
* @param {boolean} explain Used to toggle the information on the query plan.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- explain(explain = true): ParseQuery {
+ explain(explain = true): this {
if (typeof explain !== 'boolean') {
throw new Error('You can only set explain to a boolean value');
}
@@ -1155,7 +1158,7 @@ class ParseQuery {
* @param value The value that the Parse.Object must contain.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- equalTo(key: string | { [key: string]: any }, value?: any): ParseQuery {
+ equalTo(key: string | { [key: string]: any }, value?: any): this {
if (key && typeof key === 'object') {
Object.entries(key).forEach(([k, val]) => this.equalTo(k, val));
return this;
@@ -1176,7 +1179,7 @@ class ParseQuery {
* @param value The value that must not be equalled.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- notEqualTo(key: string | { [key: string]: any }, value?: any): ParseQuery {
+ notEqualTo(key: string | { [key: string]: any }, value?: any): this {
if (key && typeof key === 'object') {
Object.entries(key).forEach(([k, val]) => this.notEqualTo(k, val));
return this;
@@ -1192,7 +1195,7 @@ class ParseQuery {
* @param value The value that provides an upper bound.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- lessThan(key: string, value: any): ParseQuery {
+ lessThan(key: string, value: any): this {
return this._addCondition(key, '$lt', value);
}
@@ -1204,7 +1207,7 @@ class ParseQuery {
* @param value The value that provides an lower bound.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- greaterThan(key: string, value: any): ParseQuery {
+ greaterThan(key: string, value: any): this {
return this._addCondition(key, '$gt', value);
}
@@ -1216,7 +1219,7 @@ class ParseQuery {
* @param value The value that provides an upper bound.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- lessThanOrEqualTo(key: string, value: any): ParseQuery {
+ lessThanOrEqualTo(key: string, value: any): this {
return this._addCondition(key, '$lte', value);
}
@@ -1228,7 +1231,7 @@ class ParseQuery {
* @param {*} value The value that provides an lower bound.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- greaterThanOrEqualTo(key: string, value: any): ParseQuery {
+ greaterThanOrEqualTo(key: string, value: any): this {
return this._addCondition(key, '$gte', value);
}
@@ -1240,7 +1243,7 @@ class ParseQuery {
* @param {Array<*>} value The values that will match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- containedIn(key: string, value: Array): ParseQuery {
+ containedIn(key: string, value: Array): this {
return this._addCondition(key, '$in', value);
}
@@ -1252,7 +1255,7 @@ class ParseQuery {
* @param {Array<*>} value The values that will not match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- notContainedIn(key: string, value: Array): ParseQuery {
+ notContainedIn(key: string, value: Array): this {
return this._addCondition(key, '$nin', value);
}
@@ -1264,7 +1267,7 @@ class ParseQuery {
* @param {Array} values The values that will match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- containedBy(key: string, values: Array): ParseQuery {
+ containedBy(key: string, values: Array): this {
return this._addCondition(key, '$containedBy', values);
}
@@ -1276,7 +1279,7 @@ class ParseQuery {
* @param {Array} values The values that will match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- containsAll(key: string, values: Array): ParseQuery {
+ containsAll(key: string, values: Array): this {
return this._addCondition(key, '$all', values);
}
@@ -1288,7 +1291,7 @@ class ParseQuery {
* @param {Array} values The string values that will match as starting string.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- containsAllStartingWith(key: string, values: Array): ParseQuery {
+ containsAllStartingWith(key: string, values: Array): this {
if (!Array.isArray(values)) {
values = [values];
}
@@ -1306,7 +1309,7 @@ class ParseQuery {
* @param {string} key The key that should exist.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- exists(key: string): ParseQuery {
+ exists(key: string): this {
return this._addCondition(key, '$exists', true);
}
@@ -1316,7 +1319,7 @@ class ParseQuery {
* @param {string} key The key that should not exist
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- doesNotExist(key: string): ParseQuery {
+ doesNotExist(key: string): this {
return this._addCondition(key, '$exists', false);
}
@@ -1330,7 +1333,7 @@ class ParseQuery {
* @param {string} modifiers The regular expression mode.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- matches(key: string, regex: RegExp | string, modifiers: string): ParseQuery {
+ matches(key: string, regex: RegExp | string, modifiers?: string): this {
this._addCondition(key, '$regex', regex);
if (!modifiers) {
modifiers = '';
@@ -1358,7 +1361,7 @@ class ParseQuery {
* @param {Parse.Query} query The query that should match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- matchesQuery(key: string, query: ParseQuery): ParseQuery {
+ matchesQuery(key: string, query: ParseQuery): this {
const queryJSON = query.toJSON();
queryJSON.className = query.className;
return this._addCondition(key, '$inQuery', queryJSON);
@@ -1373,7 +1376,7 @@ class ParseQuery {
* @param {Parse.Query} query The query that should not match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- doesNotMatchQuery(key: string, query: ParseQuery): ParseQuery {
+ doesNotMatchQuery(key: string, query: ParseQuery): this {
const queryJSON = query.toJSON();
queryJSON.className = query.className;
return this._addCondition(key, '$notInQuery', queryJSON);
@@ -1390,7 +1393,7 @@ class ParseQuery {
* @param {Parse.Query} query The query to run.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- matchesKeyInQuery(key: string, queryKey: string, query: ParseQuery): ParseQuery {
+ matchesKeyInQuery(key: string, queryKey: string, query: ParseQuery): this {
const queryJSON = query.toJSON();
queryJSON.className = query.className;
return this._addCondition(key, '$select', {
@@ -1410,7 +1413,7 @@ class ParseQuery {
* @param {Parse.Query} query The query to run.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- doesNotMatchKeyInQuery(key: string, queryKey: string, query: ParseQuery): ParseQuery {
+ doesNotMatchKeyInQuery(key: string, queryKey: string, query: ParseQuery): this {
const queryJSON = query.toJSON();
queryJSON.className = query.className;
return this._addCondition(key, '$dontSelect', {
@@ -1427,7 +1430,7 @@ class ParseQuery {
* @param {string} substring The substring that the value must contain.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- contains(key: string, substring: string): ParseQuery {
+ contains(key: string, substring: string): this {
if (typeof substring !== 'string') {
throw new Error('The value being searched for must be a string.');
}
@@ -1463,7 +1466,7 @@ class ParseQuery {
* @param {boolean} options.diacriticSensitive A boolean flag to enable or disable diacritic sensitive search.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fullText(key: string, value: string, options: FullTextQueryOptions = {}): ParseQuery {
+ fullText(key: string, value: string, options: FullTextQueryOptions = {}): this {
options = options || {};
if (!key) {
@@ -1524,7 +1527,7 @@ class ParseQuery {
* @param {string} modifiers The regular expression mode.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- startsWith(key: string, prefix: string, modifiers: string): ParseQuery {
+ startsWith(key: string, prefix: string, modifiers?: string): this {
if (typeof prefix !== 'string') {
throw new Error('The value being searched for must be a string.');
}
@@ -1540,7 +1543,7 @@ class ParseQuery {
* @param {string} modifiers The regular expression mode.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- endsWith(key: string, suffix: string, modifiers: string): ParseQuery {
+ endsWith(key: string, suffix: string, modifiers?: string): this {
if (typeof suffix !== 'string') {
throw new Error('The value being searched for must be a string.');
}
@@ -1555,7 +1558,7 @@ class ParseQuery {
* @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- near(key: string, point: ParseGeoPoint): ParseQuery {
+ near(key: string, point: ParseGeoPoint): this {
if (!(point instanceof ParseGeoPoint)) {
// Try to cast it as a GeoPoint
point = new ParseGeoPoint(point);
@@ -1575,12 +1578,7 @@ class ParseQuery {
* defaults to true.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinRadians(
- key: string,
- point: ParseGeoPoint,
- maxDistance: number,
- sorted: boolean
- ): ParseQuery {
+ withinRadians(key: string, point: ParseGeoPoint, maxDistance: number, sorted?: boolean): this {
if (sorted || sorted === undefined) {
this.near(key, point);
return this._addCondition(key, '$maxDistance', maxDistance);
@@ -1604,7 +1602,7 @@ class ParseQuery {
* defaults to true.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinMiles(key: string, point: ParseGeoPoint, maxDistance: number, sorted: boolean): ParseQuery {
+ withinMiles(key: string, point: ParseGeoPoint, maxDistance: number, sorted: boolean): this {
return this.withinRadians(key, point, maxDistance / 3958.8, sorted);
}
@@ -1621,12 +1619,7 @@ class ParseQuery {
* defaults to true.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinKilometers(
- key: string,
- point: ParseGeoPoint,
- maxDistance: number,
- sorted: boolean
- ): ParseQuery {
+ withinKilometers(key: string, point: ParseGeoPoint, maxDistance: number, sorted: boolean): this {
return this.withinRadians(key, point, maxDistance / 6371.0, sorted);
}
@@ -1642,7 +1635,7 @@ class ParseQuery {
* The upper-right inclusive corner of the box.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinGeoBox(key: string, southwest: ParseGeoPoint, northeast: ParseGeoPoint): ParseQuery {
+ withinGeoBox(key: string, southwest: ParseGeoPoint, northeast: ParseGeoPoint): this {
if (!(southwest instanceof ParseGeoPoint)) {
southwest = new ParseGeoPoint(southwest);
}
@@ -1664,7 +1657,7 @@ class ParseQuery {
* @param {Array} points Array of Coordinates / GeoPoints
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinPolygon(key: string, points: Array>): ParseQuery {
+ withinPolygon(key: string, points: Array>): this {
return this._addCondition(key, '$geoWithin', { $polygon: points });
}
@@ -1676,7 +1669,7 @@ class ParseQuery {
* @param {Parse.GeoPoint} point
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- polygonContains(key: string, point: ParseGeoPoint): ParseQuery {
+ polygonContains(key: string, point: ParseGeoPoint): this {
return this._addCondition(key, '$geoIntersects', { $point: point });
}
@@ -1689,7 +1682,7 @@ class ParseQuery {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- ascending(...keys: Array): ParseQuery {
+ ascending(...keys: Array): this {
this._order = [];
return this.addAscending.apply(this, keys);
}
@@ -1702,7 +1695,7 @@ class ParseQuery {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- addAscending(...keys: Array): ParseQuery {
+ addAscending(...keys: Array): this {
if (!this._order) {
this._order = [];
}
@@ -1723,7 +1716,7 @@ class ParseQuery {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- descending(...keys: Array): ParseQuery {
+ descending(...keys: Array): this {
this._order = [];
return this.addDescending.apply(this, keys);
}
@@ -1736,7 +1729,7 @@ class ParseQuery {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- addDescending(...keys: Array): ParseQuery {
+ addDescending(...keys: Array): this {
if (!this._order) {
this._order = [];
}
@@ -1767,7 +1760,7 @@ class ParseQuery {
* @param {number} n the number of results to skip.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- skip(n: number): ParseQuery {
+ skip(n: number): this {
if (typeof n !== 'number' || n < 0) {
throw new Error('You can only skip by a positive number');
}
@@ -1781,7 +1774,7 @@ class ParseQuery {
* @param {number} n the number of results to limit to.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- limit(n: number): ParseQuery {
+ limit(n: number): this {
if (typeof n !== 'number') {
throw new Error('You can only set the limit to a numeric value');
}
@@ -1798,7 +1791,7 @@ class ParseQuery {
* @param {boolean} includeCount false - disable, true - enable.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withCount(includeCount = true): ParseQuery {
+ withCount(includeCount = true): this {
if (typeof includeCount !== 'boolean') {
throw new Error('You can only set withCount to a boolean value');
}
@@ -1816,7 +1809,7 @@ class ParseQuery {
* @param {...string|Array} keys The name(s) of the key(s) to include.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- include(...keys: Array>): ParseQuery {
+ include(...keys: Array>): this {
keys.forEach(key => {
if (Array.isArray(key)) {
this._include = this._include.concat(key);
@@ -1834,7 +1827,7 @@ class ParseQuery {
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- includeAll(): ParseQuery {
+ includeAll(): this {
return this.include('*');
}
@@ -1846,7 +1839,7 @@ class ParseQuery {
* @param {...string|Array} keys The name(s) of the key(s) to include.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- select(...keys: Array>): ParseQuery {
+ select(...keys: Array>): this {
if (!this._select) {
this._select = [];
}
@@ -1869,7 +1862,7 @@ class ParseQuery {
* @param {...string|Array} keys The name(s) of the key(s) to exclude.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- exclude(...keys: Array>): ParseQuery {
+ exclude(...keys: Array>): this {
keys.forEach(key => {
if (Array.isArray(key)) {
this._exclude = this._exclude.concat(key);
@@ -1888,7 +1881,7 @@ class ParseQuery {
* @param {...string|Array} keys The name(s) of the key(s) to watch.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- watch(...keys: Array>): ParseQuery {
+ watch(...keys: Array>): this {
keys.forEach(key => {
if (Array.isArray(key)) {
this._watch = this._watch.concat(key);
@@ -1911,7 +1904,7 @@ class ParseQuery {
readPreference: string,
includeReadPreference?: string,
subqueryReadPreference?: string
- ): ParseQuery {
+ ): this {
this._readPreference = readPreference;
this._includeReadPreference = includeReadPreference || null;
this._subqueryReadPreference = subqueryReadPreference || null;
@@ -1925,7 +1918,7 @@ class ParseQuery {
* @returns {Promise} Returns the liveQuerySubscription, it's an event emitter
* which can be used to get liveQuery updates.
*/
- async subscribe(sessionToken?: string): Promise {
+ async subscribe(sessionToken?: string | null): Promise {
const currentUser = await CoreManager.getUserController().currentUserAsync();
if (!sessionToken) {
sessionToken = currentUser ? currentUser.getSessionToken() || undefined : undefined;
@@ -2002,7 +1995,7 @@ class ParseQuery {
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fromNetwork(): ParseQuery {
+ fromNetwork(): this {
this._queriesLocalDatastore = false;
this._localDatastorePinName = null;
return this;
@@ -2013,7 +2006,7 @@ class ParseQuery {
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fromLocalDatastore(): ParseQuery {
+ fromLocalDatastore(): this {
return this.fromPinWithName(null);
}
@@ -2022,7 +2015,7 @@ class ParseQuery {
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fromPin(): ParseQuery {
+ fromPin(): this {
return this.fromPinWithName(DEFAULT_PIN);
}
@@ -2032,7 +2025,7 @@ class ParseQuery {
* @param {string} name The name of query source.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fromPinWithName(name?: string | null): ParseQuery {
+ fromPinWithName(name?: string | null): this {
const localDatastore = CoreManager.getLocalDatastore();
if (localDatastore.checkIfEnabled()) {
this._queriesLocalDatastore = true;
@@ -2046,7 +2039,7 @@ class ParseQuery {
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- cancel(): ParseQuery {
+ cancel(): this {
if (this._xhrRequest.task && typeof this._xhrRequest.task.abort === 'function') {
this._xhrRequest.task._aborted = true;
this._xhrRequest.task.abort();
@@ -2072,7 +2065,7 @@ class ParseQuery {
* @param {string} value a comment can make your profile data easier to interpret and trace.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- comment(value: string): ParseQuery {
+ comment(value: string): this {
if (value == null) {
delete this._comment;
return this;
diff --git a/src/ParseRelation.ts b/src/ParseRelation.ts
index d53126d98..ea5844e35 100644
--- a/src/ParseRelation.ts
+++ b/src/ParseRelation.ts
@@ -15,8 +15,8 @@ import CoreManager from './CoreManager';
*
* @alias Parse.Relation
*/
-class ParseRelation {
- parent?: ParseObject;
+class ParseRelation {
+ parent?: S;
key?: string;
targetClassName?: string | null;
@@ -24,7 +24,7 @@ class ParseRelation {
* @param {Parse.Object} parent The parent of this relation.
* @param {string} key The key for this relation on the parent.
*/
- constructor(parent?: ParseObject, key?: string) {
+ constructor(parent?: S, key?: string) {
this.parent = parent;
this.key = key;
this.targetClassName = null;
@@ -33,7 +33,7 @@ class ParseRelation {
/*
* Makes sure that this relation has the right parent and key.
*/
- _ensureParentAndKey(parent: ParseObject, key: string) {
+ _ensureParentAndKey(parent: S, key: string) {
this.key = this.key || key;
if (this.key !== key) {
throw new Error('Internal Error. Relation retrieved from two different keys.');
@@ -60,7 +60,7 @@ class ParseRelation {
* @param {(Parse.Object|Array)} objects The item or items to add.
* @returns {Parse.Object} The parent of the relation.
*/
- add(objects: ParseObject | Array): ParseObject {
+ add(objects: T | T[]): S {
if (!Array.isArray(objects)) {
objects = [objects];
}
@@ -83,7 +83,7 @@ class ParseRelation {
*
* @param {(Parse.Object|Array)} objects The item or items to remove.
*/
- remove(objects: ParseObject | Array) {
+ remove(objects: T | T[]): void {
if (!Array.isArray(objects)) {
objects = [objects];
}
@@ -117,7 +117,7 @@ class ParseRelation {
*
* @returns {Parse.Query} Relation Query
*/
- query(): ParseQuery {
+ query(): ParseQuery {
let query;
const parent = this.parent;
if (!parent) {
diff --git a/src/ParseRole.ts b/src/ParseRole.ts
index 6ce7ca754..50262c37d 100644
--- a/src/ParseRole.ts
+++ b/src/ParseRole.ts
@@ -1,10 +1,11 @@
import CoreManager from './CoreManager';
import ParseACL from './ParseACL';
import ParseError from './ParseError';
-import ParseObject from './ParseObject';
+import ParseObject, { Attributes, SetOptions } from './ParseObject';
import type { AttributeMap } from './ObjectStateMutations';
import type ParseRelation from './ParseRelation';
+import type ParseUser from './ParseUser';
/**
* Represents a Role on the Parse server. Roles represent groupings of
@@ -19,7 +20,7 @@ import type ParseRelation from './ParseRelation';
* @alias Parse.Role
* @augments Parse.Object
*/
-class ParseRole extends ParseObject {
+class ParseRole extends ParseObject {
/**
* @param {string} name The name of the Role to create.
* @param {Parse.ACL} acl The ACL for this role. Roles must have an ACL.
@@ -62,9 +63,9 @@ class ParseRole extends ParseObject {
* @param {string} name The name of the role.
* @param {object} options Standard options object with success and error
* callbacks.
- * @returns {(ParseObject|boolean)} true if the set succeeded.
+ * @returns {Parse.Object} Returns the object, so you can chain this call.
*/
- setName(name: string, options?: any): ParseObject | boolean {
+ setName(name: string, options?: SetOptions): this {
this._validateName(name);
return this.set('name', name, options);
}
@@ -80,8 +81,8 @@ class ParseRole extends ParseObject {
* @returns {Parse.Relation} the relation for the users belonging to this
* role.
*/
- getUsers(): ParseRelation {
- return this.relation('users');
+ getUsers(): ParseRelation {
+ return this.relation('users' as any);
}
/**
@@ -95,8 +96,8 @@ class ParseRole extends ParseObject {
* @returns {Parse.Relation} the relation for the roles belonging to this
* role.
*/
- getRoles(): ParseRelation {
- return this.relation('roles');
+ getRoles(): ParseRelation {
+ return this.relation('roles' as any);
}
_validateName(newName) {
diff --git a/src/ParseSchema.ts b/src/ParseSchema.ts
index 4decdcf4f..8daab6076 100644
--- a/src/ParseSchema.ts
+++ b/src/ParseSchema.ts
@@ -4,6 +4,45 @@ import ParseCLP from './ParseCLP';
import type { PermissionsMap } from './ParseCLP';
+interface CLPField {
+ '*'?: boolean | undefined;
+ requiresAuthentication?: boolean | undefined;
+ [userIdOrRoleName: string]: boolean | undefined;
+}
+
+interface CLP {
+ find?: CLPField | undefined;
+ get?: CLPField | undefined;
+ count?: CLPField | undefined;
+ create?: CLPField | undefined;
+ update?: CLPField | undefined;
+ delete?: CLPField | undefined;
+ addField?: CLPField | undefined;
+ readUserFields?: string[] | undefined;
+ writeUserFields?: string[] | undefined;
+ protectedFields?: {
+ [userIdOrRoleName: string]: string[];
+ };
+}
+
+interface RestSchema {
+ className: string;
+ fields: {
+ [key: string]: {
+ type: string;
+ targetClass?: string;
+ required?: boolean;
+ defaultValue?: string;
+ };
+ };
+ classLevelPermissions: CLP;
+ indexes?: {
+ [key: string]: {
+ [key: string]: any;
+ };
+ };
+}
+
const FIELD_TYPES = [
'String',
'Number',
@@ -70,7 +109,7 @@ class ParseSchema {
* @returns {Promise} A promise that is resolved with the result when
* the query completes.
*/
- static all() {
+ static all(): Promise {
const controller = CoreManager.getSchemaController();
return controller.get('').then(response => {
if (response.results.length === 0) {
@@ -86,7 +125,7 @@ class ParseSchema {
* @returns {Promise} A promise that is resolved with the result when
* the query completes.
*/
- get() {
+ get(): Promise {
this.assertClassName();
const controller = CoreManager.getSchemaController();
diff --git a/src/ParseSession.ts b/src/ParseSession.ts
index e783a305b..6395a5b43 100644
--- a/src/ParseSession.ts
+++ b/src/ParseSession.ts
@@ -1,6 +1,6 @@
import CoreManager from './CoreManager';
import isRevocableSession from './isRevocableSession';
-import ParseObject from './ParseObject';
+import ParseObject, { Attributes } from './ParseObject';
import ParseUser from './ParseUser';
import type { RequestOptions, FullOptions } from './RESTController';
@@ -13,11 +13,11 @@ import type { RequestOptions, FullOptions } from './RESTController';
* @alias Parse.Session
* @augments Parse.Object
*/
-class ParseSession extends ParseObject {
+class ParseSession extends ParseObject {
/**
* @param {object} attributes The initial set of data to store in the user.
*/
- constructor(attributes?: any) {
+ constructor(attributes?: T) {
super('_Session');
if (attributes && typeof attributes === 'object') {
try {
diff --git a/src/ParseUser.ts b/src/ParseUser.ts
index 47be73de2..558495f0e 100644
--- a/src/ParseUser.ts
+++ b/src/ParseUser.ts
@@ -1,17 +1,16 @@
import CoreManager from './CoreManager';
import isRevocableSession from './isRevocableSession';
import ParseError from './ParseError';
-import ParseObject from './ParseObject';
+import ParseObject, { Attributes } from './ParseObject';
import Storage from './Storage';
-import type { AttributeMap } from './ObjectStateMutations';
import type { RequestOptions, FullOptions } from './RESTController';
export type AuthData = { [key: string]: any };
-export type AuthProviderType = {
+export type AuthProvider = {
authenticate?(options: {
- error?: (provider: AuthProviderType, error: string | any) => void;
- success?: (provider: AuthProviderType, result: AuthData) => void;
+ error?: (provider: AuthProvider, error: string | any) => void;
+ success?: (provider: AuthProvider, result: AuthData) => void;
}): void;
restoreAuthentication(authData: any): boolean;
getAuthType(): string;
@@ -22,7 +21,7 @@ let canUseCurrentUser = !CoreManager.get('IS_NODE');
let currentUserCacheMatchesDisk = false;
let currentUserCache: ParseUser | null = null;
-const authProviders: { [key: string]: AuthProviderType } = {};
+const authProviders: { [key: string]: AuthProvider } = {};
/**
* A Parse.User object is a local representation of a user persisted to the
@@ -34,11 +33,11 @@ const authProviders: { [key: string]: AuthProviderType } = {};
* @alias Parse.User
* @augments Parse.Object
*/
-class ParseUser extends ParseObject {
+class ParseUser extends ParseObject {
/**
* @param {object} attributes The initial set of data to store in the user.
*/
- constructor(attributes?: AttributeMap) {
+ constructor(attributes?: T) {
super('_User');
if (attributes && typeof attributes === 'object') {
try {
@@ -83,7 +82,7 @@ class ParseUser extends ParseObject {
* @returns {Promise} A promise that is fulfilled with the user is linked
*/
linkWith(
- provider: AuthProviderType,
+ provider: AuthProvider,
options: { authData?: AuthData },
saveOpts: FullOptions = {}
): Promise {
@@ -168,7 +167,7 @@ class ParseUser extends ParseObject {
*
* @param provider
*/
- _synchronizeAuthData(provider: string | AuthProviderType) {
+ _synchronizeAuthData(provider: string | AuthProvider) {
if (!this.isCurrent() || !provider) {
return;
}
@@ -295,7 +294,7 @@ class ParseUser extends ParseObject {
*
* @returns {object} sessionToken
*/
- _preserveFieldsOnFetch(): AttributeMap {
+ _preserveFieldsOnFetch(): Attributes {
return {
sessionToken: this.get('sessionToken'),
};
@@ -436,8 +435,8 @@ class ParseUser extends ParseObject {
* finishes.
*/
signUp(
- attrs: AttributeMap,
- options?: FullOptions & { context?: AttributeMap }
+ attrs?: Attributes | null,
+ options?: FullOptions & { context?: Attributes }
): Promise {
const signupOptions = ParseObject._getRequestOptions(options);
const controller = CoreManager.getUserController();
@@ -462,7 +461,7 @@ class ParseUser extends ParseObject {
* @returns {Promise} A promise that is fulfilled with the user when
* the login is complete.
*/
- logIn(options: FullOptions & { context?: AttributeMap } = {}): Promise {
+ logIn(options: FullOptions & { context?: Attributes } = {}): Promise {
const loginOptions = ParseObject._getRequestOptions(options);
if (!Object.hasOwn(loginOptions, 'usePost')) {
loginOptions.usePost = true;
@@ -510,11 +509,11 @@ class ParseUser extends ParseObject {
* @param {...any} args
* @returns {Parse.User}
*/
- async fetch(...args: Array): Promise {
+ async fetch(...args: Array): Promise {
await super.fetch.apply(this, args);
const current = await this.isCurrentAsync();
if (current) {
- return CoreManager.getUserController().updateUserOnDisk(this);
+ return CoreManager.getUserController().updateUserOnDisk(this) as Promise;
}
return this;
}
@@ -526,11 +525,11 @@ class ParseUser extends ParseObject {
* @param {...any} args
* @returns {Parse.User}
*/
- async fetchWithInclude(...args: Array): Promise {
+ async fetchWithInclude(...args: Array): Promise {
await super.fetchWithInclude.apply(this, args);
const current = await this.isCurrentAsync();
if (current) {
- return CoreManager.getUserController().updateUserOnDisk(this);
+ return CoreManager.getUserController().updateUserOnDisk(this) as Promise;
}
return this;
}
@@ -597,7 +596,7 @@ class ParseUser extends ParseObject {
* either from memory or localStorage, if necessary.
*
* @static
- * @returns {Parse.Object} The currently logged in Parse.User.
+ * @returns {Parse.User} The currently logged in Parse.User.
*/
static current(): ParseUser | null {
if (!canUseCurrentUser) {
@@ -636,7 +635,7 @@ class ParseUser extends ParseObject {
* @returns {Promise} A promise that is fulfilled with the user when
* the signup completes.
*/
- static signUp(username: string, password: string, attrs: AttributeMap, options?: FullOptions) {
+ static signUp(username: string, password: string, attrs: Attributes, options?: FullOptions) {
attrs = attrs || {};
attrs.username = username;
attrs.password = password;
@@ -663,7 +662,7 @@ class ParseUser extends ParseObject {
return Promise.reject(new ParseError(ParseError.OTHER_CAUSE, 'Password must be a string.'));
}
const user = new this();
- user._finishFetch({ username: username, password: password });
+ user._finishFetch({ username, password });
return user.logIn(options);
}
@@ -696,7 +695,7 @@ class ParseUser extends ParseObject {
return Promise.reject(new ParseError(ParseError.OTHER_CAUSE, 'Auth must be an object.'));
}
const user = new this();
- user._finishFetch({ username: username, password: password, authData });
+ user._finishFetch({ username, password, authData });
return user.logIn(options);
}
@@ -772,7 +771,7 @@ class ParseUser extends ParseObject {
* @returns {Promise} A promise that is fulfilled with the user when
* the login completes.
*/
- static hydrate(userJSON: AttributeMap) {
+ static hydrate(userJSON: Attributes) {
const controller = CoreManager.getUserController();
const user = new this();
return controller.hydrate(user, userJSON);
@@ -1099,7 +1098,7 @@ const DefaultController = {
});
},
- signUp(user: ParseUser, attrs: AttributeMap, options: RequestOptions): Promise {
+ signUp(user: ParseUser, attrs: Attributes, options: RequestOptions): Promise {
const username = (attrs && attrs.username) || user.get('username');
const password = (attrs && attrs.password) || user.get('password');
@@ -1173,7 +1172,7 @@ const DefaultController = {
});
},
- hydrate(user: ParseUser, userJSON: AttributeMap): Promise {
+ hydrate(user: ParseUser, userJSON: Attributes): Promise {
user._finishFetch(userJSON);
user._setExisted(true);
if (userJSON.sessionToken && canUseCurrentUser) {
@@ -1219,7 +1218,7 @@ const DefaultController = {
requestPasswordReset(email: string, options: RequestOptions) {
const RESTController = CoreManager.getRESTController();
- return RESTController.request('POST', 'requestPasswordReset', { email: email }, options);
+ return RESTController.request('POST', 'requestPasswordReset', { email }, options);
},
async upgradeToRevocableSession(user: ParseUser, options: RequestOptions) {
@@ -1265,7 +1264,7 @@ const DefaultController = {
requestEmailVerification(email: string, options: RequestOptions) {
const RESTController = CoreManager.getRESTController();
- return RESTController.request('POST', 'verificationEmailRequest', { email: email }, options);
+ return RESTController.request('POST', 'verificationEmailRequest', { email }, options);
},
};
diff --git a/types/CoreManager.d.ts b/types/CoreManager.d.ts
index f7aeefda3..2abc0c2c5 100644
--- a/types/CoreManager.d.ts
+++ b/types/CoreManager.d.ts
@@ -13,7 +13,6 @@ import type ParseSession from './ParseSession';
import type { HookDeclaration, HookDeleteArg } from './ParseHooks';
import type ParseConfig from './ParseConfig';
import type LiveQueryClient from './LiveQueryClient';
-import type ParseSchema from './ParseSchema';
import type ParseInstallation from './ParseInstallation';
type AnalyticsController = {
track: (
@@ -147,12 +146,7 @@ type RESTController = {
};
type SchemaController = {
purge: (className: string) => Promise;
- get: (
- className: string,
- options?: RequestOptions
- ) => Promise<{
- results: ParseSchema[];
- }>;
+ get: (className: string, options?: RequestOptions) => Promise;
delete: (className: string, options?: RequestOptions) => Promise;
create: (className: string, params: any, options?: RequestOptions) => Promise;
update: (className: string, params: any, options?: RequestOptions) => Promise;
diff --git a/types/FacebookUtils.d.ts b/types/FacebookUtils.d.ts
index 3cfebcaff..fcb4d4d00 100644
--- a/types/FacebookUtils.d.ts
+++ b/types/FacebookUtils.d.ts
@@ -1,5 +1,5 @@
import ParseUser from './ParseUser';
-import type { AuthProviderType } from './ParseUser';
+import type { AuthProvider } from './ParseUser';
/**
* Provides a set of utilities for using Parse with Facebook.
*
@@ -62,7 +62,7 @@ declare const FacebookUtils: {
* @param {object} options MasterKey / SessionToken. Alternatively can be used for authData if permissions is a string
* @returns {Promise}
*/
- logIn(permissions: any, options: any): Promise;
+ logIn(permissions: any, options: any): Promise>;
/**
* Links Facebook to an existing PFUser. This method delegates to the
* Facebook SDK to authenticate the user, and then automatically links
@@ -102,6 +102,6 @@ declare const FacebookUtils: {
* @returns {Promise}
*/
unlink: (user: any, options: any) => any;
- _getAuthProvider(): AuthProviderType;
+ _getAuthProvider(): AuthProvider;
};
export default FacebookUtils;
diff --git a/types/LiveQuerySubscription.d.ts b/types/LiveQuerySubscription.d.ts
index e312d2a86..0008a4eee 100644
--- a/types/LiveQuerySubscription.d.ts
+++ b/types/LiveQuerySubscription.d.ts
@@ -81,7 +81,7 @@ import type ParseQuery from './ParseQuery';
*
* });
*/
-declare class Subscription {
+declare class LiveQuerySubscription {
id: string | number;
query: ParseQuery;
sessionToken?: string;
@@ -99,4 +99,4 @@ declare class Subscription {
*/
unsubscribe(): Promise;
}
-export default Subscription;
+export default LiveQuerySubscription;
diff --git a/types/Parse.d.ts b/types/Parse.d.ts
index 4500ea0ab..55237e7ff 100644
--- a/types/Parse.d.ts
+++ b/types/Parse.d.ts
@@ -347,16 +347,7 @@ declare const Parse: {
headers?: any,
options?: import('./RESTController').FullOptions
) => Promise;
- handleError: (
- err? /**
- * Call this method to set your LocalDatastoreStorage engine
- * If using React-Native use {@link Parse.setAsyncStorage Parse.setAsyncStorage()}
- *
- * @param {LocalDatastoreController} controller a data storage.
- * @static
- */
- : any
- ) => void;
+ handleError: (err?: any) => void;
}): void;
getRESTController(): {
request: (
@@ -372,25 +363,11 @@ declare const Parse: {
headers?: any,
options?: import('./RESTController').FullOptions
) => Promise;
- handleError: (
- err? /**
- * Call this method to set your LocalDatastoreStorage engine
- * If using React-Native use {@link Parse.setAsyncStorage Parse.setAsyncStorage()}
- *
- * @param {LocalDatastoreController} controller a data storage.
- * @static
- */
- : any
- ) => void;
+ handleError: (err?: any) => void;
};
setSchemaController(controller: {
purge: (className: string) => Promise;
- get: (
- className: string,
- options?: import('./RESTController').RequestOptions
- ) => Promise<{
- results: Schema[];
- }>;
+ get: (className: string, options?: import('./RESTController').RequestOptions) => Promise;
delete: (
className: string,
options?: import('./RESTController').RequestOptions
@@ -414,12 +391,7 @@ declare const Parse: {
}): void;
getSchemaController(): {
purge: (className: string) => Promise;
- get: (
- className: string,
- options?: import('./RESTController').RequestOptions
- ) => Promise<{
- results: Schema[];
- }>;
+ get: (className: string, options?: import('./RESTController').RequestOptions) => Promise;
delete: (
className: string,
options?: import('./RESTController').RequestOptions
@@ -731,10 +703,10 @@ declare const Parse: {
FacebookUtils: {
init(options: any): void;
isLinked(user: any): any;
- logIn(permissions: any, options: any): Promise;
+ logIn(permissions: any, options: any): Promise>;
link(user: any, permissions: any, options: any): any;
unlink: (user: any, options: any) => any;
- _getAuthProvider(): import('./ParseUser').AuthProviderType;
+ _getAuthProvider(): import('./ParseUser').AuthProvider;
};
File: typeof File;
GeoPoint: typeof GeoPoint;
diff --git a/types/ParseACL.d.ts b/types/ParseACL.d.ts
index fc8da8570..322a9f855 100644
--- a/types/ParseACL.d.ts
+++ b/types/ParseACL.d.ts
@@ -23,9 +23,9 @@ type ByIdMap = {
declare class ParseACL {
permissionsById: ByIdMap;
/**
- * @param {(Parse.User | object)} arg1 The user to initialize the ACL for
+ * @param {(Parse.User | object | null)} arg1 The user to initialize the ACL for
*/
- constructor(arg1: ParseUser | ByIdMap);
+ constructor(arg1?: ParseUser | ByIdMap | null);
/**
* Returns a JSON-encoded version of the ACL.
*
diff --git a/types/ParseGeoPoint.d.ts b/types/ParseGeoPoint.d.ts
index 7c2c6b432..0d8271878 100644
--- a/types/ParseGeoPoint.d.ts
+++ b/types/ParseGeoPoint.d.ts
@@ -29,7 +29,7 @@ declare class ParseGeoPoint {
* @param {number} arg2 The longitude of the GeoPoint
*/
constructor(
- arg1:
+ arg1?:
| Array
| {
latitude: number;
diff --git a/types/ParseInstallation.d.ts b/types/ParseInstallation.d.ts
index 1743dce1d..28cf2a661 100644
--- a/types/ParseInstallation.d.ts
+++ b/types/ParseInstallation.d.ts
@@ -1,5 +1,4 @@
-import ParseObject from './ParseObject';
-import type { AttributeMap } from './ObjectStateMutations';
+import ParseObject, { Attributes } from './ParseObject';
type DeviceInterface = {
IOS: string;
MACOS: string;
@@ -19,11 +18,11 @@ type DeviceInterface = {
*
* @alias Parse.Installation
*/
-declare class ParseInstallation extends ParseObject {
+declare class ParseInstallation extends ParseObject {
/**
* @param {object} attributes The initial set of data to store in the object.
*/
- constructor(attributes?: AttributeMap);
+ constructor(attributes?: T);
/**
* A unique identifier for this installation’s client application. In iOS, this is the Bundle Identifier.
*
@@ -154,7 +153,7 @@ declare class ParseInstallation extends ParseObject {
* @param {...any} args
* @returns {Promise}
*/
- fetch(...args: Array): Promise;
+ fetch(...args: Array): Promise;
/**
* Wrap the default save behavior with functionality to update the local storage.
* If the installation is deleted on the server, retry saving a new installation.
diff --git a/types/ParseObject.d.ts b/types/ParseObject.d.ts
index 7b49bfce2..db6233798 100644
--- a/types/ParseObject.d.ts
+++ b/types/ParseObject.d.ts
@@ -5,6 +5,8 @@ import { Op } from './ParseOp';
import ParseRelation from './ParseRelation';
import type { AttributeMap, OpsMap } from './ObjectStateMutations';
import type { RequestOptions, FullOptions } from './RESTController';
+import type ParseGeoPoint from './ParseGeoPoint';
+import type ParsePolygon from './ParsePolygon';
export type Pointer = {
__type: string;
className: string;
@@ -28,6 +30,36 @@ type FetchOptions = {
include?: string | string[];
context?: AttributeMap;
};
+export type SetOptions = {
+ ignoreValidation: boolean;
+};
+export interface Attributes {
+ [key: string]: any;
+}
+interface JSONBaseAttributes {
+ objectId: string;
+ createdAt: string;
+ updatedAt: string;
+}
+type Encode = T extends ParseObject
+ ? ReturnType | Pointer
+ : T extends ParseACL | ParseGeoPoint | ParsePolygon | ParseRelation | ParseFile
+ ? ReturnType
+ : T extends Date
+ ? {
+ __type: 'Date';
+ iso: string;
+ }
+ : T extends RegExp
+ ? string
+ : T extends Array
+ ? Array>
+ : T extends object
+ ? ToJSON
+ : T;
+type ToJSON = {
+ [K in keyof T]: Encode;
+};
/**
* Creates a new model with defined attributes.
*
@@ -46,7 +78,7 @@ type FetchOptions = {
*
* @alias Parse.Object
*/
-declare class ParseObject {
+declare class ParseObject {
/**
* @param {string} className The class name for the object
* @param {object} attributes The initial set of data to store in the object.
@@ -60,12 +92,8 @@ declare class ParseObject {
className: string;
[attr: string]: any;
},
- attributes?: {
- [attr: string]: any;
- },
- options?: {
- ignoreValidation: boolean;
- }
+ attributes?: T | Attributes,
+ options?: SetOptions
);
/**
* The ID of this object, unique within its class.
@@ -76,7 +104,7 @@ declare class ParseObject {
_localId?: string;
_objCount: number;
className: string;
- get attributes(): AttributeMap;
+ get attributes(): T;
/**
* The first time this object was saved on the server.
*
@@ -108,7 +136,7 @@ declare class ParseObject {
id: string;
className: string;
};
- _getServerData(): AttributeMap;
+ _getServerData(): Attributes;
_clearServerData(): void;
_getPendingOps(): Array;
/**
@@ -116,14 +144,14 @@ declare class ParseObject {
* these fields will be cleared
*/
_clearPendingOps(keysToClear?: Array): void;
- _getDirtyObjectAttributes(): AttributeMap;
- _toFullJSON(seen?: Array, offline?: boolean): AttributeMap;
- _getSaveJSON(): AttributeMap;
+ _getDirtyObjectAttributes(): Attributes;
+ _toFullJSON(seen?: Array, offline?: boolean): Attributes;
+ _getSaveJSON(): Attributes;
_getSaveParams(): SaveParams;
- _finishFetch(serverData: AttributeMap): void;
+ _finishFetch(serverData: Attributes): void;
_setExisted(existed: boolean): void;
_migrateId(serverId: string): void;
- _handleSaveResponse(response: AttributeMap, status: number): void;
+ _handleSaveResponse(response: Attributes, status: number): void;
_handleSaveError(): void;
static _getClassMap(): AttributeMap;
static _getRequestOptions(
@@ -143,7 +171,7 @@ declare class ParseObject {
* @param offline
* @returns {object}
*/
- toJSON(seen: Array | void, offline?: boolean): AttributeMap;
+ toJSON(seen: Array | void, offline?: boolean): ToJSON & JSONBaseAttributes;
/**
* Determines whether this ParseObject is equal to another ParseObject
*
@@ -197,7 +225,9 @@ declare class ParseObject {
* @param {string} attr The attribute to get the relation for.
* @returns {Parse.Relation}
*/
- relation(attr: string): ParseRelation;
+ relation = Extract>(
+ attr: T[K] extends ParseRelation ? K : never
+ ): ParseRelation;
/**
* Gets the HTML-escaped value of an attribute.
*
@@ -353,7 +383,7 @@ declare class ParseObject {
*
* @returns {Parse.Object}
*/
- newInstance(): any;
+ newInstance(): this;
/**
* Returns true if this object has never been saved to Parse.
*
@@ -397,7 +427,7 @@ declare class ParseObject {
* @returns {Parse.Error|boolean} False if the data is valid. An error object otherwise.
* @see Parse.Object#set
*/
- validate(attrs: AttributeMap): ParseError | boolean;
+ validate(attrs: Attributes): ParseError | boolean;
/**
* Returns the ACL for this object.
*
@@ -443,7 +473,7 @@ declare class ParseObject {
* @returns {Promise} A promise that is fulfilled when the fetch
* completes.
*/
- fetch(options: FetchOptions): Promise;
+ fetch(options: FetchOptions): Promise;
/**
* Fetch the model from the server. If the server's representation of the
* model differs from its current attributes, they will be overriden.
@@ -464,8 +494,8 @@ declare class ParseObject {
*/
fetchWithInclude(
keys: string | Array>,
- options: RequestOptions
- ): Promise;
+ options?: RequestOptions
+ ): Promise;
/**
* Saves this object to the server at some unspecified time in the future,
* even if Parse is currently inaccessible.
@@ -555,14 +585,14 @@ declare class ParseObject {
* completes.
*/
save(
- arg1:
+ arg1?:
| undefined
| string
| {
[attr: string]: any;
}
| null,
- arg2: SaveOptions | any,
+ arg2?: SaveOptions | any,
arg3?: SaveOptions
): Promise;
/**
@@ -709,10 +739,7 @@ declare class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static fetchAll(
- list: Array,
- options?: RequestOptions
- ): Promise;
+ static fetchAll(list: T[], options?: RequestOptions): Promise;
/**
* Fetches the given list of Parse.Object.
*
@@ -742,11 +769,11 @@ declare class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static fetchAllWithInclude(
- list: Array,
+ static fetchAllWithInclude(
+ list: T[],
keys: string | Array>,
- options: RequestOptions
- ): Promise;
+ options?: RequestOptions
+ ): Promise;
/**
* Fetches the given list of Parse.Object if needed.
* If any error is encountered, stops and calls the error handler.
@@ -777,11 +804,11 @@ declare class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static fetchAllIfNeededWithInclude(
- list: Array,
+ static fetchAllIfNeededWithInclude(
+ list: T[],
keys: string | Array>,
- options: RequestOptions
- ): Promise;
+ options?: RequestOptions
+ ): Promise;
/**
* Fetches the given list of Parse.Object if needed.
* If any error is encountered, stops and calls the error handler.
@@ -809,10 +836,7 @@ declare class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static fetchAllIfNeeded(
- list: Array,
- options: FetchOptions
- ): Promise;
+ static fetchAllIfNeeded(list: T[], options?: FetchOptions): Promise;
static handleIncludeOptions(options: { include?: string | string[] }): any[];
/**
* Destroy the given list of models on the server if it was already persisted.
@@ -872,7 +896,7 @@ declare class ParseObject {
static destroyAll(
list: Array,
options?: SaveOptions
- ): Promise;
+ ): Promise | ParseObject[]>;
/**
* Saves the given list of Parse.Object.
* If any error is encountered, stops and calls the error handler.
@@ -902,10 +926,7 @@ declare class ParseObject {
* @static
* @returns {Parse.Object[]}
*/
- static saveAll(
- list: Array,
- options?: SaveOptions
- ): Promise;
+ static saveAll(list: T, options?: SaveOptions): Promise;
/**
* Creates a reference to a subclass of Parse.Object with the given id. This
* does not exist on Parse.Object, only on subclasses.
diff --git a/types/ParseQuery.d.ts b/types/ParseQuery.d.ts
index 968f13f80..dbd841983 100644
--- a/types/ParseQuery.d.ts
+++ b/types/ParseQuery.d.ts
@@ -88,7 +88,7 @@ export type QueryJSON = {
*
* @alias Parse.Query
*/
-declare class ParseQuery {
+declare class ParseQuery {
/**
* @property {string} className
*/
@@ -117,28 +117,28 @@ declare class ParseQuery {
/**
* @param {(string | Parse.Object)} objectClass An instance of a subclass of Parse.Object, or a Parse className string.
*/
- constructor(objectClass: string | ParseObject);
+ constructor(objectClass: string | (new (...args: any[]) => T | ParseObject));
/**
* Adds constraint that at least one of the passed in queries matches.
*
* @param {Array} queries
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- _orQuery(queries: Array): ParseQuery;
+ _orQuery(queries: Array): this;
/**
* Adds constraint that all of the passed in queries match.
*
* @param {Array} queries
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- _andQuery(queries: Array): ParseQuery;
+ _andQuery(queries: Array): this;
/**
* Adds constraint that none of the passed in queries match.
*
* @param {Array} queries
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- _norQuery(queries: Array): ParseQuery;
+ _norQuery(queries: Array): this;
/**
* Helper for condition queries
*
@@ -147,7 +147,7 @@ declare class ParseQuery {
* @param value
* @returns {Parse.Query}
*/
- _addCondition(key: string, condition: string, value: any): ParseQuery;
+ _addCondition(key: string, condition: string, value: any): this;
/**
* Converts string for regular expression at the beginning
*
@@ -183,7 +183,7 @@ declare class ParseQuery {
* @param {QueryJSON} json from Parse.Query.toJSON() method
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withJSON(json: QueryJSON): ParseQuery;
+ withJSON(json: QueryJSON): this;
/**
* Static method to restore Parse.Query by json representation
* Internally calling Parse.Query.withJSON
@@ -210,7 +210,7 @@ declare class ParseQuery {
* @returns {Promise} A promise that is resolved with the result when
* the query completes.
*/
- get(objectId: string, options?: QueryOptions): Promise;
+ get(objectId: string, options?: QueryOptions): Promise;
/**
* Retrieves a list of ParseObjects that satisfy this query.
*
@@ -226,7 +226,7 @@ declare class ParseQuery {
* @returns {Promise} A promise that is resolved with the results when
* the query completes.
*/
- find(options?: QueryOptions): Promise>;
+ find(options?: QueryOptions): Promise;
/**
* Retrieves a complete list of ParseObjects that satisfy this query.
* Using `eachBatch` under the hood to fetch all the valid objects.
@@ -242,7 +242,7 @@ declare class ParseQuery {
* @returns {Promise} A promise that is resolved with the results when
* the query completes.
*/
- findAll(options?: BatchOptions): Promise>;
+ findAll(options?: BatchOptions): Promise;
/**
* Counts the number of objects that match this query.
*
@@ -303,7 +303,7 @@ declare class ParseQuery {
* @returns {Promise} A promise that is resolved with the object when
* the query completes.
*/
- first(options?: QueryOptions): Promise;
+ first(options?: QueryOptions): Promise;
/**
* Iterates over objects matching a query, calling a callback for each batch.
* If the callback returns a promise, the iteration will not continue until
@@ -325,7 +325,10 @@ declare class ParseQuery {
* @returns {Promise} A promise that will be fulfilled once the
* iteration has completed.
*/
- eachBatch(callback: (objs: Array) => void, options?: BatchOptions): Promise;
+ eachBatch(
+ callback: (objs: T[]) => PromiseLike | void,
+ options?: BatchOptions
+ ): Promise;
/**
* Iterates over each result of a query, calling a callback for each one. If
* the callback returns a promise, the iteration will not continue until
@@ -346,21 +349,21 @@ declare class ParseQuery {
* @returns {Promise} A promise that will be fulfilled once the
* iteration has completed.
*/
- each(callback: (obj: ParseObject) => any, options?: BatchOptions): Promise;
+ each(callback: (obj: T) => PromiseLike | void, options?: BatchOptions): Promise;
/**
* Adds a hint to force index selection. (https://docs.mongodb.com/manual/reference/operator/meta/hint/)
*
* @param {(string|object)} value String or Object of index that should be used when executing query
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- hint(value: any): ParseQuery;
+ hint(value: any): this;
/**
* Investigates the query execution plan. Useful for optimizing queries. (https://docs.mongodb.com/manual/reference/operator/meta/explain/)
*
* @param {boolean} explain Used to toggle the information on the query plan.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- explain(explain?: boolean): ParseQuery;
+ explain(explain?: boolean): this;
/**
* Iterates over each result of a query, calling a callback for each one. If
* the callback returns a promise, the iteration will not continue until
@@ -456,7 +459,7 @@ declare class ParseQuery {
[key: string]: any;
},
value?: any
- ): ParseQuery;
+ ): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be not equal to the provided value.
@@ -472,7 +475,7 @@ declare class ParseQuery {
[key: string]: any;
},
value?: any
- ): ParseQuery;
+ ): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be less than the provided value.
@@ -481,7 +484,7 @@ declare class ParseQuery {
* @param value The value that provides an upper bound.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- lessThan(key: string, value: any): ParseQuery;
+ lessThan(key: string, value: any): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be greater than the provided value.
@@ -490,7 +493,7 @@ declare class ParseQuery {
* @param value The value that provides an lower bound.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- greaterThan(key: string, value: any): ParseQuery;
+ greaterThan(key: string, value: any): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be less than or equal to the provided value.
@@ -499,7 +502,7 @@ declare class ParseQuery {
* @param value The value that provides an upper bound.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- lessThanOrEqualTo(key: string, value: any): ParseQuery;
+ lessThanOrEqualTo(key: string, value: any): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be greater than or equal to the provided value.
@@ -508,7 +511,7 @@ declare class ParseQuery {
* @param {*} value The value that provides an lower bound.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- greaterThanOrEqualTo(key: string, value: any): ParseQuery;
+ greaterThanOrEqualTo(key: string, value: any): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be contained in the provided list of values.
@@ -517,7 +520,7 @@ declare class ParseQuery {
* @param {Array<*>} value The values that will match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- containedIn(key: string, value: Array): ParseQuery;
+ containedIn(key: string, value: Array): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* not be contained in the provided list of values.
@@ -526,7 +529,7 @@ declare class ParseQuery {
* @param {Array<*>} value The values that will not match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- notContainedIn(key: string, value: Array): ParseQuery;
+ notContainedIn(key: string, value: Array): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be contained by the provided list of values. Get objects where all array elements match.
@@ -535,7 +538,7 @@ declare class ParseQuery {
* @param {Array} values The values that will match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- containedBy(key: string, values: Array): ParseQuery;
+ containedBy(key: string, values: Array): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* contain each one of the provided list of values.
@@ -544,7 +547,7 @@ declare class ParseQuery {
* @param {Array} values The values that will match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- containsAll(key: string, values: Array): ParseQuery;
+ containsAll(key: string, values: Array): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* contain each one of the provided list of values starting with given strings.
@@ -553,21 +556,21 @@ declare class ParseQuery {
* @param {Array} values The string values that will match as starting string.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- containsAllStartingWith(key: string, values: Array): ParseQuery;
+ containsAllStartingWith(key: string, values: Array): this;
/**
* Adds a constraint for finding objects that contain the given key.
*
* @param {string} key The key that should exist.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- exists(key: string): ParseQuery;
+ exists(key: string): this;
/**
* Adds a constraint for finding objects that do not contain a given key.
*
* @param {string} key The key that should not exist
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- doesNotExist(key: string): ParseQuery;
+ doesNotExist(key: string): this;
/**
* Adds a regular expression constraint for finding string values that match
* the provided regular expression.
@@ -578,7 +581,7 @@ declare class ParseQuery {
* @param {string} modifiers The regular expression mode.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- matches(key: string, regex: RegExp | string, modifiers: string): ParseQuery;
+ matches(key: string, regex: RegExp | string, modifiers?: string): this;
/**
* Adds a constraint that requires that a key's value matches a Parse.Query
* constraint.
@@ -588,7 +591,7 @@ declare class ParseQuery {
* @param {Parse.Query} query The query that should match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- matchesQuery(key: string, query: ParseQuery): ParseQuery;
+ matchesQuery(key: string, query: ParseQuery): this;
/**
* Adds a constraint that requires that a key's value not matches a
* Parse.Query constraint.
@@ -598,7 +601,7 @@ declare class ParseQuery {
* @param {Parse.Query} query The query that should not match.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- doesNotMatchQuery(key: string, query: ParseQuery): ParseQuery;
+ doesNotMatchQuery(key: string, query: ParseQuery): this;
/**
* Adds a constraint that requires that a key's value matches a value in
* an object returned by a different Parse.Query.
@@ -610,7 +613,7 @@ declare class ParseQuery {
* @param {Parse.Query} query The query to run.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- matchesKeyInQuery(key: string, queryKey: string, query: ParseQuery): ParseQuery;
+ matchesKeyInQuery(key: string, queryKey: string, query: ParseQuery): this;
/**
* Adds a constraint that requires that a key's value not match a value in
* an object returned by a different Parse.Query.
@@ -622,7 +625,7 @@ declare class ParseQuery {
* @param {Parse.Query} query The query to run.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- doesNotMatchKeyInQuery(key: string, queryKey: string, query: ParseQuery): ParseQuery;
+ doesNotMatchKeyInQuery(key: string, queryKey: string, query: ParseQuery): this;
/**
* Adds a constraint for finding string values that contain a provided
* string. This may be slow for large datasets.
@@ -631,7 +634,7 @@ declare class ParseQuery {
* @param {string} substring The substring that the value must contain.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- contains(key: string, substring: string): ParseQuery;
+ contains(key: string, substring: string): this;
/**
* Adds a constraint for finding string values that contain a provided
* string. This may be slow for large datasets. Requires Parse-Server > 2.5.0
@@ -661,7 +664,7 @@ declare class ParseQuery {
* @param {boolean} options.diacriticSensitive A boolean flag to enable or disable diacritic sensitive search.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fullText(key: string, value: string, options?: FullTextQueryOptions): ParseQuery;
+ fullText(key: string, value: string, options?: FullTextQueryOptions): this;
/**
* Method to sort the full text search by text score
*
@@ -678,7 +681,7 @@ declare class ParseQuery {
* @param {string} modifiers The regular expression mode.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- startsWith(key: string, prefix: string, modifiers: string): ParseQuery;
+ startsWith(key: string, prefix: string, modifiers?: string): this;
/**
* Adds a constraint for finding string values that end with a provided
* string. This will be slow for large datasets.
@@ -688,7 +691,7 @@ declare class ParseQuery {
* @param {string} modifiers The regular expression mode.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- endsWith(key: string, suffix: string, modifiers: string): ParseQuery;
+ endsWith(key: string, suffix: string, modifiers?: string): this;
/**
* Adds a proximity based constraint for finding objects with key point
* values near the point given.
@@ -697,7 +700,7 @@ declare class ParseQuery {
* @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- near(key: string, point: ParseGeoPoint): ParseQuery;
+ near(key: string, point: ParseGeoPoint): this;
/**
* Adds a proximity based constraint for finding objects with key point
* values near the point given and within the maximum distance given.
@@ -710,12 +713,7 @@ declare class ParseQuery {
* defaults to true.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinRadians(
- key: string,
- point: ParseGeoPoint,
- maxDistance: number,
- sorted: boolean
- ): ParseQuery;
+ withinRadians(key: string, point: ParseGeoPoint, maxDistance: number, sorted?: boolean): this;
/**
* Adds a proximity based constraint for finding objects with key point
* values near the point given and within the maximum distance given.
@@ -729,7 +727,7 @@ declare class ParseQuery {
* defaults to true.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinMiles(key: string, point: ParseGeoPoint, maxDistance: number, sorted: boolean): ParseQuery;
+ withinMiles(key: string, point: ParseGeoPoint, maxDistance: number, sorted: boolean): this;
/**
* Adds a proximity based constraint for finding objects with key point
* values near the point given and within the maximum distance given.
@@ -743,12 +741,7 @@ declare class ParseQuery {
* defaults to true.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinKilometers(
- key: string,
- point: ParseGeoPoint,
- maxDistance: number,
- sorted: boolean
- ): ParseQuery;
+ withinKilometers(key: string, point: ParseGeoPoint, maxDistance: number, sorted: boolean): this;
/**
* Adds a constraint to the query that requires a particular key's
* coordinates be contained within a given rectangular geographic bounding
@@ -761,7 +754,7 @@ declare class ParseQuery {
* The upper-right inclusive corner of the box.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinGeoBox(key: string, southwest: ParseGeoPoint, northeast: ParseGeoPoint): ParseQuery;
+ withinGeoBox(key: string, southwest: ParseGeoPoint, northeast: ParseGeoPoint): this;
/**
* Adds a constraint to the query that requires a particular key's
* coordinates be contained within and on the bounds of a given polygon.
@@ -773,7 +766,7 @@ declare class ParseQuery {
* @param {Array} points Array of Coordinates / GeoPoints
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withinPolygon(key: string, points: Array>): ParseQuery;
+ withinPolygon(key: string, points: Array>): this;
/**
* Add a constraint to the query that requires a particular key's
* coordinates that contains a ParseGeoPoint
@@ -782,7 +775,7 @@ declare class ParseQuery {
* @param {Parse.GeoPoint} point
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- polygonContains(key: string, point: ParseGeoPoint): ParseQuery;
+ polygonContains(key: string, point: ParseGeoPoint): this;
/**
* Sorts the results in ascending order by the given key.
*
@@ -790,7 +783,7 @@ declare class ParseQuery {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- ascending(...keys: Array): ParseQuery;
+ ascending(...keys: Array): this;
/**
* Sorts the results in ascending order by the given key,
* but can also add secondary sort descriptors without overwriting _order.
@@ -799,7 +792,7 @@ declare class ParseQuery {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- addAscending(...keys: Array): ParseQuery;
+ addAscending(...keys: Array): this;
/**
* Sorts the results in descending order by the given key.
*
@@ -807,7 +800,7 @@ declare class ParseQuery {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- descending(...keys: Array): ParseQuery;
+ descending(...keys: Array): this;
/**
* Sorts the results in descending order by the given key,
* but can also add secondary sort descriptors without overwriting _order.
@@ -816,7 +809,7 @@ declare class ParseQuery {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- addDescending(...keys: Array): ParseQuery;
+ addDescending(...keys: Array): this;
/**
* Sets the number of results to skip before returning any results.
* This is useful for pagination.
@@ -825,14 +818,14 @@ declare class ParseQuery {
* @param {number} n the number of results to skip.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- skip(n: number): ParseQuery;
+ skip(n: number): this;
/**
* Sets the limit of the number of results to return. The default limit is 100.
*
* @param {number} n the number of results to limit to.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- limit(n: number): ParseQuery;
+ limit(n: number): this;
/**
* Sets the flag to include with response the total number of objects satisfying this query,
* despite limits/skip. Might be useful for pagination.
@@ -842,7 +835,7 @@ declare class ParseQuery {
* @param {boolean} includeCount false - disable, true - enable.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- withCount(includeCount?: boolean): ParseQuery;
+ withCount(includeCount?: boolean): this;
/**
* Includes nested Parse.Objects for the provided key. You can use dot
* notation to specify which fields in the included object are also fetched.
@@ -854,7 +847,7 @@ declare class ParseQuery {
* @param {...string|Array} keys The name(s) of the key(s) to include.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- include(...keys: Array>): ParseQuery;
+ include(...keys: Array>): this;
/**
* Includes all nested Parse.Objects one level deep.
*
@@ -862,7 +855,7 @@ declare class ParseQuery {
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- includeAll(): ParseQuery;
+ includeAll(): this;
/**
* Restricts the fields of the returned Parse.Objects to include only the
* provided keys. If this is called multiple times, then all of the keys
@@ -871,7 +864,7 @@ declare class ParseQuery {
* @param {...string|Array} keys The name(s) of the key(s) to include.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- select(...keys: Array>): ParseQuery;
+ select(...keys: Array>): this;
/**
* Restricts the fields of the returned Parse.Objects to all keys except the
* provided keys. Exclude takes precedence over select and include.
@@ -881,7 +874,7 @@ declare class ParseQuery {
* @param {...string|Array} keys The name(s) of the key(s) to exclude.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- exclude(...keys: Array>): ParseQuery;
+ exclude(...keys: Array>): this;
/**
* Restricts live query to trigger only for watched fields.
*
@@ -890,7 +883,7 @@ declare class ParseQuery {
* @param {...string|Array} keys The name(s) of the key(s) to watch.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- watch(...keys: Array>): ParseQuery;
+ watch(...keys: Array>): this;
/**
* Changes the read preference that the backend will use when performing the query to the database.
*
@@ -903,7 +896,7 @@ declare class ParseQuery {
readPreference: string,
includeReadPreference?: string,
subqueryReadPreference?: string
- ): ParseQuery;
+ ): this;
/**
* Subscribe this query to get liveQuery updates
*
@@ -911,7 +904,7 @@ declare class ParseQuery {
* @returns {Promise} Returns the liveQuerySubscription, it's an event emitter
* which can be used to get liveQuery updates.
*/
- subscribe(sessionToken?: string): Promise;
+ subscribe(sessionToken?: string | null): Promise;
/**
* Constructs a Parse.Query that is the OR of the passed in queries. For
* example:
@@ -956,32 +949,32 @@ declare class ParseQuery {
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fromNetwork(): ParseQuery;
+ fromNetwork(): this;
/**
* Changes the source of this query to all pinned objects.
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fromLocalDatastore(): ParseQuery;
+ fromLocalDatastore(): this;
/**
* Changes the source of this query to the default group of pinned objects.
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fromPin(): ParseQuery;
+ fromPin(): this;
/**
* Changes the source of this query to a specific group of pinned objects.
*
* @param {string} name The name of query source.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- fromPinWithName(name?: string | null): ParseQuery;
+ fromPinWithName(name?: string | null): this;
/**
* Cancels the current network request (if any is running).
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- cancel(): ParseQuery;
+ cancel(): this;
_setRequestTask(options: any): void;
/**
* Sets a comment to the query so that the query
@@ -990,6 +983,6 @@ declare class ParseQuery {
* @param {string} value a comment can make your profile data easier to interpret and trace.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
- comment(value: string): ParseQuery;
+ comment(value: string): this;
}
export default ParseQuery;
diff --git a/types/ParseRelation.d.ts b/types/ParseRelation.d.ts
index 5426f7c83..facccad82 100644
--- a/types/ParseRelation.d.ts
+++ b/types/ParseRelation.d.ts
@@ -13,29 +13,32 @@ import type ParseQuery from './ParseQuery';
*
* @alias Parse.Relation
*/
-declare class ParseRelation {
- parent?: ParseObject;
+declare class ParseRelation<
+ S extends ParseObject = ParseObject,
+ T extends ParseObject = ParseObject,
+> {
+ parent?: S;
key?: string;
targetClassName?: string | null;
/**
* @param {Parse.Object} parent The parent of this relation.
* @param {string} key The key for this relation on the parent.
*/
- constructor(parent?: ParseObject, key?: string);
- _ensureParentAndKey(parent: ParseObject, key: string): void;
+ constructor(parent?: S, key?: string);
+ _ensureParentAndKey(parent: S, key: string): void;
/**
* Adds a Parse.Object or an array of Parse.Objects to the relation.
*
* @param {(Parse.Object|Array)} objects The item or items to add.
* @returns {Parse.Object} The parent of the relation.
*/
- add(objects: ParseObject | Array): ParseObject;
+ add(objects: T | T[]): S;
/**
* Removes a Parse.Object or an array of Parse.Objects from this relation.
*
* @param {(Parse.Object|Array)} objects The item or items to remove.
*/
- remove(objects: ParseObject | Array