From 2faf0abbd7827d3a1c1e186134149ee3f3fd482a Mon Sep 17 00:00:00 2001 From: Martin Nuc Date: Sat, 30 Mar 2019 23:59:59 +0100 Subject: [PATCH] improve types for flowjs --- types/flowjs/index.d.ts | 3 +- types/flowjs/package.json | 7 ++ types/flowjs/ts3.1/flowjs-tests.ts | 85 ++++++++++++++ types/flowjs/ts3.1/index.d.ts | 159 +++++++++++++++++++++++++++ types/flowjs/ts3.1/tsconfig.json | 16 +++ types/flowjs/ts3.1/tslint.json | 1 + types/ng-flow/index.d.ts | 1 + types/ng-flow/package.json | 7 ++ types/ng-flow/ts3.1/index.d.ts | 11 ++ types/ng-flow/ts3.1/ng-flow-tests.ts | 2 + types/ng-flow/ts3.1/tsconfig.json | 16 +++ types/ng-flow/ts3.1/tslint.json | 1 + 12 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 types/flowjs/package.json create mode 100644 types/flowjs/ts3.1/flowjs-tests.ts create mode 100644 types/flowjs/ts3.1/index.d.ts create mode 100644 types/flowjs/ts3.1/tsconfig.json create mode 100644 types/flowjs/ts3.1/tslint.json create mode 100644 types/ng-flow/package.json create mode 100644 types/ng-flow/ts3.1/index.d.ts create mode 100644 types/ng-flow/ts3.1/ng-flow-tests.ts create mode 100644 types/ng-flow/ts3.1/tsconfig.json create mode 100644 types/ng-flow/ts3.1/tslint.json diff --git a/types/flowjs/index.d.ts b/types/flowjs/index.d.ts index 0a6c361c73..d56385e1b9 100644 --- a/types/flowjs/index.d.ts +++ b/types/flowjs/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for flowjs +// Type definitions for flowjs 2.13 // Project: https://github.com/flowjs/flow.js // Definitions by: Ryan McNamara +// Martin Nuc // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace flowjs { diff --git a/types/flowjs/package.json b/types/flowjs/package.json new file mode 100644 index 0000000000..bb80441dc0 --- /dev/null +++ b/types/flowjs/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "types": "index", + "typesVersions": { + ">=3.1.0-0": { "*": ["ts3.1/*"] } + } +} diff --git a/types/flowjs/ts3.1/flowjs-tests.ts b/types/flowjs/ts3.1/flowjs-tests.ts new file mode 100644 index 0000000000..5c68c768e2 --- /dev/null +++ b/types/flowjs/ts3.1/flowjs-tests.ts @@ -0,0 +1,85 @@ +// flow object +let flowObject!: flowjs.Flow; +let bool: boolean = flowObject.support; +bool = flowObject.supportDirectory; +let flowOpts: flowjs.FlowOptions = flowObject.opts; +let flowFileArray: flowjs.FlowFile[] = flowObject.files; +let flowChunkParams: flowjs.FlowChunkParams; + +flowObject.assignBrowse( []); +flowObject.assignBrowse( [], false, false, {}); +flowObject.assignDrop( []); +flowObject.unAssignDrop( []); +flowObject.on("fileSuccess", (file: flowjs.FlowFile, serverMessage: string, chunk: flowjs.FlowChunk) => {}); +flowObject.off("fileSuccess", () => {}); +flowObject.upload(); +flowObject.pause(); +flowObject.resume(); +flowObject.cancel(); +flowObject.progress(); +bool = flowObject.isUploading(); +flowObject.addFile({} as any as File); +flowObject.removeFile({} as any as flowjs.FlowFile); +let flowFile: flowjs.FlowFile = flowObject.getFromUniqueIdentifier(""); +let num: number = flowObject.getSize(); +num = flowObject.sizeUploaded(); +num = flowObject.timeRemaining(); + +// flow options +let flowOptions: flowjs.FlowOptions = {}; +flowOptions.target = ""; +flowOptions.singleFile = true; +flowOptions.chunkSize = 0; +flowOptions.forceChunkSize = true; +flowOptions.simultaneousUploads = 0; +flowOptions.fileParameterName = ""; +flowOptions.query = {}; +flowOptions.headers = {}; +flowOptions.withCredentials = true; +flowOptions.method = ""; +flowOptions.testMethod = ""; +flowOptions.uploadMethod = ""; +flowOptions.allowDuplicateUploads = true; +flowOptions.prioritizeFirstAndLastChunk = true; +flowOptions.testChunks = true; +flowOptions.preprocess = () => {}; +flowOptions.initFileFn = () => {}; +flowOptions.generateUniqueIdentifier = () => {}; +flowOptions.maxChunkRetries = 0; +flowOptions.chunkRetryInterval = 0; +flowOptions.progressCallbacksInterval = 0; +flowOptions.speedSmoothingFactor = 0; +flowOptions.successStatuses = [""]; +flowOptions.permanentErrors = [""]; + +// flow file +flowObject = flowFile.flowObj; +let htmlFile: File = flowFile.file; +let str: string = flowFile.name; +str = flowFile.relativePath; +num = flowFile.size; +str = flowFile.uniqueIdentifier; +num = flowFile.averageSpeed; +num = flowFile.currentSpeed; +let chunksArray: ReadonlyArray = flowFile.chunks; +chunksArray[0].abort(); +num = chunksArray[0].chunkSize; +num = chunksArray[0].endByte; +flowFile = chunksArray[0].fileObj; +flowObject = chunksArray[0].flowObj; +flowChunkParams = chunksArray[0].getParams(); +num = chunksArray[0].startByte; +bool = flowFile.paused; +bool = flowFile.error; +num = flowFile.progress(true); +flowFile.pause(); +flowFile.resume(); +flowFile.cancel(); +flowFile.retry(); +flowFile.bootstrap(); +bool = flowFile.isUploading(); +bool = flowFile.isComplete(); +num = flowFile.sizeUploaded(); +num = flowFile.timeRemaining(); +str = flowFile.getExtension(); +str = flowFile.getType(); diff --git a/types/flowjs/ts3.1/index.d.ts b/types/flowjs/ts3.1/index.d.ts new file mode 100644 index 0000000000..f9f0bbd460 --- /dev/null +++ b/types/flowjs/ts3.1/index.d.ts @@ -0,0 +1,159 @@ +declare namespace flowjs { + interface Flow { + support: boolean; + supportDirectory: boolean; + opts: FlowOptions; + files: FlowFile[]; + + assignBrowse( + domNodes: ReadonlyArray, + isDirectory?: boolean, + singleFile?: boolean, + attributes?: object + ): void; + assignDrop(node: HTMLElement | ReadonlyArray): void; + unAssignDrop(node: HTMLElement | ReadonlyArray): void; + on(event: T, callback: (...args: FlowEventMap[T]) => void): void; + off(event?: EventName, callback?: () => void): void; + upload(): void; + pause(): void; + resume(): void; + cancel(): void; + progress(): number; + isUploading(): boolean; + addFile(file: File): void; + removeFile(file: FlowFile): void; + getFromUniqueIdentifier(uniqueIdentifier: string): FlowFile; + getSize(): number; + sizeUploaded(): number; + timeRemaining(): number; + } + + interface FlowOptions { + target?: string; + singleFile?: boolean; + chunkSize?: number; + forceChunkSize?: boolean; + simultaneousUploads?: number; + fileParameterName?: string; + query?: object; + headers?: object; + withCredentials?: boolean; + method?: string; + testMethod?: string; + uploadMethod?: string; + allowDuplicateUploads?: boolean; + prioritizeFirstAndLastChunk?: boolean; + testChunks?: boolean; + preprocess?: (chunk: FlowChunk) => void; + initFileFn?: (file: FlowFile, chunk: FlowChunk) => void; + readFileFn?: (file: FlowFile, startByte: number, endByte: number, fileType: string, chunk: FlowChunk) => void; + generateUniqueIdentifier?: (file: FlowFile) => any; + maxChunkRetries?: number; + chunkRetryInterval?: number; + progressCallbacksInterval?: number; + speedSmoothingFactor?: number; + successStatuses?: string[]; + permanentErrors?: string[]; + } + + interface FlowFile { + flowObj: Flow; + file: File; + name: string; + relativePath: string; + size: number; + uniqueIdentifier: string; + averageSpeed: number; + currentSpeed: number; + chunks: ReadonlyArray; + paused: boolean; + error: boolean; + + progress(relative: boolean): number; + pause(): void; + resume(): void; + cancel(): void; + retry(): void; + bootstrap(): void; + isUploading(): boolean; + isComplete(): boolean; + sizeUploaded(): number; + timeRemaining(): number; + getExtension(): string; + getType(): string; + } + + interface FlowChunk { + flowObj: Flow; + fileObj: FlowFile; + offset: number; + tested: boolean; + retries: number; + pendingRetry: false; + preprocessState: 0 | 1 | 2; + readState: 0 | 1 | 2; + loaded: number; + total: number; + chunkSize: number; + startByte: number; + endByte: number; + xhr: XMLHttpRequest; + getParams(): FlowChunkParams; + test(): void; + send(): void; + abort(): void; + status(): void; + message(): void; + progress(): void; + sizeUploaded(): number; + } + + interface FlowChunkParams { + flowChunkNumber: number; + flowChunkSize: number; + flowCurrentChunkSize: number; + flowTotalSize: number; + flowIdentifier: any; + flowFilename: string; + flowRelativePath: string; + flowTotalChunks: number; + } + + interface FlowEventMap { + fileSuccess: FileSuccessCallbackArguments; + fileProgress: FileProgressCallbackArguments; + fileAdded: FilesAddedCallbackArguments; + filesAdded: FileAddedCallbackArguments; + filesSubmitted: FilesSubmittedCallbackArguments; + fileRemoved: FileRemovedCallbackArguments; + fileRetry: FileRetryCallbackArguments; + fileError: FileErrorCallbackArguments; + uploadStart: UploadStartCallbackArguments; + complete: UploadStartCallbackArguments; + progress: ProgressCallbackArguments; + error: ErrorCallbackArguments; + catchAll: CatchAllCallbackArguments; + } + + type EventName = keyof FlowEventMap; + type FlowEvent = FlowEventMap[keyof FlowEventMap]; + + type FlowEventFromEventName = FlowEventMap[T]; + type FlowEventTypeFromFlowEvent = + T extends FlowEventFromEventName ? U : never; + + type FileSuccessCallbackArguments = [FlowFile, string, FlowChunk]; + type FileProgressCallbackArguments = [FlowFile, FlowChunk]; + type FileAddedCallbackArguments = [FlowFile, Event]; + type FilesAddedCallbackArguments = [FlowFile[], Event]; + type FilesSubmittedCallbackArguments = [FlowFile[], Event]; + type FileRemovedCallbackArguments = [FlowFile]; + type FileRetryCallbackArguments = [FlowFile, FlowChunk]; + type FileErrorCallbackArguments = [FlowFile, string, FlowChunk]; + type UploadStartCallbackArguments = []; + type CompleteCallbackArguments = []; + type ProgressCallbackArguments = []; + type ErrorCallbackArguments = [string, FlowFile, FlowChunk]; + type CatchAllCallbackArguments = [Event]; +} diff --git a/types/flowjs/ts3.1/tsconfig.json b/types/flowjs/ts3.1/tsconfig.json new file mode 100644 index 0000000000..c18324eb21 --- /dev/null +++ b/types/flowjs/ts3.1/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6", "dom"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": ["../../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "flowjs-tests.ts"] +} diff --git a/types/flowjs/ts3.1/tslint.json b/types/flowjs/ts3.1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/flowjs/ts3.1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/ng-flow/index.d.ts b/types/ng-flow/index.d.ts index 2699a99cd6..9977f5ee28 100644 --- a/types/ng-flow/index.d.ts +++ b/types/ng-flow/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for ng-flow // Project: https://github.com/flowjs/ng-flow // Definitions by: Ryan McNamara +// Martin Nuc // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /// diff --git a/types/ng-flow/package.json b/types/ng-flow/package.json new file mode 100644 index 0000000000..bb80441dc0 --- /dev/null +++ b/types/ng-flow/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "types": "index", + "typesVersions": { + ">=3.1.0-0": { "*": ["ts3.1/*"] } + } +} diff --git a/types/ng-flow/ts3.1/index.d.ts b/types/ng-flow/ts3.1/index.d.ts new file mode 100644 index 0000000000..80964a7437 --- /dev/null +++ b/types/ng-flow/ts3.1/index.d.ts @@ -0,0 +1,11 @@ +/// + +import * as angular from 'angular'; + +declare module 'angular' { + namespace flow { + interface FlowFactory { + create(options?: flowjs.FlowOptions): flowjs.Flow; + } + } +} diff --git a/types/ng-flow/ts3.1/ng-flow-tests.ts b/types/ng-flow/ts3.1/ng-flow-tests.ts new file mode 100644 index 0000000000..9b4505efcc --- /dev/null +++ b/types/ng-flow/ts3.1/ng-flow-tests.ts @@ -0,0 +1,2 @@ +let flowFactory: ng.flow.FlowFactory; +flowFactory.create({} as any as flowjs.FlowOptions); diff --git a/types/ng-flow/ts3.1/tsconfig.json b/types/ng-flow/ts3.1/tsconfig.json new file mode 100644 index 0000000000..f05945a82a --- /dev/null +++ b/types/ng-flow/ts3.1/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6", "dom"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": ["../../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "ng-flow-tests.ts"] +} diff --git a/types/ng-flow/ts3.1/tslint.json b/types/ng-flow/ts3.1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ng-flow/ts3.1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }