-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsul-service-wrapper.d.ts
98 lines (86 loc) · 2.45 KB
/
consul-service-wrapper.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/// <reference types="consul" />
import * as Consul from 'consul'
/**
* Factory function for creating a new ConsulService
* @param options options you would pass to the official Consul client
*/
declare function SSConsul(
options?: Consul.ConsulOptions
): SSConsul.ConsulService
declare namespace SSConsul {
/**
* ConsulService acts as a wrapper around the "consul" packge allowing you to
* easly reigster a service and get dependent services from Consul
*/
interface ConsulService {
/**
* connection options supported by the official
* consul npm package
*/
consulSettings: Consul.ConsulOptions
/**
* The consul instance
*/
consul: Consul.Consul
/**
* Register a service with consul
* Example:
*
* {
* name: 'redis,
* port: 6379,
* tags: ['stable'],
* address: '127.0.0.1',
* id: 'redis'
* }
*/
registerService(service: SSConsul.Service): Promise<void>
/**
* Fetches a service by name, if more than one is available
* a random one is returned
*/
getService(serviceName: string): Promise<object>
/**
* Fetches a service by tag, if more than one is available
* a random one is returned
* Example:
*
* consul.getServiceBytag('redis', 'stable')
*/
getServiceByTag(serviceName: string, tag: string): Promise<object>
/**
* Fetches a service(s) associated with a set of tags. If the tags
* do not match all of the tags a service is associated with, then it
* will not be returned.
* Example:
*
* // returns any nodes that match the tags: stable && testing.
* consul.getServiceByTag('redis', ['stable', 'testing'])
*/
getServiceByTag(serviceName: string, tags: Array<string>) : Promise<object>
/**
* Returns a uri for a service
*/
formatUri(service: object): string
}
/**
* Options for registering a service with Consul
*/
interface Service {
/** The name of the service **/
name: string
/** The port the service runs on **/
port: number
/** The tags to register the service with **/
tags?: Array<string>
/** The id to register the service with (defaults to service name) **/
id?: string
/** The address of the service **/
address?: string
}
/**
* Validates the configuration for a service
*/
export function validateServiceConfig(configuration: Service): Service
}
export = SSConsul