node-consul-service 1.0.44 → 1.0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +23 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +22 -3
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('consul');
|
|
3
|
+
var Consul = require('consul');
|
|
4
4
|
var require$$1 = require('util');
|
|
5
5
|
var stream = require('stream');
|
|
6
6
|
var require$$1$1 = require('path');
|
|
@@ -14,10 +14,29 @@ var zlib = require('zlib');
|
|
|
14
14
|
var events = require('events');
|
|
15
15
|
|
|
16
16
|
// src/lib/client.ts
|
|
17
|
+
let consulClient = null;
|
|
18
|
+
function initClient(config) {
|
|
19
|
+
var _a;
|
|
20
|
+
consulClient = new Consul({
|
|
21
|
+
host: config.host,
|
|
22
|
+
port: config.port,
|
|
23
|
+
secure: (_a = config.secure) !== null && _a !== void 0 ? _a : true,
|
|
24
|
+
});
|
|
25
|
+
// optional test connection
|
|
26
|
+
consulClient.agent.self((err) => {
|
|
27
|
+
if (err) {
|
|
28
|
+
console.error("❌ Failed to connect to Consul:", err.message);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
console.log("✅ Connected to Consul successfully");
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
17
35
|
function getClient() {
|
|
18
|
-
{
|
|
36
|
+
if (!consulClient) {
|
|
19
37
|
throw new Error("Consul client not initialized. Call initClient() first.");
|
|
20
38
|
}
|
|
39
|
+
return consulClient;
|
|
21
40
|
}
|
|
22
41
|
|
|
23
42
|
const registeredServices = new Set();
|
|
@@ -19156,9 +19175,11 @@ exports.DataLinkError = DataLinkError;
|
|
|
19156
19175
|
exports.callService = callService;
|
|
19157
19176
|
exports.dataLink = dataLink;
|
|
19158
19177
|
exports.deregisterService = deregisterService;
|
|
19178
|
+
exports.getClient = getClient;
|
|
19159
19179
|
exports.getRandomServiceInstance = getRandomServiceInstance;
|
|
19160
19180
|
exports.getServiceInstances = getServiceInstances;
|
|
19161
19181
|
exports.getServiceUrl = getServiceUrl;
|
|
19182
|
+
exports.initClient = initClient;
|
|
19162
19183
|
exports.listServices = listServices;
|
|
19163
19184
|
exports.registerService = registerService;
|
|
19164
19185
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import 'consul';
|
|
1
|
+
import Consul from 'consul';
|
|
2
2
|
import require$$1 from 'util';
|
|
3
3
|
import stream, { Readable } from 'stream';
|
|
4
4
|
import require$$1$1 from 'path';
|
|
@@ -12,10 +12,29 @@ import zlib from 'zlib';
|
|
|
12
12
|
import { EventEmitter } from 'events';
|
|
13
13
|
|
|
14
14
|
// src/lib/client.ts
|
|
15
|
+
let consulClient = null;
|
|
16
|
+
function initClient(config) {
|
|
17
|
+
var _a;
|
|
18
|
+
consulClient = new Consul({
|
|
19
|
+
host: config.host,
|
|
20
|
+
port: config.port,
|
|
21
|
+
secure: (_a = config.secure) !== null && _a !== void 0 ? _a : true,
|
|
22
|
+
});
|
|
23
|
+
// optional test connection
|
|
24
|
+
consulClient.agent.self((err) => {
|
|
25
|
+
if (err) {
|
|
26
|
+
console.error("❌ Failed to connect to Consul:", err.message);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.log("✅ Connected to Consul successfully");
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
15
33
|
function getClient() {
|
|
16
|
-
{
|
|
34
|
+
if (!consulClient) {
|
|
17
35
|
throw new Error("Consul client not initialized. Call initClient() first.");
|
|
18
36
|
}
|
|
37
|
+
return consulClient;
|
|
19
38
|
}
|
|
20
39
|
|
|
21
40
|
const registeredServices = new Set();
|
|
@@ -19150,5 +19169,5 @@ async function dataLink(data, schema) {
|
|
|
19150
19169
|
return isArray ? result : result[0];
|
|
19151
19170
|
}
|
|
19152
19171
|
|
|
19153
|
-
export { DataLinkError, callService, dataLink, deregisterService, getRandomServiceInstance, getServiceInstances, getServiceUrl, listServices, registerService };
|
|
19172
|
+
export { DataLinkError, callService, dataLink, deregisterService, getClient, getRandomServiceInstance, getServiceInstances, getServiceUrl, initClient, listServices, registerService };
|
|
19154
19173
|
//# sourceMappingURL=index.esm.js.map
|