diff --git a/README.md b/README.md index f4213b5..e83d111 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,10 @@ This project is still in active development. This project will be versioned in a ## Examples ### Unix Socket Example -```javascript -const docker = require('../index'); +```typescript +import { DockerClient } from "../index"; -const client = docker.Client({ +const client = new DockerClient({ socket: '/var/run/docker.sock' }); @@ -44,10 +44,10 @@ client.info().then((info) => { ``` ### Remote Host Example -```javascript -const docker = require('../index'); +```typescript +import { DockerClient } from "../index"; -const client = docker.Client({ +const client = new DockerClient({ host: 'swarm.example.com', port: '2375' }); @@ -61,9 +61,9 @@ client.info().then((info) => { ### SSL Configuration ```javascript -const docker = require('../index'); +import { DockerClient } from "../index"; -const client = docker.Client({ +const client = new DockerClient({ host: 'swarm.example.com', port: '2376', tls: { @@ -83,7 +83,7 @@ client.info().then((info) => { ## API Documentation -#### `docker.Client(options)` - Harbor Master Client +#### `new DockerClient(options)` - Harbor Master Client - `options` + `host` - the IP address or Hostname of the Docker server + `port` - the port number the Docker server exposes @@ -97,27 +97,27 @@ client.info().then((info) => { ### Configs -#### `client.configs().list(options)` - List Configs +#### `new ConfigClient().list(options)` - List Configs - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ConfigList) - `options` + `filters` - `map[string][]string` to process on the configs list -#### `client.configs().create(model, options)` - Create Config +#### `new ConfigClient().create(model, options)` - Create Config - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ConfigCreate) - `model` - the JSON model that the Docker API consumes - `options` -#### `client.configs().inspect(id, options)` - Inspect Config +#### `new ConfigClient().inspect(id, options)` - Inspect Config - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ConfigInspect) - `id` - the id or name of the config - `options` -#### `client.configs().remove(id, options)` - Remove Config +#### `new ConfigClient().remove(id, options)` - Remove Config - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ConfigDelete) - `name` - the id of the config - `options` -#### `client.configs().update(id, model, options)` - Update Config +#### `new ConfigClient().update(id, model, options)` - Update Config - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ConfigUpdate) - `id` - the id or name of the config - `model` - the JSON model that the Docker API consumes @@ -126,7 +126,7 @@ client.info().then((info) => { ### Containers -#### `client.containers().list(options)` - List Containers +#### `new ContainersClient().list(options)` - List Containers - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerList) - `options` + `all` - *default: `false`* Show all containers. Only running containers are shown by default. @@ -136,25 +136,25 @@ client.info().then((info) => { + `size` - *default: `false`* Show the containers sizes + `filters` - `map[string][]string` to process on the containers list -#### `client.containers().create(model, options)` - Create Container +#### `new ContainersClient().create(model, options)` - Create Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerCreate) - `model` - the JSON model that the Docker API consumes - `options` + `name` - Assign the specified name to the container. Must match `/?[a-zA-Z0-9_-]+`. -#### `client.containers().inspect(name, options)` - Inspect Container +#### `new ContainersClient().inspect(name, options)` - Inspect Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerInspect) - `name` - the name or id of the container - `options` + `size` - *default: `false`* Show the containers sizes -#### `client.containers().top(name)` - List Processes Running Inside a Container +#### `new ContainersClient().top(name)` - List Processes Running Inside a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerTop) - `name` - the name or id of the container - `options` + `ps_args` - `ps` arguments to use (e.g., aux), defaults to `-ef` -#### `client.containers().logs(name, options)` - Container Logs +#### `new ContainersClient().logs(name, options)` - Container Logs - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerLogs) - `name` - the name or id of the container - `options` @@ -166,76 +166,76 @@ client.info().then((info) => { + `timestamps` - print timestamps for every log line *default: `false`* + `tail` - Output specified number of lines at the end of logs: all or *default: `all`* -#### `client.containers().changes(name, options)` - Inspect Container Filesystem Changes +#### `new ContainersClient().changes(name, options)` - Inspect Container Filesystem Changes - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerChanges) - `name` - the name or id of the container - `options` -#### `client.containers().export(name, options)` - Export a Container +#### `new ContainersClient().export(name, options)` - Export a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerExport) - `name` - the name or id of the container - `options` -#### `client.containers().stats(name, options)` - Export a Container +#### `new ContainersClient().stats(name, options)` - Export a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerStats) - `name` - the name or id of the container - `options` + `stream` - stream statistics *default: `true`* -#### `client.containers().resize(name, options)` - Resize a container TTY +#### `new ContainersClient().resize(name, options)` - Resize a container TTY - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerResize) - `name` - the name or id of the container - `options` + `h` - height + `w` - width -#### `client.containers().start(name, options)` - Start a Container +#### `new ContainersClient().start(name, options)` - Start a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerStart) - `name` - the name or id of the container - `options` + `detachKeys` - Override the key sequence for detaching a container. Format is a single character. -#### `client.containers().stop(name, options)` - Stop a Container +#### `new ContainersClient().stop(name, options)` - Stop a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerStop) - `name` - the name or id of the container - `options` + `t` - number of seconds to wait before killing the container -#### `client.containers().restart(name, options)` - Restart a Container +#### `new ContainersClient().restart(name, options)` - Restart a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerRestart) - `name` - the name or id of the container - `options` + `t` - number of seconds to wait before killing the container -#### `client.containers().kill(name, options)` - Kill a Container +#### `new ContainersClient().kill(name, options)` - Kill a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerKill) - `name` - the name or id of the container - `options` + `signal` - Signal to send to the container: integer or string like SIGINT. When not set, SIGKILL is assumed and the call waits for the container to exit. -#### `client.containers().update(name, model, options)` - Update a Container +#### `new ContainersClient().update(name, model, options)` - Update a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerUpdate) - `name` - the name or id of the container - `model` - the JSON model that the Docker API consumes - `options` -#### `client.containers().rename(name, options)` - Rename a Container +#### `new ContainersClient().rename(name, options)` - Rename a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerRename) - `name` - the name or id of the container - `options` + `name` - new name for the container -#### `client.containers().pause(name)` - Pause a Container +#### `new ContainersClient().pause(name)` - Pause a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerPause) - `name` - the name or id of the container - `options` -#### `client.containers().unpause(name)` - Unpause a Container +#### `new ContainersClient().unpause(name)` - Unpause a Container - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/unpause-a-container) - `name` - the name or id of the container - `options` -#### `client.containers().attach(name, options)` - Attach a Container +#### `new ContainersClient().attach(name, options)` - Attach a Container - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/attach-to-a-container) - `name` - the name or id of the container - `options` @@ -246,12 +246,12 @@ client.info().then((info) => { + `stdout` - return stdout *default: `false`* + `stderr` - return stderr *default: `false`* -#### `client.containers().unpause(name, options)` - Wait a Container +#### `new ContainersClient().unpause(name, options)` - Wait a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerPause) - `name` - the name or id of the container - `options` -#### `client.containers().remove(name, options)` - Wait a Container +#### `new ContainersClient().remove(name, options)` - Wait a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ContainerDelete) - `name` - the name or id of the container - `options` @@ -260,12 +260,12 @@ client.info().then((info) => { ### Images -#### `client.images().list(options)` - Wait a Container +#### `new ImagesClient().list(options)` - Wait a Container - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImageList) - `options` + `filters` - `map[string][]string` to process on the images list -#### `client.images().build(stream, options, registryAuth)` - Build an Image From a Dockerfile +#### `new ImagesClient().build(stream, options, registryAuth)` - Build an Image From a Dockerfile - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImageBuild) - `options` + @@ -274,7 +274,7 @@ client.info().then((info) => { + `password` + `serveraddress` -#### `client.images().create(options, registryAuth)` - Create Image +#### `new ImagesClient().create(options, registryAuth)` - Create Image - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImageCreate) - `options` + `fromImage` @@ -287,17 +287,17 @@ client.info().then((info) => { + `password` + `serveraddress` -#### `client.images().inspect(name, options)` - Inspect an Image +#### `new ImagesClient().inspect(name, options)` - Inspect an Image - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImageInspect) - `name` - the name or id of the image - `options` -#### `client.images().history(name, options)` - History of an Image +#### `new ImagesClient().history(name, options)` - History of an Image - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImageHistory) - `name` - the name or id of the image - `options` -#### `client.images().push(name, options, registryAuth)` - Push an Image on the Registry +#### `new ImagesClient().push(name, options, registryAuth)` - Push an Image on the Registry - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImagePush) - `name` - the name or id of the image - `options` @@ -307,21 +307,21 @@ client.info().then((info) => { + `password` + `serveraddress` -#### `client.images().tag(name, options)` - Tag an Image +#### `new ImagesClient().tag(name, options)` - Tag an Image - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImageTag) - `name` - the name or id of the image - `options` + `repo` + `tag` -#### `client.images().remove(name, options)` - Remove of Image +#### `new ImagesClient().remove(name, options)` - Remove of Image - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImageDelete) - `name` - the name or id of the image - `options` + `repo` + `tag` -#### `client.images().search(options)` - Search Images +#### `new ImagesClient().search(options)` - Search Images - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ImageSearch) - `name` - the name or id of the image - `options` @@ -331,55 +331,55 @@ client.info().then((info) => { ### Networks -#### `client.networks().list(options)` - List Networks +#### `new NetworksClient().list(options)` - List Networks - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NetworkList) - `options` + `filters` - JSON encoded network list filter. -#### `client.networks().create(model, options)` - Create a Network +#### `new NetworksClient().create(model, options)` - Create a Network - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NetworkCreate) - `model` - a json model representing the network - `options` -#### `client.networks().inspect(id, options)` - Inspect a Network +#### `new NetworksClient().inspect(id, options)` - Inspect a Network - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NetworkInspect) - `id` - the network id or name - `options` -#### `client.networks().remove(id, options)` - Remove a Network +#### `new NetworksClient().remove(id, options)` - Remove a Network - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NetworkDelete) - `id` - the network id or name - `options` -#### `client.networks().connect(id, options)` - Connect a Container to a Network +#### `new NetworksClient().connect(id, options)` - Connect a Container to a Network - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NetworkConnect) - `id` - the network id or name - `options` -#### `client.networks().disconnect(id, options)` - Disconnect a Container to a Network +#### `new NetworksClient().disconnect(id, options)` - Disconnect a Container to a Network - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NetworkDisconnect) - `id` - the network id or name - `options` ### Nodes -#### `client.nodes().list(options)` - List Nodes +#### `new NodesClient().list(options)` - List Nodes - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NetworkDisconnect) - `id` - the node id - `options` + `filters` - JSON encoded node list filter. -#### `client.nodes().inspect(id, options)` - Inspect a Node +#### `new NodesClient().inspect(id, options)` - Inspect a Node - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NodeInspect) - `id` - the node id - `options` -#### `client.nodes().remove(id, options)` - Remove a Node +#### `new NodesClient().remove(id, options)` - Remove a Node - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NodeDelete) - `id` - the node id - `options` -#### `client.nodes().update(id, options)` - Update A Node +#### `new NodesClient().update(id, options)` - Update A Node - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/NodeUpdate) - `id` - the node id - `options` @@ -387,54 +387,83 @@ client.info().then((info) => { ### Plugins -#### `client.plugins().list(options)` - List Plugins +#### `new PluginsClient().list(options)` - List Plugins - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#list-plugins) - `options` + `filters` - a JSON encoded value of the filters (a map[string][]string) to process on the services list. -#### `client.plugins().install(options)` - Install a Plugin +#### `new PluginsClient().install(options)` - Install a Plugin - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#install-a-plugin) - `options` + `name` - Name of the plugin to pull. The name may include a tag or digest. This parameter is required. -#### `client.plugins().inspect(id, options)` - Inspect a Plugin +#### `new PluginsClient().inspect(id, options)` - Inspect a Plugin - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#inspect-a-plugin) - `options` -#### `client.plugins().enable(id, options)` - Enable a Plugin +#### `new PluginsClient().enable(id, options)` - Enable a Plugin - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#enable-a-plugin) - `options` -#### `client.plugins().disable(id, options)` - Disable a Plugin +#### `new PluginsClient().disable(id, options)` - Disable a Plugin - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#disable-a-plugin) - `options` -#### `client.plugins().remove(id, options)` - Remove a Plugin +#### `new PluginsClient().remove(id, options)` - Remove a Plugin - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#remove-a-plugin) - `options` +### Secrets + +#### `new SecretsClient().list(options)` - List Secret +- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretList) +- `options` + + `filters` - `map[string][]string` to process on the secrets list + +#### `new SecretsClient().create(model, options)` - Create Secret +- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretCreate) +- `model` - the JSON model that the Docker API consumes +- `options` + +#### `new SecretsClient().inspect(id, options)` - Inspect Secret +- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretInspect) +- `id` - the id or name of the secret +- `options` + +#### `new SecretsClient().remove(id, options)` - Remove Secret +- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretDelete) +- `name` - the id of the secret +- `options` + +#### `new SecretsClient().update(id, model, options)` - Update Secret +- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretUpdate) +- `id` - the id or name of the secret +- `model` - the JSON model that the Docker API consumes +- `options` + + `version` - The version number of the secret object being updated. This is required to avoid conflicting writes. + ### Services -#### `client.services().list(options)` - List Services +#### `new ServicesClient().list(options)` - List Services - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/list-services) - `options` + `filters` - a JSON encoded value of the filters (a map[string][]string) to process on the services list. -#### `client.services().create(options, registryAuth)` - Create a Service +#### `new ServicesClient().create(options, registryAuth)` - Create a Service - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/create-a-service) - `options` -#### `client.services().remove(id, options)` - Remove a Service +#### `new ServicesClient().remove(id, options)` - Remove a Service - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/remove-a-service) - `id` - id or name of the service - `options` -#### `client.services().inspect(id, options)` - Inspect a Service +#### `new ServicesClient().inspect(id, options)` - Inspect a Service - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/inspect-one-or-more-services) - `id` - id or name of the service - `options` -#### `client.services().logs(id, options)` - Get Service Logs +#### `new ServicesClient().logs(id, options)` - Get Service Logs - [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/ServiceLogs) - `id` - id or name of the service - `options` @@ -446,7 +475,7 @@ client.info().then((info) => { + `timestamps` - boolean, Add timestamps to every log line + `tail` - Only return this number of log lines from the end of the logs. Specify as an integer or all to output all log lines. -#### `client.services().update(id, options, registryAuth)` - Update a Service +#### `new ServicesClient().update(id, options, registryAuth)` - Update a Service - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/update-a-service) - `id` - id or name of the service - `options` @@ -455,24 +484,24 @@ client.info().then((info) => { ### Swarm -#### `client.swarm().info(options)` - Swarm Info +#### `new SwarmClient().info(options)` - Swarm Info - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/swarm) - `options` -#### `client.swarm().init(options)` - Initialize a Swarm +#### `new SwarmClient().init(options)` - Initialize a Swarm - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/initialize-a-new-swarm) - `options` -#### `client.swarm().join(options)` - Join a Swarm +#### `new SwarmClient().join(options)` - Join a Swarm - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/join-an-existing-swarm) - `options` -#### `client.swarm().leave(options)` - Leave a Swarm +#### `new SwarmClient().leave(options)` - Leave a Swarm - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/join-an-existing-swarm) - `options` + `force` - Boolean (false/true). Force leave swarm, even if this is the last manager or that it will break the cluster. -#### `client.swarm().update(options)` - Update a Swarm +#### `new SwarmClient().update(options)` - Update a Swarm - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/update-a-swarm) - `options` + `version` - The version number of the swarm object being updated. This is required to avoid conflicting writes. @@ -481,85 +510,56 @@ client.info().then((info) => { ### Tasks -#### `client.tasks().list(options)` - List Services +#### `new TasksClient().list(options)` - List Services - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/list-tasks) - `options` + `filters` - a JSON encoded value of the filters (a map[string][]string) to process on the tasks list. -#### `client.tasks().inspect(id, options)` - Inspect a Task +#### `new TasksClient().inspect(id, options)` - Inspect a Task - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/inspect-one-or-more-services) - `options` ### Volumes -#### `client.volumes().list(options)` - List Volumes +#### `new VolumesClient().list(options)` - List Volumes - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/list-volumes) - `options` + `filters` - a JSON encoded value of the filters (a map[string][]string) to process on the volumes list. -#### `client.volumes().create(options, registryAuth)` - Create a Volume +#### `new VolumesClient().create(options, registryAuth)` - Create a Volume - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#create-a-volume) - `id` or name of the volume - `options` -#### `client.volumes().remove(id, options)` - Remove a Volume +#### `new VolumesClient().remove(id, options)` - Remove a Volume - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#remove-a-volume) - `id` or name of the volume - `options` -#### `client.volumes().inspect(id, options)` - Inspect a Volume +#### `new VolumesClient().inspect(id, options)` - Inspect a Volume - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#inspect-a-volume) - `id` or name of the volume - `options` -### Secrets - -#### `client.secrets().list(options)` - List Secret -- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretList) -- `options` - + `filters` - `map[string][]string` to process on the secrets list - -#### `client.secrets().create(model, options)` - Create Secret -- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretCreate) -- `model` - the JSON model that the Docker API consumes -- `options` - -#### `client.secrets().inspect(id, options)` - Inspect Secret -- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretInspect) -- `id` - the id or name of the secret -- `options` - -#### `client.secrets().remove(id, options)` - Remove Secret -- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretDelete) -- `name` - the id of the secret -- `options` - -#### `client.secrets().update(id, model, options)` - Update Secret -- [Docker Documentation](https://docs.docker.com/engine/api/v1.32/#operation/SecretUpdate) -- `id` - the id or name of the secret -- `model` - the JSON model that the Docker API consumes -- `options` - + `version` - The version number of the secret object being updated. This is required to avoid conflicting writes. - ### Daemon -#### `client.info()` - System Wide Information +#### `new DockerClient.info()` - System Wide Information - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#display-system-wide-information) -#### `client.auth(options)` - Authentication Configuration +#### `new DockerClient.auth(options)` - Authentication Configuration - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#check-auth-configuration) - `options` + `username` + `password` + `serveraddress` -#### `client.version()` - Version +#### `new DockerClient.version()` - Version - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#show-the-docker-version-information) -#### `client.ping()` - Ping Daemon +#### `new DockerClient.ping()` - Ping Daemon - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#ping-the-docker-server) -#### `client.events()` - Events Stream +#### `new DockerClient.events()` - Events Stream - [Docker Documentation](https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#monitor-dockers-events) - `options` + `since` - Timestamp. Show all events created since timestamp and then stream diff --git a/examples/containers.js b/examples/containers.ts similarity index 64% rename from examples/containers.js rename to examples/containers.ts index 3ebc641..a27bdcf 100644 --- a/examples/containers.js +++ b/examples/containers.ts @@ -1,8 +1,6 @@ -'use strict'; +import { DockerClient } from "../lib/docker"; -const docker = require('../index'); - -const client = docker.Client({ +const client = new DockerClient({ socket: '/var/run/docker.sock' }); diff --git a/examples/events.js b/examples/events.ts similarity index 63% rename from examples/events.js rename to examples/events.ts index bc33246..59b456c 100644 --- a/examples/events.js +++ b/examples/events.ts @@ -1,8 +1,6 @@ -'use strict'; +import { DockerClient } from "../lib/docker"; -const docker = require('../index'); - -const client = docker.Client({ +const client = new DockerClient({ socket: '/var/run/docker.sock' }); diff --git a/examples/info.js b/examples/info.ts similarity index 75% rename from examples/info.js rename to examples/info.ts index 15c0386..8810ebd 100644 --- a/examples/info.js +++ b/examples/info.ts @@ -1,8 +1,6 @@ -'use strict'; +import { DockerClient } from "../lib/docker"; -const docker = require('../index'); - -const client = docker.Client({ +const client = new DockerClient({ socket: '/var/run/docker.sock' }); diff --git a/examples/logs.js b/examples/logs.ts similarity index 71% rename from examples/logs.js rename to examples/logs.ts index c0c263e..fdc5318 100644 --- a/examples/logs.js +++ b/examples/logs.ts @@ -1,8 +1,6 @@ -'use strict'; +import { DockerClient } from "../lib/docker"; -const docker = require('../index'); - -const client = docker.Client({ +const client = new DockerClient({ socket: '/var/run/docker.sock' }); diff --git a/examples/stats.js b/examples/stats.ts similarity index 73% rename from examples/stats.js rename to examples/stats.ts index 959623a..b1c09fd 100644 --- a/examples/stats.js +++ b/examples/stats.ts @@ -1,8 +1,6 @@ -'use strict'; +import { DockerClient } from "../lib/docker"; -const docker = require('../index'); - -const client = docker.Client({ +const client = new DockerClient({ socket: '/var/run/docker.sock' }); @@ -13,16 +11,16 @@ client.containers().stats('ping').then((emitter) => { //console.log(data); /* jshint ignore:start */ - if(data && data.memory_stats) { - const mem = (data.memory_stats.usage / Math.pow(1024, 2)) * (Math.pow(2, 20) / Math.pow(10, 6)).toFixed(2); + if (data && data.memory_stats) { + const mem = (data.memory_stats.usage / Math.pow(1024, 2)) * Number((Math.pow(2, 20) / Math.pow(10, 6)).toFixed(2)); const memUsage = ((data.memory_stats.usage / data.memory_stats.limit) * 100).toFixed(2); - let cpuPercent = (data.cpu_stats.cpu_usage.total_usage / data.cpu_stats.system_cpu_usage); + let cpuPercent: any = (data.cpu_stats.cpu_usage.total_usage / data.cpu_stats.system_cpu_usage); cpuPercent = cpuPercent * data.cpu_stats.cpu_usage.percpu_usage.length * 100; cpuPercent = cpuPercent.toFixed(2); - const networkIn = (data.networks.eth0.rx_bytes / 1024 / 1024).toFixed(3) - const networkOut = (data.networks.eth0.tx_bytes / 1024 / 1024).toFixed(3) + const networkIn = (data.networks.eth0.rx_bytes / 1024 / 1024).toFixed(3); + const networkOut = (data.networks.eth0.tx_bytes / 1024 / 1024).toFixed(3); console.log('Memory Usage:', mem + 'MB', memUsage + '%'); console.log('CPU Usage:', cpuPercent + '%'); diff --git a/examples/swarm-nodes.js b/examples/swarm-nodes.ts similarity index 85% rename from examples/swarm-nodes.js rename to examples/swarm-nodes.ts index 3020b14..d2fe343 100644 --- a/examples/swarm-nodes.js +++ b/examples/swarm-nodes.ts @@ -1,9 +1,7 @@ -'use strict'; +import { DockerClient } from "../lib/docker"; +import * as fs from "fs"; -const docker = require('../index'); -const fs = require('fs'); - -const client = docker.Client({ +const client = new DockerClient({ host: '192.168.99.100', port: '2376', tls: { diff --git a/index.js b/index.js deleted file mode 100644 index 0f353cf..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -module.exports = require('./lib/docker'); diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..121485d --- /dev/null +++ b/index.ts @@ -0,0 +1 @@ +export { DockerClient } from './lib/docker'; diff --git a/lib/docker.js b/lib/docker.ts similarity index 55% rename from lib/docker.js rename to lib/docker.ts index 2c8a32e..397aaf9 100644 --- a/lib/docker.js +++ b/lib/docker.ts @@ -1,25 +1,26 @@ -'use strict'; - -const Joi = require('joi'); -const Promise = require('bluebird'); -const modem = require('./modem'); -const schemas = require('./schemas/system'); -const configs = require('./endpoints/configs'); -const containers = require('./endpoints/containers'); -const images = require('./endpoints/images'); -const networks = require('./endpoints/networks'); -const nodes = require('./endpoints/nodes'); -const plugins = require('./endpoints/plugins'); -const services = require('./endpoints/services'); -const swarm = require('./endpoints/swarm'); -const secrets = require('./endpoints/secrets'); -const tasks = require('./endpoints/tasks'); -const volumes = require('./endpoints/volumes'); - -class DockerClient { +import * as Joi from 'joi'; +import * as Promise from 'bluebird'; +import * as schemas from './schemas/system'; +import Modem from "./modem"; +import ConfigClient from "./endpoints/configs"; +import ContainersClient from "./endpoints/containers"; +import ImagesClient from "./endpoints/images"; +import NetworksClient from "./endpoints/networks"; +import NodesClient from "./endpoints/nodes"; +import PluginsClient from "./endpoints/plugins"; +import ServicesClient from "./endpoints/services"; +import SwarmClient from "./endpoints/swarm"; +import SecretsClient from "./endpoints/secrets"; +import TasksClient from "./endpoints/tasks"; +import VolumesClient from "./endpoints/volumes"; + +export class DockerClient { + + private modem: Modem; + private _services: any; constructor(options) { - this.modem = modem.Client(options); + this.modem = new Modem(options); this._services = {}; } @@ -79,11 +80,9 @@ class DockerClient { }); } - events(options) { + events(options = {}) { const self = this; - options = options || {}; - return self._validate(options, schemas.events.options).then((params) => { return self.modem.stream({ method: 'GET', @@ -102,88 +101,88 @@ class DockerClient { } configs() { - if(!this._services.configs) { - this._services.configs = configs.Client(this); + if (!this._services.configs) { + this._services.configs = new ConfigClient(this); } return this._services.configs; } containers() { - if(!this._services.containers) { - this._services.containers = containers.Client(this); + if (!this._services.containers) { + this._services.containers = new ContainersClient(this); } return this._services.containers; } images() { - if(!this._services.images) { - this._services.images = images.Client(this); + if (!this._services.images) { + this._services.images = new ImagesClient(this); } return this._services.images; } swarm() { - if(!this._services.swarm) { - this._services.swarm = swarm.Client(this); + if (!this._services.swarm) { + this._services.swarm = new SwarmClient(this); } return this._services.swarm; } networks() { - if(!this._services.networks) { - this._services.networks = networks.Client(this); + if (!this._services.networks) { + this._services.networks = new NetworksClient(this); } return this._services.networks; } nodes() { - if(!this._services.nodes) { - this._services.nodes = nodes.Client(this); + if (!this._services.nodes) { + this._services.nodes = new NodesClient(this); } return this._services.nodes; } plugins() { - if(!this._services.plugins) { - this._services.plugins = plugins.Client(this); + if (!this._services.plugins) { + this._services.plugins = new PluginsClient(this); } return this._services.plugins; } secrets() { - if(!this._services.secrets) { - this._services.secrets = secrets.Client(this); + if (!this._services.secrets) { + this._services.secrets = new SecretsClient(this); } return this._services.secrets; } services() { - if(!this._services.services) { - this._services.services = services.Client(this); + if (!this._services.services) { + this._services.services = new ServicesClient(this); } return this._services.services; } tasks() { - if(!this._services.tasks) { - this._services.tasks = tasks.Client(this); + if (!this._services.tasks) { + this._services.tasks = new TasksClient(this); } return this._services.tasks; } volumes() { - if(!this._services.volumes) { - this._services.volumes = volumes.Client(this); + if (!this._services.volumes) { + this._services.volumes = new VolumesClient(this); } return this._services.volumes; @@ -194,7 +193,7 @@ class DockerClient { return new Promise((resolve, reject) => { Joi.validate(value, schema, {}, (err, value) => { - if(!err) { + if (!err) { resolve(value); } else { reject(err); @@ -206,7 +205,3 @@ class DockerClient { } } - -module.exports.Client = function(options) { - return new DockerClient(options); -}; diff --git a/lib/endpoints/configs.js b/lib/endpoints/configs.ts similarity index 91% rename from lib/endpoints/configs.js rename to lib/endpoints/configs.ts index 238ea0b..3c38862 100644 --- a/lib/endpoints/configs.js +++ b/lib/endpoints/configs.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/configs'; -const schemas = require('../schemas/configs'); +export default class ConfigClient { -class ConfigClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -112,7 +109,3 @@ class ConfigClient { } } - -module.exports.Client = function(docker) { - return new ConfigClient(docker); -}; diff --git a/lib/endpoints/containers.js b/lib/endpoints/containers.ts similarity index 95% rename from lib/endpoints/containers.js rename to lib/endpoints/containers.ts index 1c97c57..c693f7e 100644 --- a/lib/endpoints/containers.js +++ b/lib/endpoints/containers.ts @@ -1,12 +1,9 @@ -'use strict'; +import * as schemas from '../schemas/containers'; +import * as auth from '../helpers/auth'; -const schemas = require('../schemas/containers'); -const auth = require('../helpers/auth'); +export default class ContainersClient { -class ContainersClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -36,7 +33,7 @@ class ContainersClient { return self.docker._validate(options, schemas.create.options).then((params) => { - const requestOptions = { + const requestOptions: any = { url: '/containers/create', qs: params, body: model, @@ -52,7 +49,7 @@ class ContainersClient { } }; - if(auth) { + if (auth) { requestOptions.headers = { 'X-Registry-Auth': auth.generate(auth) }; @@ -109,7 +106,7 @@ class ContainersClient { return self.docker._validate(options, schemas.logs.options).then((params) => { - const req = { + const req: any = { url: `/containers/${id}/logs`, qs: params, successCodes: { @@ -122,7 +119,7 @@ class ContainersClient { } }; - if(params.follow) { + if (params.follow) { req.method = 'GET'; return self.docker.modem.stream(req); } else { @@ -156,7 +153,7 @@ class ContainersClient { options = options || {}; - return self.docker._validate(options, schemas.export.options).then((params) => { + return self.docker._validate(options, schemas._export.options).then((params) => { return self.docker.modem.download({ method: 'GET', url: `/containers/${id}/export`, @@ -198,7 +195,7 @@ class ContainersClient { options = options || {}; return self.docker._validate(options, schemas.stats.options).then((params) => { - const req = { + const req: any = { url: `/containers/${id}/stats`, qs: params, successCodes: { @@ -211,7 +208,7 @@ class ContainersClient { } }; - if(params.stream) { + if (params.stream) { req.method = 'GET'; return self.docker.modem.stream(req); } else { @@ -307,7 +304,7 @@ class ContainersClient { return self.docker._validate(options, schemas.update.options).then((params) => { - const requestOptions = { + const requestOptions: any = { url: `/containers/${id}/update`, qs: params, body: model, @@ -320,7 +317,7 @@ class ContainersClient { } }; - if(auth) { + if (auth) { requestOptions.headers = { 'X-Registry-Auth': auth.generate(auth) }; @@ -513,7 +510,3 @@ class ContainersClient { } } - -module.exports.Client = function(docker) { - return new ContainersClient(docker); -}; diff --git a/lib/endpoints/images.js b/lib/endpoints/images.ts similarity index 92% rename from lib/endpoints/images.js rename to lib/endpoints/images.ts index a88b939..6f917a0 100644 --- a/lib/endpoints/images.js +++ b/lib/endpoints/images.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/images'; -const schemas = require('../schemas/images'); +export default class ImagesClient { -class ImagesClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -209,7 +206,7 @@ class ImagesClient { options = options || {}; - return self.docker._validate(options, schemas.prune.option).then((params) => { + return self.docker._validate(options, schemas.prune.options).then((params) => { return self.docker.modem.post({ url: '/images/prune', qs: params, @@ -228,7 +225,7 @@ class ImagesClient { options = options || {}; - return self.docker._validate(options, schemas.commit.option).then((params) => { + return self.docker._validate(options, schemas.commit.options).then((params) => { return self.docker.modem.post({ url: '/commit', qs: params, @@ -248,7 +245,7 @@ class ImagesClient { options = options || {}; - return self.docker._validate(options, schemas.export.options).then((params) => { + return self.docker._validate(options, schemas._export.options).then((params) => { return self.docker.modem.download({ method: 'GET', url: `/images/${id}/export`, @@ -264,7 +261,3 @@ class ImagesClient { } } - -module.exports.Client = function(docker) { - return new ImagesClient(docker); -}; diff --git a/lib/endpoints/networks.js b/lib/endpoints/networks.ts similarity index 93% rename from lib/endpoints/networks.js rename to lib/endpoints/networks.ts index c4fe9aa..a8df3a5 100644 --- a/lib/endpoints/networks.js +++ b/lib/endpoints/networks.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/networks'; -const schemas = require('../schemas/networks'); +export default class NetworksClient { -class NetworksClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -136,7 +133,3 @@ class NetworksClient { } } - -module.exports.Client = function(docker) { - return new NetworksClient(docker); -}; diff --git a/lib/endpoints/nodes.js b/lib/endpoints/nodes.ts similarity index 90% rename from lib/endpoints/nodes.js rename to lib/endpoints/nodes.ts index 9d04880..9b38cea 100644 --- a/lib/endpoints/nodes.js +++ b/lib/endpoints/nodes.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/nodes'; -const schemas = require('../schemas/nodes'); +export default class NodesClient { -class NodesClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -98,7 +95,3 @@ class NodesClient { } } - -module.exports.Client = function(docker) { - return new NodesClient(docker); -}; diff --git a/lib/endpoints/plugins.js b/lib/endpoints/plugins.ts similarity index 92% rename from lib/endpoints/plugins.js rename to lib/endpoints/plugins.ts index b6cb7a7..51ac1e6 100644 --- a/lib/endpoints/plugins.js +++ b/lib/endpoints/plugins.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/plugins'; -const schemas = require('../schemas/plugins'); +export default class PluginsClient { -class PluginsClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -91,7 +88,7 @@ class PluginsClient { return self.docker._validate(options, schemas.upgrade.options).then((params) => { - const requestOptions = { + const requestOptions: any = { url: `/plugins/${name}/upgrade`, qs: params, successCodes: { @@ -102,7 +99,7 @@ class PluginsClient { } }; - if(auth) { + if (auth) { requestOptions.headers = { 'X-Registry-Auth': auth.generate(auth) }; @@ -152,7 +149,3 @@ class PluginsClient { } } - -module.exports.Client = function(docker) { - return new PluginsClient(docker); -}; diff --git a/lib/endpoints/secrets.js b/lib/endpoints/secrets.ts similarity index 91% rename from lib/endpoints/secrets.js rename to lib/endpoints/secrets.ts index e29d101..eec724f 100644 --- a/lib/endpoints/secrets.js +++ b/lib/endpoints/secrets.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/secrets'; -const schemas = require('../schemas/secrets'); +export default class SecretsClient { -class SecretsClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -112,7 +109,3 @@ class SecretsClient { } } - -module.exports.Client = function(docker) { - return new SecretsClient(docker); -}; diff --git a/lib/endpoints/services.js b/lib/endpoints/services.ts similarity index 92% rename from lib/endpoints/services.js rename to lib/endpoints/services.ts index 477164a..104d6e6 100644 --- a/lib/endpoints/services.js +++ b/lib/endpoints/services.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/services'; -const schemas = require('../schemas/services'); +export default class ServicesClient { -class ServicesClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -136,7 +133,3 @@ class ServicesClient { } } - -module.exports.Client = function(docker) { - return new ServicesClient(docker); -}; diff --git a/lib/endpoints/swarm.js b/lib/endpoints/swarm.ts similarity index 93% rename from lib/endpoints/swarm.js rename to lib/endpoints/swarm.ts index b5a273f..c39648b 100644 --- a/lib/endpoints/swarm.js +++ b/lib/endpoints/swarm.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/swarm'; -const schemas = require('../schemas/swarm'); +export default class SwarmClient { -class SwarmClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } inspect(options) { @@ -143,7 +140,3 @@ class SwarmClient { } } - -module.exports.Client = function(docker) { - return new SwarmClient(docker); -}; diff --git a/lib/endpoints/tasks.js b/lib/endpoints/tasks.ts similarity index 79% rename from lib/endpoints/tasks.js rename to lib/endpoints/tasks.ts index c30c59a..b367b3f 100644 --- a/lib/endpoints/tasks.js +++ b/lib/endpoints/tasks.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/tasks'; -const schemas = require('../schemas/tasks'); +export default class TasksClient { -class TasksClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -48,7 +45,3 @@ class TasksClient { } } - -module.exports.Client = function(docker) { - return new TasksClient(docker); -}; diff --git a/lib/endpoints/volumes.js b/lib/endpoints/volumes.ts similarity index 88% rename from lib/endpoints/volumes.js rename to lib/endpoints/volumes.ts index c0f2f3c..cb612b1 100644 --- a/lib/endpoints/volumes.js +++ b/lib/endpoints/volumes.ts @@ -1,11 +1,8 @@ -'use strict'; +import * as schemas from '../schemas/volumes'; -const schemas = require('../schemas/volumes'); +export default class VolumesClient { -class VolumesClient { - - constructor(docker) { - this.docker = docker; + constructor(private docker) { } list(options) { @@ -89,7 +86,3 @@ class VolumesClient { } } - -module.exports.Client = function(docker) { - return new VolumesClient(docker); -}; diff --git a/lib/helpers/auth.js b/lib/helpers/auth.ts similarity index 58% rename from lib/helpers/auth.js rename to lib/helpers/auth.ts index a419c07..7697af5 100644 --- a/lib/helpers/auth.js +++ b/lib/helpers/auth.ts @@ -1,16 +1,14 @@ -'use strict'; +import * as Joi from 'joi'; +import * as schemas from '../schemas/system'; -const Joi = require('joi'); -const schemas = require('../schemas/system'); - -module.exports.generate = function(options) { +export function generate(options) { const result = Joi.validate(options, schemas.auth); - if(result.error) { + if (result.error) { throw new Error('Invalid Registry Authentication Parameters'); } else { options = JSON.stringify(result.value); return new Buffer(options).toString('base64'); } -}; +} diff --git a/lib/modem.js b/lib/modem.ts similarity index 76% rename from lib/modem.js rename to lib/modem.ts index c8aca76..3677e67 100644 --- a/lib/modem.js +++ b/lib/modem.ts @@ -1,11 +1,11 @@ -'use strict'; +import { EventEmitter } from 'events'; +import * as Promise from 'bluebird'; +import * as request from 'request'; +import * as _ from 'lodash'; -const EventEmitter = require('events'); -const Promise = require('bluebird'); -const request = require('request'); -const _ = require('lodash'); +export default class Modem { -class Modem { + private opts: any; constructor(options) { @@ -44,22 +44,22 @@ class Modem { return this.http(options); } - stream(method, path, params, headers) { + stream(options, cb?) { return new Promise((resolve) => { const dest = new EventEmitter(); - const src = this._request(method, path, params, headers); + const src = this._request(options, cb); - src.on('data', function(chunk) { + src.on('data', function (chunk) { const payload = chunk.toString('utf-8').trim(); dest.emit('data', payload); }); - src.on('error', function(err) { + src.on('error', function (err) { dest.emit('error', err); }); - src.on('end', function(err) { + src.on('end', function (err) { dest.emit('end', err); }); @@ -93,42 +93,42 @@ class Modem { return new Promise((resolve, reject) => { self._request(options, (err, resp, body) => { - if(!err && _.hasIn(codes.successCodes, resp.statusCode)) { + if (!err && _.hasIn(codes.successCodes, resp.statusCode)) { - if(_.isString(body)) { + if (_.isString(body)) { try { body = JSON.parse(body); - } catch(exc) { + } catch (exc) { console.log('[harbor-master][modem] error parsing body as json'); } } resolve(body); } else { - reject({ error: err, response: resp, body: body }); + reject({error: err, response: resp, body: body}); } }); }); } - _request(options, cb) { + _request(options, cb?) { options.headers = options.headers || {}; options.url = this.url(options.url); - if(options.method !== 'GET') { + if (options.method !== 'GET') { options.json = true; } - if(this.isSecure()) { + if (this.isSecure()) { options.ca = this.opts.tls.ca; options.cert = this.opts.tls.cert; options.key = this.opts.tls.key; options.passphrase = this.opts.tls.passphrase; } - if(this.isSocket()) { + if (this.isSocket()) { options.headers.host = 'http'; } @@ -139,7 +139,7 @@ class Modem { const protocol = this.opts.tls.cert !== null ? 'https' : 'http'; let url = protocol + '://'; - if(this.isSocket()) { + if (this.isSocket()) { url = url + 'unix:' + this.opts.socket + ':'; } else { url = url + this.opts.host + ':' + this.opts.port; @@ -159,7 +159,3 @@ class Modem { } } - -module.exports.Client = function(options) { - return new Modem(options); -}; diff --git a/lib/schemas/secrets.js b/lib/schemas/configs.ts similarity index 55% rename from lib/schemas/secrets.js rename to lib/schemas/configs.ts index 781e266..3b853e3 100644 --- a/lib/schemas/secrets.js +++ b/lib/schemas/configs.ts @@ -1,27 +1,25 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object().keys({ filters: Joi.object() }) }; -module.exports.create = { +export const create = { options: Joi.object() }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; -module.exports.update = { +export const update = { options: Joi.object().keys({ version: Joi.string() }) }; -module.exports.remove = { +export const remove = { options: Joi.object() }; diff --git a/lib/schemas/containers.js b/lib/schemas/containers.ts similarity index 77% rename from lib/schemas/containers.js rename to lib/schemas/containers.ts index 63b8996..f1555d7 100644 --- a/lib/schemas/containers.js +++ b/lib/schemas/containers.ts @@ -1,8 +1,6 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object().keys({ all: Joi.boolean().default(false), limit: Joi.number(), @@ -13,19 +11,19 @@ module.exports.list = { }) }; -module.exports.create = { +export const create = { options: Joi.object().keys({ name: Joi.string() }) }; -module.exports.inspect = { +export const inspect = { options: Joi.object().keys({ size: Joi.boolean().default(false) }) }; -module.exports.top = { +export const top = { options: Joi.object().keys({ /* jshint ignore:start */ ps_args: Joi.string().default('-ef') @@ -33,7 +31,7 @@ module.exports.top = { }) }; -module.exports.logs = { +export const logs = { options: Joi.object().keys({ details: Joi.boolean().default(false), follow: Joi.boolean().default(false), @@ -45,70 +43,70 @@ module.exports.logs = { }) }; -module.exports.change = { +export const changes = { options: Joi.object() }; -module.exports.export = { +export const _export = { options: Joi.object() }; -module.exports.stats = { +export const stats = { options: Joi.object().keys({ stream: Joi.boolean().default(true) }) }; -module.exports.resize = { +export const resize = { options: Joi.object().keys({ h: Joi.number().required(), w: Joi.number().required() }) }; -module.exports.start = { +export const start = { options: Joi.object().keys({ detachKeys: Joi.string() }) }; -module.exports.stop = { +export const stop = { options: Joi.object().keys({ t: Joi.number().min(0) }) }; -module.exports.restart = { +export const restart = { options: Joi.object().keys({ t: Joi.number().min(0) }) }; -module.exports.kill = { +export const kill = { options: Joi.object().keys({ signal: Joi.string() }) }; -module.exports.update = { +export const upload = { options: Joi.object() }; -module.exports.rename = { +export const rename = { options: Joi.object().keys({ name: Joi.string().required() }) }; -module.exports.pause = { +export const pause = { options: Joi.object() }; -module.exports.unpause = { +export const unpause = { options: Joi.object() }; -module.exports.attach = { +export const attach = { options: Joi.object().keys({ detachKeys: Joi.string(), logs: Joi.boolean().default(false), @@ -119,31 +117,31 @@ module.exports.attach = { }) }; -module.exports.wait = { +export const wait = { options: Joi.object() }; -module.exports.remove = { +export const remove = { options: Joi.object().keys({ v: Joi.boolean().default(false), force: Joi.boolean().default(false) }) }; -module.exports.archive = { +export const archive = { options: Joi.object().keys({ path: Joi.string().required() }) }; -module.exports.update = { +export const update = { options: Joi.object().keys({ path: Joi.string().required(), noOverwriteDirNonDir: Joi.boolean().default(false) }) }; -module.exports.prune = { +export const prune = { options: Joi.object().keys({ filters: Joi.object() }) diff --git a/lib/schemas/images.js b/lib/schemas/images.ts similarity index 81% rename from lib/schemas/images.js rename to lib/schemas/images.ts index 5ce11db..8757de8 100644 --- a/lib/schemas/images.js +++ b/lib/schemas/images.ts @@ -1,8 +1,6 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object().keys({ all: Joi.boolean().default(false), digest: Joi.boolean().default(false), @@ -10,7 +8,7 @@ module.exports.list = { }) }; -module.exports.build = { +export const build = { options: Joi.object().keys({ dockerfile: Joi.string().required(), t: Joi.array(), @@ -32,7 +30,7 @@ module.exports.build = { }) }; -module.exports.create = { +export const create = { options: Joi.object().keys({ fromImage: Joi.string().required(), fromSrc: Joi.array(), @@ -42,31 +40,35 @@ module.exports.create = { }) }; -module.exports.push = { +export const history = { + options: Joi.object() +}; + +export const push = { options: Joi.object().keys({ tag: Joi.string() }) }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; -module.exports.tag = { +export const tag = { options: Joi.object().keys({ repo: Joi.string(), tag: Joi.string(), }) }; -module.exports.remove = { +export const remove = { options: Joi.object().keys({ force: Joi.boolean().default(false), noprune: Joi.boolean().default(false), }) }; -module.exports.search = { +export const search = { options: Joi.object().keys({ term: Joi.string().required(), limit: Joi.number(), @@ -74,13 +76,13 @@ module.exports.search = { }) }; -module.exports.prune = { +export const prune = { options: Joi.object().keys({ filters: Joi.object() }) }; -module.exports.commit = { +export const commit = { options: Joi.object().keys({ container: Joi.string().required(), repo: Joi.string().required(), @@ -91,3 +93,7 @@ module.exports.commit = { changes: Joi.string(), }) }; + +export const _export = { + options: Joi.object() +}; diff --git a/lib/schemas/networks.js b/lib/schemas/networks.js deleted file mode 100644 index f40711d..0000000 --- a/lib/schemas/networks.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -const Joi = require('joi'); - -module.exports.list = { - options: Joi.object().keys({ - filters: Joi.object() - }) -}; - -module.exports.create = { - options: Joi.object() -}; - -module.exports.inspect = { - options: Joi.object() -}; - -module.exports.remove = { - options: Joi.object() -}; diff --git a/lib/schemas/networks.ts b/lib/schemas/networks.ts new file mode 100644 index 0000000..83d29da --- /dev/null +++ b/lib/schemas/networks.ts @@ -0,0 +1,23 @@ +import * as Joi from 'joi'; + +export const list = { + options: Joi.object().keys({ + filters: Joi.object() + }) +}; + +export const create = { + options: Joi.object() +}; + +export const inspect = { + options: Joi.object() +}; + +export const remove = { + options: Joi.object() +}; + +export const connect = { + options: Joi.object() +}; diff --git a/lib/schemas/nodes.js b/lib/schemas/nodes.ts similarity index 63% rename from lib/schemas/nodes.js rename to lib/schemas/nodes.ts index aca45af..078a3f2 100644 --- a/lib/schemas/nodes.js +++ b/lib/schemas/nodes.ts @@ -1,24 +1,22 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object().keys({ filters: Joi.object() }) }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; -module.exports.update = { +export const update = { options: Joi.object().keys({ version: Joi.string().required() }) }; -module.exports.remove = { +export const remove = { options: Joi.object().keys({ force: Joi.boolean().default(false) }) diff --git a/lib/schemas/plugins.js b/lib/schemas/plugins.ts similarity index 56% rename from lib/schemas/plugins.js rename to lib/schemas/plugins.ts index 1cbbc31..bc956c1 100644 --- a/lib/schemas/plugins.js +++ b/lib/schemas/plugins.ts @@ -1,35 +1,33 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object() }; -module.exports.install = { +export const install = { options: Joi.object().keys({ name: Joi.string().required() }) }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; -module.exports.enable = { +export const enable = { options: Joi.object() }; -module.exports.disable = { +export const disable = { options: Joi.object() }; -module.exports.upgrade = { +export const upgrade = { options: Joi.object().keys({ remote: Joi.string().required() }) }; -module.exports.remove = { +export const remove = { options: Joi.object() }; diff --git a/lib/schemas/configs.js b/lib/schemas/secrets.ts similarity index 55% rename from lib/schemas/configs.js rename to lib/schemas/secrets.ts index 781e266..3b853e3 100644 --- a/lib/schemas/configs.js +++ b/lib/schemas/secrets.ts @@ -1,27 +1,25 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object().keys({ filters: Joi.object() }) }; -module.exports.create = { +export const create = { options: Joi.object() }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; -module.exports.update = { +export const update = { options: Joi.object().keys({ version: Joi.string() }) }; -module.exports.remove = { +export const remove = { options: Joi.object() }; diff --git a/lib/schemas/services.js b/lib/schemas/services.ts similarity index 73% rename from lib/schemas/services.js rename to lib/schemas/services.ts index f9fed92..4546021 100644 --- a/lib/schemas/services.js +++ b/lib/schemas/services.ts @@ -1,24 +1,22 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object().keys({ filters: Joi.object() }) }; -module.exports.create = { +export const create = { options: Joi.object() }; -module.exports.update = { +export const update = { options: Joi.object().keys({ version: Joi.string().required() }) }; -module.exports.log = { +export const log = { options: Joi.object().keys({ details: Joi.boolean().default(false), follow: Joi.boolean().default(false), @@ -30,10 +28,10 @@ module.exports.log = { }) }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; -module.exports.remove = { +export const remove = { options: Joi.object() }; diff --git a/lib/schemas/swarm.js b/lib/schemas/swarm.ts similarity index 64% rename from lib/schemas/swarm.js rename to lib/schemas/swarm.ts index 6fb2a1b..15f6deb 100644 --- a/lib/schemas/swarm.js +++ b/lib/schemas/swarm.ts @@ -1,26 +1,24 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.leave = { +export const leave = { options: Joi.object().keys({ force: Joi.boolean().default(false) }) }; -module.exports.join = { +export const join = { options: Joi.object() }; -module.exports.init = { +export const init = { options: Joi.object() }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; -module.exports.update = { +export const update = { options: Joi.object().keys({ version: Joi.string().required(), rotateManagerToken: Joi.boolean().default(false), @@ -28,10 +26,10 @@ module.exports.update = { }) }; -module.exports.unlockKey = { +export const unlockKey = { options: Joi.object() }; -module.exports.unlock = { +export const unlock = { options: Joi.object() }; diff --git a/lib/schemas/system.js b/lib/schemas/system.ts similarity index 80% rename from lib/schemas/system.js rename to lib/schemas/system.ts index 25cbc6f..906e3f7 100644 --- a/lib/schemas/system.js +++ b/lib/schemas/system.ts @@ -1,8 +1,6 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.auth = { +export const auth = { options: Joi.object().keys({ username: Joi.string().optional(), password: Joi.string().optional(), @@ -12,7 +10,7 @@ module.exports.auth = { }) }; -module.exports.events = { +export const events = { options: Joi.object().keys({ since: Joi.number(), until: Joi.number(), diff --git a/lib/schemas/tasks.js b/lib/schemas/tasks.ts similarity index 50% rename from lib/schemas/tasks.js rename to lib/schemas/tasks.ts index fab5c1d..a7c04c2 100644 --- a/lib/schemas/tasks.js +++ b/lib/schemas/tasks.ts @@ -1,13 +1,11 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object().keys({ filters: Joi.object() }) }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; diff --git a/lib/schemas/volumes.js b/lib/schemas/volumes.ts similarity index 50% rename from lib/schemas/volumes.js rename to lib/schemas/volumes.ts index f40711d..f8bdc84 100644 --- a/lib/schemas/volumes.js +++ b/lib/schemas/volumes.ts @@ -1,21 +1,19 @@ -'use strict'; +import * as Joi from 'joi'; -const Joi = require('joi'); - -module.exports.list = { +export const list = { options: Joi.object().keys({ filters: Joi.object() }) }; -module.exports.create = { +export const create = { options: Joi.object() }; -module.exports.inspect = { +export const inspect = { options: Joi.object() }; -module.exports.remove = { +export const remove = { options: Joi.object() }; diff --git a/package-lock.json b/package-lock.json index 4b4d124..f8cb24b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,14 @@ { "name": "harbor-master", - "version": "1.27.3", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/node": { + "version": "9.4.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.6.tgz", + "integrity": "sha512-CTUtLb6WqCCgp6P59QintjHWqzf4VL1uPA27bipLAPxFqrtK1gEYllePzTICGqQ8rYsCbpnsNypXjjDzGAAjEQ==" + }, "acorn": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz", @@ -120,9 +125,9 @@ "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" }, "assertion-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.2.tgz", - "integrity": "sha1-E8pRXYYgbaC6xm6DTdOX2HWBCUw=", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, "async": { @@ -249,7 +254,7 @@ "integrity": "sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=", "dev": true, "requires": { - "assertion-error": "1.0.2", + "assertion-error": "1.1.0", "deep-eql": "0.1.3", "type-detect": "1.0.0" } @@ -718,7 +723,7 @@ "js-yaml": "3.10.0", "json-stable-stringify": "1.0.1", "levn": "0.3.0", - "lodash": "4.17.4", + "lodash": "4.17.5", "mkdirp": "0.5.1", "natural-compare": "1.4.0", "optionator": "0.8.2", @@ -1118,7 +1123,7 @@ "cli-cursor": "1.0.2", "cli-width": "2.2.0", "figures": "1.7.0", - "lodash": "4.17.4", + "lodash": "4.17.5", "readline2": "1.0.1", "run-async": "0.1.0", "rx-lite": "3.1.2", @@ -1379,9 +1384,9 @@ } }, "lodash": { - "version": "4.17.4", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", - "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" + "version": "4.17.5", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" }, "longest": { "version": "1.0.1", @@ -1451,20 +1456,20 @@ "dev": true }, "nock": { - "version": "9.1.4", - "resolved": "https://registry.npmjs.org/nock/-/nock-9.1.4.tgz", - "integrity": "sha512-O0tkPO0VkiQ7mfCAg3QyL+6tt7srXHq0+m6BMy+SyzuKX+2Oz10ERXnqDL0nJxpVhKFx/E/K/6nT75U6RpvugQ==", + "version": "9.1.6", + "resolved": "https://registry.npmjs.org/nock/-/nock-9.1.6.tgz", + "integrity": "sha512-DuKF+1W/FnMO6MXIGgCIWcM95bETjBbmFdR4v7dAj1zH9a9XhOjAa//PuWh98XIXxcZt7wdiv0JlO0AA0e2kqQ==", "dev": true, "requires": { "chai": "3.5.0", "debug": "2.6.9", "deep-equal": "1.0.1", "json-stringify-safe": "5.0.1", - "lodash": "4.17.4", + "lodash": "4.17.5", "mkdirp": "0.5.1", "propagate": "0.4.0", "qs": "6.5.1", - "semver": "5.4.1" + "semver": "5.5.0" } }, "number-is-nan": { @@ -1769,9 +1774,9 @@ "dev": true }, "semver": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", - "integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==", + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", "dev": true }, "shelljs": { @@ -1899,7 +1904,7 @@ "ajv": "4.11.8", "ajv-keywords": "1.5.1", "chalk": "1.1.3", - "lodash": "4.17.4", + "lodash": "4.17.5", "slice-ansi": "0.0.4", "string-width": "2.1.1" }, @@ -2016,6 +2021,11 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "typescript": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz", + "integrity": "sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==" + }, "uglify-js": { "version": "2.8.29", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", diff --git a/package.json b/package.json index 01ecfe9..156a972 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "harbor-master", - "version": "1.32.1", + "version": "2.0.0", "description": "Harbor Master is a Docker Remote API client written in Node.js", "keywords": [ "docker", @@ -8,15 +8,17 @@ "docker-remote", "node-docker", "containers", + "typescript", "node.js" ], - "main": "index.js", + "main": "dist/index.js", "files": [ - "lib/", - "index.js" + "dist/lib/", + "dist/index.js" ], "scripts": { - "test": "lab --timeout 1000 --assert code", + "compile": "tsc", + "test": "tsc && lab dist/test --timeout 1000 --assert code", "lint": "jshint ." }, "author": "Alex Rhea ", @@ -32,15 +34,17 @@ "node": ">= 4" }, "dependencies": { + "@types/node": "^9.4.6", "bluebird": "^3.4.7", "joi": "^10.2.0", - "lodash": "^4.17.4", - "request": "^2.79.0" + "lodash": "^4.17.5", + "request": "^2.79.0", + "typescript": "^2.7.2" }, "devDependencies": { "code": "^4.0.0", "jshint": "^2.9.4", "lab": "^11.2.2", - "nock": "^9.0.2" + "nock": "^9.1.6" } } diff --git a/test/containers/create.js b/test/containers/create.ts similarity index 95% rename from test/containers/create.js rename to test/containers/create.ts index f5a6b90..88c79f6 100644 --- a/test/containers/create.js +++ b/test/containers/create.ts @@ -1,10 +1,8 @@ -'use strict'; +import * as Code from 'code'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Code = require('code'); -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('containers - create', () => { diff --git a/test/containers/inspect.js b/test/containers/inspect.ts similarity index 75% rename from test/containers/inspect.js rename to test/containers/inspect.ts index b02e228..24877da 100644 --- a/test/containers/inspect.js +++ b/test/containers/inspect.ts @@ -1,10 +1,8 @@ -'use strict'; +import * as Code from 'code'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Code = require('code'); -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('containers - inspect', () => { diff --git a/test/containers/list.js b/test/containers/list.ts similarity index 91% rename from test/containers/list.js rename to test/containers/list.ts index afe858e..3582d51 100644 --- a/test/containers/list.js +++ b/test/containers/list.ts @@ -1,10 +1,8 @@ -'use strict'; +import * as Code from 'code'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Code = require('code'); -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('containers - list', () => { diff --git a/test/daemon/auth.js b/test/daemon/auth.ts similarity index 76% rename from test/daemon/auth.js rename to test/daemon/auth.ts index b2e02e4..3d2dac9 100644 --- a/test/daemon/auth.js +++ b/test/daemon/auth.ts @@ -1,10 +1,8 @@ -'use strict'; +import * as Code from 'code'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Code = require('code'); -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('daemon - auth', () => { diff --git a/test/daemon/info.js b/test/daemon/info.ts similarity index 71% rename from test/daemon/info.js rename to test/daemon/info.ts index c8f5fbf..2612557 100644 --- a/test/daemon/info.js +++ b/test/daemon/info.ts @@ -1,10 +1,8 @@ -'use strict'; +import * as Code from 'code'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Code = require('code'); -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('daemon - info', () => { diff --git a/test/daemon/ping.js b/test/daemon/ping.ts similarity index 71% rename from test/daemon/ping.js rename to test/daemon/ping.ts index ceabd49..520e1a7 100644 --- a/test/daemon/ping.js +++ b/test/daemon/ping.ts @@ -1,10 +1,8 @@ -'use strict'; +import * as Code from 'code'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Code = require('code'); -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('daemon - ping', () => { diff --git a/test/daemon/version.js b/test/daemon/version.ts similarity index 71% rename from test/daemon/version.js rename to test/daemon/version.ts index 0de6144..55403a1 100644 --- a/test/daemon/version.js +++ b/test/daemon/version.ts @@ -1,10 +1,8 @@ -'use strict'; +import * as Code from 'code'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Code = require('code'); -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('daemon - version', () => { diff --git a/test/harness.js b/test/harness.ts similarity index 63% rename from test/harness.js rename to test/harness.ts index 96d68b7..8e9e80e 100644 --- a/test/harness.js +++ b/test/harness.ts @@ -1,29 +1,27 @@ -'use strict'; - -const Code = require('code'); -const docker = require('../index'); -const nock = require('nock'); +import * as Code from 'code'; +import { DockerClient } from "../lib/docker"; +import * as nock from 'nock'; module.exports.options = { host: '10.0.0.1', port: 2375 }; -module.exports.client = docker.Client(module.exports.options); +export const client = new DockerClient(module.exports.options); -module.exports.mock = () => { +export const mock = () => { return nock(`http://${module.exports.options.host}:${module.exports.options.port}/v1.32`); }; -module.exports.clean = () => { +export const clean = () => { return nock.cleanAll(); }; -module.exports.unmock = () => { +export const unmock = () => { return nock.restore(); }; -module.exports.handleSuccess = (scope, statusCode, promise, done) => { +export const handleSuccess = (scope, statusCode, promise, done) => { promise.then(() => { Code.expect(scope.isDone()).to.equal(true); @@ -37,7 +35,7 @@ module.exports.handleSuccess = (scope, statusCode, promise, done) => { }; -module.exports.handleError = (scope, statusCode, promise, done) => { +export const handleError = (scope, statusCode, promise, done) => { promise.then(() => { Code.fail(`should be a ${statusCode} response`); diff --git a/test/images/inspect.js b/test/images/inspect.ts similarity index 70% rename from test/images/inspect.js rename to test/images/inspect.ts index 3d0f28d..5e16510 100644 --- a/test/images/inspect.js +++ b/test/images/inspect.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('images - inspect', () => { diff --git a/test/images/list.js b/test/images/list.ts similarity index 68% rename from test/images/list.js rename to test/images/list.ts index afdb5cb..1e31c20 100644 --- a/test/images/list.js +++ b/test/images/list.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('images - list', () => { diff --git a/test/images/search.js b/test/images/search.ts similarity index 73% rename from test/images/search.js rename to test/images/search.ts index 2220e76..2c1a06c 100644 --- a/test/images/search.js +++ b/test/images/search.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('images - search', () => { diff --git a/test/networks/list.js b/test/networks/list.ts similarity index 69% rename from test/networks/list.js rename to test/networks/list.ts index d5e8605..d49fe91 100644 --- a/test/networks/list.js +++ b/test/networks/list.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('networks - list', () => { diff --git a/test/nodes/list.js b/test/nodes/list.ts similarity index 68% rename from test/nodes/list.js rename to test/nodes/list.ts index 12a6659..07bf545 100644 --- a/test/nodes/list.js +++ b/test/nodes/list.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('nodes - list', () => { diff --git a/test/plugins/list.js b/test/plugins/list.ts similarity index 68% rename from test/plugins/list.js rename to test/plugins/list.ts index 1a68290..88852bc 100644 --- a/test/plugins/list.js +++ b/test/plugins/list.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('plugins - list', () => { diff --git a/test/swarm/init.js b/test/swarm/init.ts similarity index 68% rename from test/swarm/init.js rename to test/swarm/init.ts index 69dfd07..d72dec8 100644 --- a/test/swarm/init.js +++ b/test/swarm/init.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('swarm - init', () => { diff --git a/test/swarm/inspect.js b/test/swarm/inspect.ts similarity index 68% rename from test/swarm/inspect.js rename to test/swarm/inspect.ts index 4070f41..23b4b22 100644 --- a/test/swarm/inspect.js +++ b/test/swarm/inspect.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('swarm - inspect', () => { diff --git a/test/swarm/join.js b/test/swarm/join.ts similarity index 68% rename from test/swarm/join.js rename to test/swarm/join.ts index ed9d0b8..9050538 100644 --- a/test/swarm/join.js +++ b/test/swarm/join.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('swarm - join', () => { diff --git a/test/swarm/leave.js b/test/swarm/leave.ts similarity index 71% rename from test/swarm/leave.js rename to test/swarm/leave.ts index 46a551f..f9a4e4e 100644 --- a/test/swarm/leave.js +++ b/test/swarm/leave.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('swarm - leave', () => { diff --git a/test/swarm/unlock.js b/test/swarm/unlock.ts similarity index 69% rename from test/swarm/unlock.js rename to test/swarm/unlock.ts index 5aef04b..f327a67 100644 --- a/test/swarm/unlock.js +++ b/test/swarm/unlock.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('swarm - unlock', () => { diff --git a/test/swarm/unlockKey.js b/test/swarm/unlockKey.ts similarity index 69% rename from test/swarm/unlockKey.js rename to test/swarm/unlockKey.ts index df046c0..397a049 100644 --- a/test/swarm/unlockKey.js +++ b/test/swarm/unlockKey.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('swarm - unlock key', () => { diff --git a/test/swarm/update.js b/test/swarm/update.ts similarity index 70% rename from test/swarm/update.js rename to test/swarm/update.ts index 43b95eb..cca9c83 100644 --- a/test/swarm/update.js +++ b/test/swarm/update.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('swarm - update', () => { @@ -14,7 +12,7 @@ lab.experiment('swarm - update', () => { .query({ version: 2, rotateManagerToken: false, - rotateWorkerToken:false + rotateWorkerToken: false }) .reply(200, {}); diff --git a/test/tasks/inspect.js b/test/tasks/inspect.ts similarity index 70% rename from test/tasks/inspect.js rename to test/tasks/inspect.ts index 0b262a2..0b9e870 100644 --- a/test/tasks/inspect.js +++ b/test/tasks/inspect.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('tasks - list', () => { diff --git a/test/tasks/list.js b/test/tasks/list.ts similarity index 68% rename from test/tasks/list.js rename to test/tasks/list.ts index 2f6c6c8..5ba71e6 100644 --- a/test/tasks/list.js +++ b/test/tasks/list.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('tasks - list', () => { diff --git a/test/volumes/create.js b/test/volumes/create.ts similarity index 71% rename from test/volumes/create.js rename to test/volumes/create.ts index 3aba082..899c9e6 100644 --- a/test/volumes/create.js +++ b/test/volumes/create.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('volumes - create', () => { diff --git a/test/volumes/inspect.js b/test/volumes/inspect.ts similarity index 70% rename from test/volumes/inspect.js rename to test/volumes/inspect.ts index 2fa3632..fe46a14 100644 --- a/test/volumes/inspect.js +++ b/test/volumes/inspect.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('volumes - inspect', () => { diff --git a/test/volumes/list.js b/test/volumes/list.ts similarity index 68% rename from test/volumes/list.js rename to test/volumes/list.ts index 9024500..fb96351 100644 --- a/test/volumes/list.js +++ b/test/volumes/list.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('volumes - list', () => { diff --git a/test/volumes/remove.js b/test/volumes/remove.ts similarity index 71% rename from test/volumes/remove.js rename to test/volumes/remove.ts index 2394da7..231d567 100644 --- a/test/volumes/remove.js +++ b/test/volumes/remove.ts @@ -1,9 +1,7 @@ -'use strict'; +import * as Lab from 'lab'; +import * as harness from '../harness'; -const Lab = require('lab'); -const harness = require('../harness'); - -const lab = exports.lab = Lab.script(); +const lab = exports.lab = Lab.script(); lab.experiment('volumes - remove', () => { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7beeb9d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "outDir": "./dist", + "sourceMap": true, + "declaration": true + } +}