diff --git a/README.md b/README.md index 290617c..170f028 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,18 @@ request.get('/images/json', function(err, stream) { }) ``` +### TypeScript + +Change `var` to `import` in order to tell typescript to use the declarations like so: + +``` ts +import docker = require('docker-remote-api') +var request = docker({ + host: '/var/run/docker.sock' +}) +``` + + ## API #### `request = docker(options)` diff --git a/package.json b/package.json index b00cd56..74470c5 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "description": "Basic http wrapper to call the docker remote api from node", "version": "5.0.0", "main": "index.js", + "types": "types.d.ts", "dependencies": { "concat-stream": "^1.4.6", "docker-host": "^3.0.0", diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 0000000..8d9264c --- /dev/null +++ b/types.d.ts @@ -0,0 +1,30 @@ +declare module 'docker-remote-api' { + interface InitOptions { + host: string; + } + + interface GetOptions { + qs?: { [name: string]: string }; // set querystring parameters + headers?: { [name: string]: string }; // set request headers + json?: boolean; // return json instead of a stream + buffer?: boolean; // return a buffer instead of a stream + drain?: boolean; // will drain the response stream before calling cb + timeout?: number; // set request timeout + version: string; // set explicit api version "v1.14" (required) + } + + interface PostOptions extends GetOptions { + body: string | null; // set to NULL if there is no body json + } + + class DockerRequest { + get(path: string, opt: GetOptions, fn: (err: Error, data: T) => void): void; + delete(path: string, opt: GetOptions, fn: (err: Error, data: T) => void): void; + head(path: string, opt: GetOptions, fn: (err: Error, data: T) => void): void; + post(path: string, opt: PostOptions, fn: (err: Error, data: T) => void): void; + put(path: string, opt: PostOptions, fn: (err: Error, data: T) => void): void; + } + + function DockerInit(opt: InitOptions): DockerRequest; + export = DockerInit; +}