Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Fix TypeScript error that namespace Parse cannot be found #2452

Merged
merged 4 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
- run: npm ci
- name: Build Types
run: npm run build:types
- name: Test Types
run: npm run test:types
- name: Lint Types
run: npm run lint:types
- name: Test Types
run: npm run test:types
check-docs:
name: Check Docs
timeout-minutes: 10
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"test": "cross-env PARSE_BUILD=node jest",
"test:mongodb": "npm run test:mongodb:runnerstart && npm run integration",
"test:mongodb:runnerstart": "mongodb-runner start -- --port 27017",
"test:types": "dtslint --expectOnly types",
"test:types": "dtslint --expectOnly types 2>&1 | tee temp.txt; echo \"Type tests failed: $(grep 'ERROR:' temp.txt -c)\"; rm temp.txt;",
"posttest:mongodb": "mongodb-runner stop --all",
"lint": "eslint --cache src/ integration/",
"lint:fix": "eslint --fix --cache src/ integration/",
Expand Down
138 changes: 29 additions & 109 deletions src/Parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,101 +37,21 @@ import LocalDatastoreController from './LocalDatastoreController';
import StorageController from './StorageController';
import WebSocketController from './WebSocketController';

/**
* Contains all Parse API classes and functions.
*
* @static
* @global
* @class
* @hideconstructor
*/
interface ParseType {
ACL: typeof ACL;
Parse?: ParseType;
Analytics: typeof Analytics;
AnonymousUtils: typeof AnonymousUtils;
Cloud: typeof Cloud & {
/** only available in server environments */
useMasterKey?: () => void;
};
CLP: typeof CLP;
CoreManager: typeof CoreManager;
Config: typeof Config;
Error: typeof ParseError;
EventuallyQueue: typeof EventuallyQueue;
FacebookUtils: typeof FacebookUtils;
File: typeof File;
GeoPoint: typeof GeoPoint;
Hooks?: any;
Polygon: typeof Polygon;
Installation: typeof Installation;
LocalDatastore: typeof LocalDatastore;
Object: typeof ParseObject;
Op: {
Set: typeof ParseOp.SetOp;
Unset: typeof ParseOp.UnsetOp;
Increment: typeof ParseOp.IncrementOp;
Add: typeof ParseOp.AddOp;
Remove: typeof ParseOp.RemoveOp;
AddUnique: typeof ParseOp.AddUniqueOp;
Relation: typeof ParseOp.RelationOp;
};
Push: typeof Push;
Query: typeof Query;
Relation: typeof Relation;
Role: typeof Role;
Schema: typeof Schema;
Session: typeof Session;
Storage: typeof Storage;
User: typeof User;
LiveQuery: typeof ParseLiveQuery;
LiveQueryClient: typeof LiveQueryClient;

initialize(applicationId: string, javaScriptKey: string): void;
_initialize(applicationId: string, javaScriptKey: string, masterKey?: string): void;
setAsyncStorage(storage: any): void;
setLocalDatastoreController(controller: any): void;
getServerHealth(): Promise<any>;

applicationId: string;
javaScriptKey: string;
masterKey: string;
serverURL: string;
serverAuthToken: string;
serverAuthType: string;
liveQueryServerURL: string;
encryptedUser: boolean;
secret: string;
idempotency: boolean;
allowCustomObjectId: boolean;
IndexedDB?: any;
_request(...args: any[]): void;
_ajax(...args: any[]): void;
_decode(...args: any[]): void;
_encode(...args: any[]): void;
_getInstallationId?(): Promise<string>;
enableLocalDatastore(polling: boolean, ms: number): void;
isLocalDatastoreEnabled(): boolean;
dumpLocalDatastore(): void;
enableEncryptedUser(): void;
isEncryptedUserEnabled(): void;
}

const Parse: ParseType = {
ACL: ACL,
Analytics: Analytics,
AnonymousUtils: AnonymousUtils,
Cloud: Cloud,
CLP: CLP,
CoreManager: CoreManager,
Config: Config,
const Parse = {
ACL,
Analytics,
AnonymousUtils,
Cloud,
CLP,
CoreManager,
Config,
Error: ParseError,
FacebookUtils: FacebookUtils,
File: File,
GeoPoint: GeoPoint,
Polygon: Polygon,
Installation: Installation,
LocalDatastore: LocalDatastore,
FacebookUtils,
File,
GeoPoint,
Polygon,
Installation,
LocalDatastore,
Object: ParseObject,
Op: {
Set: ParseOp.SetOp,
Expand All @@ -142,15 +62,15 @@ const Parse: ParseType = {
AddUnique: ParseOp.AddUniqueOp,
Relation: ParseOp.RelationOp,
},
Push: Push,
Query: Query,
Relation: Relation,
Role: Role,
Schema: Schema,
Session: Session,
Storage: Storage,
User: User,
LiveQueryClient: LiveQueryClient,
Push,
Query,
Relation,
Role,
Schema,
Session,
Storage,
User,
LiveQueryClient,
IndexedDB: undefined,
Hooks: undefined,
Parse: undefined,
Expand Down Expand Up @@ -314,10 +234,10 @@ const Parse: ParseType = {
* @member {ParseLiveQuery} Parse.LiveQuery
* @static
*/
set LiveQuery(liveQuery: typeof ParseLiveQuery) {
set LiveQuery(liveQuery: ParseLiveQuery) {
CoreManager.setLiveQuery(liveQuery);
},
get LiveQuery() {
get LiveQuery(): ParseLiveQuery {
return CoreManager.getLiveQuery();
},

Expand Down Expand Up @@ -404,15 +324,15 @@ const Parse: ParseType = {
* @param [ms] Milliseconds to ping the server. Default 2000ms
* @static
*/
enableLocalDatastore(polling = true, ms = 2000) {
enableLocalDatastore(polling?: boolean, ms?: number) {
if (!this.applicationId) {
console.log("'enableLocalDataStore' must be called after 'initialize'");
return;
}
if (!this.LocalDatastore.isEnabled) {
this.LocalDatastore.isEnabled = true;
if (polling) {
CoreManager.getEventuallyQueue().poll(ms);
if (polling || typeof polling === 'undefined') {
CoreManager.getEventuallyQueue().poll(ms || 2000);
}
}
},
Expand Down Expand Up @@ -470,7 +390,7 @@ CoreManager.setRESTController(RESTController);
if (process.env.PARSE_BUILD === 'node') {
Parse.initialize = Parse._initialize;
Parse.Cloud = Parse.Cloud || ({} as any);
Parse.Cloud.useMasterKey = function () {
(Parse.Cloud as any).useMasterKey = function () {
CoreManager.set('USE_MASTER_KEY', true);
};
Parse.Hooks = Hooks;
Expand Down
Loading
Loading