diff --git a/consul/consul-tests.ts b/consul/consul-tests.ts new file mode 100644 index 000000000..2a8619aca --- /dev/null +++ b/consul/consul-tests.ts @@ -0,0 +1,799 @@ +/// + +import * as Consul from "consul"; + +let ConsulStatic: Consul.ConsulStatic; +let AclStatic: Consul.AclStatic = ConsulStatic.Acl; +let AgentStatic: Consul.AgentStatic = ConsulStatic.Agent; +let AgentCheckStatic: Consul.Agent.CheckStatic = ConsulStatic.Agent.Check; +let AgentServiceStatic: Consul.Agent.ServiceStatic = ConsulStatic.Agent.Service; +let CatalogStatic: Consul.CatalogStatic = ConsulStatic.Catalog; +let CatalogNodeStatic: Consul.Catalog.NodeStatic = ConsulStatic.Catalog.Node; +let CatalogServiceStatic: Consul.Catalog.ServiceStatic = ConsulStatic.Catalog.Service; +let EventStatic: Consul.EventStatic = ConsulStatic.Event; +let HealthStatic: Consul.HealthStatic = ConsulStatic.Health; +let KvStatic: Consul.KvStatic = ConsulStatic.Kv; +let LockStatic: Consul.LockStatic = ConsulStatic.Lock; +let SessionStatic: Consul.SessionStatic = ConsulStatic.Session; +let StatusStatic: Consul.StatusStatic = ConsulStatic.Status; +let WatchStatic: Consul.WatchStatic = ConsulStatic.Watch; + +let consul: Consul.Consul; + +consul = Consul(); +consul = new Consul(); + + +// Consul.Acl +{ + let acl: Consul.Acl = consul.acl; + + acl = new AclStatic(consul); + consul = acl.consul; + + { + let opts: Consul.Acl.CreateOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + acl.create(opts, callback); + acl.create(callback); + + result = acl.create(opts); + result = acl.create(); + } + + { + let opts: Consul.Acl.UpdateOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + acl.update(opts, callback); + + result = acl.update(opts); + } + + { + let id: string; + let opts: Consul.Acl.DestroyOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + acl.destroy(id, callback); + acl.destroy(opts, callback); + + result = acl.destroy(id); + result = acl.destroy(opts); + } + + { + let id: string; + let opts: Consul.Acl.InfoOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + acl.info(id, callback); + acl.info(opts, callback); + + result = acl.info(id); + result = acl.info(opts); + + acl.get(id, callback); + acl.get(opts, callback); + + result = acl.get(id); + result = acl.get(opts); + } + + { + let id: string; + let opts: Consul.Acl.CloneOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + acl.clone(id, callback); + acl.clone(opts, callback); + + result = acl.clone(id); + result = acl.clone(opts); + } + + { + let opts: Consul.Acl.ListOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + acl.list(opts, callback); + acl.list(callback); + + result = acl.list(opts); + result = acl.list(); + } +} + + +// Consul.Agent +{ + let agent: Consul.Agent = consul.agent; + + agent = new AgentStatic(consul); + consul = agent.consul; + + { + let opts: Consul.Agent.ChecksOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + agent.checks(opts, callback); + agent.checks(callback); + + result = agent.checks(opts); + result = agent.checks(); + } + + { + let opts: Consul.Agent.ServicesOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + agent.services(opts, callback); + agent.services(callback); + + result = agent.services(opts); + result = agent.services(); + } + + { + let opts: Consul.Agent.MembersOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + agent.members(opts, callback); + agent.members(callback); + + result = agent.members(opts); + result = agent.members(); + } + + { + let opts: Consul.Agent.SelfOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + agent.self(opts, callback); + agent.self(callback); + + result = agent.self(opts); + result = agent.self(); + } + + { + let enable: boolean; + let opts: Consul.Agent.MaintenanceOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + agent.maintenance(enable, callback); + agent.maintenance(opts, callback); + + result = agent.maintenance(enable); + result = agent.maintenance(opts); + } + + { + let address: string; + let opts: Consul.Agent.JoinOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + agent.join(address, callback); + agent.join(opts, callback); + + result = agent.join(address); + result = agent.join(opts); + } + + { + let node: string; + let opts: Consul.Agent.ForceLeaveOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + agent.forceLeave(node, callback); + agent.forceLeave(opts, callback); + + result = agent.forceLeave(node); + result = agent.forceLeave(opts); + } + + + // Consul.Agent.Check + { + let check: Consul.Agent.Check = consul.agent.check; + + check = new AgentCheckStatic(consul); + consul = check.consul; + + { + let id: string; + let opts: Consul.Agent.Check.ListOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + check.list(opts, callback); + check.list(callback); + + result = check.list(opts); + result = check.list(); + } + + { + let opts: Consul.Agent.Check.RegisterOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + check.register(opts, callback); + + result = check.register(opts); + } + + { + let id: string; + let opts: Consul.Agent.Check.DeregisterOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + check.deregister(id, callback); + check.deregister(opts, callback); + + result = check.deregister(id); + result = check.deregister(opts); + } + + { + let id: string; + let opts: Consul.Agent.Check.PassOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + check.pass(id, callback); + check.pass(opts, callback); + + result = check.pass(id); + result = check.pass(opts); + } + + { + let id: string; + let opts: Consul.Agent.Check.WarnOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + check.warn(id, callback); + check.warn(opts, callback); + + result = check.warn(id); + result = check.warn(opts); + } + + { + let id: string; + let opts: Consul.Agent.Check.WarnOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + check.fail(id, callback); + check.fail(opts, callback); + + result = check.fail(id); + result = check.fail(opts); + } + } + + + // Consul.Agent.Service + { + let service: Consul.Agent.Service = consul.agent.service; + + service = new AgentServiceStatic(consul); + consul = service.consul; + + { + let opts: Consul.Agent.Service.ListOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + service.list(opts, callback); + service.list(callback); + + result = service.list(opts); + result = service.list(); + } + + { + let id: string; + let opts: Consul.Agent.Service.RegisterOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + service.register(id, callback); + service.register(opts, callback); + + result = service.register(id); + result = service.register(opts); + } + + { + let id: string; + let opts: Consul.Agent.Service.DeregisterOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + service.deregister(id, callback); + service.deregister(opts, callback); + + result = service.deregister(id); + result = service.deregister(opts); + } + + { + let opts: Consul.Agent.Service.MaintenanceOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + service.maintenance(opts, callback); + + result = service.maintenance(opts); + } + } +} + +// Consul.Catalog +{ + let catalog: Consul.Catalog = consul.catalog; + + catalog = new CatalogStatic(consul); + consul = catalog.consul; + + { + let opts: Consul.Catalog.DatacentersOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + catalog.datacenters(opts, callback); + catalog.datacenters(callback); + + result = catalog.datacenters(opts); + result = catalog.datacenters(); + } + + { + let dc: string; + let opts: Consul.Catalog.NodesOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + catalog.nodes(dc, callback); + catalog.nodes(opts, callback); + catalog.nodes(callback); + + result = catalog.nodes(dc); + result = catalog.nodes(opts); + result = catalog.nodes(); + } + + { + let dc: string; + let opts: Consul.Catalog.ServicesOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + catalog.services(dc, callback); + catalog.services(opts, callback); + catalog.services(callback); + + result = catalog.services(dc); + result = catalog.services(opts); + result = catalog.services(); + } + + + // Consul.Catalog.Node + { + let node: Consul.Catalog.Node = consul.catalog.node; + + node = new CatalogNodeStatic(consul); + consul = node.consul; + + { + let dc: string; + let opts: Consul.Catalog.Node.ListOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + node.list(dc, callback); + node.list(opts, callback); + node.list(callback); + + result = node.list(dc); + result = node.list(opts); + result = node.list(); + } + + { + let nodeOption: string; + let opts: Consul.Catalog.Node.ServicesOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + node.services(nodeOption, callback); + node.services(opts, callback); + + result = node.services(nodeOption); + result = node.services(opts); + } + } + + // Consul.Catalog.Service + { + let service: Consul.Catalog.Service = consul.catalog.service; + + service = new CatalogServiceStatic(consul); + consul = service.consul; + + { + let dc: string; + let opts: Consul.Catalog.Service.ListOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + service.list(dc, callback); + service.list(opts, callback); + service.list(callback); + + result = service.list(dc); + result = service.list(opts); + result = service.list(); + } + + { + let serviceOption: string; + let opts: Consul.Catalog.Service.NodesOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + service.nodes(serviceOption, callback); + service.nodes(opts, callback); + + result = service.nodes(serviceOption); + result = service.nodes(opts); + } + } +} + +// Consul.Event +{ + let event: Consul.Event = consul.event; + + event = new EventStatic(consul); + consul = event.consul; + + { + let name: string; + let payload: string|Buffer; + let opts: Consul.Event.FireOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + event.fire(name, payload, callback); + event.fire(name, callback); + event.fire(opts, callback); + + result = event.fire(name, payload); + result = event.fire(name); + result = event.fire(opts); + } + + { + let name: string; + let opts: Consul.Event.ListOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + event.list(name, callback); + event.list(opts, callback); + event.list(callback); + + result = event.list(name); + result = event.list(opts); + result = event.list(); + } +} + +// Consul.Health +{ + let health: Consul.Health = consul.health; + + health = new HealthStatic(consul); + consul = health.consul; + + { + let node: string; + let opts: Consul.Health.NodeOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + health.node(name, callback); + health.node(opts, callback); + + result = health.node(name); + result = health.node(opts); + } + + { + let service: string; + let opts: Consul.Health.ChecksOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + health.checks(service, callback); + health.checks(opts, callback); + + result = health.checks(service); + result = health.checks(opts); + } + + { + let service: string; + let opts: Consul.Health.ServiceOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + health.service(service, callback); + health.service(opts, callback); + + result = health.service(service); + result = health.service(opts); + } + + { + let state: string; + let opts: Consul.Health.StateOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + health.state(state, callback); + health.state(opts, callback); + + result = health.state(state); + result = health.state(opts); + } +} + + +// Consul.Kv +{ + let kv: Consul.Kv = consul.kv; + + kv = new KvStatic(consul); + consul = kv.consul; + + { + let key: string; + let opts: Consul.Kv.GetOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + kv.get(key, callback); + kv.get(opts, callback); + + result = kv.get(key); + result = kv.get(opts); + } + + { + let key: string; + let opts: Consul.Kv.KeysOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + kv.keys(key, callback); + kv.keys(opts, callback); + kv.keys(callback); + + result = kv.keys(key); + result = kv.keys(opts); + result = kv.keys(); + } + + { + let key: string; + let value: string|Buffer; + let opts: Consul.Kv.SetOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + kv.set(key, value, opts, callback); + kv.set(key, value, callback); + kv.set(opts, callback); + + result = kv.set(key, value, opts); + result = kv.set(key, value); + result = kv.set(opts); + } + + { + let key: string; + let opts: Consul.Kv.DelOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + kv.del(key, callback); + kv.del(opts, callback); + + result = kv.del(key); + result = kv.del(opts); + + kv.delete(key, callback); + kv.delete(opts, callback); + + result = kv.delete(key); + result = kv.delete(opts); + } +} + + +// Consul.Lock +{ + let lock: Consul.Lock; + let opts: Consul.Lock.Options; + + lock = new LockStatic(consul, opts); + lock = consul.lock(opts); + consul = lock.consul; + + lock.acquire(); + + lock.release(); +} + + +// Consul.Session +{ + let session: Consul.Session = consul.session; + + session = new SessionStatic(consul); + consul = session.consul; + + { + let opts: Consul.Session.CreateOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + session.create(opts, callback); + session.create(callback); + + result = session.create(opts); + result = session.create(); + } + + { + let id: string; + let opts: Consul.Session.DestroyOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + session.destroy(id, callback); + session.destroy(opts, callback); + + result = session.destroy(id); + result = session.destroy(opts); + } + + { + let id: string; + let opts: Consul.Session.InfoOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + session.info(id, callback); + session.info(opts, callback); + + result = session.info(id); + result = session.info(opts); + + session.get(id, callback); + session.get(opts, callback); + + result = session.get(id); + result = session.get(opts); + } + + { + let node: string; + let opts: Consul.Session.NodeOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + session.node(node, callback); + session.node(opts, callback); + + result = session.node(node); + result = session.node(opts); + } + + { + let opts: Consul.Session.ListOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + session.list(opts, callback); + session.list(callback); + + result = session.list(opts); + result = session.list(); + } + + { + let id: string; + let opts: Consul.Session.RenewOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + session.renew(id, callback); + session.renew(opts, callback); + + result = session.renew(id); + result = session.renew(opts); + } +} + + +// Consul.Status +{ + let status: Consul.Status = consul.status; + + status = new StatusStatic(consul); + consul = status.consul; + + { + let opts: Consul.Status.LeaderOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + status.leader(opts, callback); + status.leader(callback); + + result = status.leader(opts); + result = status.leader(); + } + + { + let opts: Consul.Status.LeaderOptions; + let callback: Consul.Callback; + let result: Consul.Thenable; + + status.peers(opts, callback); + status.peers(callback); + + result = status.peers(opts); + result = status.peers(); + } +} + + +// Consul.Watch +{ + let watch: Consul.Watch; + let opts: Consul.Watch.Options; + + watch = new WatchStatic(consul, opts); + watch = consul.watch(opts); + consul = watch.consul; + + watch.isRunning(); + + watch.updateTime(); + + watch.end(); +} diff --git a/consul/consul.d.ts b/consul/consul.d.ts new file mode 100644 index 000000000..23c39186e --- /dev/null +++ b/consul/consul.d.ts @@ -0,0 +1,1034 @@ +// Type definitions for Consul v0.23.0 +// Project: https://github.com/silas/node-consul +// Definitions by: Ilya Mochalov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "consul" { + + import {IncomingMessage as HttpIncomingMessage} from "http"; + + namespace Consul { + + interface Thenable { + then(onFulfilled?: (value: T) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; + then(onFulfilled?: (value: T) => U | Thenable, onRejected?: (error: any) => void): Thenable; + catch(onRejected?: (error: any) => U | Thenable): Thenable; + } + + interface CommonOptions { + consistent?: boolean; + dc?: string; + stale?: boolean; + token?: string; + wait?: string; + wan?: boolean; + + ctx?: NodeJS.EventEmitter; + timeout?: number; + } + + interface Response extends HttpIncomingMessage { + body?: Object|string|Buffer; + } + + interface Callback { + (err?: Error, data?: TData, res?: Response): any; + } + + namespace Acl { + + interface CreateOptions extends CommonOptions { + name?: string; + type?: string; + rules?: string; + } + + interface UpdateOptions extends CommonOptions { + id: string; + name?: string; + type?: string; + rules?: string; + } + + interface DestroyOptions extends CommonOptions { + id: string; + } + + interface InfoOptions extends CommonOptions { + id: string; + } + + interface GetOptions extends InfoOptions {} + + interface CloneOptions extends CommonOptions { + id: string; + } + + interface ListOptions extends CommonOptions {} + } + + interface Acl { + consul: Consul; + + /** + * Creates a new token with policy + */ + create: { + (opts: Acl.CreateOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Acl.CreateOptions): Thenable; + }; + + /** + * Update the policy of a token + */ + update: { + (opts: Acl.UpdateOptions, callback: Callback): void; + (opts: Acl.UpdateOptions): Thenable; + } + + /** + * Destroys a given token + */ + destroy: { + (id: string, callback: Callback): void; + (opts: Acl.DestroyOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Acl.DestroyOptions): Thenable; + }; + + /** + * Queries the policy of a given token + */ + info: { + (id: string, callback: Callback): void; + (opts: Acl.InfoOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Acl.InfoOptions): Thenable; + }; + get: { + (id: string, callback: Callback): void; + (opts: Acl.GetOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Acl.GetOptions): Thenable; + }; + + /** + * Creates a new token by cloning an existing token + */ + clone: { + (id: string, callback: Callback): void; + (opts: Acl.CloneOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Acl.CloneOptions): Thenable; + }; + + /** + * Lists all the active tokens + */ + list: { + (opts: Acl.ListOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Acl.ListOptions): Thenable; + }; + } + + interface AclStatic { + new (consul: Consul): Acl; + } + + namespace Agent { + + namespace Check { + + interface ListOptions extends CommonOptions {} + + interface RegisterOptions extends CommonOptions { + name: string; + id?: string; + serviceid?: string; + http?: string; + script?: string; + interval?: string; + ttl?: string; + notes?: string; + status?: string; + } + + interface DeregisterOptions extends CommonOptions { + id: string; + } + + interface PassOptions extends CommonOptions { + id: string; + note?: string; + } + + interface WarnOptions extends CommonOptions { + id: string; + note?: string; + } + + interface FailOptions extends CommonOptions { + id: string; + note?: string; + } + } + + interface Check { + consul: Consul; + + /** + * Returns the checks the local agent is managing + */ + list: { + (opts: Check.ListOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Check.ListOptions): Thenable; + }; + + /** + * Registers a new local check + */ + register: { + (opts: Check.RegisterOptions, callback: Callback): void; + (opts: Check.RegisterOptions): Thenable; + }; + + /** + * Deregister a local check + */ + deregister: { + (id: string, callback: Callback): void; + (opts: Check.DeregisterOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Check.DeregisterOptions): Thenable; + }; + + /** + * Mark a local test as passing + */ + pass: { + (id: string, callback: Callback): void; + (opts: Check.PassOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Check.PassOptions): Thenable; + }; + + /** + * Mark a local test as warning + */ + warn: { + (id: string, callback: Callback): void; + (opts: Check.WarnOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Check.WarnOptions): Thenable; + }; + + /** + * Mark a local test as critical + */ + fail: { + (id: string, callback: Callback): void; + (opts: Check.FailOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Check.FailOptions): Thenable; + }; + } + + interface CheckStatic { + new (consul: Consul): Check; + } + + namespace Service { + + interface RegisterCheck { + http?: string; + script?: string; + interval?: string; + ttl?: string; + notes?: string; + status?: string; + } + + interface ListOptions extends CommonOptions {} + + interface RegisterOptions extends CommonOptions { + name: string; + id?: string; + tags?: string[]; + address?: string; + port?: number; + check?: RegisterCheck; + checks?: RegisterCheck[]; + } + + interface DeregisterOptions extends CommonOptions { + id: string; + } + + interface MaintenanceOptions extends CommonOptions { + id: string; + enable: boolean; + reason?: string; + } + } + + interface Service { + consul: Consul; + + /** + * Returns the services local agent is managing + */ + list: { + (opts: Service.ListOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Service.ListOptions): Thenable; + }; + + /** + * Registers a new local service + */ + register: { + (name: string, callback: Callback): void; + (opts: Service.RegisterOptions, callback: Callback): void; + (name: string): Thenable; + (opts: Service.RegisterOptions): Thenable; + }; + + /** + * Deregister a local service + */ + deregister: { + (id: string, callback: Callback): void; + (opts: Service.DeregisterOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Service.DeregisterOptions): Thenable; + }; + + /** + * Manages node maintenance mode + */ + maintenance: { + (opts: Service.MaintenanceOptions, callback: Callback): void; + (opts: Service.MaintenanceOptions): Thenable; + }; + } + + interface ServiceStatic { + new (consul: Consul): Service; + } + + interface ChecksOptions extends Check.ListOptions {} + + interface ServicesOptions extends Service.ListOptions {} + + interface MembersOptions extends CommonOptions { + wan?: boolean; + } + + interface SelfOptions extends CommonOptions {} + + interface MaintenanceOptions extends CommonOptions { + enable: boolean; + reason?: string; + } + + interface JoinOptions extends CommonOptions { + address: string; + wan?: boolean; + } + + interface ForceLeaveOptions extends CommonOptions { + node: string; + } + } + + interface Agent { + consul: Consul; + check: Agent.Check; + service: Agent.Service; + + /** + * Returns the checks the local agent is managing + */ + checks: { + (opts: Agent.ChecksOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Agent.ChecksOptions): Thenable; + }; + + /** + * Returns the services local agent is managing + */ + services: { + (opts: Agent.ServicesOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Agent.ServicesOptions): Thenable; + }; + + /** + * Returns the members as seen by the local consul agent + */ + members: { + (opts: Agent.MembersOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Agent.MembersOptions): Thenable; + }; + + /** + * Returns the local node configuration + */ + self: { + (opts: Agent.SelfOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Agent.SelfOptions): Thenable; + }; + + /** + * Manages node maintenance mode + */ + maintenance: { + (enable: boolean, callback: Callback): void; + (opts: Agent.MaintenanceOptions, callback: Callback): void; + (enable: boolean): Thenable; + (opts: Agent.MaintenanceOptions): Thenable; + }; + + /** + * Trigger local agent to join a node + */ + join: { + (address: string, callback: Callback): void; + (opts: Agent.JoinOptions, callback: Callback): void; + (address: string): Thenable; + (opts: Agent.JoinOptions): Thenable; + }; + + /** + * Force remove node + */ + forceLeave: { + (node: string, callback: Callback): void; + (opts: Agent.ForceLeaveOptions, callback: Callback): void; + (node: string): Thenable; + (opts: Agent.ForceLeaveOptions): Thenable; + }; + } + + interface AgentStatic { + new (consul: Consul): Agent; + + Check: Agent.CheckStatic; + Service: Agent.ServiceStatic; + } + + namespace Catalog { + + namespace Node { + + interface ListOptions extends CommonOptions { + dc?: string; + } + + interface ServicesOptions extends CommonOptions { + node: string; + } + } + + interface Node { + consul: Consul; + + /** + * Lists nodes in a given DC + */ + list: { + (dc: string, callback: Callback): void; + (opts: Node.ListOptions, callback: Callback): void; + (callback: Callback): void; + (dc?: string): Thenable; + (opts?: Node.ListOptions): Thenable; + }; + + /** + * Lists the services provided by a node + */ + services: { + (node: string, callback: Callback): void; + (opts: Node.ServicesOptions, callback: Callback): void; + (node: string): Thenable; + (opts: Node.ServicesOptions): Thenable; + }; + } + + interface NodeStatic { + new(consul: Consul): Node; + } + + namespace Service { + + interface ListOptions extends CommonOptions { + dc?: string; + } + + interface NodesOptions extends CommonOptions { + service: string; + dc?: string; + tag?: string; + } + } + + + + interface Service { + consul: Consul; + + /** + * Lists services in a given DC + */ + list: { + (dc: string, callback: Callback): void; + (opts: Service.ListOptions, callback: Callback): void; + (callback: Callback): void; + (dc?: string): Thenable; + (opts?: Service.ListOptions): Thenable; + }; + + /** + * Lists the nodes in a given service + */ + nodes: { + (service: string, callback: Callback): void; + (opts: Service.NodesOptions, callback: Callback): void; + (service: string): Thenable; + (opts: Service.NodesOptions): Thenable; + }; + } + + interface ServiceStatic { + new(consul: Consul): Service; + } + + interface DatacentersOptions extends CommonOptions {} + + interface NodesOptions extends Node.ListOptions {} + + interface ServicesOptions extends Service.ListOptions {} + } + + interface Catalog { + consul: Consul; + node: Catalog.Node; + service: Catalog.Service; + + /** + * Lists known datacenters + */ + datacenters: { + (opts: Catalog.DatacentersOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Catalog.DatacentersOptions): Thenable; + }; + + /** + * Lists nodes in a given DC + */ + nodes: { + (dc: string, callback: Callback): void; + (opts: Catalog.NodesOptions, callback: Callback): void; + (callback: Callback): void; + (dc?: string): Thenable; + (opts?: Catalog.NodesOptions): Thenable; + }; + + /** + * Lists services in a given DC + */ + services: { + (dc: string, callback: Callback): void; + (opts: Catalog.ServicesOptions, callback: Callback): void; + (callback: Callback): void; + (dc?: string): Thenable; + (opts?: Catalog.ServicesOptions): Thenable; + }; + } + + interface CatalogStatic { + new(consul: Consul): Catalog; + + Node: Catalog.NodeStatic; + Service: Catalog.ServiceStatic; + } + + namespace Event { + + interface FireOptions extends CommonOptions { + name: string; + payload: string|Buffer; + node?: string; + service?: string; + tag?: string; + } + + interface ListOptions extends CommonOptions { + name?: string; + } + } + + interface Event { + consul: Consul; + + /** + * Fires a new user event + */ + fire: { + (name: string, payload: string|Buffer, callback: Callback): void; + (name: string, callback: Callback): void; + (opts: Event.FireOptions, callback: Callback): void; + (name: string, payload: string|Buffer): Thenable; + (name: string): Thenable; + (opts: Event.FireOptions): Thenable; + }; + + /** + * Lists the most recent events an agent has seen + */ + list: { + (name: string, callback: Callback): void; + (opts: Event.ListOptions, callback: Callback): void; + (callback: Callback): void; + (name?: string): Thenable; + (opts?: Event.ListOptions): Thenable; + }; + } + + interface EventStatic { + new(consul: Consul): Event; + } + + namespace Health { + + interface NodeOptions extends CommonOptions { + node: string; + dc?: string; + } + + interface ChecksOptions extends CommonOptions { + service: string; + dc?: string; + } + + interface ServiceOptions extends CommonOptions { + service: string; + dc?: string; + tag?: string; + passing?: boolean; + } + + interface StateOptions extends CommonOptions { + state: string; + dc?: string; + } + } + + interface Health { + consul: Consul; + + /** + * Returns the health info of a node + */ + node: { + (node: string, callback: Callback): void; + (opts: Health.NodeOptions, callback: Callback): void; + (node: string): Thenable; + (opts: Health.NodeOptions): Thenable; + }; + + /** + * Returns the checks of a service + */ + checks: { + (service: string, callback: Callback): void; + (opts: Health.ChecksOptions, callback: Callback): void; + (service: string): Thenable; + (opts: Health.ChecksOptions): Thenable; + }; + + /** + * Returns the nodes and health info of a service + */ + service: { + (service: string, callback: Callback): void; + (opts: Health.ServiceOptions, callback: Callback): void; + (service: string): Thenable; + (opts: Health.ServiceOptions): Thenable; + }; + + /** + * Returns the checks in a given state + */ + state: { + (state: string, callback: Callback): void; + (opts: Health.StateOptions, callback: Callback): void; + (state: string): Thenable; + (opts: Health.StateOptions): Thenable; + }; + } + + interface HealthStatic { + new(consul: Consul): Health; + } + + namespace Kv { + + interface GetOptions extends CommonOptions { + key: string; + dc?: string; + recurse?: boolean; + index?: string; + wait?: string; + raw?: boolean; + buffer?: boolean; + } + + interface KeysOptions extends CommonOptions { + key: string; + dc?: string; + separator?: string; + } + + interface SetOptions extends CommonOptions { + key: string; + value: string|Buffer; + dc?: string; + flags?: number; + cas?: string; + acquire?: string; + release?: string; + } + + interface DelOptions extends CommonOptions { + key: string; + dc?: string; + recurse?: boolean; + cas?: string; + } + + interface DeleteOptions extends DelOptions {} + } + + interface Kv { + consul: Consul; + + /** + * Get + */ + get: { + (key: string, callback: Callback): void; + (opts: Kv.GetOptions, callback: Callback): void; + (key: string): Thenable; + (opts: Kv.GetOptions): Thenable; + }; + + /** + * Keys + */ + keys: { + (key: string, callback: Callback): void; + (opts: Kv.KeysOptions, callback: Callback): void; + (callback: Callback): void; + (key?: string): Thenable; + (opts?: Kv.KeysOptions): Thenable; + }; + + /** + * Set + */ + set: { + (key: string, value: string|Buffer, opts: Kv.SetOptions, callback: Callback): void; + (key: string, value: string|Buffer, callback: Callback): void; + (opts: Kv.SetOptions, callback: Callback): void; + (key: string, value: string|Buffer, opts: Kv.SetOptions): Thenable; + (key: string, value: string|Buffer): Thenable; + (opts: Kv.SetOptions): Thenable; + }; + + /** + * Delete + */ + del: { + (key: string, callback: Callback): void; + (opts: Kv.DelOptions, callback: Callback): void; + (key: string): Thenable; + (opts: Kv.DelOptions): Thenable; + }; + delete: { + (key: string, callback: Callback): void; + (opts: Kv.DeleteOptions, callback: Callback): void; + (key: string): Thenable; + (opts: Kv.DeleteOptions): Thenable; + }; + } + + interface KvStatic { + new(consul: Consul): Kv; + } + + namespace Lock { + + interface Options { + key: string; + session?: Object|string; + value?: string|Buffer; + lockwaittime?: string; + lockretrytime?: string; + } + } + + interface Lock extends NodeJS.EventEmitter { + consul: Consul; + + /** + * Acquire lock + */ + acquire(): void; + + /** + * Release lock + */ + release(): void; + } + + interface LockStatic { + new(consul: Consul, opts: Lock.Options): Lock; + } + + namespace Session { + + interface CreateOptions extends CommonOptions { + dc?: string; + lockdelay?: string; + name?: string; + node?: string; + checks?: string[]; + behavior?: string; + ttl?: string; + } + + interface DestroyOptions extends CommonOptions { + id: string; + dc?: string; + } + + interface InfoOptions extends CommonOptions { + id: string; + dc?: string; + } + + interface GetOptions extends InfoOptions {} + + interface NodeOptions extends CommonOptions { + node: string; + dc?: string; + } + + interface ListOptions extends CommonOptions { + dc?: string; + } + + interface RenewOptions extends CommonOptions { + id: string; + dc?: string; + } + } + + + interface Session { + consul: Consul; + + /** + * Creates a new session + */ + create: { + (opts: Session.CreateOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Session.CreateOptions): Thenable; + }; + + /** + * Destroys a given session + */ + destroy: { + (id: string, callback: Callback): void; + (opts: Session.DestroyOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Session.DestroyOptions): Thenable; + }; + + /** + * Queries a given session + */ + info: { + (id: string, callback: Callback): void; + (opts: Session.InfoOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Session.InfoOptions): Thenable; + }; + get: { + (id: string, callback: Callback): void; + (opts: Session.GetOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Session.GetOptions): Thenable; + }; + + /** + * Lists sessions belonging to a node + */ + node: { + (node: string, callback: Callback): void; + (opts: Session.NodeOptions, callback: Callback): void; + (node: string): Thenable; + (opts: Session.NodeOptions): Thenable; + }; + + /** + * Lists all the active sessions + */ + list: { + (opts: Session.ListOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Session.ListOptions): Thenable; + }; + + /** + * Renews a TTL-based session + */ + renew: { + (id: string, callback: Callback): void; + (opts: Session.RenewOptions, callback: Callback): void; + (id: string): Thenable; + (opts: Session.RenewOptions): Thenable; + }; + } + + interface SessionStatic { + new(consul: Consul): Session; + } + + namespace Status { + + interface LeaderOptions extends CommonOptions {} + + interface PeersOptions extends CommonOptions {} + } + + interface Status { + consul: Consul; + + /** + * Returns the current Raft leader. + */ + leader: { + (opts: Status.LeaderOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Status.LeaderOptions): Thenable; + }; + + /** + * Returns the current Raft peer set + */ + peers: { + (opts: Status.PeersOptions, callback: Callback): void; + (callback: Callback): void; + (opts?: Status.PeersOptions): Thenable; + }; + } + + interface StatusStatic { + new(consul: Consul): Status; + } + + namespace Watch { + + interface Options { + method: Function; + options?: CommonOptions; + } + } + + interface Watch extends NodeJS.EventEmitter { + consul: Consul; + + /** + * Is running + */ + isRunning(): boolean; + + /** + * Update time + */ + updateTime(): number; + + /** + * End watch + */ + end(): void; + } + + interface WatchStatic { + new(consul: Consul, opts: Watch.Options): Watch; + } + + interface ConsulOptions { + host?: string; + port?: string; + secure?: boolean; + ca?: string[]; + defaults?: CommonOptions; + promisify?: boolean|Function; + } + + interface Consul { + acl: Acl; + agent: Agent; + catalog: Catalog; + event: Event; + health: Health; + kv: Kv; + session: Session; + status: Status; + + /** + * Lock helper. + */ + lock(opts: Lock.Options): Lock; + + /** + * Watch helper. + */ + watch(opts: Watch.Options): Watch; + } + + interface ConsulStatic { + (opts?: ConsulOptions): Consul; + new (opts?: ConsulOptions): Consul; + + Acl: AclStatic; + Agent: AgentStatic; + Catalog: CatalogStatic; + Event: EventStatic; + Health: HealthStatic; + Kv: KvStatic; + Lock: LockStatic; + Session: SessionStatic; + Status: StatusStatic; + Watch: WatchStatic; + } + } + + let Consul: Consul.ConsulStatic; + + export = Consul; +}