From 6fce17d92cf06d19972400f92fe3c30deb004814 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Mon, 10 Aug 2015 20:06:42 +0200 Subject: [PATCH 1/8] Add maildev definition. --- maildev/maildev.d.ts | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 maildev/maildev.d.ts diff --git a/maildev/maildev.d.ts b/maildev/maildev.d.ts new file mode 100644 index 000000000..fadd1aceb --- /dev/null +++ b/maildev/maildev.d.ts @@ -0,0 +1,109 @@ +// Type definitions for maildev 0.11.0 +// Project: https://github.com/djfarrelly/maildev +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +import fs = require("fs"); + +/** + * Interface for {@link MailDev} options. + */ +interface MailDevOptions { + /** + * SMTP host for outgoing emails + * + * @type {string} + */ + outgoingHost: string; + + /** + * SMTP password for outgoing emails + * + * @type {string} + */ + outgoingPass: string; + + /** + * SMTP port for outgoing emails. + * + * @type {number} + */ + outgoingPort: number; + + /** + * SMTP user for outgoing emails + * + * @type {string} + */ + outgoingUser: string; + + /** + * SMTP port to catch emails. + * + * @type {number} + */ + smtp: number; +} + +/** + * Interface for {@link MailDev}. + */ +interface MailDev { + /** + * Constructor. + * + * @public + * @param options The options. + */ + new(options: MailDevOptions): MailDev; + + /** + * Stops the SMTP server. + * + * @public + * @param callback The error callback. + */ + end(callback?: (error: Error) => void): void; + + /** + * Accepts e-mail identifier, returns email object. + * + * @public + * @param id The e-mail identifier. + */ + getEmail(id: string, callback?: (error: Error) => void): void; + + /** + * Returns a readable stream of the raw e-mail. + * + * @public + * @param id The e-mail identifier. + */ + getRawEmail(id: string, callback?: (error: Error, readStream: fs.ReadStream) => void): void; + + /** + * Returns array of all e-mail. + + * @public + */ + getAllEmail(): void; + + /** + * Starts the SMTP server. + * + * @public + * @param callback The error callback. + */ + listen(callback?: (error: Error) => void): void; + + /** + * Event called when a new e-mail is received. Callback receives single mail object. + * + * @public + * @param eventName The event name. + * @param callback The callback for obtains the received email. + */ + on(eventName: string, callback: (email: string) => void): void; +} From 18bd87062f1763d752033c3e31617231dca9cdec Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Thu, 13 Aug 2015 22:31:57 +0200 Subject: [PATCH 2/8] Add definition for "node-schedule". Update definition for "maildev". --- maildev/maildev-tests.ts | 12 ++ maildev/maildev.d.ts | 195 ++++++++++++++----------- node-schedule/node-schedule-tests.ts | 79 ++++++++++ node-schedule/node-schedule.d.ts | 207 +++++++++++++++++++++++++++ 4 files changed, 409 insertions(+), 84 deletions(-) create mode 100644 maildev/maildev-tests.ts create mode 100644 node-schedule/node-schedule-tests.ts create mode 100644 node-schedule/node-schedule.d.ts diff --git a/maildev/maildev-tests.ts b/maildev/maildev-tests.ts new file mode 100644 index 000000000..156dbd446 --- /dev/null +++ b/maildev/maildev-tests.ts @@ -0,0 +1,12 @@ +/// + +import MailDev = require("maildev") + +var options: MailDevOptions = {smtp: 1025}; +var maildev = new MailDev(options); + +var errorCallback = (error: Error) => {}; +maildev.listen(errorCallback); + +var eventName = 'new'; +maildev.on(eventName, errorCallback) diff --git a/maildev/maildev.d.ts b/maildev/maildev.d.ts index fadd1aceb..9887ddbfd 100644 --- a/maildev/maildev.d.ts +++ b/maildev/maildev.d.ts @@ -5,105 +5,132 @@ /// -import fs = require("fs"); - /** * Interface for {@link MailDev} options. */ interface MailDevOptions { - /** - * SMTP host for outgoing emails - * - * @type {string} - */ - outgoingHost: string; + /** + * SMTP host for outgoing emails + * + * @type {string} + */ + outgoingHost?: string; - /** - * SMTP password for outgoing emails - * - * @type {string} - */ - outgoingPass: string; + /** + * SMTP password for outgoing emails + * + * @type {string} + */ + outgoingPass?: string; - /** - * SMTP port for outgoing emails. - * - * @type {number} - */ - outgoingPort: number; + /** + * SMTP port for outgoing emails. + * + * @type {number} + */ + outgoingPort?: number; - /** - * SMTP user for outgoing emails - * - * @type {string} - */ - outgoingUser: string; + /** + * SMTP user for outgoing emails + * + * @type {string} + */ + outgoingUser?: string; - /** - * SMTP port to catch emails. - * - * @type {number} - */ - smtp: number; + /** + * SMTP port to catch emails. + * + * @type {number} + */ + smtp?: number; } /** - * Interface for {@link MailDev}. + * Interface for mail. */ -interface MailDev { +interface Mail { /** - * Constructor. - * - * @public - * @param options The options. + * Identifier. */ - new(options: MailDevOptions): MailDev; + id?: string; /** - * Stops the SMTP server. - * - * @public - * @param callback The error callback. + * Client. */ - end(callback?: (error: Error) => void): void; - - /** - * Accepts e-mail identifier, returns email object. - * - * @public - * @param id The e-mail identifier. - */ - getEmail(id: string, callback?: (error: Error) => void): void; - - /** - * Returns a readable stream of the raw e-mail. - * - * @public - * @param id The e-mail identifier. - */ - getRawEmail(id: string, callback?: (error: Error, readStream: fs.ReadStream) => void): void; - - /** - * Returns array of all e-mail. - - * @public - */ - getAllEmail(): void; - - /** - * Starts the SMTP server. - * - * @public - * @param callback The error callback. - */ - listen(callback?: (error: Error) => void): void; - - /** - * Event called when a new e-mail is received. Callback receives single mail object. - * - * @public - * @param eventName The event name. - * @param callback The callback for obtains the received email. - */ - on(eventName: string, callback: (email: string) => void): void; + envelope?: Object; +} + +declare module "maildev" { + import fs = require("fs"); + + /** + * Interface for {@link MailDev}. + */ + class MailDev { + /** + * Constructor. + * + * @public + * @param {MailDevOptions} options The options. + */ + constructor(options: MailDevOptions); + + /** + * Stops the SMTP server. + * + * @public + * @param callback The error callback. + */ + end(callback?: (error: Error) => void): void; + + /** + * Accepts e-mail identifier, returns email object. + * + * @public + * @param {string} id The e-mail identifier. + */ + getEmail(id: string, callback?: (error: Error) => void): void; + + /** + * Returns a readable stream of the raw e-mail. + * + * @public + * @param {string} id The e-mail identifier. + */ + getRawEmail(id: string, callback?: (error: Error, readStream: fs.ReadStream) => void): void; + + /** + * Returns array of all e-mail. + + * @public + */ + getAllEmail(done: (error: Error, emails: Array) => void): void; + + /** + * Starts the SMTP server. + * + * @public + * @param callback The error callback. + */ + listen(callback?: (error: Error) => void): void; + + /** + * Event called when a new e-mail is received. Callback receives single mail object. + * + * @public + * @param {string} eventName The event name. + * @param callback The callback for obtains the received email. + */ + on(eventName: string, callback: (email: string) => void): void; + + /** + * Relay the e-mail. + * + * @param {string} idOrMailObject The identifier or mail object. + */ + relayMail(idOrMailObject: string, done: (error: Error) => void): void; + } + + var out: typeof MailDev; + export = out; } diff --git a/node-schedule/node-schedule-tests.ts b/node-schedule/node-schedule-tests.ts new file mode 100644 index 000000000..35a03d9d6 --- /dev/null +++ b/node-schedule/node-schedule-tests.ts @@ -0,0 +1,79 @@ +/// + +import nodeSchedule = require("node-schedule"); + +/** + * Test for {@link Job} class. + */ +function testJob() { + var name: string = ''; + var job: Function = null; + var callback: Function = null; + + new nodeSchedule.Job(job, callback); + new nodeSchedule.Job(name, job, callback); +} + +/** + * Test for {@link Range} class. + */ +function testRange() { + var range = new nodeSchedule.Range(0); + var twoParametersRange = new nodeSchedule.Range(0, 0); + var threeParametersRange = new nodeSchedule.Range(0, 0, 0); + + var contained: boolean = range.contains(0); +} + +/** + * Test for {@link RecurrenceRule} class. + */ +function testRecurrenceRule() { + var range = new nodeSchedule.Range(0, 0, 0); + var rule: nodeSchedule.RecurrenceRule = { + date: 0, + dayOfWeek: [0, range], + hour: 0, + minute: 0, + month: 0, + second: 0, + year: 0 + } +} + +/** + * Test for {@link Invocation} class. + */ +function testInvocation() { + var job = new nodeSchedule.Job(); + var fireDate = new Date(); + var rule: nodeSchedule.RecurrenceRule = {}; + + var invocation = new nodeSchedule.Invocation(job, fireDate, rule); + invocation.timerID = 0; +} + +/** + * Test for {@link ScheduleJob} class. + */ +function testScheduleJob() { + var callback: Function = null; + new nodeSchedule.ScheduleJob('', callback); + + var rule: nodeSchedule.RecurrenceRule = {}; + new nodeSchedule.ScheduleJob(rule, callback); + + var date: Date = new Date(); + new nodeSchedule.ScheduleJob(date, callback); + + var date: Date = new Date(); + new nodeSchedule.ScheduleJob(date, callback); +} + +/** + * Test for {@link cancelJob} function. + */ +function testCancelJob() { + var job = new nodeSchedule.Job(); + nodeSchedule.cancelJob(job); +} diff --git a/node-schedule/node-schedule.d.ts b/node-schedule/node-schedule.d.ts new file mode 100644 index 000000000..1e8f65312 --- /dev/null +++ b/node-schedule/node-schedule.d.ts @@ -0,0 +1,207 @@ +// Type definitions for node-schedule +// Project: https://github.com/tejasmanohar/node-schedule/ +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "node-schedule" { + import nodeSchedule = require('node-schedule'); + + /** + * Recurrence rules. + */ + export interface RecurrenceRule { + /** + * Day of the month. + * + * @public + * @type {number} + */ + date?: number; + + /** + * Day of the week. + * + * @public + * @type {number|Array} + */ + dayOfWeek?: number|Array; + + /** + * Hour. + * + * @public + * @type {number} + */ + hour?: number; + + /** + * Minute. + * + * @public + * @type {number} + */ + minute?: number; + + /** + * Month. + * + * @public + * @type {number} + */ + month?: number; + + /** + * Second. + * + * @public + * @type {number} + */ + second?: number; + + /** + * Year. + * + * @public + * @type {number} + */ + year?: number; + } + + /** + * Range. + * + * @class + */ + export class Range { + /** + * Constructor. + * + * @constructor + * @param {number} start The start. + * @param {end} end The end. + * @param {step} step The step. + */ + constructor(start?: number, end?: number, step?: number); + + /** + * Return a {boolean} if the class contains the specified value. + * + * @param {number} value The value. + * @returns {boolean} {true} if the class contains the specified value, otherwise, {false}. + */ + contains(value: number): boolean; + } + + /** + * Scheduler job. + * + * @class + */ + export class ScheduleJob { + /** + * Constructor. + * + * @constructor + * @param {RecurrenceRule} rule The rule. + * @param + */ + constructor(rule: RecurrenceRule|Date|string, callback: Function); + } + + /** + * Scheduler jobs. + * + * @class + */ + export class Job { + /** + * Constructor. + * + * @constructor + * @param {RecurrenceRule} rule The rule. + * @param + */ + constructor(name?: string, job?: Function, callback?: Function); + + /** + * Constructor. + * + * @constructor + * @param {RecurrenceRule} rule The rule. + * @param + */ + constructor(job?: Function, callback?: Function); + + /** + * Attach an event handler function. + * + * @public + * @param {string} eventName The event name. + * @param {Function} handler The function to execute when the event is triggered. + */ + on(eventName: string, handler: Function): void; + + /** + * + * @public + */ + schedule(date: Date): void; + } + + /** + * Invocation. + * + * @class + */ + export class Invocation { + /** + * Fire date. + * + * @public + * @type {Date} + */ + public fireDate: Date; + + /** + * Job. + * + * @public + * @type {Job} + */ + public job: Job; + + /** + * Recurrence rule. + * + * @public + * @type {RecurrenceRule} + */ + public recurrenceRule: RecurrenceRule; + + /** + * Timer identifier. + * + * @public + * @type {number} + */ + public timerID: number; + + /** + * Constructor. + * + * @constructor + * @param job The job. + * @param fireDate The fire date. + * @param recurrenceRule The recurrence rule. + */ + constructor(job: Job, fireDate: Date, recurrenceRule: RecurrenceRule); + } + + /** + * Cancels the job. + * + * @param job The job. + * @returns {boolean} {true} if the job has been cancelled with success, otherwise, {false}. + */ + export function cancelJob(job: Job): boolean; +} From e51aa4f3215cb59a9124e9da6d7b9c7088e63912 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Fri, 14 Aug 2015 19:33:40 +0200 Subject: [PATCH 3/8] Update definition for "maildev". --- maildev/maildev-tests.ts | 5 +++-- maildev/maildev.d.ts | 47 ++++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/maildev/maildev-tests.ts b/maildev/maildev-tests.ts index 156dbd446..62c324c5e 100644 --- a/maildev/maildev-tests.ts +++ b/maildev/maildev-tests.ts @@ -5,8 +5,9 @@ import MailDev = require("maildev") var options: MailDevOptions = {smtp: 1025}; var maildev = new MailDev(options); -var errorCallback = (error: Error) => {}; +var errorCallback = (error: Error): void => {}; maildev.listen(errorCallback); var eventName = 'new'; -maildev.on(eventName, errorCallback) +var emailCallback = (email: Object): void => {}; +maildev.on(eventName, emailCallback) diff --git a/maildev/maildev.d.ts b/maildev/maildev.d.ts index 9887ddbfd..a02fdb34b 100644 --- a/maildev/maildev.d.ts +++ b/maildev/maildev.d.ts @@ -49,15 +49,15 @@ interface MailDevOptions { * Interface for mail. */ interface Mail { - /** - * Identifier. - */ - id?: string; + /** + * Identifier. + */ + id?: string; - /** - * Client. - */ - envelope?: Object; + /** + * Client. + */ + envelope?: Object; } declare module "maildev" { @@ -75,11 +75,28 @@ declare module "maildev" { */ constructor(options: MailDevOptions); + /** + * Deletes a given email by identifier. + * + * @public + * @param {string} id The email identifier. + * @param {Function} callback The error callback. + */ + deleteEmail(id: string, callback?: (error: Error) => void): void; + + /** + * Deletes all email and their attachments. + * + * @public + * @param {Function} callback The error callback. + */ + deleteAllEmail(callback?: (error: Error) => void): void; + /** * Stops the SMTP server. * * @public - * @param callback The error callback. + * @param {Function} callback The error callback. */ end(callback?: (error: Error) => void): void; @@ -87,7 +104,8 @@ declare module "maildev" { * Accepts e-mail identifier, returns email object. * * @public - * @param {string} id The e-mail identifier. + * @param {string} id The e-mail identifier. + * @param {Function} callback The error callback. */ getEmail(id: string, callback?: (error: Error) => void): void; @@ -110,7 +128,7 @@ declare module "maildev" { * Starts the SMTP server. * * @public - * @param callback The error callback. + * @param {Function} callback The error callback. */ listen(callback?: (error: Error) => void): void; @@ -118,15 +136,16 @@ declare module "maildev" { * Event called when a new e-mail is received. Callback receives single mail object. * * @public - * @param {string} eventName The event name. - * @param callback The callback for obtains the received email. + * @param {string} eventName The event name. + * @param {Function} email The email. */ - on(eventName: string, callback: (email: string) => void): void; + on(eventName: string, callback: (email: Object) => void): void; /** * Relay the e-mail. * * @param {string} idOrMailObject The identifier or mail object. + * @param {Function} done The callback. */ relayMail(idOrMailObject: string, done: (error: Error) => void): void; } From 4b7c8a8764470c1764953bac4173d9f1116ba2b8 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Fri, 14 Aug 2015 19:48:41 +0200 Subject: [PATCH 4/8] Fix errors. --- node-schedule/node-schedule-tests.ts | 8 +++---- node-schedule/node-schedule.d.ts | 36 +++++++++++----------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/node-schedule/node-schedule-tests.ts b/node-schedule/node-schedule-tests.ts index 35a03d9d6..ca8ab60c7 100644 --- a/node-schedule/node-schedule-tests.ts +++ b/node-schedule/node-schedule-tests.ts @@ -58,16 +58,16 @@ function testInvocation() { */ function testScheduleJob() { var callback: Function = null; - new nodeSchedule.ScheduleJob('', callback); + new nodeSchedule.scheduleJob('', callback); var rule: nodeSchedule.RecurrenceRule = {}; - new nodeSchedule.ScheduleJob(rule, callback); + new nodeSchedule.scheduleJob(rule, callback); var date: Date = new Date(); - new nodeSchedule.ScheduleJob(date, callback); + new nodeSchedule.scheduleJob(date, callback); var date: Date = new Date(); - new nodeSchedule.ScheduleJob(date, callback); + new nodeSchedule.scheduleJob(date, callback); } /** diff --git a/node-schedule/node-schedule.d.ts b/node-schedule/node-schedule.d.ts index 1e8f65312..ca1dcd094 100644 --- a/node-schedule/node-schedule.d.ts +++ b/node-schedule/node-schedule.d.ts @@ -92,22 +92,6 @@ declare module "node-schedule" { contains(value: number): boolean; } - /** - * Scheduler job. - * - * @class - */ - export class ScheduleJob { - /** - * Constructor. - * - * @constructor - * @param {RecurrenceRule} rule The rule. - * @param - */ - constructor(rule: RecurrenceRule|Date|string, callback: Function); - } - /** * Scheduler jobs. * @@ -118,8 +102,8 @@ declare module "node-schedule" { * Constructor. * * @constructor - * @param {RecurrenceRule} rule The rule. - * @param + * @param {RecurrenceRule} rule The rule. + * @param {callback} callback The callback. */ constructor(name?: string, job?: Function, callback?: Function); @@ -190,9 +174,9 @@ declare module "node-schedule" { * Constructor. * * @constructor - * @param job The job. - * @param fireDate The fire date. - * @param recurrenceRule The recurrence rule. + * @param {Job} job The job. + * @param {Date} fireDate The fire date. + * @param {RecurrenceRule} recurrenceRule The recurrence rule. */ constructor(job: Job, fireDate: Date, recurrenceRule: RecurrenceRule); } @@ -200,8 +184,16 @@ declare module "node-schedule" { /** * Cancels the job. * - * @param job The job. + * @param {Job} job The job. * @returns {boolean} {true} if the job has been cancelled with success, otherwise, {false}. */ export function cancelJob(job: Job): boolean; + + /** + * Create a schedule job. + * + * @param {RecurrenceRule} rule The rule. + * @param {Function} callback The callback. + */ + export function scheduleJob(rule: RecurrenceRule|Date|string, callback: Function); } From d6f3edd0494d93b300b066775a389222ac8b9e6d Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Fri, 14 Aug 2015 19:53:20 +0200 Subject: [PATCH 5/8] Update tests. --- node-schedule/node-schedule-tests.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node-schedule/node-schedule-tests.ts b/node-schedule/node-schedule-tests.ts index ca8ab60c7..bc4dbbd74 100644 --- a/node-schedule/node-schedule-tests.ts +++ b/node-schedule/node-schedule-tests.ts @@ -58,16 +58,16 @@ function testInvocation() { */ function testScheduleJob() { var callback: Function = null; - new nodeSchedule.scheduleJob('', callback); + nodeSchedule.scheduleJob('', callback); var rule: nodeSchedule.RecurrenceRule = {}; - new nodeSchedule.scheduleJob(rule, callback); + nodeSchedule.scheduleJob(rule, callback); var date: Date = new Date(); - new nodeSchedule.scheduleJob(date, callback); + nodeSchedule.scheduleJob(date, callback); var date: Date = new Date(); - new nodeSchedule.scheduleJob(date, callback); + nodeSchedule.scheduleJob(date, callback); } /** From c2f9c4c3690b265c9b33519e2c75717c475538b4 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Fri, 14 Aug 2015 19:58:56 +0200 Subject: [PATCH 6/8] Update "node-schedule" definition. --- node-schedule/node-schedule.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node-schedule/node-schedule.d.ts b/node-schedule/node-schedule.d.ts index ca1dcd094..e1ff005df 100644 --- a/node-schedule/node-schedule.d.ts +++ b/node-schedule/node-schedule.d.ts @@ -195,5 +195,5 @@ declare module "node-schedule" { * @param {RecurrenceRule} rule The rule. * @param {Function} callback The callback. */ - export function scheduleJob(rule: RecurrenceRule|Date|string, callback: Function); + export function scheduleJob(rule: RecurrenceRule|Date|string, callback: Function): void; } From 15d55818e52a8788ff74a8bd13433571e6668d78 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Sat, 15 Aug 2015 15:25:14 +0200 Subject: [PATCH 7/8] Add the method "head". --- express/express.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/express/express.d.ts b/express/express.d.ts index 97b4ef2b8..42b0f6267 100644 --- a/express/express.d.ts +++ b/express/express.d.ts @@ -40,6 +40,7 @@ declare module "express" { delete(...handler: RequestHandler[]): IRoute; patch(...handler: RequestHandler[]): IRoute; options(...handler: RequestHandler[]): IRoute; + head(...handler: RequestHandler[]): IRoute; } interface IRouterMatcher { From c4759462f7d5aaa30d7712c692b2a59d7845e057 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Sat, 15 Aug 2015 15:46:12 +0200 Subject: [PATCH 8/8] Update definition: express. --- express/express.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/express/express.d.ts b/express/express.d.ts index 42b0f6267..b54f6e2fb 100644 --- a/express/express.d.ts +++ b/express/express.d.ts @@ -98,6 +98,7 @@ declare module "express" { delete: IRouterMatcher; patch: IRouterMatcher; options: IRouterMatcher; + head: IRouterMatcher; route(path: string): IRoute;