From 96c9c7f10caeba27ccba8703c1832cb0fff9f0bc Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Wed, 29 Aug 2018 16:43:06 -0700 Subject: [PATCH] adds typings for the 'megajs' package --- types/megajs/index.d.ts | 116 +++++++++++++++++++++++++++++++++++ types/megajs/megajs-tests.ts | 9 +++ types/megajs/tsconfig.json | 19 ++++++ types/megajs/tslint.json | 3 + 4 files changed, 147 insertions(+) create mode 100644 types/megajs/index.d.ts create mode 100644 types/megajs/megajs-tests.ts create mode 100644 types/megajs/tsconfig.json create mode 100644 types/megajs/tslint.json diff --git a/types/megajs/index.d.ts b/types/megajs/index.d.ts new file mode 100644 index 0000000000..8162d6d648 --- /dev/null +++ b/types/megajs/index.d.ts @@ -0,0 +1,116 @@ +// Type definitions for megajs 0.14 +// Project: https://github.com/qgustavor/mega +// Definitions by: Daniel Byrne +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// + +import { Readable, Writable, Stream } from 'stream'; + +export interface AccountInfo { + type: string; + spaceUsed: number; + spaceTotal: number; + downloadBandwidthUsed: number; + downloadBandwidthTotal: number; + sharedBandwidthUsed: number; + sharedBandwidthLimit: number; +} + +export interface DownloadOptions { + maxConnections?: number; + initialChunkSize?: number; + chunkSizeIncrement?: number; + maxChunkSize?: number; + returnCiphertext?: boolean; + start?: any; + end?: any; +} + +export interface UploadOptions { + name: string; + attributes?: object; + size?: any; + thumbnailImage?: Buffer | Readable; + previewImage?: Buffer | Readable; +} + +export interface LinkOptions { + noKey?: boolean; + key?: string | Buffer; +} + +export interface MakeDirectoryOptions { + name: string; + attributes?: object; + key?: string | Buffer; +} + +export interface FileOptions { + downloadId: string; + key: string; + directory: boolean; +} + +export interface StorageOptions { + email: string; + password: string; + keepalive?: boolean; + autologin?: boolean; + autoload?: boolean; +} + +export class File { + constructor(options: FileOptions | string); + static fromURL(options: FileOptions | string): File; + static unpackAttributes(at: any): JSON; + name: string; + attributes: object; + size: number; + key: Buffer; + timestamp: number; + nodeId: string; + downloadId: string; + directory: boolean; + children: ReadonlyArray; + loadAttributes(cb?: any): Readable; + download(options?: DownloadOptions, cb?: any): Readable; +} + +export class Storage { + constructor(options: StorageOptions, callback?: any); + static fromJSON(json: JSON): Storage; + name: string; + key: Buffer; + sid: string; + files: {[id in string]: MutableFile}; + root: MutableFile; + trash: MutableFile; + inbox: MutableFile; + mounts: ReadonlyArray; + upload(options: UploadOptions | string, buffer?: Buffer, cb?: any): Writable; + mkdir(options: MakeDirectoryOptions | string, cb: (err: Error | undefined, file: MutableFile) => void): Readable; + reload(cb: any): Readable; + login(cb: any): Readable; + getAccountInfo(cb: any): AccountInfo; + toJSON(): JSON; +} + +export class MutableFile extends File { + constructor(options: FileOptions | string, storage: Storage); + upload(options: UploadOptions | string, buffer?: Buffer, cb?: any): Writable; + mkdir(options: MakeDirectoryOptions | string, cb?: any): Readable; + importFile(file: File | string, cb: (err: Error | undefined, file: MutableFile) => void): Readable; + link(options: LinkOptions | undefined, cb: (err: Error | undefined, url: string) => void): Readable; + shareFolder(options: LinkOptions | undefined, cb: (err: Error | undefined, url: string) => void): Readable; + delete(permanent: true | undefined, cb: (err: Error | undefined) => void): Readable; + moveTo(target: MutableFile | string, cb: (err: Error | undefined) => void): Readable; + setAttributes(attributes: object, cb: (err: Error | undefined) => void): Readable; + uploadAttribute(type: string | number, opt?: Buffer | Stream, cb?: any): Readable; + rename(newFileName: string, cb: (err: Error | undefined) => void): Readable; + setLabel(label: string, cb: (err: Error | undefined) => void): Readable; + setFavorite(isFavorite: boolean, cb: (err: Error | undefined) => void): Readable; +} + +export default function mega(options: StorageOptions, cb?: any): Storage; diff --git a/types/megajs/megajs-tests.ts b/types/megajs/megajs-tests.ts new file mode 100644 index 0000000000..862373c85a --- /dev/null +++ b/types/megajs/megajs-tests.ts @@ -0,0 +1,9 @@ +import mega from 'megajs'; + +// $ExpectType Storage +mega({email: 'test@test.net', password: '1234'}); + +// tslint:disable-next-line no-duplicate-imports +import { Storage } from 'megajs'; + +const storage = new Storage({email: 'test@test.net', password: '1234'}); diff --git a/types/megajs/tsconfig.json b/types/megajs/tsconfig.json new file mode 100644 index 0000000000..0e6bb53df1 --- /dev/null +++ b/types/megajs/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "megajs-tests.ts" + ] +} diff --git a/types/megajs/tslint.json b/types/megajs/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/megajs/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}