diff --git a/express-rate-limit/express-rate-limit-tests.ts b/express-rate-limit/express-rate-limit-tests.ts new file mode 100644 index 0000000000..761a6d23f8 --- /dev/null +++ b/express-rate-limit/express-rate-limit-tests.ts @@ -0,0 +1,25 @@ +import RateLimit = require("express-rate-limit"); + +var apiLimiter = new RateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 100, + delayMs: 0 // disabled +}); + +var createAccountLimiter = new RateLimit({ + windowMs: 60 * 60 * 1000, // 1 hour window + delayAfter: 1, // begin slowing down responses after the first request + delayMs: 3 * 1000, // slow down subsequent responses by 3 seconds per request + max: 5, // start blocking after 5 requests + message: "Too many accounts created from this IP, please try again after an hour" +}); + +class SomeStore implements RateLimit.Store { + incr(key: string, cb: RateLimit.StoreIncrementCallback) { } + resetAll() { } + resetKey(key: string) { }; +}; + +var limiterWithStore = new RateLimit({ + store: new SomeStore() +}); diff --git a/express-rate-limit/index.d.ts b/express-rate-limit/index.d.ts new file mode 100644 index 0000000000..38ef8f8b29 --- /dev/null +++ b/express-rate-limit/index.d.ts @@ -0,0 +1,37 @@ +// Type definitions for express-rate-limit 2.6 +// Project: https://github.com/nfriedly/express-rate-limit +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import express = require("express"); + +declare namespace RateLimit { + type StoreIncrementCallback = (err?: {}, hits?: number) => void; + + export interface Store { + incr: (key: string, cb: StoreIncrementCallback) => void; + resetAll: () => void; + resetKey: (key: string) => void; + } + + export interface Options { + delayAfter?: number; + delayMs?: number; + handlers?: () => any; + headers?: boolean; + keyGenerator?: () => string; + max?: number; + message?: string; + skip?: () => boolean; + statusCode?: number; + store?: Store; + windowMs?: number; + } +} + +interface RateLimitStatic { + new(options: RateLimit.Options): express.RequestHandler; +} + +declare var RateLimit: RateLimitStatic; +export = RateLimit; diff --git a/express-rate-limit/tsconfig.json b/express-rate-limit/tsconfig.json new file mode 100644 index 0000000000..ca3c32c3bb --- /dev/null +++ b/express-rate-limit/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "express-rate-limit-tests.ts" + ] +} diff --git a/express-rate-limit/tslint.json b/express-rate-limit/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/express-rate-limit/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/shipit-utils/index.d.ts b/shipit-utils/index.d.ts new file mode 100644 index 0000000000..aec379f5f2 --- /dev/null +++ b/shipit-utils/index.d.ts @@ -0,0 +1,15 @@ +// Type definitions for shipit-utils 1.4 +// Project: https://github.com/shipitjs/shipit-utils +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import shipit = require("shipit"); + +type GruntOrShipit = typeof shipit | {}; +type EmptyCallback = () => void; + +export function equalValues(value: any[]): void; +export function getShipit(gruntOrShipit: GruntOrShipit): typeof shipit; +export function getShipit(gruntOrShipit: GruntOrShipit): typeof shipit; +export function registerTask(gruntOrShipit: GruntOrShipit, name: string, dependenciesOrTask: string[] | EmptyCallback): typeof shipit; +export function runTask(gruntOrShipit: {}): void; diff --git a/shipit-utils/shipit-utils-tests.ts b/shipit-utils/shipit-utils-tests.ts new file mode 100644 index 0000000000..81cb741054 --- /dev/null +++ b/shipit-utils/shipit-utils-tests.ts @@ -0,0 +1,11 @@ +import shipit = require("shipit"); +import utils = require("shipit-utils"); + +var originalShipit = utils.getShipit(shipit); + +var task = () => { + return shipit.local("sleep 10s"); +}; + +utils.registerTask(originalShipit, "myTask", task); +utils.registerTask(originalShipit, "myTask", ["some", "other", "tasks"]); diff --git a/shipit-utils/tsconfig.json b/shipit-utils/tsconfig.json new file mode 100644 index 0000000000..d2fdb45d17 --- /dev/null +++ b/shipit-utils/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "shipit-utils-tests.ts" + ] +} diff --git a/shipit-utils/tslint.json b/shipit-utils/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/shipit-utils/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/shipit/index.d.ts b/shipit/index.d.ts new file mode 100644 index 0000000000..8c614f1627 --- /dev/null +++ b/shipit/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for shipit-cli 1.5 +// Project: https://github.com/shipitjs/shipit +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as fs from "fs"; +import * as child_process from "child_process"; + +declare namespace shipit { + type LocalOrRemoteCommand = (command: string, options?: child_process.ExecOptions, callback?: (error: Error, stdout: string, stderr: string) => void) => PromiseLike; + type EmptyCallback = () => void; + type TaskExecution = (name: string, depsOrFn: string[] | EmptyCallback, fn: () => void) => any; + + interface Options { + environment: string; + stderr: fs.WriteStream; + stdout: fs.WriteStream; + } + + interface ShipitLocal { + child: child_process.ChildProcess; + stderr: fs.WriteStream; + stdout: fs.WriteStream; + } + + interface Tasks { + [name: string]: Task; + } + + interface Task { + blocking: boolean; + dep: string[]; + fn: () => void; + name: string; + } + + export function blTask(name: string, depsOrFn: string[] | EmptyCallback, fn?: () => void): any; + export function emit(name: string): any; + export function initConfig(config: {}): typeof shipit; + export function local(command: string, options?: child_process.ExecOptions, callback?: (error: Error, stdout: string, stderr: string) => void): PromiseLike; + export function log(log: any): void; + export function log(...log: any[]): void; + export function on(name: string, callback: (e: any) => void): any; + export function remote(command: string, options?: child_process.ExecOptions, callback?: (error: Error, stdout: string, stderr: string) => void): PromiseLike; + export function remoteCopy(src: string, dest: string, options?: child_process.ExecOptions, callback?: (error: Error, stdout: string, stderr: string) => void): PromiseLike; + export function start(tasks: string | string[]): typeof shipit; + export function start(...tasks: string[]): typeof shipit; + export function task(name: string, depsOrFn: string[] | EmptyCallback, fn?: () => void): typeof shipit; + + export var config: {}; + export var domain: any; + export var doneCallback: any; + export var environment: string; + export var seq: any[]; + export var tasks: Tasks; + export var isRunning: boolean; +} + +//tslint:disable-next-line:export-just-namespace +export = shipit; +export as namespace shipit; diff --git a/shipit/shipit-tests.ts b/shipit/shipit-tests.ts new file mode 100644 index 0000000000..a256f87e07 --- /dev/null +++ b/shipit/shipit-tests.ts @@ -0,0 +1,50 @@ +import shipit = require("shipit"); + +shipit.initConfig({ + default: { + workspace: "/tmp/github-monitor", + deployTo: "/tmp/deploy_to", + repositoryUrl: "https://github.com/user/repo.git", + ignores: [".git", "node_modules"], + rsync: ["--del"], + keepReleases: 2, + key: "/path/to/key", + shallowClone: true + }, + staging: { + servers: "user@myserver.com" + } +}); + +shipit.task("build", () => { + shipit.emit("built"); +}); + +shipit.on("built", () => { + shipit.start("start-server"); +}); + +shipit.task("pwd", () => { + return shipit.remote("pwd"); +}); + +shipit.blTask("pwd", () => { + return shipit.remote("pwd"); +}); + +shipit.start("task"); +shipit.start("task1", "task2"); +shipit.start(["task1", "task2"]); + +shipit.local("ls -lah", {cwd: "/tmp/deploy/workspace"}).then((res: any) => { + console.log(res.stdout); + console.log(res.stderr); +}); + +shipit.remote("ls -lah").then((res: any) => { + console.log(res[0].stdout); + console.log(res[0].stderr); +}); + +shipit.remoteCopy("/tmp/workspace", "/opt/web/myapp").then(() => {}); +shipit.log("hello %s", "world"); diff --git a/shipit/tsconfig.json b/shipit/tsconfig.json new file mode 100644 index 0000000000..17049e7271 --- /dev/null +++ b/shipit/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "shipit-tests.ts" + ] +} diff --git a/shipit/tslint.json b/shipit/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/shipit/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }