UNPKG

6.71 kBTypeScriptView Raw
1import { IReferenceable } from 'pip-services3-commons-node';
2import { IReferences } from 'pip-services3-commons-node';
3import { IConfigurable } from 'pip-services3-commons-node';
4import { ConfigParams } from 'pip-services3-commons-node';
5import { CredentialParams } from '../auth/CredentialParams';
6import { CredentialResolver } from '../auth/CredentialResolver';
7import { ConnectionParams } from './ConnectionParams';
8import { ConnectionResolver } from './ConnectionResolver';
9/**
10 * Helper class that resolves connection and credential parameters,
11 * validates them and generates connection options.
12 *
13 * ### Configuration parameters ###
14 *
15 * - connection(s):
16 * - discovery_key: (optional) a key to retrieve the connection from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]]
17 * - protocol: communication protocol
18 * - host: host name or IP address
19 * - port: port number
20 * - uri: resource URI or connection string with all parameters in it
21 * - credential(s):
22 * - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html ICredentialStore]]
23 * - username: user name
24 * - password: user password
25 *
26 * ### References ###
27 *
28 * - <code>\*:discovery:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connections
29 * - <code>\*:credential-store:\*:\*:1.0</code> (optional) Credential stores to resolve credentials
30 */
31export declare class CompositeConnectionResolver implements IReferenceable, IConfigurable {
32 /**
33 * The connection options
34 */
35 protected _options: ConfigParams;
36 /**
37 * The connections resolver.
38 */
39 protected _connectionResolver: ConnectionResolver;
40 /**
41 * The credentials resolver.
42 */
43 protected _credentialResolver: CredentialResolver;
44 /**
45 * The cluster support (multiple connections)
46 */
47 protected _clusterSupported: boolean;
48 /**
49 * The default protocol
50 */
51 protected _defaultProtocol: string;
52 /**
53 * The default port number
54 */
55 protected _defaultPort: number;
56 /**
57 * The list of supported protocols
58 */
59 protected _supportedProtocols: string[];
60 /**
61 * Configures component by passing configuration parameters.
62 *
63 * @param config configuration parameters to be set.
64 */
65 configure(config: ConfigParams): void;
66 /**
67 * Sets references to dependent components.
68 *
69 * @param references references to locate the component dependencies.
70 */
71 setReferences(references: IReferences): void;
72 /**
73 * Resolves connection options from connection and credential parameters.
74 *
75 * @param correlationId (optional) transaction id to trace execution through call chain.
76 * @param callback callback function that receives resolved options or error.
77 */
78 resolve(correlationId: string, callback: (err: any, options: ConfigParams) => void): void;
79 /**
80 * Composes Composite connection options from connection and credential parameters.
81 *
82 * @param correlationId (optional) transaction id to trace execution through call chain.
83 * @param connections connection parameters
84 * @param credential credential parameters
85 * @param parameters optional parameters
86 * @param callback callback function that receives resolved options or error.
87 */
88 compose(correlationId: string, connections: ConnectionParams[], credential: CredentialParams, parameters: ConfigParams, callback: (err: any, options: any) => void): void;
89 /**
90 * Validates connection parameters.
91 * This method can be overriden in child classes.
92 *
93 * @param correlationId (optional) transaction id to trace execution through call chain.
94 * @param connection connection parameters to be validated
95 * @returns error or <code>null</code> if validation was successful
96 */
97 protected validateConnection(correlationId: string, connection: ConnectionParams): any;
98 /**
99 * Validates credential parameters.
100 * This method can be overriden in child classes.
101 *
102 * @param correlationId (optional) transaction id to trace execution through call chain.
103 * @param credential credential parameters to be validated
104 * @returns error or <code>null</code> if validation was successful
105 */
106 protected validateCredential(correlationId: string, credential: CredentialParams): any;
107 /**
108 * Composes connection and credential parameters into connection options.
109 * This method can be overriden in child classes.
110 *
111 * @param connections a list of connection parameters
112 * @param credential credential parameters
113 * @param parameters optional parameters
114 * @returns a composed connection options.
115 */
116 protected composeOptions(connections: ConnectionParams[], credential: CredentialParams, parameters: ConfigParams): ConfigParams;
117 /**
118 * Merges connection options with connection parameters
119 * This method can be overriden in child classes.
120 *
121 * @param options connection options
122 * @param connection connection parameters to be merged
123 * @returns merged connection options.
124 */
125 protected mergeConnection(options: ConfigParams, connection: ConnectionParams): ConfigParams;
126 /**
127 * Merges connection options with credential parameters
128 * This method can be overriden in child classes.
129 *
130 * @param options connection options
131 * @param credential credential parameters to be merged
132 * @returns merged connection options.
133 */
134 protected mergeCredential(options: ConfigParams, credential: CredentialParams): ConfigParams;
135 /**
136 * Merges connection options with optional parameters
137 * This method can be overriden in child classes.
138 *
139 * @param options connection options
140 * @param parameters optional parameters to be merged
141 * @returns merged connection options.
142 */
143 protected mergeOptional(options: ConfigParams, parameters: ConfigParams): ConfigParams;
144 /**
145 * Finalize merged options
146 * This method can be overriden in child classes.
147 *
148 * @param options connection options
149 * @returns finalized connection options
150 */
151 protected finalizeOptions(options: ConfigParams): ConfigParams;
152}