diff --git a/types/sticky-cluster/index.d.ts b/types/sticky-cluster/index.d.ts new file mode 100644 index 0000000000..7d51cad34f --- /dev/null +++ b/types/sticky-cluster/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for sticky-cluster 0.3 +// Project: https://github.com/uqee/sticky-cluster +// Definitions by: Austin Turner +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// +import * as http from 'http'; + +declare namespace stickyCluster { + type InitializeFn = (callback: Callback) => void; + type Callback = (server: http.Server) => void; + interface Options { + concurrency?: number; + port?: number; + debug?: boolean; + prefix?: string; + env?: (index: number) => { stickycluster_worker_index: number }; + hardShutdownDelay?: number; + errorHandler?: (err: any) => void; + } +} + +declare function stickyCluster(callback: stickyCluster.InitializeFn, options?: stickyCluster.Options): void; +export = stickyCluster; diff --git a/types/sticky-cluster/sticky-cluster-tests.ts b/types/sticky-cluster/sticky-cluster-tests.ts new file mode 100644 index 0000000000..e730275d78 --- /dev/null +++ b/types/sticky-cluster/sticky-cluster-tests.ts @@ -0,0 +1,34 @@ +import stickyCluster = require('sticky-cluster'); +import * as express from 'express'; +import * as http from 'http'; + +/** test with all params */ +stickyCluster( + (callback) => { + const app = express(); + const server = http.createServer(app); + + // don't do server.listen(), just pass the server instance into the callback + callback(server); + }, + { + prefix: 'sticky-cluster:', + concurrency: 10, + port: 3000, + debug: true, + hardShutdownDelay: 60 * 1000, + env: (index) => ({ stickycluster_worker_index: index }), + errorHandler: (err) => { console.log(err); process.exit(1); } + } +); + +/** test with no params */ +stickyCluster( + (callback) => { + const app = express(); + const server = http.createServer(app); + + // don't do server.listen(), just pass the server instance into the callback + callback(server); + } +); diff --git a/types/sticky-cluster/tsconfig.json b/types/sticky-cluster/tsconfig.json new file mode 100644 index 0000000000..dcfc338f93 --- /dev/null +++ b/types/sticky-cluster/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "sticky-cluster-tests.ts" + ] +} diff --git a/types/sticky-cluster/tslint.json b/types/sticky-cluster/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/sticky-cluster/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }