From 2cc27287277b3e9af53ba8b31ed4642f618d16db Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 25 Mar 2025 13:22:25 -0500 Subject: [PATCH 1/2] refactor: Add stricter type checking --- .npmignore | 3 +- eslint.config.js | 6 +- integration/test/ParseUserTest.js | 4 - package.json | 2 +- src/Analytics.ts | 4 +- src/CoreManager.ts | 133 +++---- src/LocalDatastore.ts | 6 +- src/LocalDatastoreController.default.ts | 2 +- src/LocalDatastoreController.react-native.ts | 2 +- src/ObjectStateMutations.ts | 24 +- src/ParseACL.ts | 4 +- src/ParseCLP.ts | 9 +- src/ParseConfig.ts | 8 +- src/ParseFile.ts | 16 +- src/ParseInstallation.ts | 8 +- src/ParseObject.ts | 74 ++-- src/ParseOp.ts | 28 +- src/ParsePolygon.ts | 6 +- src/ParseQuery.ts | 98 ++--- src/ParseSchema.ts | 29 +- src/ParseUser.ts | 22 +- src/Push.ts | 4 +- src/RESTController.ts | 12 +- src/SingleInstanceStateController.ts | 8 +- src/Storage.ts | 4 +- src/StorageController.react-native.ts | 4 +- src/TaskQueue.ts | 7 +- src/UniqueInstanceStateController.ts | 2 +- src/__tests__/ParseObject-test.js | 6 +- src/arrayContainsObject.ts | 2 +- src/encode.ts | 4 +- src/interfaces/react-native.ts | 2 +- src/unique.ts | 2 +- src/unsavedChildren.ts | 10 +- types/Analytics.d.ts | 4 +- types/CoreManager.d.ts | 118 +++--- types/LocalDatastore.d.ts | 6 +- types/LocalDatastoreController.default.d.ts | 2 +- ...LocalDatastoreController.react-native.d.ts | 2 +- types/ObjectStateMutations.d.ts | 30 +- types/Parse.d.ts | 359 +++--------------- types/ParseACL.d.ts | 8 +- types/ParseCLP.d.ts | 8 +- types/ParseConfig.d.ts | 14 +- types/ParseFile.d.ts | 20 +- types/ParseInstallation.d.ts | 8 +- types/ParseObject.d.ts | 50 ++- types/ParseOp.d.ts | 28 +- types/ParsePolygon.d.ts | 6 +- types/ParseQuery.d.ts | 84 ++-- types/ParseSchema.d.ts | 40 +- types/ParseUser.d.ts | 22 +- types/Push.d.ts | 4 +- types/RESTController.d.ts | 8 +- types/SingleInstanceStateController.d.ts | 2 +- types/Storage.d.ts | 4 +- types/StorageController.react-native.d.ts | 4 +- types/TaskQueue.d.ts | 6 +- types/UniqueInstanceStateController.d.ts | 2 +- types/arrayContainsObject.d.ts | 2 +- types/encode.d.ts | 2 +- .../eslint.config.mjs | 0 types/unique.d.ts | 2 +- types/unsavedChildren.d.ts | 2 +- 64 files changed, 520 insertions(+), 882 deletions(-) rename eslint.config.test.mjs => types/eslint.config.mjs (100%) diff --git a/.npmignore b/.npmignore index 50d65e592..d01dcfdc6 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,2 @@ -types/tests +types/tests.ts +types/eslint.config.js diff --git a/eslint.config.js b/eslint.config.js index f457b3813..55e9349db 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -6,7 +6,8 @@ module.exports = tseslint.config({ files: ['**/*.js', '**/*.ts'], extends: [ eslint.configs.recommended, - ...tseslint.configs.recommended, + ...tseslint.configs.stylistic, + ...tseslint.configs.strict, ], plugins: { '@typescript-eslint': tseslint.plugin, @@ -34,6 +35,9 @@ module.exports = tseslint.config({ "@typescript-eslint/no-var-requires": "off", "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-require-imports": "off", + "@typescript-eslint/no-dynamic-delete": "off", + "@typescript-eslint/prefer-for-of": "off", + "@typescript-eslint/no-extraneous-class": "off", "@typescript-eslint/no-unused-vars": [ "error", { diff --git a/integration/test/ParseUserTest.js b/integration/test/ParseUserTest.js index 89ecfa460..4b1db73b4 100644 --- a/integration/test/ParseUserTest.js +++ b/integration/test/ParseUserTest.js @@ -6,10 +6,6 @@ const { v4: uuidv4 } = require('uuid'); const { twitterAuthData } = require('./helper'); class CustomUser extends Parse.User { - constructor(attributes) { - super(attributes); - } - doSomething() { return 5; } diff --git a/package.json b/package.json index 1f836b03a..e71a23e96 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "posttest:mongodb": "mongodb-runner stop --all", "lint": "eslint --cache src/ integration/", "lint:fix": "eslint --fix --cache src/ integration/", - "test:types": "eslint types/tests.ts -c eslint.config.test.mjs", + "test:types": "eslint types/tests.ts -c ./types/eslint.config.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/Analytics.ts b/src/Analytics.ts index 9a38f5912..d901b380a 100644 --- a/src/Analytics.ts +++ b/src/Analytics.ts @@ -40,7 +40,7 @@ import CoreManager from './CoreManager'; * @returns {Promise} A promise that is resolved when the round-trip * to the server completes. */ -export function track(name: string, dimensions: { [key: string]: string }): Promise { +export function track(name: string, dimensions: Record): Promise { name = name || ''; name = name.replace(/^\s*/, ''); name = name.replace(/\s*$/, ''); @@ -58,7 +58,7 @@ export function track(name: string, dimensions: { [key: string]: string }): Prom } const DefaultController = { - track(name: string, dimensions: { [key: string]: string }) { + track(name: string, dimensions: Record) { const path = 'events/' + name; const RESTController = CoreManager.getRESTController(); return RESTController.request('POST', path, { dimensions }); diff --git a/src/CoreManager.ts b/src/CoreManager.ts index f6889174a..047f2463f 100644 --- a/src/CoreManager.ts +++ b/src/CoreManager.ts @@ -15,28 +15,25 @@ import type ParseConfig from './ParseConfig'; import type LiveQueryClient from './LiveQueryClient'; import type ParseInstallation from './ParseInstallation'; -type AnalyticsController = { - track: (name: string, dimensions: { [key: string]: string }) => Promise; -}; -type CloudController = { +export interface AnalyticsController { + track: (name: string, dimensions: Record) => Promise; +} +export interface CloudController { run: (name: string, data: any, options?: RequestOptions) => Promise; getJobsData: (options?: RequestOptions) => Promise; /** Returns promise which resolves with JobStatusId of the job */ startJob: (name: string, data: any, options?: RequestOptions) => Promise; -}; -type ConfigController = { +} +export interface ConfigController { current: () => Promise | ParseConfig; get: (opts?: RequestOptions) => Promise; - save: ( - attrs: { [key: string]: any }, - masterKeyOnlyFlags?: { [key: string]: any } - ) => Promise; -}; -type CryptoController = { + save: (attrs: Record, masterKeyOnlyFlags?: Record) => Promise; +} +export interface CryptoController { encrypt: (obj: any, secretKey: string) => string; decrypt: (encryptedText: string, secretKey: any) => string; -}; -type FileController = { +} +export interface FileController { saveFile: (name: string, source: FileSource, options?: FullOptions) => Promise; saveBase64: ( name: string, @@ -45,34 +42,34 @@ type FileController = { ) => Promise<{ name: string; url: string }>; download: (uri: string, options?: any) => Promise<{ base64?: string; contentType?: string }>; deleteFile: (name: string, options?: { useMasterKey?: boolean }) => Promise; -}; -type InstallationController = { +} +export interface InstallationController { currentInstallationId: () => Promise; currentInstallation: () => Promise; updateInstallationOnDisk: (installation: ParseInstallation) => Promise; -}; -type ObjectController = { +} +export interface ObjectController { fetch: ( - object: ParseObject | Array, + object: ParseObject | ParseObject[], forceFetch: boolean, options?: RequestOptions - ) => Promise | ParseObject | undefined>; + ) => Promise<(ParseObject | undefined)[] | ParseObject | undefined>; save: ( - object: ParseObject | Array | null, + object: ParseObject | (ParseObject | ParseFile)[] | null, options?: RequestOptions - ) => Promise | ParseFile | undefined>; + ) => Promise; destroy: ( - object: ParseObject | Array, + object: ParseObject | ParseObject[], options?: RequestOptions - ) => Promise>; -}; -type ObjectStateController = { + ) => Promise; +} +export interface ObjectStateController { getState: (obj: any) => State | null; initializeState: (obj: any, initial?: State) => State; removeState: (obj: any) => State | null; getServerData: (obj: any) => AttributeMap; setServerData: (obj: any, attributes: AttributeMap) => void; - getPendingOps: (obj: any) => Array; + getPendingOps: (obj: any) => OpsMap[]; setPendingOp: (obj: any, attr: string, op?: Op) => void; pushPendingState: (obj: any) => void; popPendingState: (obj: any) => OpsMap | undefined; @@ -84,23 +81,19 @@ type ObjectStateController = { enqueueTask: (obj: any, task: () => Promise) => Promise; clearAllState: () => void; duplicateState: (source: any, dest: any) => void; -}; -type PushController = { +} +export interface PushController { send: (data: PushData, options?: FullOptions) => Promise; -}; -type QueryController = { +} +export interface QueryController { find( className: string, params: QueryJSON, options?: RequestOptions - ): Promise<{ results?: Array; className?: string; count?: number }>; - aggregate( - className: string, - params: any, - options?: RequestOptions - ): Promise<{ results?: Array }>; -}; -export type QueueObject = { + ): Promise<{ results?: ParseObject[]; className?: string; count?: number }>; + aggregate(className: string, params: any, options?: RequestOptions): Promise<{ results?: any[] }>; +} +export interface QueueObject { queueId: string; action: string; object: ParseObject; @@ -109,9 +102,9 @@ export type QueueObject = { className: string; hash: string; createdAt: Date; -}; -export type Queue = Array; -export type EventuallyQueue = { +} +export type Queue = QueueObject[]; +export interface EventuallyQueue { save: (object: ParseObject, serverOptions?: SaveOptions) => Promise; destroy: (object: ParseObject, serverOptions?: RequestOptions) => Promise; generateQueueId: (action: string, object: ParseObject) => string; @@ -138,8 +131,8 @@ export type EventuallyQueue = { byId(ObjectType: any, queueObject: any): Promise; byHash(ObjectType: any, queueObject: any): Promise; }; -}; -type RESTController = { +} +export interface RESTController { request: (method: string, path: string, data?: any, options?: RequestOptions) => Promise; ajax: ( method: string, @@ -149,18 +142,18 @@ type RESTController = { options?: FullOptions ) => Promise; handleError: (err?: any) => void; -}; -type SchemaController = { +} +export interface SchemaController { purge: (className: string) => Promise; 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; send(className: string, method: string, params: any, options?: RequestOptions): Promise; -}; -type SessionController = { +} +export interface SessionController { getSession: (options?: RequestOptions) => Promise; -}; +} type StorageController = | { async: 0; @@ -171,8 +164,8 @@ type StorageController = setItemAsync?: (path: string, value: string) => Promise; removeItemAsync?: (path: string) => Promise; clear: () => void; - getAllKeys?: () => Array; - getAllKeysAsync?: () => Promise>; + getAllKeys?: () => string[]; + getAllKeysAsync?: () => Promise; } | { async: 1; @@ -183,10 +176,10 @@ type StorageController = setItemAsync: (path: string, value: string) => Promise; removeItemAsync: (path: string) => Promise; clear: () => void; - getAllKeys?: () => Array; - getAllKeysAsync?: () => Promise>; + getAllKeys?: () => string[]; + getAllKeysAsync?: () => Promise; }; -type LocalDatastoreController = { +export interface LocalDatastoreController { fromPinWithName: (name: string) => any | undefined; pinWithName: (name: string, objects: any) => void; unPinWithName: (name: string) => void; @@ -194,8 +187,8 @@ type LocalDatastoreController = { clear: () => void; // Use for testing // getRawStorage(): Promise, -}; -type UserController = { +} +export interface UserController { setCurrentUser: (user: ParseUser) => Promise; currentUser: () => ParseUser | null; currentUserAsync: () => Promise; @@ -210,29 +203,29 @@ type UserController = { updateUserOnDisk: (user: ParseUser) => Promise; upgradeToRevocableSession: (user: ParseUser, options?: RequestOptions) => Promise; linkWith: (user: ParseUser, authData: AuthData, options?: FullOptions) => Promise; - removeUserFromDisk: () => Promise; + removeUserFromDisk: () => Promise; verifyPassword: ( username: string, password: string, options?: RequestOptions ) => Promise; requestEmailVerification: (email: string, options?: RequestOptions) => Promise; -}; -type HooksController = { +} +export interface HooksController { get: (type: string, functionName?: string, triggerName?: string) => Promise; create: (hook: HookDeclaration) => Promise; remove: (hook: HookDeleteArg) => Promise; update: (hook: HookDeclaration) => Promise; // Renamed to sendRequest since ParseHooks file & tests file uses this. (originally declared as just "send") sendRequest?: (method: string, path: string, body?: any) => Promise; -}; -type LiveQueryControllerType = { +} +export interface LiveQueryControllerType { setDefaultLiveQueryClient(liveQueryClient: LiveQueryClient): void; getDefaultLiveQueryClient(): Promise; _clearCachedDefaultClient(): void; -}; +} /** Based on https://github.com/react-native-async-storage/async-storage/blob/main/packages/default-storage-backend/src/types.ts */ -type AsyncStorageType = { +export interface AsyncStorageType { /** Fetches an item for a `key` and invokes a callback upon completion. */ getItem: ( key: string, @@ -302,16 +295,16 @@ type AsyncStorageType = { keyValuePairs: [string, string][], callback?: (errors?: readonly (Error | null)[] | null) => void ) => Promise; -}; -export type WebSocketController = { +} +export interface WebSocketController { onopen: () => void; onmessage: (message: any) => void; onclose: (arg?: any) => void; onerror: (error: any) => void; send: (data: any) => void; close: () => void; -}; -type Config = { +} +interface Config { AnalyticsController?: AnalyticsController; CloudController?: CloudController; ConfigController?: ConfigController; @@ -334,9 +327,9 @@ type Config = { ) => WebSocketController; LiveQueryController?: LiveQueryControllerType; AsyncStorage?: AsyncStorageType; -}; +} -const config: Config & { [key: string]: any } = { +const config: Config & Record = { IS_NODE: typeof process !== 'undefined' && !!process.versions && @@ -364,7 +357,7 @@ const config: Config & { [key: string]: any } = { PARSE_ERRORS: [], }; -function requireMethods(name: string, methods: Array, controller: any) { +function requireMethods(name: string, methods: string[], controller: any) { methods.forEach(func => { if (typeof controller[func] !== 'function') { throw new Error(`${name} must implement ${func}()`); diff --git a/src/LocalDatastore.ts b/src/LocalDatastore.ts index 069a44c48..82d624fe2 100644 --- a/src/LocalDatastore.ts +++ b/src/LocalDatastore.ts @@ -28,7 +28,7 @@ const LocalDatastore = { isEnabled: false, isSyncing: false, - fromPinWithName(name: string): Promise> { + fromPinWithName(name: string): Promise { const controller = CoreManager.getLocalDatastoreController(); return controller.fromPinWithName(name); }, @@ -61,7 +61,7 @@ const LocalDatastore = { // Pin the object and children recursively // Saves the object and children key to Pin Name - async _handlePinAllWithName(name: string, objects: Array): Promise { + async _handlePinAllWithName(name: string, objects: ParseObject[]): Promise { const pinName = this.getPinName(name); const toPinPromises = []; const objectKeys = []; @@ -86,7 +86,7 @@ const LocalDatastore = { // Removes object and children keys from pin name // Keeps the object and children pinned - async _handleUnPinAllWithName(name: string, objects: Array) { + async _handleUnPinAllWithName(name: string, objects: ParseObject[]) { const localDatastore = await this._getAllContents(); const pinName = this.getPinName(name); const promises = []; diff --git a/src/LocalDatastoreController.default.ts b/src/LocalDatastoreController.default.ts index 80bbba421..5d424950c 100644 --- a/src/LocalDatastoreController.default.ts +++ b/src/LocalDatastoreController.default.ts @@ -2,7 +2,7 @@ import { isLocalDatastoreKey } from './LocalDatastoreUtils'; import Storage from './Storage'; const LocalDatastoreController = { - async fromPinWithName(name: string): Promise> { + async fromPinWithName(name: string): Promise { const values = await Storage.getItemAsync(name); if (!values) { return []; diff --git a/src/LocalDatastoreController.react-native.ts b/src/LocalDatastoreController.react-native.ts index c555bffb2..bf08a4b42 100644 --- a/src/LocalDatastoreController.react-native.ts +++ b/src/LocalDatastoreController.react-native.ts @@ -2,7 +2,7 @@ import { isLocalDatastoreKey } from './LocalDatastoreUtils'; import RNStorage from './StorageController.react-native'; const LocalDatastoreController = { - async fromPinWithName(name: string): Promise> { + async fromPinWithName(name: string): Promise { const values = await RNStorage.getItemAsync(name); if (!values) { return []; diff --git a/src/ObjectStateMutations.ts b/src/ObjectStateMutations.ts index cd3616278..f7caf6711 100644 --- a/src/ObjectStateMutations.ts +++ b/src/ObjectStateMutations.ts @@ -7,17 +7,17 @@ import { RelationOp } from './ParseOp'; import type { Op } from './ParseOp'; import type ParseObject from './ParseObject'; -export type AttributeMap = { [attr: string]: any }; -export type OpsMap = { [attr: string]: Op }; -export type ObjectCache = { [attr: string]: string }; +export type AttributeMap = Record; +export type OpsMap = Record; +export type ObjectCache = Record; -export type State = { +export interface State { serverData: AttributeMap; - pendingOps: Array; + pendingOps: OpsMap[]; objectCache: ObjectCache; tasks: TaskQueue; existed: boolean; -}; +} export function defaultState(): State { return { @@ -39,7 +39,7 @@ export function setServerData(serverData: AttributeMap, attributes: AttributeMap } } -export function setPendingOp(pendingOps: Array, attr: string, op?: Op) { +export function setPendingOp(pendingOps: OpsMap[], attr: string, op?: Op) { const last = pendingOps.length - 1; if (op) { pendingOps[last][attr] = op; @@ -48,11 +48,11 @@ export function setPendingOp(pendingOps: Array, attr: string, op?: Op) { } } -export function pushPendingState(pendingOps: Array) { +export function pushPendingState(pendingOps: OpsMap[]) { pendingOps.push({}); } -export function popPendingState(pendingOps: Array): OpsMap { +export function popPendingState(pendingOps: OpsMap[]): OpsMap { const first = pendingOps.shift(); if (!pendingOps.length) { pendingOps[0] = {}; @@ -60,7 +60,7 @@ export function popPendingState(pendingOps: Array): OpsMap { return first; } -export function mergeFirstPendingState(pendingOps: Array) { +export function mergeFirstPendingState(pendingOps: OpsMap[]) { const first = popPendingState(pendingOps); const next = pendingOps[0]; for (const attr in first) { @@ -77,7 +77,7 @@ export function mergeFirstPendingState(pendingOps: Array) { export function estimateAttribute( serverData: AttributeMap, - pendingOps: Array, + pendingOps: OpsMap[], object: ParseObject, attr: string ): any { @@ -98,7 +98,7 @@ export function estimateAttribute( export function estimateAttributes( serverData: AttributeMap, - pendingOps: Array, + pendingOps: OpsMap[], object: ParseObject ): AttributeMap { const data = {}; diff --git a/src/ParseACL.ts b/src/ParseACL.ts index 5e07772fa..3cfbb212d 100644 --- a/src/ParseACL.ts +++ b/src/ParseACL.ts @@ -2,8 +2,8 @@ import CoreManager from './CoreManager'; import type ParseRole from './ParseRole'; import type ParseUser from './ParseUser'; -type PermissionsMap = { [permission: string]: boolean }; -type ByIdMap = { [userId: string]: PermissionsMap }; +type PermissionsMap = Record; +type ByIdMap = Record; const PUBLIC_KEY = '*'; diff --git a/src/ParseCLP.ts b/src/ParseCLP.ts index 56289adc5..199f7306e 100644 --- a/src/ParseCLP.ts +++ b/src/ParseCLP.ts @@ -2,10 +2,11 @@ import ParseRole from './ParseRole'; import ParseUser from './ParseUser'; type Entity = ParseUser | ParseRole | string; -type UsersMap = { [userId: string]: boolean | any }; -export type PermissionsMap = { writeUserFields?: string[]; readUserFields?: string[] } & { - [permission: string]: UsersMap; -}; +type UsersMap = Record; +export type PermissionsMap = { writeUserFields?: string[]; readUserFields?: string[] } & Record< + string, + UsersMap +>; const PUBLIC_KEY = '*'; diff --git a/src/ParseConfig.ts b/src/ParseConfig.ts index 6bdd38807..938a6adca 100644 --- a/src/ParseConfig.ts +++ b/src/ParseConfig.ts @@ -14,8 +14,8 @@ import type { RequestOptions } from './RESTController'; * @alias Parse.Config */ class ParseConfig { - attributes: { [key: string]: any }; - _escapedAttributes: { [key: string]: any }; + attributes: Record; + _escapedAttributes: Record; constructor() { this.attributes = {}; @@ -95,7 +95,7 @@ class ParseConfig { * @returns {Promise} A promise that is resolved with a newly-created * configuration object or with the current with the update. */ - static save(attrs: { [key: string]: any }, masterKeyOnlyFlags: { [key: string]: any }) { + static save(attrs: Record, masterKeyOnlyFlags: Record) { const controller = CoreManager.getConfigController(); //To avoid a mismatch with the local and the cloud config we get a new version return controller.save(attrs, masterKeyOnlyFlags).then( @@ -190,7 +190,7 @@ const DefaultController = { }); }, - save(attrs?: { [key: string]: any }, masterKeyOnlyFlags?: { [key: string]: any }) { + save(attrs?: Record, masterKeyOnlyFlags?: Record) { const RESTController = CoreManager.getRESTController(); const encodedAttrs = {}; for (const key in attrs) { diff --git a/src/ParseFile.ts b/src/ParseFile.ts index d53c8f947..af3581c78 100644 --- a/src/ParseFile.ts +++ b/src/ParseFile.ts @@ -12,12 +12,16 @@ if (process.env.PARSE_BUILD === 'weapp') { XHR = XhrWeapp; } -type Base64 = { base64: string }; -type Uri = { uri: string }; -type FileData = Array | Base64 | Blob | Uri; +interface Base64 { + base64: string; +} +interface Uri { + uri: string; +} +type FileData = number[] | Base64 | Blob | Uri; export type FileSaveOptions = FullOptions & { - metadata?: { [key: string]: any }; - tags?: { [key: string]: any }; + metadata?: Record; + tags?: Record; }; export type FileSource = | { @@ -411,7 +415,7 @@ class ParseFile { return file; } - static encodeBase64(bytes: Array | Uint8Array): string { + static encodeBase64(bytes: number[] | Uint8Array): string { const chunks = []; chunks.length = Math.ceil(bytes.length / 3); for (let i = 0; i < chunks.length; i++) { diff --git a/src/ParseInstallation.ts b/src/ParseInstallation.ts index 8110e4a78..0a0fbdfb9 100644 --- a/src/ParseInstallation.ts +++ b/src/ParseInstallation.ts @@ -3,14 +3,14 @@ import ParseError from './ParseError'; import ParseObject, { Attributes } from './ParseObject'; import type { AttributeKey } from './ParseObject'; -type DeviceInterface = { +interface DeviceInterface { IOS: string; MACOS: string; TVOS: string; FCM: string; ANDROID: string; WEB: string; -}; +} const DEVICE_TYPES: DeviceInterface = { IOS: 'ios', @@ -219,7 +219,7 @@ class ParseInstallation extends ParseObject): Promise { + async fetch(...args: any[]): Promise { try { await super.fetch.apply(this, args); } catch (e) { @@ -244,7 +244,7 @@ class ParseInstallation extends ParseObject): Promise { + async save(...args: any[]): Promise { try { await super.save.apply(this, args); } catch (e) { diff --git a/src/ParseObject.ts b/src/ParseObject.ts index 059021384..a3503e41a 100644 --- a/src/ParseObject.ts +++ b/src/ParseObject.ts @@ -32,18 +32,18 @@ import type { RequestOptions, FullOptions } from './RESTController'; import type ParseGeoPoint from './ParseGeoPoint'; import type ParsePolygon from './ParsePolygon'; -export type Pointer = { +export interface Pointer { __type: string; className: string; objectId?: string; _localId?: string; -}; +} -type SaveParams = { +interface SaveParams { method: string; path: string; body: AttributeMap; -}; +} export type SaveOptions = FullOptions & { cascadeSave?: boolean; @@ -52,23 +52,21 @@ export type SaveOptions = FullOptions & { transaction?: boolean; }; -type FetchOptions = { +interface FetchOptions { useMasterKey?: boolean; sessionToken?: string; include?: string | string[]; context?: AttributeMap; -}; +} -export type SetOptions = { +export interface SetOptions { ignoreValidation?: boolean; unset?: boolean; -}; +} export type AttributeKey = Extract; -export interface Attributes { - [key: string]: any; -} +export type Attributes = Record; interface JSONBaseAttributes { objectId: string; @@ -92,8 +90,8 @@ type Encode = T extends ParseObject ? { __type: 'Date'; iso: string } : T extends RegExp ? string - : T extends Array - ? Array> + : T extends (infer R)[] + ? Encode[] : T extends object ? ToJSON : T; @@ -281,7 +279,7 @@ class ParseObject { stateController.setServerData(this._getStateIdentifier(), unset); } - _getPendingOps(): Array { + _getPendingOps(): OpsMap[] { const stateController = CoreManager.getObjectStateController(); return stateController.getPendingOps(this._getStateIdentifier()); } @@ -290,7 +288,7 @@ class ParseObject { * @param {Array} [keysToClear] - if specified, only ops matching * these fields will be cleared */ - _clearPendingOps(keysToClear?: Array) { + _clearPendingOps(keysToClear?: string[]) { const pending = this._getPendingOps(); const latest = pending[pending.length - 1]; const keys = keysToClear || Object.keys(latest); @@ -331,7 +329,7 @@ class ParseObject { return dirty; } - _toFullJSON(seen?: Array, offline?: boolean): Attributes { + _toFullJSON(seen?: any[], offline?: boolean): Attributes { const json: Attributes = this.toJSON(seen, offline); json.__type = 'Object'; json.className = this.className; @@ -556,7 +554,7 @@ class ParseObject { * @param offline * @returns {object} */ - toJSON(seen: Array | void, offline?: boolean): ToJSON & JSONBaseAttributes { + toJSON(seen?: any[], offline?: boolean): ToJSON & JSONBaseAttributes { const seenEntry = this.id ? this.className + ':' + this.id : this; seen = seen || [seenEntry]; const json: any = {}; @@ -1190,7 +1188,7 @@ class ParseObject { * * @param {string} [keys] - specify which fields to revert */ - revert(...keys: Array>): void { + revert(...keys: Extract[]): void { let keysToRevert; if (keys.length) { keysToRevert = []; @@ -1266,10 +1264,7 @@ class ParseObject { * @returns {Promise} A promise that is fulfilled when the fetch * completes. */ - fetchWithInclude( - keys: string | Array>, - options?: RequestOptions - ): Promise { + fetchWithInclude(keys: string | (string | string[])[], options?: RequestOptions): Promise { options = options || {}; options.include = keys; return this.fetch(options); @@ -1476,9 +1471,9 @@ class ParseObject { * @returns {Promise} A promise that is fulfilled when the destroy * completes. */ - destroy(options?: RequestOptions): Promise { + destroy(options?: RequestOptions): Promise { if (!this.id) { - return Promise.resolve(); + return Promise.resolve(undefined); } const destroyOptions = ParseObject._getRequestOptions(options); return CoreManager.getObjectController().destroy(this, destroyOptions) as Promise; @@ -1668,7 +1663,7 @@ class ParseObject { */ static fetchAllWithInclude( list: T[], - keys: keyof T['attributes'] | Array, + keys: keyof T['attributes'] | (keyof T['attributes'])[], options?: RequestOptions ): Promise { options = options || {}; @@ -1708,7 +1703,7 @@ class ParseObject { */ static fetchAllIfNeededWithInclude( list: T[], - keys: keyof T['attributes'] | Array, + keys: keyof T['attributes'] | (keyof T['attributes'])[], options?: RequestOptions ): Promise { options = options || {}; @@ -1819,7 +1814,7 @@ class ParseObject { * @returns {Promise} A promise that is fulfilled when the destroyAll * completes. */ - static destroyAll(list: Array, options?: SaveOptions) { + static destroyAll(list: ParseObject[], options?: SaveOptions) { const destroyOptions = ParseObject._getRequestOptions(options); return CoreManager.getObjectController().destroy(list, destroyOptions); } @@ -2145,7 +2140,7 @@ class ParseObject { * @returns {Promise} A promise that is fulfilled when the pin completes. * @static */ - static pinAll(objects: Array): Promise { + static pinAll(objects: ParseObject[]): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -2171,7 +2166,7 @@ class ParseObject { * @returns {Promise} A promise that is fulfilled when the pin completes. * @static */ - static pinAllWithName(name: string, objects: Array): Promise { + static pinAllWithName(name: string, objects: ParseObject[]): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -2191,7 +2186,7 @@ class ParseObject { * @returns {Promise} A promise that is fulfilled when the unPin completes. * @static */ - static unPinAll(objects: Array): Promise { + static unPinAll(objects: ParseObject[]): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -2211,7 +2206,7 @@ class ParseObject { * @returns {Promise} A promise that is fulfilled when the unPin completes. * @static */ - static unPinAllWithName(name: string, objects: Array): Promise { + static unPinAllWithName(name: string, objects: ParseObject[]): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -2260,10 +2255,10 @@ class ParseObject { const DefaultController = { fetch( - target: ParseObject | Array, + target: ParseObject | ParseObject[], forceFetch: boolean, options?: RequestOptions - ): Promise | ParseObject | undefined> { + ): Promise<(ParseObject | undefined)[] | ParseObject | undefined> { const localDatastore = CoreManager.getLocalDatastore(); if (Array.isArray(target)) { if (target.length < 1) { @@ -2365,9 +2360,9 @@ const DefaultController = { }, async destroy( - target: ParseObject | Array, + target: ParseObject | ParseObject[], options?: RequestOptions - ): Promise> { + ): Promise { if (options && options.batchSize && options.transaction) throw new ParseError( ParseError.OTHER_CAUSE, @@ -2452,9 +2447,9 @@ const DefaultController = { }, save( - target: ParseObject | null | Array, + target: ParseObject | null | (ParseObject | ParseFile)[], options?: RequestOptions - ): Promise | ParseFile | undefined> { + ): Promise { if (options && options.batchSize && options.transaction) return Promise.reject( new ParseError( @@ -2489,8 +2484,8 @@ const DefaultController = { } unsaved = unique(unsaved); - const filesSaved: Array | undefined> = []; - let pending: Array = []; + const filesSaved: (Promise | undefined)[] = []; + let pending: ParseObject[] = []; unsaved.forEach(el => { if (el instanceof ParseFile) { filesSaved.push(el.save(options)); @@ -2546,6 +2541,7 @@ const DefaultController = { const batchReady: ReturnType>[] = []; const batchTasks: Promise[] = []; batch.forEach((obj, index) => { + // eslint-disable-next-line const ready = resolvingPromise(); batchReady.push(ready); const task = function () { diff --git a/src/ParseOp.ts b/src/ParseOp.ts index 9242f5012..dbf1e2fed 100644 --- a/src/ParseOp.ts +++ b/src/ParseOp.ts @@ -7,7 +7,7 @@ import type Pointer from './ParseObject'; import ParseRelation from './ParseRelation'; import unique from './unique'; -export function opFromJSON(json: { [key: string]: any }): Op | null { +export function opFromJSON(json: Record): Op | null { if (!json || !json.__op) { return null; } @@ -55,7 +55,7 @@ export function opFromJSON(json: { [key: string]: any }): Op | null { export class Op { // Empty parent class applyTo(value: any): any {} /* eslint-disable-line @typescript-eslint/no-unused-vars */ - mergeWith(previous: Op): Op | void {} /* eslint-disable-line @typescript-eslint/no-unused-vars */ + mergeWith(previous: Op): Op | void {} /* eslint-disable-line */ toJSON(offline?: boolean): any {} /* eslint-disable-line @typescript-eslint/no-unused-vars */ } @@ -137,14 +137,14 @@ export class IncrementOp extends Op { } export class AddOp extends Op { - _value: Array; + _value: any[]; - constructor(value: any | Array) { + constructor(value: any | any[]) { super(); this._value = Array.isArray(value) ? value : [value]; } - applyTo(value: any): Array { + applyTo(value: any): any[] { if (value == null) { return this._value; } @@ -176,14 +176,14 @@ export class AddOp extends Op { } export class AddUniqueOp extends Op { - _value: Array; + _value: any[]; - constructor(value: any | Array) { + constructor(value: any | any[]) { super(); this._value = unique(Array.isArray(value) ? value : [value]); } - applyTo(value: any | Array): Array { + applyTo(value: any | any[]): any[] { if (value == null) { return this._value || []; } @@ -228,14 +228,14 @@ export class AddUniqueOp extends Op { } export class RemoveOp extends Op { - _value: Array; + _value: any[]; - constructor(value: any | Array) { + constructor(value: any | any[]) { super(); this._value = unique(Array.isArray(value) ? value : [value]); } - applyTo(value: any | Array): Array { + applyTo(value: any | any[]): any[] { if (value == null) { return []; } @@ -299,10 +299,10 @@ export class RemoveOp extends Op { export class RelationOp extends Op { _targetClassName: string | null; - relationsToAdd: Array; - relationsToRemove: Array; + relationsToAdd: string[]; + relationsToRemove: string[]; - constructor(adds: Array, removes: Array) { + constructor(adds: (ParseObject | string)[], removes: (ParseObject | string)[]) { super(); this._targetClassName = null; diff --git a/src/ParsePolygon.ts b/src/ParsePolygon.ts index ced17f2f0..dae45bf54 100644 --- a/src/ParsePolygon.ts +++ b/src/ParsePolygon.ts @@ -27,7 +27,7 @@ class ParsePolygon { /** * @param {(Coordinates | Parse.GeoPoint[])} coordinates An Array of coordinate pairs */ - constructor(coordinates: Coordinates | Array) { + constructor(coordinates: Coordinates | ParseGeoPoint[]) { this._coordinates = ParsePolygon._validate(coordinates); } @@ -42,7 +42,7 @@ class ParsePolygon { return this._coordinates; } - set coordinates(coords: Coordinates | Array) { + set coordinates(coords: Coordinates | ParseGeoPoint[]) { this._coordinates = ParsePolygon._validate(coords); } @@ -136,7 +136,7 @@ class ParsePolygon { * @throws {TypeError} * @returns {number[][]} Array of coordinates if validated. */ - static _validate(coords: Coordinates | Array): Coordinates { + static _validate(coords: Coordinates | ParseGeoPoint[]): Coordinates { if (!Array.isArray(coords)) { throw new TypeError('Coordinates must be an Array'); } diff --git a/src/ParseQuery.ts b/src/ParseQuery.ts index 77a2e3601..39cdfaa9d 100644 --- a/src/ParseQuery.ts +++ b/src/ParseQuery.ts @@ -16,28 +16,26 @@ type BatchOptions = FullOptions & { useMasterKey?: boolean; useMaintenanceKey?: boolean; sessionToken?: string; - context?: { [key: string]: any }; + context?: Record; json?: boolean; }; -export type WhereClause = { - [attr: string]: any; -}; +export type WhereClause = Record; -type QueryOptions = { +interface QueryOptions { useMasterKey?: boolean; sessionToken?: string; - context?: { [key: string]: any }; + context?: Record; json?: boolean; -}; +} -type FullTextQueryOptions = { +interface FullTextQueryOptions { language?: string; caseSensitive?: boolean; diacriticSensitive?: boolean; -}; +} -export type QueryJSON = { +export interface QueryJSON { where: WhereClause; watch?: string; include?: string; @@ -54,7 +52,7 @@ export type QueryJSON = { includeReadPreference?: string; subqueryReadPreference?: string; comment?: string; -}; +} interface BaseAttributes { createdAt: Date; @@ -83,7 +81,7 @@ function quote(s: string): string { * @private * @returns {string} */ -function _getClassNameFromQueries(queries: Array): string | null { +function _getClassNameFromQueries(queries: ParseQuery[]): string | null { let className: string | null = null; queries.forEach(q => { if (!className) { @@ -102,7 +100,7 @@ function _getClassNameFromQueries(queries: Array): string | null { * making sure that the data object contains keys for all objects that have * been requested with a select, so that our cached state updates correctly. */ -function handleSelectResult(data: any, select: Array) { +function handleSelectResult(data: any, select: string[]) { const serverDataMask = {}; select.forEach(field => { @@ -249,20 +247,20 @@ class ParseQuery { */ className: string; _where: any; - _watch: Array; - _include: Array; - _exclude: Array; - _select: Array; + _watch: string[]; + _include: string[]; + _exclude: string[]; + _select: string[]; _limit: number; _skip: number; _count: boolean; - _order: Array; + _order: string[]; _readPreference: string | null; _includeReadPreference: string | null; _subqueryReadPreference: string | null; _queriesLocalDatastore: boolean; _localDatastorePinName: any; - _extraOptions: { [key: string]: any }; + _extraOptions: Record; _hint: any; _explain: boolean; _xhrRequest: any; @@ -318,7 +316,7 @@ class ParseQuery { * @param {Array} queries * @returns {Parse.Query} Returns the query, so you can chain this call. */ - _orQuery(queries: Array): this { + _orQuery(queries: ParseQuery[]): this { const queryJSON = queries.map(q => { return q.toJSON().where; }); @@ -333,7 +331,7 @@ class ParseQuery { * @param {Array} queries * @returns {Parse.Query} Returns the query, so you can chain this call. */ - _andQuery(queries: Array): this { + _andQuery(queries: ParseQuery[]): this { const queryJSON = queries.map(q => { return q.toJSON().where; }); @@ -348,7 +346,7 @@ class ParseQuery { * @param {Array} queries * @returns {Parse.Query} Returns the query, so you can chain this call. */ - _norQuery(queries: Array): this { + _norQuery(queries: ParseQuery[]): this { const queryJSON = queries.map(q => { return q.toJSON().where; }); @@ -818,7 +816,7 @@ class ParseQuery { * @param {string} [options.sessionToken] A valid session token, used for making a request on behalf of a specific user. * @returns {Promise} A promise that is resolved with the query completes. */ - aggregate(pipeline: any, options?: { sessionToken?: string }): Promise> { + aggregate(pipeline: any, options?: { sessionToken?: string }): Promise { options = options || {}; const aggregateOptions: { sessionToken?: string; useMasterKey: boolean } = { useMasterKey: true, @@ -1061,7 +1059,7 @@ class ParseQuery { async map( callback: (currentObject: ParseObject, index: number, query: ParseQuery) => any, options?: BatchOptions - ): Promise> { + ): Promise { const array: ParseObject[] = []; let index = 0; await this.each(object => { @@ -1100,7 +1098,7 @@ class ParseQuery { callback: (accumulator: any, currentObject: ParseObject, index: number) => any, initialValue: any, options?: BatchOptions - ): Promise> { + ): Promise { let accumulator = initialValue; let index = 0; await this.each(object => { @@ -1149,7 +1147,7 @@ class ParseQuery { async filter( callback: (currentObject: ParseObject, index: number, query: ParseQuery) => boolean, options?: BatchOptions - ): Promise> { + ): Promise { const array: ParseObject[] = []; let index = 0; await this.each(object => { @@ -1179,7 +1177,7 @@ class ParseQuery { | T['attributes'][K] | (T['attributes'][K] extends ParseObject ? Pointer - : T['attributes'][K] extends Array + : T['attributes'][K] extends (infer E)[] ? E : never) ): this { @@ -1208,7 +1206,7 @@ class ParseQuery { | T['attributes'][K] | (T['attributes'][K] extends ParseObject ? Pointer - : T['attributes'][K] extends Array + : T['attributes'][K] extends (infer E)[] ? E : never) ): this { @@ -1289,7 +1287,7 @@ class ParseQuery { */ containedIn( key: K, - values: Array + values: (T['attributes'][K] | (T['attributes'][K] extends ParseObject ? string : never))[] ): this { return this._addCondition(key, '$in', values); } @@ -1304,7 +1302,7 @@ class ParseQuery { */ notContainedIn( key: K, - values: Array + values: T['attributes'][K][] ): this { return this._addCondition(key, '$nin', values); } @@ -1319,7 +1317,7 @@ class ParseQuery { */ containedBy( key: K, - values: Array + values: (T['attributes'][K] | (T['attributes'][K] extends ParseObject ? string : never))[] ): this { return this._addCondition(key, '$containedBy', values); } @@ -1796,7 +1794,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): this { + ascending(...keys: string[]): this { this._order = []; return this.addAscending.apply(this, keys); } @@ -1809,7 +1807,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): this { + addAscending(...keys: string[]): this { if (!this._order) { this._order = []; } @@ -1830,7 +1828,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): this { + descending(...keys: string[]): this { this._order = []; return this.addDescending.apply(this, keys); } @@ -1843,7 +1841,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): this { + addDescending(...keys: string[]): this { if (!this._order) { this._order = []; } @@ -1923,9 +1921,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> - ): this { + include(...keys: (K | K[])[]): this { keys.forEach(key => { if (Array.isArray(key)) { this._include = this._include.concat(key as string[]); @@ -1955,9 +1951,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> - ): this { + select(...keys: (K | K[])[]): this { if (!this._select) { this._select = []; } @@ -1980,9 +1974,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> - ): this { + exclude(...keys: (K | K[])[]): this { keys.forEach(key => { if (Array.isArray(key)) { this._exclude = this._exclude.concat(key as string[]); @@ -2001,9 +1993,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> - ): this { + watch(...keys: (K | K[])[]): this { keys.forEach(key => { if (Array.isArray(key)) { this._watch = this._watch.concat(key as string[]); @@ -2067,7 +2057,7 @@ class ParseQuery { * @static * @returns {Parse.Query} The query that is the OR of the passed in queries. */ - static or(...queries: Array): ParseQuery { + static or(...queries: ParseQuery[]): ParseQuery { const className = _getClassNameFromQueries(queries); const query = new ParseQuery(className!); query._orQuery(queries); @@ -2086,7 +2076,7 @@ class ParseQuery { * @static * @returns {Parse.Query} The query that is the AND of the passed in queries. */ - static and(...queries: Array): ParseQuery { + static and(...queries: ParseQuery[]): ParseQuery { const className = _getClassNameFromQueries(queries); const query = new ParseQuery(className!); query._andQuery(queries); @@ -2105,7 +2095,7 @@ class ParseQuery { * @static * @returns {Parse.Query} The query that is the NOR of the passed in queries. */ - static nor(...queries: Array): ParseQuery { + static nor(...queries: ParseQuery[]): ParseQuery { const className = _getClassNameFromQueries(queries); const query = new ParseQuery(className!); query._norQuery(queries); @@ -2205,16 +2195,12 @@ const DefaultController = { className: string, params: QueryJSON, options?: RequestOptions - ): Promise<{ results: Array }> { + ): Promise<{ results: ParseObject[] }> { const RESTController = CoreManager.getRESTController(); return RESTController.request('GET', 'classes/' + className, params, options); }, - aggregate( - className: string, - params: any, - options?: RequestOptions - ): Promise<{ results: Array }> { + aggregate(className: string, params: any, options?: RequestOptions): Promise<{ results: any[] }> { const RESTController = CoreManager.getRESTController(); return RESTController.request('GET', 'aggregate/' + className, params, options); diff --git a/src/ParseSchema.ts b/src/ParseSchema.ts index 8e849463d..d6884c8c2 100644 --- a/src/ParseSchema.ts +++ b/src/ParseSchema.ts @@ -51,9 +51,7 @@ interface FieldOptions< targetClass?: string | undefined; } -interface Index { - [fieldName: string]: number | string; -} +type Index = Record; interface CLPField { '*'?: boolean | undefined; @@ -71,27 +69,22 @@ interface CLP { addField?: CLPField | undefined; readUserFields?: string[] | undefined; writeUserFields?: string[] | undefined; - protectedFields?: { - [userIdOrRoleName: string]: string[]; - }; + protectedFields?: Record; } interface RestSchema { className: string; - fields: { - [key: string]: { + fields: Record< + string, + { type: string; targetClass?: string; required?: boolean; defaultValue?: string; - }; - }; + } + >; classLevelPermissions: CLP; - indexes?: { - [key: string]: { - [key: string]: any; - }; - }; + indexes?: Record>; } const FIELD_TYPES = [ @@ -128,9 +121,9 @@ const FIELD_TYPES = [ */ class ParseSchema { className: string; - _fields: { [key: string]: any }; - _indexes: { [key: string]: any }; - _clp: { [key: string]: any }; + _fields: Record; + _indexes: Record; + _clp: Record; /** * @param {string} className Parse Class string. diff --git a/src/ParseUser.ts b/src/ParseUser.ts index 730790f4c..5f3b39b76 100644 --- a/src/ParseUser.ts +++ b/src/ParseUser.ts @@ -7,8 +7,8 @@ import Storage from './Storage'; import type { AttributeKey } from './ParseObject'; import type { RequestOptions, FullOptions } from './RESTController'; -export type AuthData = { [key: string]: any }; -export type AuthProvider = { +export type AuthData = Record; +export interface AuthProvider { authenticate?(options: { error?: (provider: AuthProvider, error: string | any) => void; success?: (provider: AuthProvider, result: AuthData) => void; @@ -16,13 +16,13 @@ export type AuthProvider = { restoreAuthentication(authData: any): boolean; getAuthType(): string; deauthenticate?(): void; -}; +} const CURRENT_USER_KEY = 'currentUser'; let canUseCurrentUser = !CoreManager.get('IS_NODE'); let currentUserCacheMatchesDisk = false; let currentUserCache: ParseUser | null = null; -const authProviders: { [key: string]: AuthProvider } = {}; +const authProviders: Record = {}; /** *

A Parse.User object is a local representation of a user persisted to the @@ -478,7 +478,7 @@ class ParseUser extends ParseObject { * @param {...any} args * @returns {Promise} */ - async save(...args: Array): Promise { + async save(...args: any[]): Promise { await super.save.apply(this, args); const current = await this.isCurrentAsync(); if (current) { @@ -494,11 +494,11 @@ class ParseUser extends ParseObject { * @param {...any} args * @returns {Parse.User} */ - async destroy(...args: Array): Promise { + async destroy(...args: any[]): Promise { await super.destroy.apply(this, args); const current = await this.isCurrentAsync(); if (current) { - return CoreManager.getUserController().removeUserFromDisk(); + return CoreManager.getUserController().removeUserFromDisk() as undefined; } return this; } @@ -510,7 +510,7 @@ class ParseUser extends ParseObject { * @param {...any} args * @returns {Parse.User} */ - async fetch(...args: Array): Promise { + async fetch(...args: any[]): Promise { await super.fetch.apply(this, args); const current = await this.isCurrentAsync(); if (current) { @@ -526,7 +526,7 @@ class ParseUser extends ParseObject { * @param {...any} args * @returns {Parse.User} */ - async fetchWithInclude(...args: Array): Promise { + async fetchWithInclude(...args: any[]): Promise { await super.fetchWithInclude.apply(this, args); const current = await this.isCurrentAsync(); if (current) { @@ -562,7 +562,7 @@ class ParseUser extends ParseObject { * @static * @returns {Parse.User} The newly extended Parse.User class */ - static extend(protoProps: { [prop: string]: any }, classProps: { [prop: string]: any }) { + static extend(protoProps: Record, classProps: Record) { if (protoProps) { for (const prop in protoProps) { if (prop !== 'className') { @@ -1015,7 +1015,7 @@ const DefaultController = { }); }, - removeUserFromDisk() { + removeUserFromDisk(): Promise { const path = Storage.generatePath(CURRENT_USER_KEY); currentUserCacheMatchesDisk = true; currentUserCache = null; diff --git a/src/Push.ts b/src/Push.ts index 18059b626..366628e68 100644 --- a/src/Push.ts +++ b/src/Push.ts @@ -5,14 +5,14 @@ import type ParseObject from './ParseObject'; import type { WhereClause } from './ParseQuery'; import type { FullOptions } from './RESTController'; -export type PushData = { +export interface PushData { where?: WhereClause | ParseQuery; push_time?: Date | string; expiration_time?: Date | string; expiration_interval?: number; data?: any; channels?: string[]; -}; +} /** * Contains functions to deal with Push in Parse. diff --git a/src/RESTController.ts b/src/RESTController.ts index c0ea0b272..8185d65af 100644 --- a/src/RESTController.ts +++ b/src/RESTController.ts @@ -5,7 +5,7 @@ import ParseError from './ParseError'; import { resolvingPromise } from './promiseUtils'; import XhrWeapp from './Xhr.weapp'; -export type RequestOptions = { +export interface RequestOptions { useMasterKey?: boolean; useMaintenanceKey?: boolean; sessionToken?: string; @@ -18,9 +18,9 @@ export type RequestOptions = { usePost?: boolean; ignoreEmailVerification?: boolean; transaction?: boolean; -}; +} -export type FullOptions = { +export interface FullOptions { success?: any; error?: any; useMasterKey?: boolean; @@ -29,9 +29,9 @@ export type FullOptions = { installationId?: string; progress?: any; usePost?: boolean; -}; +} -type PayloadType = { +interface PayloadType { _context?: any; _method?: string; _ApplicationId: string; @@ -42,7 +42,7 @@ type PayloadType = { _RevocableSession?: string; _InstallationId?: string; _SessionToken?: string; -}; +} let XHR: any = null; if (typeof XMLHttpRequest !== 'undefined') { diff --git a/src/SingleInstanceStateController.ts b/src/SingleInstanceStateController.ts index 8e78775fb..034056b61 100644 --- a/src/SingleInstanceStateController.ts +++ b/src/SingleInstanceStateController.ts @@ -4,11 +4,7 @@ import type { Op } from './ParseOp'; import type ParseObject from './ParseObject'; import type { AttributeMap, ObjectCache, OpsMap, State } from './ObjectStateMutations'; -let objectState: { - [className: string]: { - [id: string]: State; - }; -} = {}; +let objectState: Record> = {}; export function getState(obj: ParseObject): State | null { const classData = objectState[obj.className]; @@ -55,7 +51,7 @@ export function setServerData(obj: ParseObject, attributes: AttributeMap) { ObjectStateMutations.setServerData(serverData, attributes); } -export function getPendingOps(obj: ParseObject): Array { +export function getPendingOps(obj: ParseObject): OpsMap[] { const state = getState(obj); if (state) { return state.pendingOps; diff --git a/src/Storage.ts b/src/Storage.ts index 45b6ffe43..4e5518710 100644 --- a/src/Storage.ts +++ b/src/Storage.ts @@ -54,7 +54,7 @@ const Storage = { return Promise.resolve(controller.removeItem(path)); }, - getAllKeys(): Array { + getAllKeys(): string[] { const controller = CoreManager.getStorageController(); if (controller.async === 1) { throw new Error('Synchronous storage is not supported by the current storage controller'); @@ -62,7 +62,7 @@ const Storage = { return controller.getAllKeys!(); }, - getAllKeysAsync(): Promise> { + getAllKeysAsync(): Promise { const controller = CoreManager.getStorageController(); if (controller.async === 1) { return controller.getAllKeysAsync!(); diff --git a/src/StorageController.react-native.ts b/src/StorageController.react-native.ts index 375b04799..bce3c6f54 100644 --- a/src/StorageController.react-native.ts +++ b/src/StorageController.react-native.ts @@ -51,7 +51,7 @@ const StorageController = { }); }, - multiGet(keys: Array): Promise { + multiGet(keys: string[]): Promise { return new Promise((resolve, reject) => { CoreManager.getAsyncStorage()!.multiGet(keys, (err, result) => { if (err) { @@ -63,7 +63,7 @@ const StorageController = { }); }, - multiRemove(keys: Array): Promise> { + multiRemove(keys: string[]): Promise { return new Promise((resolve, reject) => { CoreManager.getAsyncStorage()!.multiRemove(keys, err => { if (err) { diff --git a/src/TaskQueue.ts b/src/TaskQueue.ts index 92ed530d6..7816ab7f3 100644 --- a/src/TaskQueue.ts +++ b/src/TaskQueue.ts @@ -1,18 +1,19 @@ import { resolvingPromise } from './promiseUtils'; -type Task = { +interface Task { task: () => Promise; _completion: any; -}; +} class TaskQueue { - queue: Array; + queue: Task[]; constructor() { this.queue = []; } enqueue(task: () => Promise): Promise { + // eslint-disable-next-line const taskComplete = resolvingPromise(); this.queue.push({ task: task, diff --git a/src/UniqueInstanceStateController.ts b/src/UniqueInstanceStateController.ts index 9ad9e4d65..fc7e073d4 100644 --- a/src/UniqueInstanceStateController.ts +++ b/src/UniqueInstanceStateController.ts @@ -53,7 +53,7 @@ export function setServerData(obj: ParseObject, attributes: AttributeMap) { ObjectStateMutations.setServerData(serverData, attributes); } -export function getPendingOps(obj: ParseObject): Array { +export function getPendingOps(obj: ParseObject): OpsMap[] { const state = getState(obj); if (state) { return state.pendingOps; diff --git a/src/__tests__/ParseObject-test.js b/src/__tests__/ParseObject-test.js index 176f6a609..bc439c0e5 100644 --- a/src/__tests__/ParseObject-test.js +++ b/src/__tests__/ParseObject-test.js @@ -3766,11 +3766,7 @@ describe('ParseObject Subclasses', () => { }); it('can use on ParseObject subclass for multiple Parse.Object class names', () => { - class MyParseObjects extends ParseObject { - constructor(className) { - super(className); - } - } + class MyParseObjects extends ParseObject {} ParseObject.registerSubclass('TestObject', MyParseObjects); ParseObject.registerSubclass('TestObject1', MyParseObjects); ParseObject.registerSubclass('TestObject2', MyParseObjects); diff --git a/src/arrayContainsObject.ts b/src/arrayContainsObject.ts index 3c4ba6188..d79256ea6 100644 --- a/src/arrayContainsObject.ts +++ b/src/arrayContainsObject.ts @@ -1,7 +1,7 @@ import CoreManager from './CoreManager'; import type ParseObject from './ParseObject'; -export default function arrayContainsObject(array: Array, object: ParseObject): boolean { +export default function arrayContainsObject(array: any[], object: ParseObject): boolean { if (array.indexOf(object) > -1) { return true; } diff --git a/src/encode.ts b/src/encode.ts index e5558400f..a77c477de 100644 --- a/src/encode.ts +++ b/src/encode.ts @@ -9,7 +9,7 @@ function encode( value: any, disallowObjects: boolean, forcePointers: boolean, - seen: Array, + seen: any[], offline: boolean ): any { const ParseObject = CoreManager.getParseObject(); @@ -83,7 +83,7 @@ export default function ( value: any, disallowObjects?: boolean, forcePointers?: boolean, - seen?: Array, + seen?: any[], offline?: boolean ): any { return encode(value, !!disallowObjects, !!forcePointers, seen || [], offline); diff --git a/src/interfaces/react-native.ts b/src/interfaces/react-native.ts index f20af4934..cea1921c4 100644 --- a/src/interfaces/react-native.ts +++ b/src/interfaces/react-native.ts @@ -6,7 +6,7 @@ declare module 'react-native' { static getItem(path: string, cb: (err: string, value: string) => void): void; static setItem(path: string, value: string, cb: (err: string, value: string) => void): void; static removeItem(path: string, cb: (err: string, value: string) => void): void; - static getAllKeys(cb: (err: string, keys: Array) => void): void; + static getAllKeys(cb: (err: string, keys: string[]) => void): void; static clear(): void; } } diff --git a/src/unique.ts b/src/unique.ts index fd31f74bf..84177c9cb 100644 --- a/src/unique.ts +++ b/src/unique.ts @@ -1,7 +1,7 @@ import arrayContainsObject from './arrayContainsObject'; import CoreManager from './CoreManager'; -export default function unique(arr: Array): Array { +export default function unique(arr: T[]): T[] { const uniques: T[] = []; arr.forEach(value => { const ParseObject = CoreManager.getParseObject(); diff --git a/src/unsavedChildren.ts b/src/unsavedChildren.ts index b2619fb9e..851d6dadd 100644 --- a/src/unsavedChildren.ts +++ b/src/unsavedChildren.ts @@ -3,10 +3,10 @@ import ParseFile from './ParseFile'; import type ParseObject from './ParseObject'; import ParseRelation from './ParseRelation'; -type EncounterMap = { - objects: { [identifier: string]: ParseObject | boolean }; - files: Array; -}; +interface EncounterMap { + objects: Record; + files: ParseFile[]; +} /** * Return an array of unsaved children, which are either Parse Objects or Files. @@ -19,7 +19,7 @@ type EncounterMap = { export default function unsavedChildren( obj: ParseObject, allowDeepUnsaved?: boolean -): Array { +): (ParseFile | ParseObject)[] { const encountered = { objects: {}, files: [], diff --git a/types/Analytics.d.ts b/types/Analytics.d.ts index 498c9c912..6a96d9d12 100644 --- a/types/Analytics.d.ts +++ b/types/Analytics.d.ts @@ -37,6 +37,4 @@ * @returns {Promise} A promise that is resolved when the round-trip * to the server completes. */ -export declare function track(name: string, dimensions: { - [key: string]: string; -}): Promise; +export declare function track(name: string, dimensions: Record): Promise; diff --git a/types/CoreManager.d.ts b/types/CoreManager.d.ts index 93148d43c..c01c1d4a9 100644 --- a/types/CoreManager.d.ts +++ b/types/CoreManager.d.ts @@ -14,31 +14,25 @@ import type { HookDeclaration, HookDeleteArg } from './ParseHooks'; import type ParseConfig from './ParseConfig'; import type LiveQueryClient from './LiveQueryClient'; import type ParseInstallation from './ParseInstallation'; -type AnalyticsController = { - track: (name: string, dimensions: { - [key: string]: string; - }) => Promise; -}; -type CloudController = { +export interface AnalyticsController { + track: (name: string, dimensions: Record) => Promise; +} +export interface CloudController { run: (name: string, data: any, options?: RequestOptions) => Promise; getJobsData: (options?: RequestOptions) => Promise; /** Returns promise which resolves with JobStatusId of the job */ startJob: (name: string, data: any, options?: RequestOptions) => Promise; -}; -type ConfigController = { +} +export interface ConfigController { current: () => Promise | ParseConfig; get: (opts?: RequestOptions) => Promise; - save: (attrs: { - [key: string]: any; - }, masterKeyOnlyFlags?: { - [key: string]: any; - }) => Promise; -}; -type CryptoController = { + save: (attrs: Record, masterKeyOnlyFlags?: Record) => Promise; +} +export interface CryptoController { encrypt: (obj: any, secretKey: string) => string; decrypt: (encryptedText: string, secretKey: any) => string; -}; -type FileController = { +} +export interface FileController { saveFile: (name: string, source: FileSource, options?: FullOptions) => Promise; saveBase64: (name: string, source: FileSource, options?: FileSaveOptions) => Promise<{ name: string; @@ -51,24 +45,24 @@ type FileController = { deleteFile: (name: string, options?: { useMasterKey?: boolean; }) => Promise; -}; -type InstallationController = { +} +export interface InstallationController { currentInstallationId: () => Promise; currentInstallation: () => Promise; updateInstallationOnDisk: (installation: ParseInstallation) => Promise; -}; -type ObjectController = { - fetch: (object: ParseObject | Array, forceFetch: boolean, options?: RequestOptions) => Promise | ParseObject | undefined>; - save: (object: ParseObject | Array | null, options?: RequestOptions) => Promise | ParseFile | undefined>; - destroy: (object: ParseObject | Array, options?: RequestOptions) => Promise>; -}; -type ObjectStateController = { +} +export interface ObjectController { + fetch: (object: ParseObject | ParseObject[], forceFetch: boolean, options?: RequestOptions) => Promise<(ParseObject | undefined)[] | ParseObject | undefined>; + save: (object: ParseObject | (ParseObject | ParseFile)[] | null, options?: RequestOptions) => Promise; + destroy: (object: ParseObject | ParseObject[], options?: RequestOptions) => Promise; +} +export interface ObjectStateController { getState: (obj: any) => State | null; initializeState: (obj: any, initial?: State) => State; removeState: (obj: any) => State | null; getServerData: (obj: any) => AttributeMap; setServerData: (obj: any, attributes: AttributeMap) => void; - getPendingOps: (obj: any) => Array; + getPendingOps: (obj: any) => OpsMap[]; setPendingOp: (obj: any, attr: string, op?: Op) => void; pushPendingState: (obj: any) => void; popPendingState: (obj: any) => OpsMap | undefined; @@ -80,21 +74,21 @@ type ObjectStateController = { enqueueTask: (obj: any, task: () => Promise) => Promise; clearAllState: () => void; duplicateState: (source: any, dest: any) => void; -}; -type PushController = { +} +export interface PushController { send: (data: PushData, options?: FullOptions) => Promise; -}; -type QueryController = { +} +export interface QueryController { find(className: string, params: QueryJSON, options?: RequestOptions): Promise<{ - results?: Array; + results?: ParseObject[]; className?: string; count?: number; }>; aggregate(className: string, params: any, options?: RequestOptions): Promise<{ - results?: Array; + results?: any[]; }>; -}; -export type QueueObject = { +} +export interface QueueObject { queueId: string; action: string; object: ParseObject; @@ -103,9 +97,9 @@ export type QueueObject = { className: string; hash: string; createdAt: Date; -}; -export type Queue = Array; -export type EventuallyQueue = { +} +export type Queue = QueueObject[]; +export interface EventuallyQueue { save: (object: ParseObject, serverOptions?: SaveOptions) => Promise; destroy: (object: ParseObject, serverOptions?: RequestOptions) => Promise; generateQueueId: (action: string, object: ParseObject) => string; @@ -128,23 +122,23 @@ export type EventuallyQueue = { byId(ObjectType: any, queueObject: any): Promise; byHash(ObjectType: any, queueObject: any): Promise; }; -}; -type RESTController = { +} +export interface RESTController { request: (method: string, path: string, data?: any, options?: RequestOptions) => Promise; ajax: (method: string, url: string, data: any, headers?: any, options?: FullOptions) => Promise; handleError: (err?: any) => void; -}; -type SchemaController = { +} +export interface SchemaController { purge: (className: string) => Promise; 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; send(className: string, method: string, params: any, options?: RequestOptions): Promise; -}; -type SessionController = { +} +export interface SessionController { getSession: (options?: RequestOptions) => Promise; -}; +} type StorageController = { async: 0; getItem: (path: string) => string | null; @@ -154,8 +148,8 @@ type StorageController = { setItemAsync?: (path: string, value: string) => Promise; removeItemAsync?: (path: string) => Promise; clear: () => void; - getAllKeys?: () => Array; - getAllKeysAsync?: () => Promise>; + getAllKeys?: () => string[]; + getAllKeysAsync?: () => Promise; } | { async: 1; getItem?: (path: string) => string | null; @@ -165,17 +159,17 @@ type StorageController = { setItemAsync: (path: string, value: string) => Promise; removeItemAsync: (path: string) => Promise; clear: () => void; - getAllKeys?: () => Array; - getAllKeysAsync?: () => Promise>; + getAllKeys?: () => string[]; + getAllKeysAsync?: () => Promise; }; -type LocalDatastoreController = { +export interface LocalDatastoreController { fromPinWithName: (name: string) => any | undefined; pinWithName: (name: string, objects: any) => void; unPinWithName: (name: string) => void; getAllContents: () => any | undefined; clear: () => void; -}; -type UserController = { +} +export interface UserController { setCurrentUser: (user: ParseUser) => Promise; currentUser: () => ParseUser | null; currentUserAsync: () => Promise; @@ -190,24 +184,24 @@ type UserController = { updateUserOnDisk: (user: ParseUser) => Promise; upgradeToRevocableSession: (user: ParseUser, options?: RequestOptions) => Promise; linkWith: (user: ParseUser, authData: AuthData, options?: FullOptions) => Promise; - removeUserFromDisk: () => Promise; + removeUserFromDisk: () => Promise; verifyPassword: (username: string, password: string, options?: RequestOptions) => Promise; requestEmailVerification: (email: string, options?: RequestOptions) => Promise; -}; -type HooksController = { +} +export interface HooksController { get: (type: string, functionName?: string, triggerName?: string) => Promise; create: (hook: HookDeclaration) => Promise; remove: (hook: HookDeleteArg) => Promise; update: (hook: HookDeclaration) => Promise; sendRequest?: (method: string, path: string, body?: any) => Promise; -}; -type LiveQueryControllerType = { +} +export interface LiveQueryControllerType { setDefaultLiveQueryClient(liveQueryClient: LiveQueryClient): void; getDefaultLiveQueryClient(): Promise; _clearCachedDefaultClient(): void; -}; +} /** Based on https://github.com/react-native-async-storage/async-storage/blob/main/packages/default-storage-backend/src/types.ts */ -type AsyncStorageType = { +export interface AsyncStorageType { /** Fetches an item for a `key` and invokes a callback upon completion. */ getItem: (key: string, callback?: (error?: Error | null, result?: string | null) => void) => Promise; /** Sets the value for a `key` and invokes a callback upon completion. */ @@ -250,15 +244,15 @@ type AsyncStorageType = { * See https://react-native-async-storage.github.io/async-storage/docs/api#multimerge */ multiMerge: (keyValuePairs: [string, string][], callback?: (errors?: readonly (Error | null)[] | null) => void) => Promise; -}; -export type WebSocketController = { +} +export interface WebSocketController { onopen: () => void; onmessage: (message: any) => void; onclose: (arg?: any) => void; onerror: (error: any) => void; send: (data: any) => void; close: () => void; -}; +} declare const CoreManager: { get: (key: string) => any; set: (key: string, value: any) => void; diff --git a/types/LocalDatastore.d.ts b/types/LocalDatastore.d.ts index d6f795de0..c431fb44f 100644 --- a/types/LocalDatastore.d.ts +++ b/types/LocalDatastore.d.ts @@ -22,14 +22,14 @@ import type ParseObject from './ParseObject'; declare const LocalDatastore: { isEnabled: boolean; isSyncing: boolean; - fromPinWithName(name: string): Promise>; + fromPinWithName(name: string): Promise; pinWithName(name: string, value: any): Promise; unPinWithName(name: string): Promise; _getAllContents(): Promise; _getRawStorage(): Promise; _clear(): Promise; - _handlePinAllWithName(name: string, objects: Array): Promise; - _handleUnPinAllWithName(name: string, objects: Array): Promise; + _handlePinAllWithName(name: string, objects: ParseObject[]): Promise; + _handleUnPinAllWithName(name: string, objects: ParseObject[]): Promise; _getChildren(object: ParseObject): any; _traverse(object: any, encountered: any): void; _serializeObjectsFromPinName(name: string): Promise; diff --git a/types/LocalDatastoreController.default.d.ts b/types/LocalDatastoreController.default.d.ts index 14416a1b7..e7c76a72b 100644 --- a/types/LocalDatastoreController.default.d.ts +++ b/types/LocalDatastoreController.default.d.ts @@ -1,5 +1,5 @@ declare const LocalDatastoreController: { - fromPinWithName(name: string): Promise>; + fromPinWithName(name: string): Promise; pinWithName(name: string, value: any): Promise; unPinWithName(name: string): Promise; getAllContents(): Promise; diff --git a/types/LocalDatastoreController.react-native.d.ts b/types/LocalDatastoreController.react-native.d.ts index 2db09d794..6a6c0c2d4 100644 --- a/types/LocalDatastoreController.react-native.d.ts +++ b/types/LocalDatastoreController.react-native.d.ts @@ -1,5 +1,5 @@ declare const LocalDatastoreController: { - fromPinWithName(name: string): Promise>; + fromPinWithName(name: string): Promise; pinWithName(name: string, value: any): Promise; unPinWithName(name: string): Promise; getAllContents(): Promise; diff --git a/types/ObjectStateMutations.d.ts b/types/ObjectStateMutations.d.ts index 7a2086d80..b026ef277 100644 --- a/types/ObjectStateMutations.d.ts +++ b/types/ObjectStateMutations.d.ts @@ -1,28 +1,22 @@ import TaskQueue from './TaskQueue'; import type { Op } from './ParseOp'; import type ParseObject from './ParseObject'; -export type AttributeMap = { - [attr: string]: any; -}; -export type OpsMap = { - [attr: string]: Op; -}; -export type ObjectCache = { - [attr: string]: string; -}; -export type State = { +export type AttributeMap = Record; +export type OpsMap = Record; +export type ObjectCache = Record; +export interface State { serverData: AttributeMap; - pendingOps: Array; + pendingOps: OpsMap[]; objectCache: ObjectCache; tasks: TaskQueue; existed: boolean; -}; +} export declare function defaultState(): State; export declare function setServerData(serverData: AttributeMap, attributes: AttributeMap): void; -export declare function setPendingOp(pendingOps: Array, attr: string, op?: Op): void; -export declare function pushPendingState(pendingOps: Array): void; -export declare function popPendingState(pendingOps: Array): OpsMap; -export declare function mergeFirstPendingState(pendingOps: Array): void; -export declare function estimateAttribute(serverData: AttributeMap, pendingOps: Array, object: ParseObject, attr: string): any; -export declare function estimateAttributes(serverData: AttributeMap, pendingOps: Array, object: ParseObject): AttributeMap; +export declare function setPendingOp(pendingOps: OpsMap[], attr: string, op?: Op): void; +export declare function pushPendingState(pendingOps: OpsMap[]): void; +export declare function popPendingState(pendingOps: OpsMap[]): OpsMap; +export declare function mergeFirstPendingState(pendingOps: OpsMap[]): void; +export declare function estimateAttribute(serverData: AttributeMap, pendingOps: OpsMap[], object: ParseObject, attr: string): any; +export declare function estimateAttributes(serverData: AttributeMap, pendingOps: OpsMap[], object: ParseObject): AttributeMap; export declare function commitServerChanges(serverData: AttributeMap, objectCache: ObjectCache, changes: AttributeMap): void; diff --git a/types/Parse.d.ts b/types/Parse.d.ts index cefbc562f..7369fdeed 100644 --- a/types/Parse.d.ts +++ b/types/Parse.d.ts @@ -6,7 +6,6 @@ import CLP from './ParseCLP'; import Config from './ParseConfig'; import ParseError from './ParseError'; import File from './ParseFile'; -import * as Hooks from './ParseHooks'; import GeoPoint from './ParseGeoPoint'; import Polygon from './ParsePolygon'; import Installation from './ParseInstallation'; @@ -45,208 +44,38 @@ declare const Parse: { get: (key: string) => any; set: (key: string, value: any) => void; setIfNeeded: (key: string, value: any) => any; - setAnalyticsController(controller: { - track: (name: string, dimensions: { - [key: string]: string; - }) => Promise; - }): void; - getAnalyticsController(): { - track: (name: string, dimensions: { - [key: string]: string; - }) => Promise; - }; - setCloudController(controller: { - run: (name: string, data: any, options?: import("./RESTController").RequestOptions) => Promise; - getJobsData: (options?: import("./RESTController").RequestOptions) => Promise; - startJob: (name: string, data: any, options?: import("./RESTController").RequestOptions) => Promise; - }): void; - getCloudController(): { - run: (name: string, data: any, options?: import("./RESTController").RequestOptions) => Promise; - getJobsData: (options?: import("./RESTController").RequestOptions) => Promise; - startJob: (name: string, data: any, options?: import("./RESTController").RequestOptions) => Promise; - }; - setConfigController(controller: { - current: () => Promise | Config; - get: (opts?: import("./RESTController").RequestOptions) => Promise; - save: (attrs: { - [key: string]: any; - }, masterKeyOnlyFlags?: { - [key: string]: any; - }) => Promise; - }): void; - getConfigController(): { - current: () => Promise | Config; - get: (opts?: import("./RESTController").RequestOptions) => Promise; - save: (attrs: { - [key: string]: any; - }, masterKeyOnlyFlags?: { - [key: string]: any; - }) => Promise; - }; - setCryptoController(controller: { - encrypt: (obj: any, secretKey: string) => string; - decrypt: (encryptedText: string, secretKey: any) => string; - }): void; - getCryptoController(): { - encrypt: (obj: any, secretKey: string) => string; - decrypt: (encryptedText: string, secretKey: any) => string; - }; + setAnalyticsController(controller: import("./CoreManager").AnalyticsController): void; + getAnalyticsController(): import("./CoreManager").AnalyticsController; + setCloudController(controller: import("./CoreManager").CloudController): void; + getCloudController(): import("./CoreManager").CloudController; + setConfigController(controller: import("./CoreManager").ConfigController): void; + getConfigController(): import("./CoreManager").ConfigController; + setCryptoController(controller: import("./CoreManager").CryptoController): void; + getCryptoController(): import("./CoreManager").CryptoController; setEventEmitter(eventEmitter: any): void; getEventEmitter(): any; - setFileController(controller: { - saveFile: (name: string, source: import("./ParseFile").FileSource, options?: import("./RESTController").FullOptions) => Promise; - saveBase64: (name: string, source: import("./ParseFile").FileSource, options?: import("./ParseFile").FileSaveOptions) => Promise<{ - name: string; - url: string; - }>; - download: (uri: string, options?: any) => Promise<{ - base64?: string; - contentType?: string; - }>; - deleteFile: (name: string, options?: { - useMasterKey?: boolean; - }) => Promise; - }): void; + setFileController(controller: import("./CoreManager").FileController): void; setEventuallyQueue(controller: EventuallyQueue): void; getEventuallyQueue(): EventuallyQueue; - getFileController(): { - saveFile: (name: string, source: import("./ParseFile").FileSource, options?: import("./RESTController").FullOptions) => Promise; - saveBase64: (name: string, source: import("./ParseFile").FileSource, options?: import("./ParseFile").FileSaveOptions) => Promise<{ - name: string; - url: string; - }>; - download: (uri: string, options?: any) => Promise<{ - base64?: string; - contentType?: string; - }>; - deleteFile: (name: string, options?: { - useMasterKey?: boolean; - }) => Promise; - }; - setInstallationController(controller: { - currentInstallationId: () => Promise; - currentInstallation: () => Promise; - updateInstallationOnDisk: (installation: Installation) => Promise; - }): void; - getInstallationController(): { - currentInstallationId: () => Promise; - currentInstallation: () => Promise; - updateInstallationOnDisk: (installation: Installation) => Promise; - }; + getFileController(): import("./CoreManager").FileController; + setInstallationController(controller: import("./CoreManager").InstallationController): void; + getInstallationController(): import("./CoreManager").InstallationController; setLiveQuery(liveQuery: any): void; getLiveQuery(): any; - setObjectController(controller: { - fetch: (object: ParseObject | Array, forceFetch: boolean, options?: import("./RESTController").RequestOptions) => Promise | ParseObject | undefined>; - save: (object: ParseObject | Array | null, options?: import("./RESTController").RequestOptions) => Promise | File | undefined>; - destroy: (object: ParseObject | Array, options?: import("./RESTController").RequestOptions) => Promise>; - }): void; - getObjectController(): { - fetch: (object: ParseObject | Array, forceFetch: boolean, options?: import("./RESTController").RequestOptions) => Promise | ParseObject | undefined>; - save: (object: ParseObject | Array | null, options?: import("./RESTController").RequestOptions) => Promise | File | undefined>; - destroy: (object: ParseObject | Array, options?: import("./RESTController").RequestOptions) => Promise>; - }; - setObjectStateController(controller: { - getState: (obj: any) => import("./ObjectStateMutations").State | null; - initializeState: (obj: any, initial?: import("./ObjectStateMutations").State) => import("./ObjectStateMutations").State; - removeState: (obj: any) => import("./ObjectStateMutations").State | null; - getServerData: (obj: any) => import("./ObjectStateMutations").AttributeMap; - setServerData: (obj: any, attributes: import("./ObjectStateMutations").AttributeMap) => void; - getPendingOps: (obj: any) => Array; - setPendingOp: (obj: any, attr: string, op?: ParseOp.Op) => void; - pushPendingState: (obj: any) => void; - popPendingState: (obj: any) => import("./ObjectStateMutations").OpsMap | undefined; - mergeFirstPendingState: (obj: any) => void; - getObjectCache: (obj: any) => import("./ObjectStateMutations").ObjectCache; - estimateAttribute: (obj: any, attr: string) => any; - estimateAttributes: (obj: any) => import("./ObjectStateMutations").AttributeMap; - commitServerChanges: (obj: any, changes: import("./ObjectStateMutations").AttributeMap) => void; - enqueueTask: (obj: any, task: () => Promise) => Promise; - clearAllState: () => void; - duplicateState: (source: any, dest: any) => void; - }): void; - getObjectStateController(): { - getState: (obj: any) => import("./ObjectStateMutations").State | null; - initializeState: (obj: any, initial?: import("./ObjectStateMutations").State) => import("./ObjectStateMutations").State; - removeState: (obj: any) => import("./ObjectStateMutations").State | null; - getServerData: (obj: any) => import("./ObjectStateMutations").AttributeMap; - setServerData: (obj: any, attributes: import("./ObjectStateMutations").AttributeMap) => void; - getPendingOps: (obj: any) => Array; - setPendingOp: (obj: any, attr: string, op?: ParseOp.Op) => void; - pushPendingState: (obj: any) => void; - popPendingState: (obj: any) => import("./ObjectStateMutations").OpsMap | undefined; - mergeFirstPendingState: (obj: any) => void; - getObjectCache: (obj: any) => import("./ObjectStateMutations").ObjectCache; - estimateAttribute: (obj: any, attr: string) => any; - estimateAttributes: (obj: any) => import("./ObjectStateMutations").AttributeMap; - commitServerChanges: (obj: any, changes: import("./ObjectStateMutations").AttributeMap) => void; - enqueueTask: (obj: any, task: () => Promise) => Promise; - clearAllState: () => void; - duplicateState: (source: any, dest: any) => void; - }; - setPushController(controller: { - send: (data: Push.PushData, options?: import("./RESTController").FullOptions) => Promise; - }): void; - getPushController(): { - send: (data: Push.PushData, options?: import("./RESTController").FullOptions) => Promise; - }; - setQueryController(controller: { - find(className: string, params: import("./ParseQuery").QueryJSON, options?: import("./RESTController").RequestOptions): Promise<{ - results?: Array; - className?: string; - count?: number; - }>; - aggregate(className: string, params: any, options?: import("./RESTController").RequestOptions): Promise<{ - results?: Array; - }>; - }): void; - getQueryController(): { - find(className: string, params: import("./ParseQuery").QueryJSON, options?: import("./RESTController").RequestOptions): Promise<{ - results?: Array; - className?: string; - count?: number; - }>; - aggregate(className: string, params: any, options?: import("./RESTController").RequestOptions): Promise<{ - results?: Array; - }>; - }; - setRESTController(controller: { - request: (method: string, path: string, data?: any, options?: import("./RESTController").RequestOptions) => Promise; - ajax: (method: string, url: string, data: any, headers?: any, options?: import("./RESTController").FullOptions) => Promise; - handleError: (err?: any) => void; - }): void; - getRESTController(): { - request: (method: string, path: string, data?: any, options?: import("./RESTController").RequestOptions) => Promise; - ajax: (method: string, url: string, data: any, headers?: any, options?: import("./RESTController").FullOptions) => Promise; - handleError: (err?: any) => void; - }; - setSchemaController(controller: { - purge: (className: string) => Promise; - get: (className: string, options?: import("./RESTController").RequestOptions) => Promise; - delete: (className: string, options?: import("./RESTController").RequestOptions) => Promise; - create: (className: string, params: any, options? /** - * @member {string} Parse.maintenanceKey - * @static - */: import("./RESTController").RequestOptions) => Promise; - update: (className: string, params: any, options?: import("./RESTController").RequestOptions) => Promise; - send(className: string, method: string, params: any, options?: import("./RESTController").RequestOptions): Promise; - }): void; - getSchemaController(): { - purge: (className: string) => Promise; - get: (className: string, options?: import("./RESTController").RequestOptions) => Promise; - delete: (className: string, options?: import("./RESTController").RequestOptions) => Promise; - create: (className: string, params: any, options? /** - * @member {string} Parse.maintenanceKey - * @static - */: import("./RESTController").RequestOptions) => Promise; - update: (className: string, params: any, options?: import("./RESTController").RequestOptions) => Promise; - send(className: string, method: string, params: any, options?: import("./RESTController").RequestOptions): Promise; - }; - setSessionController(controller: { - getSession: (options?: import("./RESTController").RequestOptions) => Promise; - }): void; - getSessionController(): { - getSession: (options?: import("./RESTController").RequestOptions) => Promise; - }; + setObjectController(controller: import("./CoreManager").ObjectController): void; + getObjectController(): import("./CoreManager").ObjectController; + setObjectStateController(controller: import("./CoreManager").ObjectStateController): void; + getObjectStateController(): import("./CoreManager").ObjectStateController; + setPushController(controller: import("./CoreManager").PushController): void; + getPushController(): import("./CoreManager").PushController; + setQueryController(controller: import("./CoreManager").QueryController): void; + getQueryController(): import("./CoreManager").QueryController; + setRESTController(controller: import("./CoreManager").RESTController): void; + getRESTController(): import("./CoreManager").RESTController; + setSchemaController(controller: import("./CoreManager").SchemaController): void; + getSchemaController(): import("./CoreManager").SchemaController; + setSessionController(controller: import("./CoreManager").SessionController): void; + getSessionController(): import("./CoreManager").SessionController; setStorageController(controller: { async: 0; getItem: (path: string) => string | null; @@ -256,8 +85,8 @@ declare const Parse: { setItemAsync?: (path: string, value: string) => Promise; removeItemAsync?: (path: string) => Promise; clear: () => void; - getAllKeys?: () => Array; - getAllKeysAsync?: () => Promise>; + getAllKeys?: () => string[]; + getAllKeysAsync?: () => Promise; } | { async: 1; getItem?: (path: string) => string | null; @@ -267,23 +96,11 @@ declare const Parse: { setItemAsync: (path: string, value: string) => Promise; removeItemAsync: (path: string) => Promise; clear: () => void; - getAllKeys?: () => Array; - getAllKeysAsync?: () => Promise>; + getAllKeys?: () => string[]; + getAllKeysAsync?: () => Promise; }): void; - setLocalDatastoreController(controller: { - fromPinWithName: (name: string) => any | undefined; - pinWithName: (name: string, objects: any) => void; - unPinWithName: (name: string) => void; - getAllContents: () => any | undefined; - clear: () => void; - }): void; - getLocalDatastoreController(): { - fromPinWithName: (name: string) => any | undefined; - pinWithName: (name: string, objects: any) => void; - unPinWithName: (name: string) => void; - getAllContents: () => any | undefined; - clear: () => void; - }; + setLocalDatastoreController(controller: import("./CoreManager").LocalDatastoreController): void; + getLocalDatastoreController(): import("./CoreManager").LocalDatastoreController; setLocalDatastore(store: any): void; getLocalDatastore(): any; getStorageController(): { @@ -295,8 +112,8 @@ declare const Parse: { setItemAsync?: (path: string, value: string) => Promise; removeItemAsync?: (path: string) => Promise; clear: () => void; - getAllKeys?: () => Array; - getAllKeysAsync?: () => Promise>; + getAllKeys?: () => string[]; + getAllKeysAsync?: () => Promise; } | { async: 1; getItem?: (path: string) => string | null; @@ -306,97 +123,19 @@ declare const Parse: { setItemAsync: (path: string, value: string) => Promise; removeItemAsync: (path: string) => Promise; clear: () => void; - getAllKeys?: () => Array; - getAllKeysAsync?: () => Promise>; - }; - setAsyncStorage(storage: { - getItem: (key: string, callback?: (error?: Error | null, result?: string | null) => void) => Promise; - setItem: (key: string, value: string, callback?: (error?: Error | null) => void) => Promise; - removeItem: (key: string, callback?: (error?: Error | null) => void) => Promise; - mergeItem: (key: string, value: string, callback?: (error?: Error | null) => void) => Promise; - clear: (callback?: (error?: Error | null) => void) => Promise; - getAllKeys: (callback?: (error?: Error | null, result?: readonly string[] | null) => void) => Promise; - multiGet: (keys: readonly string[], callback?: (errors?: readonly (Error | null)[] | null, result?: readonly [string, string][]) => void) => Promise; - multiSet: (keyValuePairs: [string, string][], callback?: (errors?: readonly (Error | null)[] | null) => void) => Promise; - multiRemove: (keys: readonly string[], callback?: (errors?: readonly (Error | null)[] | null) => void) => Promise; - multiMerge: (keyValuePairs: [string, string][], callback?: (errors?: readonly (Error | null)[] | null) => void) => Promise; - }): void; - getAsyncStorage(): { - getItem: (key: string, callback?: (error?: Error | null, result?: string | null) => void) => Promise; - setItem: (key: string, value: string, callback?: (error?: Error | null) => void) => Promise; - removeItem: (key: string, callback?: (error?: Error | null) => void) => Promise; - mergeItem: (key: string, value: string, callback?: (error?: Error | null) => void) => Promise; - clear: (callback?: (error?: Error | null) => void) => Promise; - getAllKeys: (callback?: (error?: Error | null, result?: readonly string[] | null) => void) => Promise; - multiGet: (keys: readonly string[], callback?: (errors?: readonly (Error | null)[] | null, result?: readonly [string, string][]) => void) => Promise; - multiSet: (keyValuePairs: [string, string][], callback?: (errors?: readonly (Error | null)[] | null) => void) => Promise; - multiRemove: (keys: readonly string[], callback?: (errors?: readonly (Error | null)[] | null) => void) => Promise; - multiMerge: (keyValuePairs: [string, string][], callback?: (errors?: readonly (Error | null)[] | null) => void) => Promise; + getAllKeys?: () => string[]; + getAllKeysAsync?: () => Promise; }; + setAsyncStorage(storage: import("./CoreManager").AsyncStorageType): void; + getAsyncStorage(): import("./CoreManager").AsyncStorageType; setWebSocketController(controller: new (url: string | URL, protocols?: string | string[] | undefined) => import("./CoreManager").WebSocketController): void; getWebSocketController(): new (url: string | URL, protocols?: string | string[] | undefined) => import("./CoreManager").WebSocketController; - setUserController(controller: { - setCurrentUser: (user: User) => Promise; - currentUser: () => User | null; - currentUserAsync: () => Promise; - signUp: (user: User, attrs: import("./ObjectStateMutations").AttributeMap, options?: import("./RESTController").RequestOptions) => Promise; - logIn: (user: User, options?: import("./RESTController").RequestOptions) => Promise; - loginAs: (user: User, userId: string) => Promise; - become: (user: User, options?: import("./RESTController").RequestOptions) => Promise; - hydrate: (user: User, userJSON: import("./ObjectStateMutations").AttributeMap) => Promise; - logOut: (options?: import("./RESTController").RequestOptions) => Promise; - me: (user: User, options?: import("./RESTController").RequestOptions) => Promise; - requestPasswordReset: (email: string, options?: import("./RESTController").RequestOptions) => Promise; - updateUserOnDisk: (user: User) => Promise; - upgradeToRevocableSession: (user: User, options?: import("./RESTController").RequestOptions) => Promise; - linkWith: (user: User, authData: import("./ParseUser").AuthData, options?: import("./RESTController").FullOptions) => Promise; - removeUserFromDisk: () => Promise; - verifyPassword: (username: string, password: string, options?: import("./RESTController").RequestOptions) => Promise; - requestEmailVerification: (email: string, options?: import("./RESTController").RequestOptions) => Promise; - }): void; - getUserController(): { - setCurrentUser: (user: User) => Promise; - currentUser: () => User | null; - currentUserAsync: () => Promise; - signUp: (user: User, attrs: import("./ObjectStateMutations").AttributeMap, options?: import("./RESTController").RequestOptions) => Promise; - logIn: (user: User, options?: import("./RESTController").RequestOptions) => Promise; - loginAs: (user: User, userId: string) => Promise; - become: (user: User, options?: import("./RESTController").RequestOptions) => Promise; - hydrate: (user: User, userJSON: import("./ObjectStateMutations").AttributeMap) => Promise; - logOut: (options?: import("./RESTController").RequestOptions) => Promise; - me: (user: User, options?: import("./RESTController").RequestOptions) => Promise; - requestPasswordReset: (email: string, options?: import("./RESTController").RequestOptions) => Promise; - updateUserOnDisk: (user: User) => Promise; - upgradeToRevocableSession: (user: User, options?: import("./RESTController").RequestOptions) => Promise; - linkWith: (user: User, authData: import("./ParseUser").AuthData, options?: import("./RESTController").FullOptions) => Promise; - removeUserFromDisk: () => Promise; - verifyPassword: (username: string, password: string, options?: import("./RESTController").RequestOptions) => Promise; - requestEmailVerification: (email: string, options?: import("./RESTController").RequestOptions) => Promise; - }; - setLiveQueryController(controller: { - setDefaultLiveQueryClient(liveQueryClient: LiveQueryClient): void; - getDefaultLiveQueryClient(): Promise; - _clearCachedDefaultClient(): void; - }): void; - getLiveQueryController(): { - setDefaultLiveQueryClient(liveQueryClient: LiveQueryClient): void; - getDefaultLiveQueryClient(): Promise; - _clearCachedDefaultClient(): void; - }; - setHooksController(controller: { - get: (type: string, functionName?: string, triggerName?: string) => Promise; - create: (hook: Hooks.HookDeclaration) => Promise; - remove: (hook: Hooks.HookDeleteArg) => Promise; - update: (hook: Hooks.HookDeclaration) => Promise; - sendRequest?: (method: string, path: string, body?: any) => Promise; - }): void; - getHooksController(): { - get: (type: string, functionName?: string, triggerName?: string) => Promise; - create: (hook: Hooks.HookDeclaration) => Promise; - remove: (hook: Hooks.HookDeleteArg) => Promise; - update: (hook: Hooks.HookDeclaration) => Promise; - sendRequest?: (method: string, path: string, body?: any) => Promise; - }; + setUserController(controller: import("./CoreManager").UserController): void; + getUserController(): import("./CoreManager").UserController; + setLiveQueryController(controller: import("./CoreManager").LiveQueryControllerType): void; + getLiveQueryController(): import("./CoreManager").LiveQueryControllerType; + setHooksController(controller: import("./CoreManager").HooksController): void; + getHooksController(): import("./CoreManager").HooksController; setParseOp(op: any): void; getParseOp(): any; setParseObject(object: any): void; @@ -425,14 +164,14 @@ declare const Parse: { LocalDatastore: { isEnabled: boolean; isSyncing: boolean; - fromPinWithName(name: string): Promise>; + fromPinWithName(name: string): Promise; pinWithName(name: string, value: any): Promise; unPinWithName(name: string): Promise; _getAllContents(): Promise; _getRawStorage(): Promise; _clear(): Promise; - _handlePinAllWithName(name: string, objects: Array): Promise; - _handleUnPinAllWithName(name: string, objects: Array): Promise; + _handlePinAllWithName(name: string, objects: ParseObject[]): Promise; + _handleUnPinAllWithName(name: string, objects: ParseObject[]): Promise; _getChildren(object: ParseObject): any; _traverse(object: any, encountered: any): void; _serializeObjectsFromPinName(name: string): Promise; @@ -469,8 +208,8 @@ declare const Parse: { setItemAsync(path: string, value: string): Promise; removeItem(path: string): void; removeItemAsync(path: string): Promise; - getAllKeys(): Array; - getAllKeysAsync(): Promise>; + getAllKeys(): string[]; + getAllKeysAsync(): Promise; generatePath(path: string): string; _clear(): void; }; diff --git a/types/ParseACL.d.ts b/types/ParseACL.d.ts index 124f27d10..95acc6f41 100644 --- a/types/ParseACL.d.ts +++ b/types/ParseACL.d.ts @@ -1,11 +1,7 @@ import type ParseRole from './ParseRole'; import type ParseUser from './ParseUser'; -type PermissionsMap = { - [permission: string]: boolean; -}; -type ByIdMap = { - [userId: string]: PermissionsMap; -}; +type PermissionsMap = Record; +type ByIdMap = Record; /** * Creates a new ACL. * If no argument is given, the ACL has no permissions for anyone. diff --git a/types/ParseCLP.d.ts b/types/ParseCLP.d.ts index eaa7d6b26..d9133d510 100644 --- a/types/ParseCLP.d.ts +++ b/types/ParseCLP.d.ts @@ -1,15 +1,11 @@ import ParseRole from './ParseRole'; import ParseUser from './ParseUser'; type Entity = ParseUser | ParseRole | string; -type UsersMap = { - [userId: string]: boolean | any; -}; +type UsersMap = Record; export type PermissionsMap = { writeUserFields?: string[]; readUserFields?: string[]; -} & { - [permission: string]: UsersMap; -}; +} & Record; /** * Creates a new CLP. * If no argument is given, the CLP has no permissions for anyone. diff --git a/types/ParseConfig.d.ts b/types/ParseConfig.d.ts index cfd77f36d..73fd385e3 100644 --- a/types/ParseConfig.d.ts +++ b/types/ParseConfig.d.ts @@ -6,12 +6,8 @@ import type { RequestOptions } from './RESTController'; * @alias Parse.Config */ declare class ParseConfig { - attributes: { - [key: string]: any; - }; - _escapedAttributes: { - [key: string]: any; - }; + attributes: Record; + _escapedAttributes: Record; constructor(); /** * Gets the value of an attribute. @@ -62,11 +58,7 @@ declare class ParseConfig { * @returns {Promise} A promise that is resolved with a newly-created * configuration object or with the current with the update. */ - static save(attrs: { - [key: string]: any; - }, masterKeyOnlyFlags: { - [key: string]: any; - }): Promise; + static save(attrs: Record, masterKeyOnlyFlags: Record): Promise; /** * Used for testing * diff --git a/types/ParseFile.d.ts b/types/ParseFile.d.ts index da9c7e48e..a79b3dcf7 100644 --- a/types/ParseFile.d.ts +++ b/types/ParseFile.d.ts @@ -1,18 +1,14 @@ import type { FullOptions } from './RESTController'; -type Base64 = { +interface Base64 { base64: string; -}; -type Uri = { +} +interface Uri { uri: string; -}; -type FileData = Array | Base64 | Blob | Uri; +} +type FileData = number[] | Base64 | Blob | Uri; export type FileSaveOptions = FullOptions & { - metadata?: { - [key: string]: any; - }; - tags?: { - [key: string]: any; - }; + metadata?: Record; + tags?: Record; }; export type FileSource = { format: 'file'; @@ -187,6 +183,6 @@ declare class ParseFile { */ addTag(key: string, value: string): void; static fromJSON(obj: any): ParseFile; - static encodeBase64(bytes: Array | Uint8Array): string; + static encodeBase64(bytes: number[] | Uint8Array): string; } export default ParseFile; diff --git a/types/ParseInstallation.d.ts b/types/ParseInstallation.d.ts index 402245a50..45096398d 100644 --- a/types/ParseInstallation.d.ts +++ b/types/ParseInstallation.d.ts @@ -1,12 +1,12 @@ import ParseObject, { Attributes } from './ParseObject'; -type DeviceInterface = { +interface DeviceInterface { IOS: string; MACOS: string; TVOS: string; FCM: string; ANDROID: string; WEB: string; -}; +} /** * Parse.Installation is a local representation of installation data that can be saved and retrieved from the Parse cloud. * This class is a subclass of a Parse.Object, and retains the same functionality of a Parse.Object, but also extends it with installation-specific features. @@ -153,7 +153,7 @@ declare class ParseInstallation extends Parse * @param {...any} args * @returns {Promise} */ - fetch(...args: Array): Promise; + fetch(...args: any[]): 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. @@ -161,7 +161,7 @@ declare class ParseInstallation extends Parse * @param {...any} args * @returns {Promise} */ - save(...args: Array): Promise; + save(...args: any[]): Promise; _markAllFieldsDirty(): void; /** * Get the current Parse.Installation from disk. If doesn't exists, create an new installation. diff --git a/types/ParseObject.d.ts b/types/ParseObject.d.ts index a81cdbd2f..135759a53 100644 --- a/types/ParseObject.d.ts +++ b/types/ParseObject.d.ts @@ -7,37 +7,35 @@ 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 = { +export interface Pointer { __type: string; className: string; objectId?: string; _localId?: string; -}; -type SaveParams = { +} +interface SaveParams { method: string; path: string; body: AttributeMap; -}; +} export type SaveOptions = FullOptions & { cascadeSave?: boolean; context?: AttributeMap; batchSize?: number; transaction?: boolean; }; -type FetchOptions = { +interface FetchOptions { useMasterKey?: boolean; sessionToken?: string; include?: string | string[]; context?: AttributeMap; -}; -export type SetOptions = { +} +export interface SetOptions { ignoreValidation?: boolean; unset?: boolean; -}; -export type AttributeKey = Extract; -export interface Attributes { - [key: string]: any; } +export type AttributeKey = Extract; +export type Attributes = Record; interface JSONBaseAttributes { objectId: string; createdAt: string; @@ -52,7 +50,7 @@ type AtomicKey = { 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; +} : T extends RegExp ? string : T extends (infer R)[] ? Encode[] : T extends object ? ToJSON : T; type ToJSON = { [K in keyof T]: Encode; }; @@ -126,14 +124,14 @@ declare class ParseObject { }; _getServerData(): Attributes; _clearServerData(): void; - _getPendingOps(): Array; + _getPendingOps(): OpsMap[]; /** * @param {Array} [keysToClear] - if specified, only ops matching * these fields will be cleared */ - _clearPendingOps(keysToClear?: Array): void; + _clearPendingOps(keysToClear?: string[]): void; _getDirtyObjectAttributes(): Attributes; - _toFullJSON(seen?: Array, offline?: boolean): Attributes; + _toFullJSON(seen?: any[], offline?: boolean): Attributes; _getSaveJSON(): Attributes; _getSaveParams(): SaveParams; _finishFetch(serverData: Attributes): void; @@ -155,7 +153,7 @@ declare class ParseObject { * @param offline * @returns {object} */ - toJSON(seen: Array | void, offline?: boolean): ToJSON & JSONBaseAttributes; + toJSON(seen?: any[], offline?: boolean): ToJSON & JSONBaseAttributes; /** * Determines whether this ParseObject is equal to another ParseObject * @@ -426,7 +424,7 @@ declare class ParseObject { * * @param {string} [keys] - specify which fields to revert */ - revert(...keys: Array>): void; + revert(...keys: Extract[]): void; /** * Clears all attributes on a model * @@ -469,7 +467,7 @@ declare class ParseObject { * @returns {Promise} A promise that is fulfilled when the fetch * completes. */ - fetchWithInclude(keys: string | Array>, options?: RequestOptions): Promise; + fetchWithInclude(keys: string | (string | string[])[], options?: RequestOptions): Promise; /** * Saves this object to the server at some unspecified time in the future, * even if Parse is currently inaccessible. @@ -596,7 +594,7 @@ declare class ParseObject { * @returns {Promise} A promise that is fulfilled when the destroy * completes. */ - destroy(options?: RequestOptions): Promise; + destroy(options?: RequestOptions): Promise; /** * Asynchronously stores the object and every object it points to in the local datastore, * recursively, using a default pin name: _default. @@ -733,7 +731,7 @@ declare class ParseObject { * @static * @returns {Parse.Object[]} */ - static fetchAllWithInclude(list: T[], keys: keyof T['attributes'] | Array, options?: RequestOptions): Promise; + static fetchAllWithInclude(list: T[], keys: keyof T['attributes'] | (keyof T['attributes'])[], options?: RequestOptions): Promise; /** * Fetches the given list of Parse.Object if needed. * If any error is encountered, stops and calls the error handler. @@ -764,7 +762,7 @@ declare class ParseObject { * @static * @returns {Parse.Object[]} */ - static fetchAllIfNeededWithInclude(list: T[], keys: keyof T['attributes'] | Array, options?: RequestOptions): Promise; + static fetchAllIfNeededWithInclude(list: T[], keys: keyof T['attributes'] | (keyof T['attributes'])[], options?: RequestOptions): Promise; /** * Fetches the given list of Parse.Object if needed. * If any error is encountered, stops and calls the error handler. @@ -851,7 +849,7 @@ declare class ParseObject { * @returns {Promise} A promise that is fulfilled when the destroyAll * completes. */ - static destroyAll(list: Array, options?: SaveOptions): Promise | ParseObject[]>; + static destroyAll(list: ParseObject[], options?: SaveOptions): Promise | ParseObject[]>; /** * Saves the given list of Parse.Object. * If any error is encountered, stops and calls the error handler. @@ -998,7 +996,7 @@ declare class ParseObject { * @returns {Promise} A promise that is fulfilled when the pin completes. * @static */ - static pinAll(objects: Array): Promise; + static pinAll(objects: ParseObject[]): Promise; /** * Asynchronously stores the objects and every object they point to in the local datastore, recursively. * @@ -1017,7 +1015,7 @@ declare class ParseObject { * @returns {Promise} A promise that is fulfilled when the pin completes. * @static */ - static pinAllWithName(name: string, objects: Array): Promise; + static pinAllWithName(name: string, objects: ParseObject[]): Promise; /** * Asynchronously removes the objects and every object they point to in the local datastore, * recursively, using a default pin name: _default. @@ -1030,7 +1028,7 @@ declare class ParseObject { * @returns {Promise} A promise that is fulfilled when the unPin completes. * @static */ - static unPinAll(objects: Array): Promise; + static unPinAll(objects: ParseObject[]): Promise; /** * Asynchronously removes the objects and every object they point to in the local datastore, recursively. * @@ -1043,7 +1041,7 @@ declare class ParseObject { * @returns {Promise} A promise that is fulfilled when the unPin completes. * @static */ - static unPinAllWithName(name: string, objects: Array): Promise; + static unPinAllWithName(name: string, objects: ParseObject[]): Promise; /** * Asynchronously removes all objects in the local datastore using a default pin name: _default. * diff --git a/types/ParseOp.d.ts b/types/ParseOp.d.ts index 1ffd8bbc8..b64c66f5a 100644 --- a/types/ParseOp.d.ts +++ b/types/ParseOp.d.ts @@ -1,8 +1,6 @@ import type ParseObject from './ParseObject'; import ParseRelation from './ParseRelation'; -export declare function opFromJSON(json: { - [key: string]: any; -}): Op | null; +export declare function opFromJSON(json: Record): Op | null; export declare class Op { applyTo(value: any): any; mergeWith(previous: Op): Op | void; @@ -33,9 +31,9 @@ export declare class IncrementOp extends Op { }; } export declare class AddOp extends Op { - _value: Array; - constructor(value: any | Array); - applyTo(value: any): Array; + _value: any[]; + constructor(value: any | any[]); + applyTo(value: any): any[]; mergeWith(previous: Op): Op; toJSON(): { __op: string; @@ -43,9 +41,9 @@ export declare class AddOp extends Op { }; } export declare class AddUniqueOp extends Op { - _value: Array; - constructor(value: any | Array); - applyTo(value: any | Array): Array; + _value: any[]; + constructor(value: any | any[]); + applyTo(value: any | any[]): any[]; mergeWith(previous: Op): Op; toJSON(): { __op: string; @@ -53,9 +51,9 @@ export declare class AddUniqueOp extends Op { }; } export declare class RemoveOp extends Op { - _value: Array; - constructor(value: any | Array); - applyTo(value: any | Array): Array; + _value: any[]; + constructor(value: any | any[]); + applyTo(value: any | any[]): any[]; mergeWith(previous: Op): Op; toJSON(): { __op: string; @@ -64,9 +62,9 @@ export declare class RemoveOp extends Op { } export declare class RelationOp extends Op { _targetClassName: string | null; - relationsToAdd: Array; - relationsToRemove: Array; - constructor(adds: Array, removes: Array); + relationsToAdd: string[]; + relationsToRemove: string[]; + constructor(adds: (ParseObject | string)[], removes: (ParseObject | string)[]); _extractId(obj: string | ParseObject): string; applyTo(value: any, parent?: ParseObject, key?: string): ParseRelation; mergeWith(previous: Op): Op; diff --git a/types/ParsePolygon.d.ts b/types/ParsePolygon.d.ts index 28d4b07d2..b85b51588 100644 --- a/types/ParsePolygon.d.ts +++ b/types/ParsePolygon.d.ts @@ -25,7 +25,7 @@ declare class ParsePolygon { /** * @param {(Coordinates | Parse.GeoPoint[])} coordinates An Array of coordinate pairs */ - constructor(coordinates: Coordinates | Array); + constructor(coordinates: Coordinates | ParseGeoPoint[]); /** * Coordinates value for this Polygon. * Throws an exception if not valid type. @@ -34,7 +34,7 @@ declare class ParsePolygon { * @returns {Coordinates} */ get coordinates(): Coordinates; - set coordinates(coords: Coordinates | Array); + set coordinates(coords: Coordinates | ParseGeoPoint[]); /** * Returns a JSON representation of the Polygon, suitable for Parse. * @@ -64,6 +64,6 @@ declare class ParsePolygon { * @throws {TypeError} * @returns {number[][]} Array of coordinates if validated. */ - static _validate(coords: Coordinates | Array): Coordinates; + static _validate(coords: Coordinates | ParseGeoPoint[]): Coordinates; } export default ParsePolygon; diff --git a/types/ParseQuery.d.ts b/types/ParseQuery.d.ts index 6035c5167..50bf65612 100644 --- a/types/ParseQuery.d.ts +++ b/types/ParseQuery.d.ts @@ -8,28 +8,22 @@ type BatchOptions = FullOptions & { useMasterKey?: boolean; useMaintenanceKey?: boolean; sessionToken?: string; - context?: { - [key: string]: any; - }; + context?: Record; json?: boolean; }; -export type WhereClause = { - [attr: string]: any; -}; -type QueryOptions = { +export type WhereClause = Record; +interface QueryOptions { useMasterKey?: boolean; sessionToken?: string; - context?: { - [key: string]: any; - }; + context?: Record; json?: boolean; -}; -type FullTextQueryOptions = { +} +interface FullTextQueryOptions { language?: string; caseSensitive?: boolean; diacriticSensitive?: boolean; -}; -export type QueryJSON = { +} +export interface QueryJSON { where: WhereClause; watch?: string; include?: string; @@ -46,7 +40,7 @@ export type QueryJSON = { includeReadPreference?: string; subqueryReadPreference?: string; comment?: string; -}; +} interface BaseAttributes { createdAt: Date; objectId: string; @@ -101,22 +95,20 @@ declare class ParseQuery { */ className: string; _where: any; - _watch: Array; - _include: Array; - _exclude: Array; - _select: Array; + _watch: string[]; + _include: string[]; + _exclude: string[]; + _select: string[]; _limit: number; _skip: number; _count: boolean; - _order: Array; + _order: string[]; _readPreference: string | null; _includeReadPreference: string | null; _subqueryReadPreference: string | null; _queriesLocalDatastore: boolean; _localDatastorePinName: any; - _extraOptions: { - [key: string]: any; - }; + _extraOptions: Record; _hint: any; _explain: boolean; _xhrRequest: any; @@ -131,21 +123,21 @@ declare class ParseQuery { * @param {Array} queries * @returns {Parse.Query} Returns the query, so you can chain this call. */ - _orQuery(queries: Array): this; + _orQuery(queries: ParseQuery[]): 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): this; + _andQuery(queries: ParseQuery[]): 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): this; + _norQuery(queries: ParseQuery[]): this; /** * Helper for condition queries * @@ -290,7 +282,7 @@ declare class ParseQuery { */ aggregate(pipeline: any, options?: { sessionToken?: string; - }): Promise>; + }): Promise; /** * Retrieves at most one Parse.Object that satisfies this query. * @@ -387,7 +379,7 @@ declare class ParseQuery { * @returns {Promise} A promise that will be fulfilled once the * iteration has completed. */ - map(callback: (currentObject: ParseObject, index: number, query: ParseQuery) => any, options?: BatchOptions): Promise>; + map(callback: (currentObject: ParseObject, index: number, query: ParseQuery) => any, 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 @@ -411,7 +403,7 @@ declare class ParseQuery { * @returns {Promise} A promise that will be fulfilled once the * iteration has completed. */ - reduce(callback: (accumulator: any, currentObject: ParseObject, index: number) => any, initialValue: any, options?: BatchOptions): Promise>; + reduce(callback: (accumulator: any, currentObject: ParseObject, index: number) => any, initialValue: any, 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 @@ -434,7 +426,7 @@ declare class ParseQuery { * @returns {Promise} A promise that will be fulfilled once the * iteration has completed. */ - filter(callback: (currentObject: ParseObject, index: number, query: ParseQuery) => boolean, options?: BatchOptions): Promise>; + filter(callback: (currentObject: ParseObject, index: number, query: ParseQuery) => boolean, options?: BatchOptions): Promise; /** * Adds a constraint to the query that requires a particular key's value to * be equal to the provided value. @@ -443,7 +435,7 @@ declare 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: K, value: T['attributes'][K] | (T['attributes'][K] extends ParseObject ? Pointer : T['attributes'][K] extends Array ? E : never)): this; + equalTo(key: K, value: T['attributes'][K] | (T['attributes'][K] extends ParseObject ? Pointer : T['attributes'][K] extends (infer E)[] ? E : never)): this; /** * Adds a constraint to the query that requires a particular key's value to * be not equal to the provided value. @@ -452,7 +444,7 @@ declare 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: K, value: T['attributes'][K] | (T['attributes'][K] extends ParseObject ? Pointer : T['attributes'][K] extends Array ? E : never)): this; + notEqualTo(key: K, value: T['attributes'][K] | (T['attributes'][K] extends ParseObject ? Pointer : T['attributes'][K] extends (infer E)[] ? E : never)): this; /** * Adds a constraint to the query that requires a particular key's value to * be less than the provided value. @@ -497,7 +489,7 @@ declare class ParseQuery { * @param {Array<*>} values The values that will match. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - containedIn(key: K, values: Array): this; + containedIn(key: K, values: (T['attributes'][K] | (T['attributes'][K] extends ParseObject ? string : never))[]): this; /** * Adds a constraint to the query that requires a particular key's value to * not be contained in the provided list of values. @@ -506,7 +498,7 @@ declare class ParseQuery { * @param {Array<*>} values The values that will not match. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - notContainedIn(key: K, values: Array): this; + notContainedIn(key: K, values: T['attributes'][K][]): 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. @@ -515,7 +507,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: K, values: Array): this; + containedBy(key: K, values: (T['attributes'][K] | (T['attributes'][K] extends ParseObject ? string : never))[]): this; /** * Adds a constraint to the query that requires a particular key's value to * contain each one of the provided list of values. @@ -760,7 +752,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): this; + ascending(...keys: string[]): this; /** * Sorts the results in ascending order by the given key, * but can also add secondary sort descriptors without overwriting _order. @@ -769,7 +761,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): this; + addAscending(...keys: string[]): this; /** * Sorts the results in descending order by the given key. * @@ -777,7 +769,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): this; + descending(...keys: string[]): this; /** * Sorts the results in descending order by the given key, * but can also add secondary sort descriptors without overwriting _order. @@ -786,7 +778,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): this; + addDescending(...keys: string[]): this; /** * Sets the number of results to skip before returning any results. * This is useful for pagination. @@ -824,7 +816,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>): this; + include(...keys: (K | K[])[]): this; /** * Includes all nested Parse.Objects one level deep. * @@ -841,7 +833,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>): this; + select(...keys: (K | K[])[]): this; /** * Restricts the fields of the returned Parse.Objects to all keys except the * provided keys. Exclude takes precedence over select and include. @@ -851,7 +843,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>): this; + exclude(...keys: (K | K[])[]): this; /** * Restricts live query to trigger only for watched fields. * @@ -860,7 +852,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>): this; + watch(...keys: (K | K[])[]): this; /** * Changes the read preference that the backend will use when performing the query to the database. * @@ -890,7 +882,7 @@ declare class ParseQuery { * @static * @returns {Parse.Query} The query that is the OR of the passed in queries. */ - static or(...queries: Array): ParseQuery; + static or(...queries: ParseQuery[]): ParseQuery; /** * Constructs a Parse.Query that is the AND of the passed in queries. For * example: @@ -903,7 +895,7 @@ declare class ParseQuery { * @static * @returns {Parse.Query} The query that is the AND of the passed in queries. */ - static and(...queries: Array): ParseQuery; + static and(...queries: ParseQuery[]): ParseQuery; /** * Constructs a Parse.Query that is the NOR of the passed in queries. For * example: @@ -916,7 +908,7 @@ declare class ParseQuery { * @static * @returns {Parse.Query} The query that is the NOR of the passed in queries. */ - static nor(...queries: Array): ParseQuery; + static nor(...queries: ParseQuery[]): ParseQuery; /** * Change the source of this query to the server. * diff --git a/types/ParseSchema.d.ts b/types/ParseSchema.d.ts index 2742c599b..043d3d901 100644 --- a/types/ParseSchema.d.ts +++ b/types/ParseSchema.d.ts @@ -16,9 +16,7 @@ interface FieldOptions; interface CLPField { '*'?: boolean | undefined; requiresAuthentication?: boolean | undefined; @@ -34,26 +32,18 @@ interface CLP { addField?: CLPField | undefined; readUserFields?: string[] | undefined; writeUserFields?: string[] | undefined; - protectedFields?: { - [userIdOrRoleName: string]: string[]; - }; + protectedFields?: Record; } interface RestSchema { className: string; - fields: { - [key: string]: { - type: string; - targetClass?: string; - required?: boolean; - defaultValue?: string; - }; - }; + fields: Record; classLevelPermissions: CLP; - indexes?: { - [key: string]: { - [key: string]: any; - }; - }; + indexes?: Record>; } /** * A Parse.Schema object is for handling schema data from Parse. @@ -74,15 +64,9 @@ interface RestSchema { */ declare class ParseSchema { className: string; - _fields: { - [key: string]: any; - }; - _indexes: { - [key: string]: any; - }; - _clp: { - [key: string]: any; - }; + _fields: Record; + _indexes: Record; + _clp: Record; /** * @param {string} className Parse Class string. */ diff --git a/types/ParseUser.d.ts b/types/ParseUser.d.ts index dab0212e4..8e08dc2a5 100644 --- a/types/ParseUser.d.ts +++ b/types/ParseUser.d.ts @@ -1,9 +1,7 @@ import ParseObject, { Attributes } from './ParseObject'; import type { RequestOptions, FullOptions } from './RESTController'; -export type AuthData = { - [key: string]: any; -}; -export type AuthProvider = { +export type AuthData = Record; +export interface AuthProvider { authenticate?(options: { error?: (provider: AuthProvider, error: string | any) => void; success?: (provider: AuthProvider, result: AuthData) => void; @@ -11,7 +9,7 @@ export type AuthProvider = { restoreAuthentication(authData: any): boolean; getAuthType(): string; deauthenticate?(): void; -}; +} /** *

A Parse.User object is a local representation of a user persisted to the * Parse cloud. This class is a subclass of a Parse.Object, and retains the @@ -227,7 +225,7 @@ declare class ParseUser extends ParseObject): Promise; + save(...args: any[]): Promise; /** * Wrap the default destroy behavior with functionality that logs out * the current user when it is destroyed @@ -235,7 +233,7 @@ declare class ParseUser extends ParseObject): Promise; + destroy(...args: any[]): Promise; /** * Wrap the default fetch behavior with functionality to save to local * storage if this is current user. @@ -243,7 +241,7 @@ declare class ParseUser extends ParseObject): Promise; + fetch(...args: any[]): Promise; /** * Wrap the default fetchWithInclude behavior with functionality to save to local * storage if this is current user. @@ -251,7 +249,7 @@ declare class ParseUser extends ParseObject): Promise; + fetchWithInclude(...args: any[]): Promise; /** * Verify whether a given password is the password of the current user. * @@ -271,11 +269,7 @@ declare class ParseUser extends ParseObject, classProps: Record): typeof ParseUser; /** * Retrieves the currently logged in ParseUser with a valid session, * either from memory or localStorage, if necessary. diff --git a/types/Push.d.ts b/types/Push.d.ts index 6c65516b6..db926e9dc 100644 --- a/types/Push.d.ts +++ b/types/Push.d.ts @@ -2,14 +2,14 @@ import ParseQuery from './ParseQuery'; import type ParseObject from './ParseObject'; import type { WhereClause } from './ParseQuery'; import type { FullOptions } from './RESTController'; -export type PushData = { +export interface PushData { where?: WhereClause | ParseQuery; push_time?: Date | string; expiration_time?: Date | string; expiration_interval?: number; data?: any; channels?: string[]; -}; +} /** * Contains functions to deal with Push in Parse. * diff --git a/types/RESTController.d.ts b/types/RESTController.d.ts index 47863f391..ffd3167f0 100644 --- a/types/RESTController.d.ts +++ b/types/RESTController.d.ts @@ -1,4 +1,4 @@ -export type RequestOptions = { +export interface RequestOptions { useMasterKey?: boolean; useMaintenanceKey?: boolean; sessionToken?: string; @@ -11,8 +11,8 @@ export type RequestOptions = { usePost?: boolean; ignoreEmailVerification?: boolean; transaction?: boolean; -}; -export type FullOptions = { +} +export interface FullOptions { success?: any; error?: any; useMasterKey?: boolean; @@ -21,7 +21,7 @@ export type FullOptions = { installationId?: string; progress?: any; usePost?: boolean; -}; +} declare const RESTController: { ajax(method: string, url: string, data: any, headers?: any, options?: FullOptions): (Promise & { resolve: (res: any) => void; diff --git a/types/SingleInstanceStateController.d.ts b/types/SingleInstanceStateController.d.ts index 09743b91e..36bba09ea 100644 --- a/types/SingleInstanceStateController.d.ts +++ b/types/SingleInstanceStateController.d.ts @@ -6,7 +6,7 @@ export declare function initializeState(obj: ParseObject, initial?: State): Stat export declare function removeState(obj: ParseObject): State | null; export declare function getServerData(obj: ParseObject): AttributeMap; export declare function setServerData(obj: ParseObject, attributes: AttributeMap): void; -export declare function getPendingOps(obj: ParseObject): Array; +export declare function getPendingOps(obj: ParseObject): OpsMap[]; export declare function setPendingOp(obj: ParseObject, attr: string, op?: Op): void; export declare function pushPendingState(obj: ParseObject): void; export declare function popPendingState(obj: ParseObject): OpsMap; diff --git a/types/Storage.d.ts b/types/Storage.d.ts index 08d6483df..f863c3c4c 100644 --- a/types/Storage.d.ts +++ b/types/Storage.d.ts @@ -6,8 +6,8 @@ declare const Storage: { setItemAsync(path: string, value: string): Promise; removeItem(path: string): void; removeItemAsync(path: string): Promise; - getAllKeys(): Array; - getAllKeysAsync(): Promise>; + getAllKeys(): string[]; + getAllKeysAsync(): Promise; generatePath(path: string): string; _clear(): void; }; diff --git a/types/StorageController.react-native.d.ts b/types/StorageController.react-native.d.ts index a95ebbf73..91e4cd47b 100644 --- a/types/StorageController.react-native.d.ts +++ b/types/StorageController.react-native.d.ts @@ -4,8 +4,8 @@ declare const StorageController: { setItemAsync(path: string, value: string): Promise; removeItemAsync(path: string): Promise; getAllKeysAsync(): Promise; - multiGet(keys: Array): Promise; - multiRemove(keys: Array): Promise>; + multiGet(keys: string[]): Promise; + multiRemove(keys: string[]): Promise; clear(): Promise; }; export default StorageController; diff --git a/types/TaskQueue.d.ts b/types/TaskQueue.d.ts index ae7e55fe9..9d84900e1 100644 --- a/types/TaskQueue.d.ts +++ b/types/TaskQueue.d.ts @@ -1,9 +1,9 @@ -type Task = { +interface Task { task: () => Promise; _completion: any; -}; +} declare class TaskQueue { - queue: Array; + queue: Task[]; constructor(); enqueue(task: () => Promise): Promise; _dequeue(): void; diff --git a/types/UniqueInstanceStateController.d.ts b/types/UniqueInstanceStateController.d.ts index 7aff646fd..2ce1909e4 100644 --- a/types/UniqueInstanceStateController.d.ts +++ b/types/UniqueInstanceStateController.d.ts @@ -6,7 +6,7 @@ export declare function initializeState(obj: ParseObject, initial?: State): Stat export declare function removeState(obj: ParseObject): State | null; export declare function getServerData(obj: ParseObject): AttributeMap; export declare function setServerData(obj: ParseObject, attributes: AttributeMap): void; -export declare function getPendingOps(obj: ParseObject): Array; +export declare function getPendingOps(obj: ParseObject): OpsMap[]; export declare function setPendingOp(obj: ParseObject, attr: string, op?: Op): void; export declare function pushPendingState(obj: ParseObject): void; export declare function popPendingState(obj: ParseObject): OpsMap; diff --git a/types/arrayContainsObject.d.ts b/types/arrayContainsObject.d.ts index a6a357188..a19e6405b 100644 --- a/types/arrayContainsObject.d.ts +++ b/types/arrayContainsObject.d.ts @@ -1,2 +1,2 @@ import type ParseObject from './ParseObject'; -export default function arrayContainsObject(array: Array, object: ParseObject): boolean; +export default function arrayContainsObject(array: any[], object: ParseObject): boolean; diff --git a/types/encode.d.ts b/types/encode.d.ts index d63c1e75a..e64bfd721 100644 --- a/types/encode.d.ts +++ b/types/encode.d.ts @@ -1 +1 @@ -export default function (value: any, disallowObjects?: boolean, forcePointers?: boolean, seen?: Array, offline?: boolean): any; +export default function (value: any, disallowObjects?: boolean, forcePointers?: boolean, seen?: any[], offline?: boolean): any; diff --git a/eslint.config.test.mjs b/types/eslint.config.mjs similarity index 100% rename from eslint.config.test.mjs rename to types/eslint.config.mjs diff --git a/types/unique.d.ts b/types/unique.d.ts index c305608cf..1736d2e04 100644 --- a/types/unique.d.ts +++ b/types/unique.d.ts @@ -1 +1 @@ -export default function unique(arr: Array): Array; +export default function unique(arr: T[]): T[]; diff --git a/types/unsavedChildren.d.ts b/types/unsavedChildren.d.ts index 57881ba36..27e09d5a2 100644 --- a/types/unsavedChildren.d.ts +++ b/types/unsavedChildren.d.ts @@ -8,4 +8,4 @@ import type ParseObject from './ParseObject'; * @param {boolean} allowDeepUnsaved * @returns {Array} */ -export default function unsavedChildren(obj: ParseObject, allowDeepUnsaved?: boolean): Array; +export default function unsavedChildren(obj: ParseObject, allowDeepUnsaved?: boolean): (ParseFile | ParseObject)[]; From c9be39069b12b90e1944600334a614d9056b71fc Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 25 Mar 2025 13:44:15 -0500 Subject: [PATCH 2/2] prevent publishing types lint config --- .npmignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmignore b/.npmignore index d01dcfdc6..36526782d 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1,2 @@ types/tests.ts -types/eslint.config.js +types/eslint.config.mjs