From 89f124421574994f16ec28f5ee5c3855686389ea Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sun, 7 Feb 2016 15:48:39 +0500 Subject: [PATCH] consul: added definitions --- consul/consul.d.ts | 1034 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1034 insertions(+) create mode 100644 consul/consul.d.ts 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; +}