From 74189cca97f90067563d776252a5ac678688018a Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Mon, 27 Jan 2014 02:27:00 +0100 Subject: [PATCH] Created definitions for 'q-io' https://github.com/kriskowal/q-io remaining issues: * not sure about how to export module * describing some overloads is problematic * missing a few definitions for less-used members --- README.md | 2 + q-io/Q-io-tests.ts | 200 +++++++++++++++++++++++++++++++++++ q-io/Q-io.d.ts | 257 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 459 insertions(+) create mode 100644 q-io/Q-io-tests.ts create mode 100644 q-io/Q-io.d.ts diff --git a/README.md b/README.md index 8183ef1c4..8c892eba4 100755 --- a/README.md +++ b/README.md @@ -207,6 +207,8 @@ List of Definitions * [Platform](https://github.com/bestiejs/platform.js) (by [Jake Hickman](https://github.com/JakeH)) * [PouchDB](http://pouchdb.com) (by [Bill Sears](https://github.com/MrBigDog2U/)) * [PreloadJS](http://www.createjs.com/#!/PreloadJS) (by [Pedro Ferreira](https://bitbucket.org/drk4)) +* [Q](https://github.com/kriskowal/q) (by Barrie Nemetchek, Andrew Gaspar) +* [Q-io](https://github.com/kriskowal/q-io) (by [Bart van der Schoor](https://github.com/Bartvds)) * [QUnit](http://qunitjs.com/) (by [Diullei Gomes](https://github.com/Diullei)) * [Raven.js](https://github.com/getsentry/raven-js) (by [Santi Albo](https://github.com/santialbo)) * [Rickshaw](http://code.shutterstock.com/rickshaw/) (by [Blake Niemyjski](https://github.com/niemyjski)) diff --git a/q-io/Q-io-tests.ts b/q-io/Q-io-tests.ts new file mode 100644 index 000000000..f4ac32e9e --- /dev/null +++ b/q-io/Q-io-tests.ts @@ -0,0 +1,200 @@ +/// +/// + +var fs:typeof QioFS = require('q-io/fs'); +var http:typeof QioHTTP = require('q-io/http'); + +var bool:boolean; +var num:number; +var x:any; +var path:string; +var buffer:NodeBuffer; +var str:string; +var strArr:string[]; +var source:string; +var target:string; +var type:string; + +var options:any; +var strArrQ:Q.Promise; +var voidQ:Q.Promise; +var anyQ:Q.Promise; +var strQ:Q.Promise; +var boolQ:Q.Promise; +var dateQ:Q.Promise; +var bufferQ:Q.Promise; + +var statsQ:Q.Promise; +var readQ:Q.Promise; +var writeQ:Q.Promise; + +var headers:QioHTTP.Headers; +var reader:Qio.Reader; +var writer:Qio.Writer; +var stream:Qio.Stream; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fs.open(path, options).then((x) => { +}); +//fs.open(path, options):Q.Promise; +//fs.open(path, options):Q.Promise; +//fs.open(path, options):Q.Promise; + +//TODO how to define the multiple return types? use any for now? +anyQ = fs.read(path, options); +//strQ = fs.read(path, options); +//fs.read(path, options):Q.Promise; + +voidQ = fs.write(path, buffer, options); +voidQ = fs.write(path, str, options); + +voidQ = fs.append(path, buffer, options); +voidQ = fs.append(path, str, options); + +voidQ = fs.copy(source, target); +voidQ = fs.copyTree(source, target); + +strArrQ = fs.list(path); +strArrQ = fs.listTree(path, (path, x) => { + return true; +}); +strArrQ = fs.listDirectoryTree(path); + +voidQ = fs.makeDirectory(path, str); +voidQ = fs.makeDirectory(path, num); +voidQ = fs.makeTree(path, str); +voidQ = fs.makeTree(path, num); + +voidQ = fs.remove(path); +voidQ = fs.removeTree(path); + +voidQ = fs.rename(source, target); +voidQ = fs.move(source, target); + +voidQ = fs.link(source, target); + +voidQ = fs.symbolicCopy(source, target, type); +voidQ = fs.symbolicLink(target, str, type); + +voidQ = fs.chown(path, num, num); +voidQ = fs.chmod(path, str); +voidQ = fs.chmod(path, num); + +statsQ = fs.stat(path) +statsQ = fs.statLink(path); +statsQ = fs.statFd(num); + +boolQ = fs.exists(path); + +boolQ = fs.isFile(path); +boolQ = fs.isDirectory(path); +boolQ = fs.isSymbolicLink(path); + +dateQ = fs.lastModified(path); +dateQ = fs.lastAccessed(path); + +strArr = fs.split(path); +str = fs.join(str, str); +str = fs.join(strArr); +str = fs.resolve(str, str); +str = fs.resolve(strArr); +str = fs.normal(str, str); +str = fs.normal(strArr); +str = fs.absolute(path); + +strQ = fs.canonical(path); +strQ = fs.readLink(path); + +bool = fs.contains(str, str); + +strQ = fs.relative(source, target); + +str = fs.relativeFromFile(source, target); +str = fs.relativeFromDirectory(source, target); + +bool = fs.isAbsolute(path); +bool = fs.isRelative(path); +bool = fs.isRoot(path); + +str = fs.root(path); +str = fs.directory(path); +str = fs.base(path, str); +str = fs.extension(path); + +//this should return a q-io/fs-mock MockFS +//fs = fs.reroot(str); +x = fs.toObject(str); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +var request:QioHTTP.Request; +var headers:QioHTTP.Headers; + +str = request.url; +str = request.path; +str = request.scriptName; +str = request.pathInfo; +strArr = request.version; +str = request.method; +str = request.scheme; + +str = request.host; +num = request.port; +str = request.remoteHost; +num = request.remotePort; + +headers = request.headers; +x = request.agent; +x = request.body; +x = request.node; + +str = headers['foo']; + +var response:QioHTTP.Response; +var responseQ:Q.Promise; + +responseQ = http.request(request); +responseQ = http.request(str); + +strQ = http.read(request); +strQ = http.read(str); + +request = http.normalizeRequest(request); +request = http.normalizeRequest(str); +response = http.normalizeResponse(response); + +num = response.status; +headers = response.headers; +reader = response.body; +response.onclose = () => { + +}; +x = response.node; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +strQ = reader.read(str); +bufferQ = reader.read(); +reader.close(); +x = reader.node; +voidQ = reader.forEach((chunk:any) => { + return anyQ; +}); + +writer.write(str); +writer.write(buffer); +writer.flush(); +writer.close(); +x = writer.node; + +strQ = stream.read(str); +bufferQ = stream.read(); +stream.write(str); +stream.write(buffer); +stream.flush(); +stream.close(); +x = stream.node; +voidQ = reader.forEach((chunk:any) => { + return anyQ; +}); diff --git a/q-io/Q-io.d.ts b/q-io/Q-io.d.ts new file mode 100644 index 000000000..9f8150046 --- /dev/null +++ b/q-io/Q-io.d.ts @@ -0,0 +1,257 @@ +// Type definitions for Q-io +// Project:https://github.com/kriskowal/q-io +// Definitions by:Bart van der Schoor +// Definitions:https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +//TODO add support for q-io/http-apps +//TODO add verified support for q-io/fs-mock +//TODO fix Readers/Writers properly +//TODO find solution for overloaded return types (QioFS.open/QioFS.read) +// for some ideas see https://typescript.codeplex.com/discussions/461587#post1105930 + +declare module QioFS { + + //TODO how to define the multiple return types? use any for now? + export function open(path:string, options?:any):Q.Promise; + //export function open(path:string, options?:any):Q.Promise; + //export function open(path:string, options?:any):Q.Promise; + //export function open(path:string, options?:any):Q.Promise; + + //TODO how to define the multiple return types? use any for now? + export function read(path:string, options?:any):Q.Promise; + //export function read(path:string, options?:any):Q.Promise; + //export function read(path:string, options?:any):Q.Promise; + + export function write(path:string, content:NodeBuffer, options?:any):Q.Promise; + export function write(path:string, content:string, options?:any):Q.Promise; + + export function append(path:string, content:NodeBuffer, options?:any):Q.Promise; + export function append(path:string, content:string, options?:any):Q.Promise; + + export function copy(source:string, target:string):Q.Promise; + export function copyTree(source:string, target:string):Q.Promise; + + export function list(path:string):Q.Promise; + export function listTree(path:string, guard?:(path:string, stat:any) => boolean):Q.Promise; + export function listDirectoryTree(path:string):Q.Promise; + + export function makeDirectory(path:string, mode?:string):Q.Promise; + export function makeDirectory(path:string, mode?:number):Q.Promise; + export function makeTree(path:string, mode?:string):Q.Promise; + export function makeTree(path:string, mode?:number):Q.Promise; + + export function remove(path:string):Q.Promise; + export function removeTree(path:string):Q.Promise; + + export function rename(source:string, target:string):Q.Promise; + export function move(source:string, target:string):Q.Promise; + + export function link(source:string, target:any):Q.Promise; + + export function symbolicCopy(source:string, target:string, type:string):Q.Promise; + export function symbolicLink(target:string, link:string, type:string):Q.Promise; + + export function chown(path:string, uid:number, gid:number):Q.Promise; + export function chmod(path:string, mode?:string):Q.Promise; + export function chmod(path:string, mode?:number):Q.Promise; + + export function stat(path:string):Q.Promise; + export function statLink(path:string):Q.Promise; + export function statFd(fd:number):Q.Promise; + + export function exists(path:string):Q.Promise; + + export function isFile(path:string):Q.Promise; + export function isDirectory(path:string):Q.Promise; + export function isSymbolicLink(path:string):Q.Promise; + + export function lastModified(path:string):Q.Promise; + export function lastAccessed(path:string):Q.Promise; + + export function split(path:string):string[]; + export function join(...paths:string[]):string; + export function join(paths:string[]):string; + export function resolve(...path:string[]):string; + export function resolve(paths:string[]):string; + export function normal(...path:string[]):string; + export function normal(paths:string[]):string; + export function absolute(path:string):string; + + export function canonical(path:string):Q.Promise; + export function readLink(path:string):Q.Promise; + + export function contains(parent:string, child:string):boolean; + + export function relative(source:string, target:string):Q.Promise; + + export function relativeFromFile(source:string, target:string):string; + export function relativeFromDirectory(source:string, target:string):string; + + export function isAbsolute(path:string):boolean; + export function isRelative(path:string):boolean; + export function isRoot(path:string):boolean; + + export function root(path:string):string; + export function directory(path:string):string; + export function base(path:string, extension:string):string; + export function extension(path:string):string; + + //this should return a q-io/fs-mock MockFS + export function reroot(path:string):typeof QioFS; + + export function toObject(path:string):{[path:string]:NodeBuffer}; + + //listed but not implemented by Q-io + //export function glob(pattern):Q.Promise; + //export function match(pattern, path:string):Q.Promise; + + //TODO link this to node.js FS module (no lazy clones) + interface Stats { + node:NodeStats; + size:number; + } + interface NodeStats { + isFile():boolean; + isDirectory():boolean; + isBlockDevice():boolean; + isCharacterDevice():boolean; + isSymbolicLink():boolean; + isFIFO():boolean; + isSocket():boolean; + node:NodeStats; + dev:number; + ino:number; + mode:number; + nlink:number; + uid:number; + gid:number; + rdev:number; + size:number; + blksize:number; + blocks:number; + atime:Date; + mtime:Date; + ctime:Date; + } +} + +declare module QioHTTP { + export function request(request:Request):Q.Promise; + export function request(url:string):Q.Promise; + + export function read(request:Request):Q.Promise; + export function read(url:string):Q.Promise; + + export function normalizeRequest(request:Request):Request; + export function normalizeRequest(url:string):Request; + export function normalizeResponse(response:Response):Response; + + interface Request { + url:string; + path:string; + scriptName:string; + pathInfo:string; + version:string[]; + method:string; + scheme:string; + + host:string; + port:number; + remoteHost:string; + remotePort:number; + + headers:Headers; + agent:any; + body:any; + node:any; + } + interface Response { + status:number; + headers:Headers; + body:Qio.Reader + onclose:() => void; + node:any; + } + interface Headers { + [name:string]:any; + [name:string]:any[]; + } + interface Body extends Qio.Stream { + + } + interface Application { + (req:Request):Q.Promise; + } +} + +declare module Qio { + interface ForEachCallback { + (chunk:NodeBuffer):Q.Promise; + (chunk:string):Q.Promise; + } + interface ForEach { + forEach(callback:ForEachCallback):Q.Promise; + } + + interface Reader extends ForEach { + read(charset:string):Q.Promise; + read():Q.Promise; + close():void; + node:ReadableStream; + } + interface Writer { + write(content:string):void; + write(content:NodeBuffer):void; + flush():Q.Promise; + close():void; + destroy():void; + node:WritableStream; + } + + interface Stream { + read(charset:string):Q.Promise; + read():Q.Promise; + write(content:string):void; + write(content:NodeBuffer):void; + flush():Q.Promise; + close():void; + destroy():void; + node:any; + } + + interface BufferReader extends QioBufferReader { + + } +} +interface QioBufferReader { + new ():Qio.Reader; + read(stream:Qio.Reader, charset:string):string; + read(stream:Qio.Reader):NodeBuffer; + join(buffers:NodeBuffer[]):NodeBuffer; +} +interface QioBufferWriter { + (writer:NodeBuffer):Qio.Writer; + Writer:Qio.Writer; +} +interface QioBufferStream { + (buffer:NodeBuffer, encoding:string):Qio.Stream +} + +declare module "q-io/http" { +export = QioHTTP; +} +declare module "q-io/fs" { +export = QioFS; +} +declare module "q-io/reader" { +export = QioBufferReader; +} +declare module "q-io/writer" { +export = QioBufferWriter; +} +declare module "q-io/buffer-stream" { +export = QioBufferStream; +}