UNPKG

6.11 kBTypeScriptView Raw
1/** @module connect */
2import { ConfigParams } from 'pip-services3-commons-node';
3/**
4 * Contains connection parameters to connect to external services.
5 * They are used together with credential parameters, but usually stored
6 * separately from more protected sensitive values.
7 *
8 * ### Configuration parameters ###
9 *
10 * - discovery_key: key to retrieve parameters from discovery service
11 * - protocol: connection protocol like http, https, tcp, udp
12 * - host: host name or IP address
13 * - port: port number
14 * - uri: resource URI or connection string with all parameters in it
15 *
16 * In addition to standard parameters ConnectionParams may contain any number of custom parameters
17 *
18 * @see [[https://pip-services3-node.github.io/pip-services3-commons-node/classes/config.configparams.html ConfigParams]]
19 * @see [[CredentialParams]]
20 * @see [[ConnectionResolver]]
21 * @see [[IDiscovery]]
22 *
23 * ### Example ###
24 *
25 * Example ConnectionParams object usage:
26 *
27 * let connection = ConnectionParams.fromTuples(
28 * "protocol", "http",
29 * "host", "10.1.1.100",
30 * "port", "8080",
31 * "cluster", "mycluster"
32 * );
33 *
34 * let host = connection.getHost(); // Result: "10.1.1.100"
35 * let port = connection.getPort(); // Result: 8080
36 * let cluster = connection.getAsNullableString("cluster"); // Result: "mycluster"
37 */
38export declare class ConnectionParams extends ConfigParams {
39 /**
40 * Creates a new connection parameters and fills it with values.
41 *
42 * @param values (optional) an object to be converted into key-value pairs to initialize this connection.
43 */
44 constructor(values?: any);
45 /**
46 * Checks if these connection parameters shall be retrieved from [[DiscoveryService]].
47 * The connection parameters are redirected to [[DiscoveryService]] when discovery_key parameter is set.
48 *
49 * @returns true if connection shall be retrieved from [[DiscoveryService]]
50 *
51 * @see [[getDiscoveryKey]]
52 */
53 useDiscovery(): boolean;
54 /**
55 * Gets the key to retrieve this connection from [[DiscoveryService]].
56 * If this key is null, than all parameters are already present.
57 *
58 * @returns the discovery key to retrieve connection.
59 *
60 * @see [[useDiscovery]]
61 */
62 getDiscoveryKey(): string;
63 /**
64 * Sets the key to retrieve these parameters from [[DiscoveryService]].
65 *
66 * @param value a new key to retrieve connection.
67 */
68 setDiscoveryKey(value: string): void;
69 /**
70 * Gets the connection protocol.
71 *
72 * @returns the connection protocol or the default value if it's not set.
73 */
74 getProtocol(): string;
75 /**
76 * Gets the connection protocol with default value.
77 *
78 * @param defaultValue (optional) the default protocol
79 * @returns the connection protocol or the default value if it's not set.
80 */
81 getProtocolWithDefault(defaultValue: string): string;
82 /**
83 * Sets the connection protocol.
84 *
85 * @param value a new connection protocol.
86 */
87 setProtocol(value: string): void;
88 /**
89 * Gets the host name or IP address.
90 *
91 * @returns the host name or IP address.
92 */
93 getHost(): string;
94 /**
95 * Sets the host name or IP address.
96 *
97 * @param value a new host name or IP address.
98 */
99 setHost(value: string): void;
100 /**
101 * Gets the port number.
102 *
103 * @returns the port number.
104 */
105 getPort(): number;
106 /**
107 * Gets the port number with default value.
108 *
109 * @param defaultPort a default port number.
110 * @returns the port number.
111 */
112 getPortWithDefault(defaultPort: number): number;
113 /**
114 * Sets the port number.
115 *
116 * @param value a new port number.
117 *
118 * @see [[getHost]]
119 */
120 setPort(value: number): void;
121 /**
122 * Gets the resource URI or connection string.
123 * Usually it includes all connection parameters in it.
124 *
125 * @returns the resource URI or connection string.
126 */
127 getUri(): string;
128 /**
129 * Sets the resource URI or connection string.
130 *
131 * @param value a new resource URI or connection string.
132 */
133 setUri(value: string): void;
134 /**
135 * Creates a new ConnectionParams object filled with key-value pairs serialized as a string.
136 *
137 * @param line a string with serialized key-value pairs as "key1=value1;key2=value2;..."
138 * Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"
139 * @returns a new ConnectionParams object.
140 *
141 * @see [[StringValueMap.fromString]]
142 */
143 static fromString(line: string): ConnectionParams;
144 /**
145 * Creates a new ConnectionParams object filled with provided key-value pairs called tuples.
146 * Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs.
147 *
148 * @param tuples the tuples to fill a new ConnectionParams object.
149 * @returns a new ConnectionParams object.
150 */
151 static fromTuples(...tuples: any[]): ConnectionParams;
152 /**
153 * Retrieves all ConnectionParams from configuration parameters
154 * from "connections" section. If "connection" section is present instead,
155 * than it returns a list with only one ConnectionParams.
156 *
157 * @param config a configuration parameters to retrieve connections
158 * @returns a list of retrieved ConnectionParams
159 */
160 static manyFromConfig(config: ConfigParams): ConnectionParams[];
161 /**
162 * Retrieves a single ConnectionParams from configuration parameters
163 * from "connection" section. If "connections" section is present instead,
164 * then is returns only the first connection element.
165 *
166 * @param config ConnectionParams, containing a section named "connection(s)".
167 * @returns the generated ConnectionParams object.
168 *
169 * @see [[manyFromConfig]]
170 */
171 static fromConfig(config: ConfigParams): ConnectionParams;
172}