From d47d0b7b5ea8e90c8fbb41ba14b1f63b1cfdb56d Mon Sep 17 00:00:00 2001 From: Anatoly Bakirov Date: Tue, 7 Apr 2015 15:56:38 -0700 Subject: [PATCH 01/16] Make Promise generic --- dojo/dojo.d.ts | 56 +++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/dojo/dojo.d.ts b/dojo/dojo.d.ts index 63cda16dd..bda5c3494 100644 --- a/dojo/dojo.d.ts +++ b/dojo/dojo.d.ts @@ -927,7 +927,7 @@ declare module dojo { * * */ - class __Promise extends dojo.promise.Promise { + class __Promise implements dojo.promise.Promise { constructor(); /** * A promise resolving to an object representing @@ -988,7 +988,7 @@ declare module dojo { * @param errback OptionalCallback to be invoked when the promise is rejected.Receives the rejection error. * @param progback OptionalCallback to be invoked when the promise emits a progressupdate. Receives the progress update. */ - then(callback?: Function, errback?: Function, progback?: Function): dojo.promise.Promise; + then(callback?: Function, errback?: Function, progback?: Function): dojo.promise.Promise; /** * */ @@ -996,11 +996,11 @@ declare module dojo { /** * */ - trace(): dojo.promise.Promise; + trace(): dojo.promise.Promise; /** * */ - traceRejected(): dojo.promise.Promise; + traceRejected(): dojo.promise.Promise; } /** * Permalink: http://dojotoolkit.org/api/1.9/dojo/request/default.html @@ -1590,7 +1590,7 @@ declare module dojo { * @param listener * @param dontFix */ - once(target: any, type: any, listener: any, dontFix: any): any; + once(target: any, type: any, listener: any, dontFix?: any): any; /** * * @param target @@ -1783,7 +1783,7 @@ declare module dojo { * @param errback OptionalCallback to be invoked when the promise is rejected. * @param progback OptionalCallback to be invoked when the promise emits a progress update. */ - interface when{(valueOrPromise: any, callback?: Function, errback?: Function, progback?: Function): void} + interface when { (value: T|dojo.promise.Promise, callback: dojo.promise.Callback, errback?: any, progback?: any): U|dojo.promise.Promise } /** * Permalink: http://dojotoolkit.org/api/1.9/dojo/DeferredList.html * @@ -1822,7 +1822,7 @@ declare module dojo { /** * */ - "promise": dojo.promise.Promise; + "promise": dojo.promise.Promise; /** * Inform the deferred it may cancel its asynchronous operation. * Inform the deferred it may cancel its asynchronous operation. @@ -1863,7 +1863,7 @@ declare module dojo { * @param update The progress update. Passed to progbacks. * @param strict OptionalIf strict, will throw an error if the deferred has alreadybeen fulfilled and consequently no progress can be emitted. */ - progress(update: any, strict: boolean): dojo.promise.Promise; + progress(update: any, strict: boolean): dojo.promise.Promise; /** * Reject the deferred. * Reject the deferred, putting it in an error state. @@ -1879,7 +1879,7 @@ declare module dojo { * @param value The result of the deferred. Passed to callbacks. * @param strict OptionalIf strict, will throw an error if the deferred has alreadybeen fulfilled and consequently cannot be resolved. */ - resolve(value: any, strict?: boolean): dojo.promise.Promise; + resolve(value: any, strict?: boolean): dojo.promise.Promise; /** * Add new callbacks to the deferred. * Add new callbacks to the deferred. Callbacks can be added @@ -1889,7 +1889,7 @@ declare module dojo { * @param errback OptionalCallback to be invoked when the promise is rejected.Receives the rejection error. * @param progback OptionalCallback to be invoked when the promise emits a progressupdate. Receives the progress update. */ - then(callback: Function, errback: Function, progback: Function): dojo.promise.Promise; + then(callback: Function, errback: Function, progback: Function): dojo.promise.Promise; /** * */ @@ -9119,7 +9119,7 @@ declare module dojo { * @param errback OptionalCallback to be invoked when the promise is rejected. * @param progback OptionalCallback to be invoked when the promise emits a progress update. */ - when(valueOrPromise: any, callback: Function, errback: Function, progback: Function): dojo.promise.Promise; + when(valueOrPromise: any, callback: Function, errback: Function, progback: Function): dojo.promise.Promise; /** * signal fired by impending window destruction. You may use * dojo.addOnWIndowUnload() or dojo.connect() to this method to perform @@ -16050,7 +16050,7 @@ declare module dojo { * * @param objectOrArray OptionalThe promise will be fulfilled with a list of results if invoked with anarray, or an object of results when passed an object (using the samekeys). If passed neither an object or array it is resolved with anundefined value. */ - interface all{(objectOrArray?: Object): void} + interface all{(value: Promise[]): Promise} /** * Permalink: http://dojotoolkit.org/api/1.9/dojo/promise/all.html * @@ -16063,7 +16063,7 @@ declare module dojo { * * @param objectOrArray OptionalThe promise will be fulfilled with a list of results if invoked with anarray, or an object of results when passed an object (using the samekeys). If passed neither an object or array it is resolved with anundefined value. */ - interface all{(objectOrArray?: any[]): void} + interface all{(value: Object): Promise} /** * Permalink: http://dojotoolkit.org/api/1.9/dojo/promise/first.html * @@ -16107,6 +16107,11 @@ declare module dojo { * @param Deferred */ interface instrumentation{(Deferred: any): void} + + interface Callback { + (arg: T): U|Promise; + } + /** * Permalink: http://dojotoolkit.org/api/1.9/dojo/promise/Promise.html * @@ -16115,15 +16120,14 @@ declare module dojo { * instances of this class. * */ - class Promise { - constructor(); + interface Promise { /** * Add a callback to be invoked when the promise is resolved * or rejected. * * @param callbackOrErrback OptionalA function that is used both as a callback and errback. */ - always(callbackOrErrback: Function): any; + always(callbackOrErrback: Callback): Promise; /** * Inform the deferred it may cancel its asynchronous operation. * Inform the deferred it may cancel its asynchronous operation. @@ -16160,7 +16164,7 @@ declare module dojo { * * @param errback OptionalCallback to be invoked when the promise is rejected. */ - otherwise(errback: Function): any; + otherwise(errback: Callback): Promise; /** * Add new callbacks to the promise. * Add new callbacks to the deferred. Callbacks can be added @@ -16170,7 +16174,7 @@ declare module dojo { * @param errback OptionalCallback to be invoked when the promise is rejected.Receives the rejection error. * @param progback OptionalCallback to be invoked when the promise emits a progressupdate. Receives the progress update. */ - then(callback: Function, errback?: Function, progback?: Function): dojo.promise.Promise; + then(callback: Callback, errback?: Callback, progback?: Callback): Promise; /** * */ @@ -16184,7 +16188,7 @@ declare module dojo { * to handle traces. * */ - trace(): dojo.promise.Promise; + trace(): Promise; /** * Trace rejection of the promise. * Tracing allows you to transparently log progress, @@ -16194,7 +16198,7 @@ declare module dojo { * to handle traces. * */ - traceRejected(): dojo.promise.Promise; + traceRejected(): Promise; } /** * Permalink: http://dojotoolkit.org/api/1.9/dojo/promise/tracer.html @@ -17467,7 +17471,7 @@ declare module dojo { * * @param results The result set as an array, or a promise for an array. */ - interface QueryResults{(results: dojo.promise.Promise): void} + interface QueryResults{(results: dojo.promise.Promise): void} /** * Permalink: http://dojotoolkit.org/api/1.9/dojo/store/util/SimpleQueryEngine.html * @@ -20456,7 +20460,7 @@ declare module dojo { * @param value the number to be formatted * @param options OptionalAn object with the following properties:pattern (String, optional): override formatting patternwith this string. Default value is based on locale. Overriding this property will defeatlocalization. Literal characters in patterns are not supported.type (String, optional): choose a format type based on the locale from the following:decimal, scientific (not yet supported), percent, currency. decimal by default.places (Number, optional): fixed number of decimal places to show. This overrides anyinformation in the provided pattern.round (Number, optional): 5 rounds to nearest .5; 0 rounds to nearest whole (default). -1means do not round.locale (String, optional): override the locale used to determine formatting rulesfractional (Boolean, optional): If false, show no decimal places, overriding places and pattern settings. */ - format(value: number, options: Object): any; + format(value: number, options?: Object): any; /** * Convert a properly formatted string to a primitive Number, using * locale-specific settings. @@ -20782,7 +20786,7 @@ declare module dojo { * @param root OptionalA default starting root node from which to start the parsing. Can beomitted, defaulting to the entire document. If omitted, the optionsobject can be passed in this place. If the options object has arootNode member, that is used. * @param options a kwArgs options object, see parse() for details */ - scan(root: HTMLElement, options: Object): dojo.promise.Promise; + scan(root: HTMLElement, options: Object): dojo.promise.Promise; } /** * Permalink: http://dojotoolkit.org/api/1.9/dojo/regexp.html @@ -24419,7 +24423,7 @@ declare module dojo { * @param errback OptionalCallback to be invoked when the promise is rejected. * @param progback OptionalCallback to be invoked when the promise emits a progress update. */ - when(valueOrPromise: any, callback: Function, errback: Function, progback: Function): dojo.promise.Promise; + when(valueOrPromise: any, callback: Function, errback: Function, progback: Function): dojo.promise.Promise; /** * signal fired by impending window destruction. You may use * dojo.addOnWIndowUnload() or dojo.connect() to this method to perform @@ -28268,8 +28272,8 @@ declare module "dojo/promise/tracer" { export=exp; } declare module "dojo/promise/Promise" { - var exp: typeof dojo.promise.Promise - export=exp; + interface Promise extends dojo.promise.Promise { } + export = Promise; } declare module "dojo/rpc/JsonpService" { var exp: typeof dojo.rpc.JsonpService From b76b01450a5f3d90b92298b1204da474e8568133 Mon Sep 17 00:00:00 2001 From: Eric Byers Date: Wed, 15 Apr 2015 16:52:31 -0500 Subject: [PATCH 02/16] Split external and internal modules apart, add additional RequestValidation functions, extend Express Request to include RequestValidation. --- express-validator/express-validator.d.ts | 325 ++++++++++++----------- 1 file changed, 171 insertions(+), 154 deletions(-) diff --git a/express-validator/express-validator.d.ts b/express-validator/express-validator.d.ts index 5a5df2fa0..6ec5ece9e 100644 --- a/express-validator/express-validator.d.ts +++ b/express-validator/express-validator.d.ts @@ -5,169 +5,186 @@ /// +// Add RequestValidation Interface on to Express's Request Interface. +declare module Express { + interface Request extends ExpressValidator.RequestValidation {} +} +// External express-validator module. declare module "express-validator" { import express = require('express'); - module ExpressValidator { - - export interface ValidationError { - msg: string; - param: string; - } - - export interface RequestValidation { - check(field:string, message:string): Validator; - assert(field:string, message:string): Validator; - sanitize(field:string): Sanitizer; - onValidationError(func:(msg:string) => void): void; - validationErrors() : any; - } - - export interface Validator { - /** - * Alias for regex() - */ - is(): Validator; - /** - * Alias for notRegex() - */ - not(): Validator; - isEmail(): Validator; - /** - * Accepts http, https, ftp - */ - isUrl(): Validator; - /** - * Combines isIPv4 and isIPv6 - */ - isIP(): Validator; - isIPv4(): Validator; - isIPv6(): Validator; - isAlpha(): Validator; - isAlphanumeric(): Validator; - isNumeric(): Validator; - isHexadecimal(): Validator; - /** - * Accepts valid hexcolors with or without # prefix - */ - isHexColor(): Validator; - /** - * isNumeric accepts zero padded numbers, e.g. '001', isInt doesn't - */ - isInt(): Validator; - isLowercase(): Validator; - isUppercase(): Validator; - isDecimal(): Validator; - /** - * Alias for isDecimal - */ - isFloat(): Validator; - /** - * Check if length is 0 - */ - notNull(): Validator; - isNull(): Validator; - /** - * Not just whitespace (input.trim().length !== 0) - */ - notEmpty(): Validator; - equals(equals:any): Validator; - contains(str:string): Validator; - notContains(str:string): Validator; - /** - * Usage: regex(/[a-z]/i) or regex('[a-z]','i') - */ - regex(pattern:string, modifiers:string): Validator; - notRegex(pattern:string, modifiers:string): Validator; - /** - * max is optional - */ - len(min:number, max?:number): Validator; - /** - * Version can be 3, 4 or 5 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier - */ - isUUID(version:number): Validator; - /** - * Alias for isUUID(3) - */ - isUUIDv3(): Validator; - /** - * Alias for isUUID(4) - */ - isUUIDv4(): Validator; - /** - * Alias for isUUID(5) - */ - isUUIDv5(): Validator; - /** - * Uses Date.parse() - regex is probably a better choice - */ - isDate(): Validator; - /** - * Argument is optional and defaults to today. Comparison is non-inclusive - */ - isAfter(date:Date): Validator; - /** - * Argument is optional and defaults to today. Comparison is non-inclusive - */ - isBefore(date:Date): Validator; - isIn(options:string): Validator; - isIn(options:string[]): Validator; - notIn(options:string): Validator; - notIn(options:string[]): Validator; - max(val:string): Validator; - min(val:string): Validator; - /** - * Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats - */ - isCreditCard(): Validator; - } - - interface Sanitizer { - /** - * Trim optional `chars`, default is to trim whitespace (\r\n\t ) - */ - trim(...chars:string[]): Sanitizer; - ltrim(...chars:string[]): Sanitizer; - rtrim(...chars:string[]): Sanitizer; - ifNull(replace:any): Sanitizer; - toFloat(): Sanitizer; - toInt(): Sanitizer; - /** - * True unless str = '0', 'false', or str.length == 0 - */ - toBoolean(): Sanitizer; - /** - * False unless str = '1' or 'true' - */ - toBooleanStrict(): Sanitizer; - /** - * Decode HTML entities - */ - entityDecode(): Sanitizer; - entityEncode(): Sanitizer; - /** - * Escape &, <, >, and " - */ - escape(): Sanitizer; - /** - * Remove common XSS attack vectors from user-supplied HTML - */ - xss(): Sanitizer; - /** - * Remove common XSS attack vectors from images - */ - xss(fromImages:boolean): Sanitizer; - } - } - /** * * @middlewareOptions see: https://github.com/ctavan/express-validator#middleware-options */ function ExpressValidator(middlewareOptions?:any):express.RequestHandler; - export = ExpressValidator; } + +// Internal Module. +declare module ExpressValidator { + + export interface ValidationError { + msg: string; + param: string; + } + + export interface RequestValidation { + checkBody(field:string, message:string): Validator; + checkParams(field:string, message:string): Validator; + checkQuery(field:string, message:string): Validator; + checkHeader(field:string, message:string): Validator; + checkFiles(field:string, message:string): Validator; + + filter(field:string): Sanitizer; + sanitize(field:string): Sanitizer; + + check(field:string, message:string): Validator; + validate(field:string, message: string): Validator; + + assert(field:string, message:string): Validator; + + onValidationError(func:(msg:string) => void): void; + validationErrors(): any; + } + + export interface Validator { + /** + * Alias for regex() + */ + is(): Validator; + /** + * Alias for notRegex() + */ + not(): Validator; + isEmail(): Validator; + /** + * Accepts http, https, ftp + */ + isUrl(): Validator; + /** + * Combines isIPv4 and isIPv6 + */ + isIP(): Validator; + isIPv4(): Validator; + isIPv6(): Validator; + isAlpha(): Validator; + isAlphanumeric(): Validator; + isNumeric(): Validator; + isHexadecimal(): Validator; + /** + * Accepts valid hexcolors with or without # prefix + */ + isHexColor(): Validator; + /** + * isNumeric accepts zero padded numbers, e.g. '001', isInt doesn't + */ + isInt(): Validator; + isLowercase(): Validator; + isUppercase(): Validator; + isDecimal(): Validator; + /** + * Alias for isDecimal + */ + isFloat(): Validator; + /** + * Check if length is 0 + */ + notNull(): Validator; + isNull(): Validator; + /** + * Not just whitespace (input.trim().length !== 0) + */ + notEmpty(): Validator; + equals(equals:any): Validator; + contains(str:string): Validator; + notContains(str:string): Validator; + /** + * Usage: regex(/[a-z]/i) or regex('[a-z]','i') + */ + regex(pattern:string, modifiers:string): Validator; + notRegex(pattern:string, modifiers:string): Validator; + /** + * max is optional + */ + len(min:number, max?:number): Validator; + /** + * Version can be 3, 4 or 5 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier + */ + isUUID(version:number): Validator; + /** + * Alias for isUUID(3) + */ + isUUIDv3(): Validator; + /** + * Alias for isUUID(4) + */ + isUUIDv4(): Validator; + /** + * Alias for isUUID(5) + */ + isUUIDv5(): Validator; + /** + * Uses Date.parse() - regex is probably a better choice + */ + isDate(): Validator; + /** + * Argument is optional and defaults to today. Comparison is non-inclusive + */ + isAfter(date:Date): Validator; + /** + * Argument is optional and defaults to today. Comparison is non-inclusive + */ + isBefore(date:Date): Validator; + isIn(options:string): Validator; + isIn(options:string[]): Validator; + notIn(options:string): Validator; + notIn(options:string[]): Validator; + max(val:string): Validator; + min(val:string): Validator; + /** + * Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats + */ + isCreditCard(): Validator; + } + + interface Sanitizer { + /** + * Trim optional `chars`, default is to trim whitespace (\r\n\t ) + */ + trim(...chars:string[]): Sanitizer; + ltrim(...chars:string[]): Sanitizer; + rtrim(...chars:string[]): Sanitizer; + ifNull(replace:any): Sanitizer; + toFloat(): Sanitizer; + toInt(): Sanitizer; + /** + * True unless str = '0', 'false', or str.length == 0 + */ + toBoolean(): Sanitizer; + /** + * False unless str = '1' or 'true' + */ + toBooleanStrict(): Sanitizer; + /** + * Decode HTML entities + */ + entityDecode(): Sanitizer; + entityEncode(): Sanitizer; + /** + * Escape &, <, >, and " + */ + escape(): Sanitizer; + /** + * Remove common XSS attack vectors from user-supplied HTML + */ + xss(): Sanitizer; + /** + * Remove common XSS attack vectors from images + */ + xss(fromImages:boolean): Sanitizer; + } + +} \ No newline at end of file From 93f4df8e1a421ce209c54ab39bc4eddd925c3094 Mon Sep 17 00:00:00 2001 From: Eric Byers Date: Wed, 15 Apr 2015 17:13:29 -0500 Subject: [PATCH 03/16] Fix validationErrors parameters to have optional mapErrors parameters --- express-validator/express-validator.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/express-validator/express-validator.d.ts b/express-validator/express-validator.d.ts index 6ec5ece9e..4f3686c48 100644 --- a/express-validator/express-validator.d.ts +++ b/express-validator/express-validator.d.ts @@ -47,7 +47,7 @@ declare module ExpressValidator { assert(field:string, message:string): Validator; onValidationError(func:(msg:string) => void): void; - validationErrors(): any; + validationErrors(mapErrors?: boolean): any; } export interface Validator { From ca99daff707027bfed47f30a6603911778529e99 Mon Sep 17 00:00:00 2001 From: Eric Byers Date: Wed, 15 Apr 2015 17:16:24 -0500 Subject: [PATCH 04/16] Return valid array type for validationErrors --- express-validator/express-validator.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/express-validator/express-validator.d.ts b/express-validator/express-validator.d.ts index 4f3686c48..c265a4f8b 100644 --- a/express-validator/express-validator.d.ts +++ b/express-validator/express-validator.d.ts @@ -47,7 +47,7 @@ declare module ExpressValidator { assert(field:string, message:string): Validator; onValidationError(func:(msg:string) => void): void; - validationErrors(mapErrors?: boolean): any; + validationErrors(mapErrors?: boolean): Array; } export interface Validator { From 72fece2722cca1b9c9fe3a6c811c2717149b535a Mon Sep 17 00:00:00 2001 From: Eric Byers Date: Thu, 16 Apr 2015 11:06:23 -0500 Subject: [PATCH 05/16] Adding basic express-validator-tests --- express-validator/express-validator-tests.ts | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 express-validator/express-validator-tests.ts diff --git a/express-validator/express-validator-tests.ts b/express-validator/express-validator-tests.ts new file mode 100644 index 000000000..4cfe35c62 --- /dev/null +++ b/express-validator/express-validator-tests.ts @@ -0,0 +1,35 @@ +/// + +// @todo Most of the sanitize/validator methods are not tested here. + +import express = require('express'); +import expressValidator = require('express-validator'); + +var app = express(); + +// Add the middleware to make sure it includes. +app.use(expressValidator({ + errorFormatter: function(param: string, msg: string, value: string): {} { + return {}; + } +})); + +var router: express.Router = express.Router(); + +// Add a sample route so we can use the request. +router.get('/test/:testParam', function(req: express.Request, res: express.Response): void { + + // Various different request tests. + // The fluid calls are just random, making sure to cover a portion of the Validator. + req.checkParams('testParam', 'Invalid testParam').notEmpty().isInt(); + req.checkBody('testBody', 'Invalid testBody').isNumeric(); + req.checkFiles('testFiles', 'Invalid testFiles').isUrl(); + req.checkQuery('testQuery', 'Invalid testQuery').isDate(); + req.checkHeader('testHeader', 'Invalid testHeader').isLowercase().isUppercase(); + + var test = req.filter('postparam').toBoolean(); + var test2 = req.sanitize('postparam').toInt(); + + var errors = req.validationErrors(); + var mappedErrors = req.validationErrors(true); +}); \ No newline at end of file From 573cd80b1cc9f757620d08764ee1f7d4380e1604 Mon Sep 17 00:00:00 2001 From: Eric Byers Date: Wed, 29 Apr 2015 12:24:00 -0500 Subject: [PATCH 06/16] Fixing formatting, using express.Request since it is now extended properly --- express-validator/express-validator-tests.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/express-validator/express-validator-tests.ts b/express-validator/express-validator-tests.ts index d6ae4addb..74bd277e4 100644 --- a/express-validator/express-validator-tests.ts +++ b/express-validator/express-validator-tests.ts @@ -9,7 +9,7 @@ var app = express(); app.use(expressValidator()); -app.post('/:urlparam', function(req: expressValidator.ValidatedRequest, res: express.Response) { +app.post('/:urlparam', function(req: express.Request, res: express.Response) { // checkBody only checks req.body; none of the other req parameters // Similarly checkParams only checks in req.params (URL params) and @@ -17,17 +17,17 @@ app.post('/:urlparam', function(req: expressValidator.ValidatedRequest, res: exp req.checkBody('postparam', 'Invalid postparam').notEmpty().isInt(); req.checkParams('urlparam', 'Invalid urlparam').isAlpha(); req.checkQuery('getparam', 'Invalid getparam').isInt(); - req.checkHeader('testHeader', 'Invalid testHeader').isLowercase().isUppercase(); - req.checkFiles('testFiles', 'Invalid testFiles').isUrl(); + req.checkHeader('testHeader', 'Invalid testHeader').isLowercase().isUppercase(); + req.checkFiles('testFiles', 'Invalid testFiles').isUrl(); - // OR assert can be used to check on all 3 types of params. + // OR assert can be used to check on all 3 types of params. // req.assert('postparam', 'Invalid postparam').notEmpty().isInt(); // req.assert('urlparam', 'Invalid urlparam').isAlpha(); // req.assert('getparam', 'Invalid getparam').isInt(); req.sanitize('postparam').toBoolean(); - req.filter('postparam').toBoolean(); + req.filter('postparam').toBoolean(); var errors = req.validationErrors(); var mappedErrors = req.validationErrors(true); From fcc48530e36f079533a702a9ed68862913dfab3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e?= Date: Wed, 29 Apr 2015 23:00:06 +0200 Subject: [PATCH 07/16] socket.io: SocketIO.Namespace has an "in" method --- socket.io/socket.io.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/socket.io/socket.io.d.ts b/socket.io/socket.io.d.ts index 258b573d5..ba7a5ba70 100644 --- a/socket.io/socket.io.d.ts +++ b/socket.io/socket.io.d.ts @@ -46,6 +46,7 @@ declare module SocketIO { name: string; connected: { [id: string]: Socket }; use(fn: Function): Namespace; + in(room: string): Namespace; on(event: 'connection', listener: (socket: Socket) => void): Namespace; on(event: 'connect', listener: (socket: Socket) => void): Namespace; From bbb3bc06906df2e440d1ee306bb1aafb38a1f37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e?= Date: Thu, 30 Apr 2015 01:14:30 +0200 Subject: [PATCH 08/16] Add overload for http.Server.listen The backlog parameter should be optional while still accepting the port parameter. --- node/node.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/node/node.d.ts b/node/node.d.ts index 3771ba822..b0a7b77e5 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -340,6 +340,7 @@ declare module "http" { export interface Server extends events.EventEmitter { listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; + listen(port: number, hostname?: string, callback?: Function): Server; listen(path: string, callback?: Function): Server; listen(handle: any, listeningListener?: Function): Server; close(cb?: any): Server; From 73f40823e5b98683d2dc81876deaa0f27dc6fc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e=20Maurer?= Date: Thu, 30 Apr 2015 04:54:08 +0200 Subject: [PATCH 09/16] Add recursive-readdir library --- recursive-readdir/recursive-readdir-tests.ts | 6 ++++++ recursive-readdir/recursive-readdir.d.ts | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 recursive-readdir/recursive-readdir-tests.ts create mode 100644 recursive-readdir/recursive-readdir.d.ts diff --git a/recursive-readdir/recursive-readdir-tests.ts b/recursive-readdir/recursive-readdir-tests.ts new file mode 100644 index 000000000..2d3e1d7c9 --- /dev/null +++ b/recursive-readdir/recursive-readdir-tests.ts @@ -0,0 +1,6 @@ +/// + +import recursiveReaddir = require("recursive-readdir"); + +recursiveReaddir("some/path", (err, files) => {}); +recursiveReaddir("some/path", ["foo.cs", "*.html"], (err, files) => {}); diff --git a/recursive-readdir/recursive-readdir.d.ts b/recursive-readdir/recursive-readdir.d.ts new file mode 100644 index 000000000..5e7ecee0a --- /dev/null +++ b/recursive-readdir/recursive-readdir.d.ts @@ -0,0 +1,11 @@ +// Type definitions for recursive-readdir v1.2.1 +// Project: https://github.com/jergason/recursive-readdir/ +// Definitions by: Elisée Maurer +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "recursive-readdir" { + function readdir(path: string, callback: (error: Error, files: string[]) => any): void; + // ignorePattern supports glob syntax via https://github.com/isaacs/minimatch + function readdir(path: string, ignorePattern: string[], callback: (error: Error, files: string[]) => any): void; + export = readdir; +} From dacbb54147b14eeffd1626fd857495bd37bc8da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e=20Maurer?= Date: Thu, 30 Apr 2015 05:06:47 +0200 Subject: [PATCH 10/16] Fix module to work with ES6 import syntax --- recursive-readdir/recursive-readdir.d.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/recursive-readdir/recursive-readdir.d.ts b/recursive-readdir/recursive-readdir.d.ts index 5e7ecee0a..b948fac87 100644 --- a/recursive-readdir/recursive-readdir.d.ts +++ b/recursive-readdir/recursive-readdir.d.ts @@ -4,8 +4,15 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module "recursive-readdir" { - function readdir(path: string, callback: (error: Error, files: string[]) => any): void; - // ignorePattern supports glob syntax via https://github.com/isaacs/minimatch - function readdir(path: string, ignorePattern: string[], callback: (error: Error, files: string[]) => any): void; - export = readdir; + + module RecursiveReaddir { + interface readdir { + (path: string, callback: (error: Error, files: string[]) => any): void; + // ignorePattern supports glob syntax via https://github.com/isaacs/minimatch + (path: string, ignorePattern: string[], callback: (error: Error, files: string[]) => any): void; + } + } + + var r: RecursiveReaddir.readdir; + export = r; } From 1fe804314867cf0db933b7cc76212960a50a8935 Mon Sep 17 00:00:00 2001 From: Robert Dennis Date: Wed, 29 Apr 2015 23:09:49 -0400 Subject: [PATCH 11/16] jquery.dataTables - fix FunctionColumnRender and FunctionColumnData signitures. --- jquery.dataTables/jquery.dataTables-tests.ts | 7 ++++++- jquery.dataTables/jquery.dataTables.d.ts | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/jquery.dataTables/jquery.dataTables-tests.ts b/jquery.dataTables/jquery.dataTables-tests.ts index c90b40d09..552b997b8 100755 --- a/jquery.dataTables/jquery.dataTables-tests.ts +++ b/jquery.dataTables/jquery.dataTables-tests.ts @@ -44,6 +44,9 @@ $(document).ready(function () { }; var colDataFunc: DataTables.FunctionColumnData = function (row, type, set, meta) { + meta.col; + meta.row; + meta.settings; }; var colRenderObject: DataTables.ObjectColumnRender = { @@ -54,7 +57,9 @@ $(document).ready(function () { }; var colRenderFunc: DataTables.FunctionColumnRender = function (data, type, row, meta) { - + meta.col; + meta.row; + meta.settings; }; var col: DataTables.ColumnSettings = diff --git a/jquery.dataTables/jquery.dataTables.d.ts b/jquery.dataTables/jquery.dataTables.d.ts index cbcb1c025..50ff52edd 100755 --- a/jquery.dataTables/jquery.dataTables.d.ts +++ b/jquery.dataTables/jquery.dataTables.d.ts @@ -1498,7 +1498,7 @@ declare module DataTables { } interface FunctionColumnData { - (row: any, t: string, s: any, meta: Object): void; + (row: any, t: string, s: any, meta: CellMetaSettings): void; } interface ObjectColumnData { @@ -1513,7 +1513,13 @@ declare module DataTables { } interface FunctionColumnRender { - (data: Node, t: Node, row: Node, meta: Object): void; + (data: any, t: string, row: any, meta: CellMetaSettings): void; + } + + interface CellMetaSettings { + row: number; + col: number; + settings: DataTables.Settings; } //#endregion "colunm-settings" From c3a1f48983487c1d1bb6ddb35973931e7bb320af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e=20Maurer?= Date: Thu, 30 Apr 2015 06:12:32 +0200 Subject: [PATCH 12/16] Add SocketIO.Socket.handshake --- socket.io/socket.io.d.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/socket.io/socket.io.d.ts b/socket.io/socket.io.d.ts index ba7a5ba70..ac5381f09 100644 --- a/socket.io/socket.io.d.ts +++ b/socket.io/socket.io.d.ts @@ -59,6 +59,17 @@ declare module SocketIO { conn: any; request: any; id: string; + handshake: { + headers: any; + time: string; + address: any; + xdomain: boolean; + secure: boolean; + issued: number; + url: string; + query: any; + }; + emit(name: string, ...args: any[]): Socket; join(name: string, fn?: Function): Socket; leave(name: string, fn?: Function): Socket; From 040d2efd5edbfa10a136ad3b83da477d6e191aa6 Mon Sep 17 00:00:00 2001 From: CallMeTango Date: Thu, 30 Apr 2015 18:00:45 +0200 Subject: [PATCH 13/16] gruntjs: Fixed type of IExpandedFilesConfig.cwd Changed type of IExpandedFilesConfig.cwd from boolean to string. Added simple test for interface IExpandedFilesConfig as well. fixes #4207 --- gruntjs/gruntjs-tests.ts | 12 +++++++++++- gruntjs/gruntjs.d.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gruntjs/gruntjs-tests.ts b/gruntjs/gruntjs-tests.ts index 6b8607329..55f106d53 100644 --- a/gruntjs/gruntjs-tests.ts +++ b/gruntjs/gruntjs-tests.ts @@ -68,7 +68,17 @@ exports = (grunt: IGrunt) => { asyncedTwoArgs(2, "values", (result: string) => { console.log(result); }); - var fileMaps = grunt.file.expandMapping([''], '', { ext: '.js' }); + + // tests for module grunt.file + var expandedFilesConfig: grunt.file.IExpandedFilesConfig = { + expand: true, + cwd: 'src', + src: ['**/*.ts'], + dest: 'build', + ext: '.js', + flatten: false + }; + var fileMaps = grunt.file.expandMapping([''], '', expandedFilesConfig); fileMaps.length; fileMaps[0].src.length; fileMaps[0].dest; diff --git a/gruntjs/gruntjs.d.ts b/gruntjs/gruntjs.d.ts index baea9dcfb..850d0b226 100644 --- a/gruntjs/gruntjs.d.ts +++ b/gruntjs/gruntjs.d.ts @@ -604,7 +604,7 @@ declare module grunt { /** * All {@link IExpandedFilesConfig.src} matches are relative to (but don't include) this path. */ - cwd?: boolean + cwd?: string /** * Replace any existing extension with this value in generated {@link IExpandedFilesConfig.dest} paths. From 2034ab18e7eac536c794c503671bbcbe896f106b Mon Sep 17 00:00:00 2001 From: Horiuchi_H Date: Fri, 1 May 2015 09:44:24 +0900 Subject: [PATCH 14/16] merge .js directories --- .gitignore | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 7bfdb8b53..7a300c0af 100644 --- a/.gitignore +++ b/.gitignore @@ -28,15 +28,7 @@ _infrastructure/tests/build .idea *.iml *.js.map - -#decimal.js -!decimal.js - -#rx.js -!rx.js - -#zip.js -!zip.js +!*.js/ node_modules From c969d6275cf4832f24aae3ea9a4eec3730f8c8da Mon Sep 17 00:00:00 2001 From: Florent Chiron Date: Fri, 1 May 2015 03:30:41 +0200 Subject: [PATCH 15/16] Add signature for promise.tap(onFulfilled) --- q/Q-tests.ts | 9 +++++++++ q/Q.d.ts | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/q/Q-tests.ts b/q/Q-tests.ts index 7872f23b2..2e9b7547b 100644 --- a/q/Q-tests.ts +++ b/q/Q-tests.ts @@ -64,6 +64,15 @@ Q.allResolved([]) }) }); +Q(42) + .tap(() => "hello") + .tap(x => { + console.log(x); + }) + .then(x => { + console.log("42 == " + x); + }); + declare var arrayPromise: Q.IPromise; declare var stringPromise: Q.IPromise; declare function returnsNumPromise(text: string): Q.Promise; diff --git a/q/Q.d.ts b/q/Q.d.ts index 590fd92ad..2a239dc18 100644 --- a/q/Q.d.ts +++ b/q/Q.d.ts @@ -122,6 +122,12 @@ declare module Q { * A sugar method, equivalent to promise.then(function () { throw reason; }). */ thenReject(reason: any): Promise; + + /** + * Attaches a handler that will observe the value of the promise when it becomes fulfilled, returning a promise for that same value, perhaps deferred but not replaced by the promise returned by the onFulfilled handler. + */ + tap(onFulfilled: (value: T) => any): Promise; + timeout(ms: number, message?: string): Promise; /** * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed. From 298a4d1cb25df4ba33667c6edb3815261abf7ac0 Mon Sep 17 00:00:00 2001 From: Jed Mao Date: Thu, 30 Apr 2015 01:30:25 -0500 Subject: [PATCH 16/16] Fix vinyl-fs defs --- vinyl-fs/vinyl-fs.d.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/vinyl-fs/vinyl-fs.d.ts b/vinyl-fs/vinyl-fs.d.ts index e9f549161..c9018c400 100644 --- a/vinyl-fs/vinyl-fs.d.ts +++ b/vinyl-fs/vinyl-fs.d.ts @@ -8,24 +8,20 @@ declare module NodeJS { interface WritableStream { - write(buffer: any/* Vinyl.IFile */, cb?: Function): boolean; + write(buffer: any/* Vinyl.File */, cb?: Function): boolean; } } declare module "vinyl-fs" { import _events = require("events"); + import File = require("vinyl"); - function src(globs:string, opt?:{read?:boolean;buffer?:boolean;}):NodeJS.ReadWriteStream; + function src(globs:string|string[], opt?:{read?:boolean;buffer?:boolean;}):NodeJS.ReadWriteStream; - function src(globs:string[], opt?:{read?:boolean;buffer?:boolean;}):NodeJS.ReadWriteStream; + function watch(globs:string|string[], cb?:(outEvt:{type:any;path:any;old:any;})=>void):_events.EventEmitter; - function watch(globs:string, cb?:(outEvt:{type:any;path:any;old:any;})=>void):_events.EventEmitter; + function watch(globs:string|string[], opt?:{interval?:number;debounceDelay?:number;cwd?:string;maxListeners?:Function;}, cb?:(outEvt:{type:any;path:any;old:any;})=>void):_events.EventEmitter; - function watch(globs:string[], cb?:(outEvt:{type:any;path:any;old:any;})=>void):_events.EventEmitter; - - function watch(globs:string, opt?:{interval?:number;debounceDelay?:number;cwd?:string;maxListeners?:Function;}, cb?:(outEvt:{type:any;path:any;old:any;})=>void):_events.EventEmitter; - - function watch(globs:string[], opt?:{interval?:number;debounceDelay?:number;cwd?:string;maxListeners?:Function;}, cb?:(outEvt:{type:any;path:any;old:any;})=>void):_events.EventEmitter; - - function dest(folder:string, opt?:{cwd?:string; mode?:any/* number or string */;}):NodeJS.ReadWriteStream; + function dest(folder: string, opt?: { cwd?: string; mode?: number|string; }): NodeJS.ReadWriteStream; + function dest(getFolderPath: (file: File) => string): NodeJS.ReadWriteStream; }