@nsshunt/stsobservability 1.0.140 → 1.0.142
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 +12 -3766
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13 -3767
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -10
- package/types/index.d.ts +0 -12
- package/types/index.d.ts.map +1 -1
- package/types/instrumentation/instruments/instrumentTimerGauge.d.ts.map +1 -1
- package/types/globalServiceDefinitions.d.ts +0 -58
- package/types/globalServiceDefinitions.d.ts.map +0 -1
- package/types/publish/agentinstrumentcontroller.d.ts +0 -10
- package/types/publish/agentinstrumentcontroller.d.ts.map +0 -1
- package/types/publish/commonTypes.d.ts +0 -82
- package/types/publish/commonTypes.d.ts.map +0 -1
- package/types/publish/middleware/requestLoggerMiddleware.d.ts +0 -32
- package/types/publish/middleware/requestLoggerMiddleware.d.ts.map +0 -1
- package/types/publish/publishInstrumentController.d.ts +0 -42
- package/types/publish/publishInstrumentController.d.ts.map +0 -1
- package/types/publish/publishInstruments.d.ts +0 -19
- package/types/publish/publishInstruments.d.ts.map +0 -1
- package/types/publish/publishers/publishTransportRESTServer.d.ts +0 -9
- package/types/publish/publishers/publishTransportRESTServer.d.ts.map +0 -1
- package/types/publish/stsPluginKeys.d.ts +0 -2
- package/types/publish/stsPluginKeys.d.ts.map +0 -1
- package/types/subscribe/commonTypes.d.ts +0 -163
- package/types/subscribe/commonTypes.d.ts.map +0 -1
- package/types/subscribe/observabilitymodelutils.d.ts +0 -48
- package/types/subscribe/observabilitymodelutils.d.ts.map +0 -1
- package/types/subscribe/observabilityrestapisubscriber.d.ts +0 -9
- package/types/subscribe/observabilityrestapisubscriber.d.ts.map +0 -1
- package/types/subscribe/observabilitysocketiosubscriber.d.ts +0 -12
- package/types/subscribe/observabilitysocketiosubscriber.d.ts.map +0 -1
- package/types/subscribe/observabilitysubscriptionmanager.d.ts +0 -33
- package/types/subscribe/observabilitysubscriptionmanager.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const _cloneDeep = require("lodash.clonedeep");
|
|
4
4
|
const isNode = require("detect-node");
|
|
5
|
-
const stsutils = require("@nsshunt/stsutils");
|
|
6
|
-
const tinyEmitter = require("tiny-emitter");
|
|
7
|
-
const axios = require("axios");
|
|
8
|
-
const vue = require("vue");
|
|
9
5
|
var Gauge = /* @__PURE__ */ ((Gauge2) => {
|
|
10
6
|
Gauge2["ACTIVE_REQUEST_GAUGE"] = "a";
|
|
11
7
|
Gauge2["AUTHENTICATION_COUNT_GAUGE"] = "b";
|
|
@@ -864,12 +860,12 @@ class InstrumentLog extends InstrumentBase {
|
|
|
864
860
|
this.#useLatestMessages = useLatestMessages;
|
|
865
861
|
return this;
|
|
866
862
|
}
|
|
867
|
-
WithConsoleLogging(
|
|
868
|
-
this.#consoleLogging =
|
|
863
|
+
WithConsoleLogging(consoleLogging) {
|
|
864
|
+
this.#consoleLogging = consoleLogging;
|
|
869
865
|
return this;
|
|
870
866
|
}
|
|
871
|
-
WithInstrumentLogging(
|
|
872
|
-
this.#instrumentLogging =
|
|
867
|
+
WithInstrumentLogging(instrumentLogging) {
|
|
868
|
+
this.#instrumentLogging = instrumentLogging;
|
|
873
869
|
return this;
|
|
874
870
|
}
|
|
875
871
|
get MaxSize() {
|
|
@@ -1041,28 +1037,16 @@ class InstrumentTimerGauge extends InstrumentBase {
|
|
|
1041
1037
|
this.#pauseVal = 0;
|
|
1042
1038
|
}
|
|
1043
1039
|
Reset() {
|
|
1044
|
-
|
|
1045
|
-
this.#start = performance.now();
|
|
1046
|
-
} else {
|
|
1047
|
-
this.#start = performance.now();
|
|
1048
|
-
}
|
|
1040
|
+
this.#start = performance.now();
|
|
1049
1041
|
}
|
|
1050
1042
|
#GetVal() {
|
|
1051
1043
|
if (this.#pauseVal !== 0) {
|
|
1052
1044
|
return this.GetNumber(this.#pauseVal);
|
|
1053
1045
|
}
|
|
1054
|
-
|
|
1055
|
-
return this.GetNumber(performance.now() - this.#start);
|
|
1056
|
-
} else {
|
|
1057
|
-
return this.GetNumber(performance.now() - this.#start);
|
|
1058
|
-
}
|
|
1046
|
+
return this.GetNumber(performance.now() - this.#start);
|
|
1059
1047
|
}
|
|
1060
1048
|
#SetVal(updatedValue) {
|
|
1061
|
-
|
|
1062
|
-
this.#start = performance.now() - updatedValue;
|
|
1063
|
-
} else {
|
|
1064
|
-
this.#start = performance.now() - updatedValue;
|
|
1065
|
-
}
|
|
1049
|
+
this.#start = performance.now() - updatedValue;
|
|
1066
1050
|
}
|
|
1067
1051
|
get start() {
|
|
1068
1052
|
return this.#start;
|
|
@@ -1106,14 +1090,14 @@ var hasRequiredTimsort$1;
|
|
|
1106
1090
|
function requireTimsort$1() {
|
|
1107
1091
|
if (hasRequiredTimsort$1) return timsort$1;
|
|
1108
1092
|
hasRequiredTimsort$1 = 1;
|
|
1109
|
-
(function(
|
|
1093
|
+
(function(exports$1) {
|
|
1110
1094
|
(function(global, factory) {
|
|
1111
1095
|
{
|
|
1112
|
-
factory(
|
|
1096
|
+
factory(exports$1);
|
|
1113
1097
|
}
|
|
1114
|
-
})(timsort$1, function(
|
|
1115
|
-
|
|
1116
|
-
|
|
1098
|
+
})(timsort$1, function(exports$12) {
|
|
1099
|
+
exports$12.__esModule = true;
|
|
1100
|
+
exports$12.sort = sort;
|
|
1117
1101
|
function _classCallCheck(instance, Constructor) {
|
|
1118
1102
|
if (!(instance instanceof Constructor)) {
|
|
1119
1103
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -2192,3729 +2176,10 @@ function StopInstruments(instruments) {
|
|
|
2192
2176
|
}
|
|
2193
2177
|
}
|
|
2194
2178
|
}
|
|
2195
|
-
var TransportType = /* @__PURE__ */ ((TransportType2) => {
|
|
2196
|
-
TransportType2[TransportType2["none"] = 0] = "none";
|
|
2197
|
-
TransportType2[TransportType2["IPC"] = 1] = "IPC";
|
|
2198
|
-
TransportType2[TransportType2["websocket"] = 2] = "websocket";
|
|
2199
|
-
TransportType2[TransportType2["RESTAPI"] = 4] = "RESTAPI";
|
|
2200
|
-
TransportType2[TransportType2["redis"] = 8] = "redis";
|
|
2201
|
-
TransportType2[TransportType2["kafka"] = 16] = "kafka";
|
|
2202
|
-
TransportType2[TransportType2["influxdb"] = 32] = "influxdb";
|
|
2203
|
-
TransportType2[TransportType2["prometheus"] = 64] = "prometheus";
|
|
2204
|
-
TransportType2[TransportType2["gRPC"] = 128] = "gRPC";
|
|
2205
|
-
TransportType2[TransportType2["unixsocket"] = 256] = "unixsocket";
|
|
2206
|
-
TransportType2[TransportType2["socketio"] = 512] = "socketio";
|
|
2207
|
-
TransportType2[TransportType2["otelcollector"] = 1024] = "otelcollector";
|
|
2208
|
-
TransportType2[TransportType2["messageport"] = 2048] = "messageport";
|
|
2209
|
-
TransportType2[TransportType2["jsonrpc"] = 4096] = "jsonrpc";
|
|
2210
|
-
TransportType2[TransportType2["postgresql"] = 8192] = "postgresql";
|
|
2211
|
-
TransportType2[TransportType2["grafanaloki"] = 16384] = "grafanaloki";
|
|
2212
|
-
TransportType2[TransportType2["logstash"] = 32768] = "logstash";
|
|
2213
|
-
TransportType2[TransportType2["fluentbit"] = 65536] = "fluentbit";
|
|
2214
|
-
TransportType2[TransportType2["fluentd"] = 131072] = "fluentd";
|
|
2215
|
-
TransportType2[TransportType2["inmemory"] = 262144] = "inmemory";
|
|
2216
|
-
return TransportType2;
|
|
2217
|
-
})(TransportType || {});
|
|
2218
|
-
function GetTransportMode(transport) {
|
|
2219
|
-
let trans = 0;
|
|
2220
|
-
try {
|
|
2221
|
-
transport.split("|").forEach((item) => {
|
|
2222
|
-
switch (item) {
|
|
2223
|
-
case "IPC":
|
|
2224
|
-
trans |= 1;
|
|
2225
|
-
break;
|
|
2226
|
-
case "websocket":
|
|
2227
|
-
trans |= 2;
|
|
2228
|
-
break;
|
|
2229
|
-
case "RESTAPI":
|
|
2230
|
-
trans |= 4;
|
|
2231
|
-
break;
|
|
2232
|
-
case "redis":
|
|
2233
|
-
trans |= 8;
|
|
2234
|
-
break;
|
|
2235
|
-
case "kafka":
|
|
2236
|
-
trans |= 16;
|
|
2237
|
-
break;
|
|
2238
|
-
case "influxdb":
|
|
2239
|
-
trans |= 32;
|
|
2240
|
-
break;
|
|
2241
|
-
case "prometheus":
|
|
2242
|
-
trans |= 64;
|
|
2243
|
-
break;
|
|
2244
|
-
case "gRPC":
|
|
2245
|
-
trans |= 128;
|
|
2246
|
-
break;
|
|
2247
|
-
case "unixsocket":
|
|
2248
|
-
trans |= 256;
|
|
2249
|
-
break;
|
|
2250
|
-
case "socketio":
|
|
2251
|
-
trans |= 512;
|
|
2252
|
-
break;
|
|
2253
|
-
case "otelcollector":
|
|
2254
|
-
trans |= 1024;
|
|
2255
|
-
break;
|
|
2256
|
-
case "messageport":
|
|
2257
|
-
trans |= 2048;
|
|
2258
|
-
break;
|
|
2259
|
-
case "jsonrpc":
|
|
2260
|
-
trans |= 4096;
|
|
2261
|
-
break;
|
|
2262
|
-
case "postgresql":
|
|
2263
|
-
trans |= 8192;
|
|
2264
|
-
break;
|
|
2265
|
-
case "grafanaloki":
|
|
2266
|
-
trans |= 16384;
|
|
2267
|
-
break;
|
|
2268
|
-
case "logstash":
|
|
2269
|
-
trans |= 32768;
|
|
2270
|
-
break;
|
|
2271
|
-
case "fluentbit":
|
|
2272
|
-
trans |= 65536;
|
|
2273
|
-
break;
|
|
2274
|
-
case "fluentd":
|
|
2275
|
-
trans |= 131072;
|
|
2276
|
-
break;
|
|
2277
|
-
case "inmemory":
|
|
2278
|
-
trans |= 262144;
|
|
2279
|
-
break;
|
|
2280
|
-
}
|
|
2281
|
-
});
|
|
2282
|
-
} catch (error) {
|
|
2283
|
-
throw new Error(`GetTransportMode(): Error: [${error}]`);
|
|
2284
|
-
}
|
|
2285
|
-
return trans;
|
|
2286
|
-
}
|
|
2287
|
-
var InstrumentPayloadType = /* @__PURE__ */ ((InstrumentPayloadType2) => {
|
|
2288
|
-
InstrumentPayloadType2["agent"] = "agent";
|
|
2289
|
-
InstrumentPayloadType2["service"] = "service";
|
|
2290
|
-
return InstrumentPayloadType2;
|
|
2291
|
-
})(InstrumentPayloadType || {});
|
|
2292
|
-
var RequestLoggerMiddlewareEventName = /* @__PURE__ */ ((RequestLoggerMiddlewareEventName2) => {
|
|
2293
|
-
RequestLoggerMiddlewareEventName2["UpdateInstrument_AR_DEC"] = "UpdateInstrument_AR_DEC";
|
|
2294
|
-
RequestLoggerMiddlewareEventName2["UpdateInstrument_AR_INC"] = "UpdateInstrument_AR_INC";
|
|
2295
|
-
RequestLoggerMiddlewareEventName2["UpdateInstrument_RC_INC"] = "UpdateInstrument_RC_INC";
|
|
2296
|
-
RequestLoggerMiddlewareEventName2["UpdateInstrument_V_INC"] = "UpdateInstrument_V_INC";
|
|
2297
|
-
RequestLoggerMiddlewareEventName2["UpdateInstrument_DH_VAL"] = "UpdateInstrument_DH_VAL";
|
|
2298
|
-
RequestLoggerMiddlewareEventName2["UpdateInstrument_D_VAL"] = "UpdateInstrument_D_VAL";
|
|
2299
|
-
return RequestLoggerMiddlewareEventName2;
|
|
2300
|
-
})(RequestLoggerMiddlewareEventName || {});
|
|
2301
|
-
class RequestLoggerMiddleware extends stsutils.STSOptionsBase {
|
|
2302
|
-
#tinyEmitter = new tinyEmitter.TinyEmitter();
|
|
2303
|
-
constructor(options) {
|
|
2304
|
-
super(options);
|
|
2305
|
-
}
|
|
2306
|
-
get options() {
|
|
2307
|
-
return super.options;
|
|
2308
|
-
}
|
|
2309
|
-
on(eventName, callBackFn) {
|
|
2310
|
-
this.#tinyEmitter.on(eventName, callBackFn);
|
|
2311
|
-
}
|
|
2312
|
-
#RequestCompleted = (start) => {
|
|
2313
|
-
this.#tinyEmitter.emit(
|
|
2314
|
-
"UpdateInstrument_AR_DEC"
|
|
2315
|
-
/* UpdateInstrument_AR_DEC */
|
|
2316
|
-
);
|
|
2317
|
-
let timeInMs = 0;
|
|
2318
|
-
const end = process.hrtime(start);
|
|
2319
|
-
timeInMs = (end[0] * 1e9 + end[1]) / 1e6;
|
|
2320
|
-
timeInMs = parseFloat(timeInMs.toFixed(4));
|
|
2321
|
-
this.#tinyEmitter.emit("UpdateInstrument_DH_VAL", timeInMs);
|
|
2322
|
-
this.#tinyEmitter.emit("UpdateInstrument_D_VAL", timeInMs);
|
|
2323
|
-
};
|
|
2324
|
-
// https://stackoverflow.com/questions/18031839/how-to-use-process-hrtime-to-get-execution-time-of-async-function/18031945
|
|
2325
|
-
/**
|
|
2326
|
-
* Use with .bind(class instance).
|
|
2327
|
-
* Example;
|
|
2328
|
-
* ---
|
|
2329
|
-
* `let requestLoggerMiddleware = new RequestLoggerMiddleware();
|
|
2330
|
-
* app.use(requestLoggerMiddleware.Middleware.bind(requestLoggerMiddleware));`
|
|
2331
|
-
* @param {*} req
|
|
2332
|
-
* @param {*} res
|
|
2333
|
-
* @param {*} next
|
|
2334
|
-
* @returns
|
|
2335
|
-
*/
|
|
2336
|
-
Middleware = async (req, res, next) => {
|
|
2337
|
-
if (this.options.ignoresocketio && req.originalUrl.includes("socket.io")) {
|
|
2338
|
-
return;
|
|
2339
|
-
}
|
|
2340
|
-
const start = process.hrtime();
|
|
2341
|
-
this.#tinyEmitter.emit(
|
|
2342
|
-
"UpdateInstrument_AR_INC"
|
|
2343
|
-
/* UpdateInstrument_AR_INC */
|
|
2344
|
-
);
|
|
2345
|
-
this.#tinyEmitter.emit(
|
|
2346
|
-
"UpdateInstrument_RC_INC"
|
|
2347
|
-
/* UpdateInstrument_RC_INC */
|
|
2348
|
-
);
|
|
2349
|
-
this.#tinyEmitter.emit(
|
|
2350
|
-
"UpdateInstrument_V_INC"
|
|
2351
|
-
/* UpdateInstrument_V_INC */
|
|
2352
|
-
);
|
|
2353
|
-
req.on("aborted", () => {
|
|
2354
|
-
});
|
|
2355
|
-
req.on("close", () => {
|
|
2356
|
-
this.#RequestCompleted(start);
|
|
2357
|
-
});
|
|
2358
|
-
req.on("end", () => {
|
|
2359
|
-
});
|
|
2360
|
-
res.on("finish", () => {
|
|
2361
|
-
});
|
|
2362
|
-
next();
|
|
2363
|
-
};
|
|
2364
|
-
}
|
|
2365
|
-
var ansiStyles = { exports: {} };
|
|
2366
|
-
var colorName;
|
|
2367
|
-
var hasRequiredColorName;
|
|
2368
|
-
function requireColorName() {
|
|
2369
|
-
if (hasRequiredColorName) return colorName;
|
|
2370
|
-
hasRequiredColorName = 1;
|
|
2371
|
-
colorName = {
|
|
2372
|
-
"aliceblue": [240, 248, 255],
|
|
2373
|
-
"antiquewhite": [250, 235, 215],
|
|
2374
|
-
"aqua": [0, 255, 255],
|
|
2375
|
-
"aquamarine": [127, 255, 212],
|
|
2376
|
-
"azure": [240, 255, 255],
|
|
2377
|
-
"beige": [245, 245, 220],
|
|
2378
|
-
"bisque": [255, 228, 196],
|
|
2379
|
-
"black": [0, 0, 0],
|
|
2380
|
-
"blanchedalmond": [255, 235, 205],
|
|
2381
|
-
"blue": [0, 0, 255],
|
|
2382
|
-
"blueviolet": [138, 43, 226],
|
|
2383
|
-
"brown": [165, 42, 42],
|
|
2384
|
-
"burlywood": [222, 184, 135],
|
|
2385
|
-
"cadetblue": [95, 158, 160],
|
|
2386
|
-
"chartreuse": [127, 255, 0],
|
|
2387
|
-
"chocolate": [210, 105, 30],
|
|
2388
|
-
"coral": [255, 127, 80],
|
|
2389
|
-
"cornflowerblue": [100, 149, 237],
|
|
2390
|
-
"cornsilk": [255, 248, 220],
|
|
2391
|
-
"crimson": [220, 20, 60],
|
|
2392
|
-
"cyan": [0, 255, 255],
|
|
2393
|
-
"darkblue": [0, 0, 139],
|
|
2394
|
-
"darkcyan": [0, 139, 139],
|
|
2395
|
-
"darkgoldenrod": [184, 134, 11],
|
|
2396
|
-
"darkgray": [169, 169, 169],
|
|
2397
|
-
"darkgreen": [0, 100, 0],
|
|
2398
|
-
"darkgrey": [169, 169, 169],
|
|
2399
|
-
"darkkhaki": [189, 183, 107],
|
|
2400
|
-
"darkmagenta": [139, 0, 139],
|
|
2401
|
-
"darkolivegreen": [85, 107, 47],
|
|
2402
|
-
"darkorange": [255, 140, 0],
|
|
2403
|
-
"darkorchid": [153, 50, 204],
|
|
2404
|
-
"darkred": [139, 0, 0],
|
|
2405
|
-
"darksalmon": [233, 150, 122],
|
|
2406
|
-
"darkseagreen": [143, 188, 143],
|
|
2407
|
-
"darkslateblue": [72, 61, 139],
|
|
2408
|
-
"darkslategray": [47, 79, 79],
|
|
2409
|
-
"darkslategrey": [47, 79, 79],
|
|
2410
|
-
"darkturquoise": [0, 206, 209],
|
|
2411
|
-
"darkviolet": [148, 0, 211],
|
|
2412
|
-
"deeppink": [255, 20, 147],
|
|
2413
|
-
"deepskyblue": [0, 191, 255],
|
|
2414
|
-
"dimgray": [105, 105, 105],
|
|
2415
|
-
"dimgrey": [105, 105, 105],
|
|
2416
|
-
"dodgerblue": [30, 144, 255],
|
|
2417
|
-
"firebrick": [178, 34, 34],
|
|
2418
|
-
"floralwhite": [255, 250, 240],
|
|
2419
|
-
"forestgreen": [34, 139, 34],
|
|
2420
|
-
"fuchsia": [255, 0, 255],
|
|
2421
|
-
"gainsboro": [220, 220, 220],
|
|
2422
|
-
"ghostwhite": [248, 248, 255],
|
|
2423
|
-
"gold": [255, 215, 0],
|
|
2424
|
-
"goldenrod": [218, 165, 32],
|
|
2425
|
-
"gray": [128, 128, 128],
|
|
2426
|
-
"green": [0, 128, 0],
|
|
2427
|
-
"greenyellow": [173, 255, 47],
|
|
2428
|
-
"grey": [128, 128, 128],
|
|
2429
|
-
"honeydew": [240, 255, 240],
|
|
2430
|
-
"hotpink": [255, 105, 180],
|
|
2431
|
-
"indianred": [205, 92, 92],
|
|
2432
|
-
"indigo": [75, 0, 130],
|
|
2433
|
-
"ivory": [255, 255, 240],
|
|
2434
|
-
"khaki": [240, 230, 140],
|
|
2435
|
-
"lavender": [230, 230, 250],
|
|
2436
|
-
"lavenderblush": [255, 240, 245],
|
|
2437
|
-
"lawngreen": [124, 252, 0],
|
|
2438
|
-
"lemonchiffon": [255, 250, 205],
|
|
2439
|
-
"lightblue": [173, 216, 230],
|
|
2440
|
-
"lightcoral": [240, 128, 128],
|
|
2441
|
-
"lightcyan": [224, 255, 255],
|
|
2442
|
-
"lightgoldenrodyellow": [250, 250, 210],
|
|
2443
|
-
"lightgray": [211, 211, 211],
|
|
2444
|
-
"lightgreen": [144, 238, 144],
|
|
2445
|
-
"lightgrey": [211, 211, 211],
|
|
2446
|
-
"lightpink": [255, 182, 193],
|
|
2447
|
-
"lightsalmon": [255, 160, 122],
|
|
2448
|
-
"lightseagreen": [32, 178, 170],
|
|
2449
|
-
"lightskyblue": [135, 206, 250],
|
|
2450
|
-
"lightslategray": [119, 136, 153],
|
|
2451
|
-
"lightslategrey": [119, 136, 153],
|
|
2452
|
-
"lightsteelblue": [176, 196, 222],
|
|
2453
|
-
"lightyellow": [255, 255, 224],
|
|
2454
|
-
"lime": [0, 255, 0],
|
|
2455
|
-
"limegreen": [50, 205, 50],
|
|
2456
|
-
"linen": [250, 240, 230],
|
|
2457
|
-
"magenta": [255, 0, 255],
|
|
2458
|
-
"maroon": [128, 0, 0],
|
|
2459
|
-
"mediumaquamarine": [102, 205, 170],
|
|
2460
|
-
"mediumblue": [0, 0, 205],
|
|
2461
|
-
"mediumorchid": [186, 85, 211],
|
|
2462
|
-
"mediumpurple": [147, 112, 219],
|
|
2463
|
-
"mediumseagreen": [60, 179, 113],
|
|
2464
|
-
"mediumslateblue": [123, 104, 238],
|
|
2465
|
-
"mediumspringgreen": [0, 250, 154],
|
|
2466
|
-
"mediumturquoise": [72, 209, 204],
|
|
2467
|
-
"mediumvioletred": [199, 21, 133],
|
|
2468
|
-
"midnightblue": [25, 25, 112],
|
|
2469
|
-
"mintcream": [245, 255, 250],
|
|
2470
|
-
"mistyrose": [255, 228, 225],
|
|
2471
|
-
"moccasin": [255, 228, 181],
|
|
2472
|
-
"navajowhite": [255, 222, 173],
|
|
2473
|
-
"navy": [0, 0, 128],
|
|
2474
|
-
"oldlace": [253, 245, 230],
|
|
2475
|
-
"olive": [128, 128, 0],
|
|
2476
|
-
"olivedrab": [107, 142, 35],
|
|
2477
|
-
"orange": [255, 165, 0],
|
|
2478
|
-
"orangered": [255, 69, 0],
|
|
2479
|
-
"orchid": [218, 112, 214],
|
|
2480
|
-
"palegoldenrod": [238, 232, 170],
|
|
2481
|
-
"palegreen": [152, 251, 152],
|
|
2482
|
-
"paleturquoise": [175, 238, 238],
|
|
2483
|
-
"palevioletred": [219, 112, 147],
|
|
2484
|
-
"papayawhip": [255, 239, 213],
|
|
2485
|
-
"peachpuff": [255, 218, 185],
|
|
2486
|
-
"peru": [205, 133, 63],
|
|
2487
|
-
"pink": [255, 192, 203],
|
|
2488
|
-
"plum": [221, 160, 221],
|
|
2489
|
-
"powderblue": [176, 224, 230],
|
|
2490
|
-
"purple": [128, 0, 128],
|
|
2491
|
-
"rebeccapurple": [102, 51, 153],
|
|
2492
|
-
"red": [255, 0, 0],
|
|
2493
|
-
"rosybrown": [188, 143, 143],
|
|
2494
|
-
"royalblue": [65, 105, 225],
|
|
2495
|
-
"saddlebrown": [139, 69, 19],
|
|
2496
|
-
"salmon": [250, 128, 114],
|
|
2497
|
-
"sandybrown": [244, 164, 96],
|
|
2498
|
-
"seagreen": [46, 139, 87],
|
|
2499
|
-
"seashell": [255, 245, 238],
|
|
2500
|
-
"sienna": [160, 82, 45],
|
|
2501
|
-
"silver": [192, 192, 192],
|
|
2502
|
-
"skyblue": [135, 206, 235],
|
|
2503
|
-
"slateblue": [106, 90, 205],
|
|
2504
|
-
"slategray": [112, 128, 144],
|
|
2505
|
-
"slategrey": [112, 128, 144],
|
|
2506
|
-
"snow": [255, 250, 250],
|
|
2507
|
-
"springgreen": [0, 255, 127],
|
|
2508
|
-
"steelblue": [70, 130, 180],
|
|
2509
|
-
"tan": [210, 180, 140],
|
|
2510
|
-
"teal": [0, 128, 128],
|
|
2511
|
-
"thistle": [216, 191, 216],
|
|
2512
|
-
"tomato": [255, 99, 71],
|
|
2513
|
-
"turquoise": [64, 224, 208],
|
|
2514
|
-
"violet": [238, 130, 238],
|
|
2515
|
-
"wheat": [245, 222, 179],
|
|
2516
|
-
"white": [255, 255, 255],
|
|
2517
|
-
"whitesmoke": [245, 245, 245],
|
|
2518
|
-
"yellow": [255, 255, 0],
|
|
2519
|
-
"yellowgreen": [154, 205, 50]
|
|
2520
|
-
};
|
|
2521
|
-
return colorName;
|
|
2522
|
-
}
|
|
2523
|
-
var conversions;
|
|
2524
|
-
var hasRequiredConversions;
|
|
2525
|
-
function requireConversions() {
|
|
2526
|
-
if (hasRequiredConversions) return conversions;
|
|
2527
|
-
hasRequiredConversions = 1;
|
|
2528
|
-
const cssKeywords = requireColorName();
|
|
2529
|
-
const reverseKeywords = {};
|
|
2530
|
-
for (const key of Object.keys(cssKeywords)) {
|
|
2531
|
-
reverseKeywords[cssKeywords[key]] = key;
|
|
2532
|
-
}
|
|
2533
|
-
const convert = {
|
|
2534
|
-
rgb: { channels: 3, labels: "rgb" },
|
|
2535
|
-
hsl: { channels: 3, labels: "hsl" },
|
|
2536
|
-
hsv: { channels: 3, labels: "hsv" },
|
|
2537
|
-
hwb: { channels: 3, labels: "hwb" },
|
|
2538
|
-
cmyk: { channels: 4, labels: "cmyk" },
|
|
2539
|
-
xyz: { channels: 3, labels: "xyz" },
|
|
2540
|
-
lab: { channels: 3, labels: "lab" },
|
|
2541
|
-
lch: { channels: 3, labels: "lch" },
|
|
2542
|
-
hex: { channels: 1, labels: ["hex"] },
|
|
2543
|
-
keyword: { channels: 1, labels: ["keyword"] },
|
|
2544
|
-
ansi16: { channels: 1, labels: ["ansi16"] },
|
|
2545
|
-
ansi256: { channels: 1, labels: ["ansi256"] },
|
|
2546
|
-
hcg: { channels: 3, labels: ["h", "c", "g"] },
|
|
2547
|
-
apple: { channels: 3, labels: ["r16", "g16", "b16"] },
|
|
2548
|
-
gray: { channels: 1, labels: ["gray"] }
|
|
2549
|
-
};
|
|
2550
|
-
conversions = convert;
|
|
2551
|
-
for (const model of Object.keys(convert)) {
|
|
2552
|
-
if (!("channels" in convert[model])) {
|
|
2553
|
-
throw new Error("missing channels property: " + model);
|
|
2554
|
-
}
|
|
2555
|
-
if (!("labels" in convert[model])) {
|
|
2556
|
-
throw new Error("missing channel labels property: " + model);
|
|
2557
|
-
}
|
|
2558
|
-
if (convert[model].labels.length !== convert[model].channels) {
|
|
2559
|
-
throw new Error("channel and label counts mismatch: " + model);
|
|
2560
|
-
}
|
|
2561
|
-
const { channels, labels } = convert[model];
|
|
2562
|
-
delete convert[model].channels;
|
|
2563
|
-
delete convert[model].labels;
|
|
2564
|
-
Object.defineProperty(convert[model], "channels", { value: channels });
|
|
2565
|
-
Object.defineProperty(convert[model], "labels", { value: labels });
|
|
2566
|
-
}
|
|
2567
|
-
convert.rgb.hsl = function(rgb) {
|
|
2568
|
-
const r = rgb[0] / 255;
|
|
2569
|
-
const g = rgb[1] / 255;
|
|
2570
|
-
const b = rgb[2] / 255;
|
|
2571
|
-
const min = Math.min(r, g, b);
|
|
2572
|
-
const max = Math.max(r, g, b);
|
|
2573
|
-
const delta = max - min;
|
|
2574
|
-
let h;
|
|
2575
|
-
let s;
|
|
2576
|
-
if (max === min) {
|
|
2577
|
-
h = 0;
|
|
2578
|
-
} else if (r === max) {
|
|
2579
|
-
h = (g - b) / delta;
|
|
2580
|
-
} else if (g === max) {
|
|
2581
|
-
h = 2 + (b - r) / delta;
|
|
2582
|
-
} else if (b === max) {
|
|
2583
|
-
h = 4 + (r - g) / delta;
|
|
2584
|
-
}
|
|
2585
|
-
h = Math.min(h * 60, 360);
|
|
2586
|
-
if (h < 0) {
|
|
2587
|
-
h += 360;
|
|
2588
|
-
}
|
|
2589
|
-
const l = (min + max) / 2;
|
|
2590
|
-
if (max === min) {
|
|
2591
|
-
s = 0;
|
|
2592
|
-
} else if (l <= 0.5) {
|
|
2593
|
-
s = delta / (max + min);
|
|
2594
|
-
} else {
|
|
2595
|
-
s = delta / (2 - max - min);
|
|
2596
|
-
}
|
|
2597
|
-
return [h, s * 100, l * 100];
|
|
2598
|
-
};
|
|
2599
|
-
convert.rgb.hsv = function(rgb) {
|
|
2600
|
-
let rdif;
|
|
2601
|
-
let gdif;
|
|
2602
|
-
let bdif;
|
|
2603
|
-
let h;
|
|
2604
|
-
let s;
|
|
2605
|
-
const r = rgb[0] / 255;
|
|
2606
|
-
const g = rgb[1] / 255;
|
|
2607
|
-
const b = rgb[2] / 255;
|
|
2608
|
-
const v = Math.max(r, g, b);
|
|
2609
|
-
const diff = v - Math.min(r, g, b);
|
|
2610
|
-
const diffc = function(c) {
|
|
2611
|
-
return (v - c) / 6 / diff + 1 / 2;
|
|
2612
|
-
};
|
|
2613
|
-
if (diff === 0) {
|
|
2614
|
-
h = 0;
|
|
2615
|
-
s = 0;
|
|
2616
|
-
} else {
|
|
2617
|
-
s = diff / v;
|
|
2618
|
-
rdif = diffc(r);
|
|
2619
|
-
gdif = diffc(g);
|
|
2620
|
-
bdif = diffc(b);
|
|
2621
|
-
if (r === v) {
|
|
2622
|
-
h = bdif - gdif;
|
|
2623
|
-
} else if (g === v) {
|
|
2624
|
-
h = 1 / 3 + rdif - bdif;
|
|
2625
|
-
} else if (b === v) {
|
|
2626
|
-
h = 2 / 3 + gdif - rdif;
|
|
2627
|
-
}
|
|
2628
|
-
if (h < 0) {
|
|
2629
|
-
h += 1;
|
|
2630
|
-
} else if (h > 1) {
|
|
2631
|
-
h -= 1;
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2634
|
-
return [
|
|
2635
|
-
h * 360,
|
|
2636
|
-
s * 100,
|
|
2637
|
-
v * 100
|
|
2638
|
-
];
|
|
2639
|
-
};
|
|
2640
|
-
convert.rgb.hwb = function(rgb) {
|
|
2641
|
-
const r = rgb[0];
|
|
2642
|
-
const g = rgb[1];
|
|
2643
|
-
let b = rgb[2];
|
|
2644
|
-
const h = convert.rgb.hsl(rgb)[0];
|
|
2645
|
-
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
2646
|
-
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
2647
|
-
return [h, w * 100, b * 100];
|
|
2648
|
-
};
|
|
2649
|
-
convert.rgb.cmyk = function(rgb) {
|
|
2650
|
-
const r = rgb[0] / 255;
|
|
2651
|
-
const g = rgb[1] / 255;
|
|
2652
|
-
const b = rgb[2] / 255;
|
|
2653
|
-
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
2654
|
-
const c = (1 - r - k) / (1 - k) || 0;
|
|
2655
|
-
const m = (1 - g - k) / (1 - k) || 0;
|
|
2656
|
-
const y = (1 - b - k) / (1 - k) || 0;
|
|
2657
|
-
return [c * 100, m * 100, y * 100, k * 100];
|
|
2658
|
-
};
|
|
2659
|
-
function comparativeDistance(x, y) {
|
|
2660
|
-
return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
|
|
2661
|
-
}
|
|
2662
|
-
convert.rgb.keyword = function(rgb) {
|
|
2663
|
-
const reversed = reverseKeywords[rgb];
|
|
2664
|
-
if (reversed) {
|
|
2665
|
-
return reversed;
|
|
2666
|
-
}
|
|
2667
|
-
let currentClosestDistance = Infinity;
|
|
2668
|
-
let currentClosestKeyword;
|
|
2669
|
-
for (const keyword of Object.keys(cssKeywords)) {
|
|
2670
|
-
const value = cssKeywords[keyword];
|
|
2671
|
-
const distance = comparativeDistance(rgb, value);
|
|
2672
|
-
if (distance < currentClosestDistance) {
|
|
2673
|
-
currentClosestDistance = distance;
|
|
2674
|
-
currentClosestKeyword = keyword;
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
return currentClosestKeyword;
|
|
2678
|
-
};
|
|
2679
|
-
convert.keyword.rgb = function(keyword) {
|
|
2680
|
-
return cssKeywords[keyword];
|
|
2681
|
-
};
|
|
2682
|
-
convert.rgb.xyz = function(rgb) {
|
|
2683
|
-
let r = rgb[0] / 255;
|
|
2684
|
-
let g = rgb[1] / 255;
|
|
2685
|
-
let b = rgb[2] / 255;
|
|
2686
|
-
r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
|
|
2687
|
-
g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
|
|
2688
|
-
b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
|
|
2689
|
-
const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
|
|
2690
|
-
const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
|
2691
|
-
const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
|
|
2692
|
-
return [x * 100, y * 100, z * 100];
|
|
2693
|
-
};
|
|
2694
|
-
convert.rgb.lab = function(rgb) {
|
|
2695
|
-
const xyz = convert.rgb.xyz(rgb);
|
|
2696
|
-
let x = xyz[0];
|
|
2697
|
-
let y = xyz[1];
|
|
2698
|
-
let z = xyz[2];
|
|
2699
|
-
x /= 95.047;
|
|
2700
|
-
y /= 100;
|
|
2701
|
-
z /= 108.883;
|
|
2702
|
-
x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
2703
|
-
y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
2704
|
-
z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
2705
|
-
const l = 116 * y - 16;
|
|
2706
|
-
const a = 500 * (x - y);
|
|
2707
|
-
const b = 200 * (y - z);
|
|
2708
|
-
return [l, a, b];
|
|
2709
|
-
};
|
|
2710
|
-
convert.hsl.rgb = function(hsl) {
|
|
2711
|
-
const h = hsl[0] / 360;
|
|
2712
|
-
const s = hsl[1] / 100;
|
|
2713
|
-
const l = hsl[2] / 100;
|
|
2714
|
-
let t2;
|
|
2715
|
-
let t3;
|
|
2716
|
-
let val;
|
|
2717
|
-
if (s === 0) {
|
|
2718
|
-
val = l * 255;
|
|
2719
|
-
return [val, val, val];
|
|
2720
|
-
}
|
|
2721
|
-
if (l < 0.5) {
|
|
2722
|
-
t2 = l * (1 + s);
|
|
2723
|
-
} else {
|
|
2724
|
-
t2 = l + s - l * s;
|
|
2725
|
-
}
|
|
2726
|
-
const t1 = 2 * l - t2;
|
|
2727
|
-
const rgb = [0, 0, 0];
|
|
2728
|
-
for (let i = 0; i < 3; i++) {
|
|
2729
|
-
t3 = h + 1 / 3 * -(i - 1);
|
|
2730
|
-
if (t3 < 0) {
|
|
2731
|
-
t3++;
|
|
2732
|
-
}
|
|
2733
|
-
if (t3 > 1) {
|
|
2734
|
-
t3--;
|
|
2735
|
-
}
|
|
2736
|
-
if (6 * t3 < 1) {
|
|
2737
|
-
val = t1 + (t2 - t1) * 6 * t3;
|
|
2738
|
-
} else if (2 * t3 < 1) {
|
|
2739
|
-
val = t2;
|
|
2740
|
-
} else if (3 * t3 < 2) {
|
|
2741
|
-
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
2742
|
-
} else {
|
|
2743
|
-
val = t1;
|
|
2744
|
-
}
|
|
2745
|
-
rgb[i] = val * 255;
|
|
2746
|
-
}
|
|
2747
|
-
return rgb;
|
|
2748
|
-
};
|
|
2749
|
-
convert.hsl.hsv = function(hsl) {
|
|
2750
|
-
const h = hsl[0];
|
|
2751
|
-
let s = hsl[1] / 100;
|
|
2752
|
-
let l = hsl[2] / 100;
|
|
2753
|
-
let smin = s;
|
|
2754
|
-
const lmin = Math.max(l, 0.01);
|
|
2755
|
-
l *= 2;
|
|
2756
|
-
s *= l <= 1 ? l : 2 - l;
|
|
2757
|
-
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
2758
|
-
const v = (l + s) / 2;
|
|
2759
|
-
const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
|
|
2760
|
-
return [h, sv * 100, v * 100];
|
|
2761
|
-
};
|
|
2762
|
-
convert.hsv.rgb = function(hsv) {
|
|
2763
|
-
const h = hsv[0] / 60;
|
|
2764
|
-
const s = hsv[1] / 100;
|
|
2765
|
-
let v = hsv[2] / 100;
|
|
2766
|
-
const hi = Math.floor(h) % 6;
|
|
2767
|
-
const f = h - Math.floor(h);
|
|
2768
|
-
const p = 255 * v * (1 - s);
|
|
2769
|
-
const q = 255 * v * (1 - s * f);
|
|
2770
|
-
const t = 255 * v * (1 - s * (1 - f));
|
|
2771
|
-
v *= 255;
|
|
2772
|
-
switch (hi) {
|
|
2773
|
-
case 0:
|
|
2774
|
-
return [v, t, p];
|
|
2775
|
-
case 1:
|
|
2776
|
-
return [q, v, p];
|
|
2777
|
-
case 2:
|
|
2778
|
-
return [p, v, t];
|
|
2779
|
-
case 3:
|
|
2780
|
-
return [p, q, v];
|
|
2781
|
-
case 4:
|
|
2782
|
-
return [t, p, v];
|
|
2783
|
-
case 5:
|
|
2784
|
-
return [v, p, q];
|
|
2785
|
-
}
|
|
2786
|
-
};
|
|
2787
|
-
convert.hsv.hsl = function(hsv) {
|
|
2788
|
-
const h = hsv[0];
|
|
2789
|
-
const s = hsv[1] / 100;
|
|
2790
|
-
const v = hsv[2] / 100;
|
|
2791
|
-
const vmin = Math.max(v, 0.01);
|
|
2792
|
-
let sl;
|
|
2793
|
-
let l;
|
|
2794
|
-
l = (2 - s) * v;
|
|
2795
|
-
const lmin = (2 - s) * vmin;
|
|
2796
|
-
sl = s * vmin;
|
|
2797
|
-
sl /= lmin <= 1 ? lmin : 2 - lmin;
|
|
2798
|
-
sl = sl || 0;
|
|
2799
|
-
l /= 2;
|
|
2800
|
-
return [h, sl * 100, l * 100];
|
|
2801
|
-
};
|
|
2802
|
-
convert.hwb.rgb = function(hwb) {
|
|
2803
|
-
const h = hwb[0] / 360;
|
|
2804
|
-
let wh = hwb[1] / 100;
|
|
2805
|
-
let bl = hwb[2] / 100;
|
|
2806
|
-
const ratio = wh + bl;
|
|
2807
|
-
let f;
|
|
2808
|
-
if (ratio > 1) {
|
|
2809
|
-
wh /= ratio;
|
|
2810
|
-
bl /= ratio;
|
|
2811
|
-
}
|
|
2812
|
-
const i = Math.floor(6 * h);
|
|
2813
|
-
const v = 1 - bl;
|
|
2814
|
-
f = 6 * h - i;
|
|
2815
|
-
if ((i & 1) !== 0) {
|
|
2816
|
-
f = 1 - f;
|
|
2817
|
-
}
|
|
2818
|
-
const n = wh + f * (v - wh);
|
|
2819
|
-
let r;
|
|
2820
|
-
let g;
|
|
2821
|
-
let b;
|
|
2822
|
-
switch (i) {
|
|
2823
|
-
default:
|
|
2824
|
-
case 6:
|
|
2825
|
-
case 0:
|
|
2826
|
-
r = v;
|
|
2827
|
-
g = n;
|
|
2828
|
-
b = wh;
|
|
2829
|
-
break;
|
|
2830
|
-
case 1:
|
|
2831
|
-
r = n;
|
|
2832
|
-
g = v;
|
|
2833
|
-
b = wh;
|
|
2834
|
-
break;
|
|
2835
|
-
case 2:
|
|
2836
|
-
r = wh;
|
|
2837
|
-
g = v;
|
|
2838
|
-
b = n;
|
|
2839
|
-
break;
|
|
2840
|
-
case 3:
|
|
2841
|
-
r = wh;
|
|
2842
|
-
g = n;
|
|
2843
|
-
b = v;
|
|
2844
|
-
break;
|
|
2845
|
-
case 4:
|
|
2846
|
-
r = n;
|
|
2847
|
-
g = wh;
|
|
2848
|
-
b = v;
|
|
2849
|
-
break;
|
|
2850
|
-
case 5:
|
|
2851
|
-
r = v;
|
|
2852
|
-
g = wh;
|
|
2853
|
-
b = n;
|
|
2854
|
-
break;
|
|
2855
|
-
}
|
|
2856
|
-
return [r * 255, g * 255, b * 255];
|
|
2857
|
-
};
|
|
2858
|
-
convert.cmyk.rgb = function(cmyk) {
|
|
2859
|
-
const c = cmyk[0] / 100;
|
|
2860
|
-
const m = cmyk[1] / 100;
|
|
2861
|
-
const y = cmyk[2] / 100;
|
|
2862
|
-
const k = cmyk[3] / 100;
|
|
2863
|
-
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
2864
|
-
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
2865
|
-
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
2866
|
-
return [r * 255, g * 255, b * 255];
|
|
2867
|
-
};
|
|
2868
|
-
convert.xyz.rgb = function(xyz) {
|
|
2869
|
-
const x = xyz[0] / 100;
|
|
2870
|
-
const y = xyz[1] / 100;
|
|
2871
|
-
const z = xyz[2] / 100;
|
|
2872
|
-
let r;
|
|
2873
|
-
let g;
|
|
2874
|
-
let b;
|
|
2875
|
-
r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
2876
|
-
g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
2877
|
-
b = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
2878
|
-
r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
|
|
2879
|
-
g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
|
|
2880
|
-
b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
|
|
2881
|
-
r = Math.min(Math.max(0, r), 1);
|
|
2882
|
-
g = Math.min(Math.max(0, g), 1);
|
|
2883
|
-
b = Math.min(Math.max(0, b), 1);
|
|
2884
|
-
return [r * 255, g * 255, b * 255];
|
|
2885
|
-
};
|
|
2886
|
-
convert.xyz.lab = function(xyz) {
|
|
2887
|
-
let x = xyz[0];
|
|
2888
|
-
let y = xyz[1];
|
|
2889
|
-
let z = xyz[2];
|
|
2890
|
-
x /= 95.047;
|
|
2891
|
-
y /= 100;
|
|
2892
|
-
z /= 108.883;
|
|
2893
|
-
x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
2894
|
-
y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
2895
|
-
z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
2896
|
-
const l = 116 * y - 16;
|
|
2897
|
-
const a = 500 * (x - y);
|
|
2898
|
-
const b = 200 * (y - z);
|
|
2899
|
-
return [l, a, b];
|
|
2900
|
-
};
|
|
2901
|
-
convert.lab.xyz = function(lab) {
|
|
2902
|
-
const l = lab[0];
|
|
2903
|
-
const a = lab[1];
|
|
2904
|
-
const b = lab[2];
|
|
2905
|
-
let x;
|
|
2906
|
-
let y;
|
|
2907
|
-
let z;
|
|
2908
|
-
y = (l + 16) / 116;
|
|
2909
|
-
x = a / 500 + y;
|
|
2910
|
-
z = y - b / 200;
|
|
2911
|
-
const y2 = y ** 3;
|
|
2912
|
-
const x2 = x ** 3;
|
|
2913
|
-
const z2 = z ** 3;
|
|
2914
|
-
y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
|
|
2915
|
-
x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
|
|
2916
|
-
z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
|
|
2917
|
-
x *= 95.047;
|
|
2918
|
-
y *= 100;
|
|
2919
|
-
z *= 108.883;
|
|
2920
|
-
return [x, y, z];
|
|
2921
|
-
};
|
|
2922
|
-
convert.lab.lch = function(lab) {
|
|
2923
|
-
const l = lab[0];
|
|
2924
|
-
const a = lab[1];
|
|
2925
|
-
const b = lab[2];
|
|
2926
|
-
let h;
|
|
2927
|
-
const hr = Math.atan2(b, a);
|
|
2928
|
-
h = hr * 360 / 2 / Math.PI;
|
|
2929
|
-
if (h < 0) {
|
|
2930
|
-
h += 360;
|
|
2931
|
-
}
|
|
2932
|
-
const c = Math.sqrt(a * a + b * b);
|
|
2933
|
-
return [l, c, h];
|
|
2934
|
-
};
|
|
2935
|
-
convert.lch.lab = function(lch) {
|
|
2936
|
-
const l = lch[0];
|
|
2937
|
-
const c = lch[1];
|
|
2938
|
-
const h = lch[2];
|
|
2939
|
-
const hr = h / 360 * 2 * Math.PI;
|
|
2940
|
-
const a = c * Math.cos(hr);
|
|
2941
|
-
const b = c * Math.sin(hr);
|
|
2942
|
-
return [l, a, b];
|
|
2943
|
-
};
|
|
2944
|
-
convert.rgb.ansi16 = function(args, saturation = null) {
|
|
2945
|
-
const [r, g, b] = args;
|
|
2946
|
-
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
|
|
2947
|
-
value = Math.round(value / 50);
|
|
2948
|
-
if (value === 0) {
|
|
2949
|
-
return 30;
|
|
2950
|
-
}
|
|
2951
|
-
let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
|
2952
|
-
if (value === 2) {
|
|
2953
|
-
ansi += 60;
|
|
2954
|
-
}
|
|
2955
|
-
return ansi;
|
|
2956
|
-
};
|
|
2957
|
-
convert.hsv.ansi16 = function(args) {
|
|
2958
|
-
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
2959
|
-
};
|
|
2960
|
-
convert.rgb.ansi256 = function(args) {
|
|
2961
|
-
const r = args[0];
|
|
2962
|
-
const g = args[1];
|
|
2963
|
-
const b = args[2];
|
|
2964
|
-
if (r === g && g === b) {
|
|
2965
|
-
if (r < 8) {
|
|
2966
|
-
return 16;
|
|
2967
|
-
}
|
|
2968
|
-
if (r > 248) {
|
|
2969
|
-
return 231;
|
|
2970
|
-
}
|
|
2971
|
-
return Math.round((r - 8) / 247 * 24) + 232;
|
|
2972
|
-
}
|
|
2973
|
-
const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
|
2974
|
-
return ansi;
|
|
2975
|
-
};
|
|
2976
|
-
convert.ansi16.rgb = function(args) {
|
|
2977
|
-
let color = args % 10;
|
|
2978
|
-
if (color === 0 || color === 7) {
|
|
2979
|
-
if (args > 50) {
|
|
2980
|
-
color += 3.5;
|
|
2981
|
-
}
|
|
2982
|
-
color = color / 10.5 * 255;
|
|
2983
|
-
return [color, color, color];
|
|
2984
|
-
}
|
|
2985
|
-
const mult = (~~(args > 50) + 1) * 0.5;
|
|
2986
|
-
const r = (color & 1) * mult * 255;
|
|
2987
|
-
const g = (color >> 1 & 1) * mult * 255;
|
|
2988
|
-
const b = (color >> 2 & 1) * mult * 255;
|
|
2989
|
-
return [r, g, b];
|
|
2990
|
-
};
|
|
2991
|
-
convert.ansi256.rgb = function(args) {
|
|
2992
|
-
if (args >= 232) {
|
|
2993
|
-
const c = (args - 232) * 10 + 8;
|
|
2994
|
-
return [c, c, c];
|
|
2995
|
-
}
|
|
2996
|
-
args -= 16;
|
|
2997
|
-
let rem;
|
|
2998
|
-
const r = Math.floor(args / 36) / 5 * 255;
|
|
2999
|
-
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
3000
|
-
const b = rem % 6 / 5 * 255;
|
|
3001
|
-
return [r, g, b];
|
|
3002
|
-
};
|
|
3003
|
-
convert.rgb.hex = function(args) {
|
|
3004
|
-
const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
|
|
3005
|
-
const string = integer.toString(16).toUpperCase();
|
|
3006
|
-
return "000000".substring(string.length) + string;
|
|
3007
|
-
};
|
|
3008
|
-
convert.hex.rgb = function(args) {
|
|
3009
|
-
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
3010
|
-
if (!match) {
|
|
3011
|
-
return [0, 0, 0];
|
|
3012
|
-
}
|
|
3013
|
-
let colorString = match[0];
|
|
3014
|
-
if (match[0].length === 3) {
|
|
3015
|
-
colorString = colorString.split("").map((char) => {
|
|
3016
|
-
return char + char;
|
|
3017
|
-
}).join("");
|
|
3018
|
-
}
|
|
3019
|
-
const integer = parseInt(colorString, 16);
|
|
3020
|
-
const r = integer >> 16 & 255;
|
|
3021
|
-
const g = integer >> 8 & 255;
|
|
3022
|
-
const b = integer & 255;
|
|
3023
|
-
return [r, g, b];
|
|
3024
|
-
};
|
|
3025
|
-
convert.rgb.hcg = function(rgb) {
|
|
3026
|
-
const r = rgb[0] / 255;
|
|
3027
|
-
const g = rgb[1] / 255;
|
|
3028
|
-
const b = rgb[2] / 255;
|
|
3029
|
-
const max = Math.max(Math.max(r, g), b);
|
|
3030
|
-
const min = Math.min(Math.min(r, g), b);
|
|
3031
|
-
const chroma = max - min;
|
|
3032
|
-
let grayscale;
|
|
3033
|
-
let hue;
|
|
3034
|
-
if (chroma < 1) {
|
|
3035
|
-
grayscale = min / (1 - chroma);
|
|
3036
|
-
} else {
|
|
3037
|
-
grayscale = 0;
|
|
3038
|
-
}
|
|
3039
|
-
if (chroma <= 0) {
|
|
3040
|
-
hue = 0;
|
|
3041
|
-
} else if (max === r) {
|
|
3042
|
-
hue = (g - b) / chroma % 6;
|
|
3043
|
-
} else if (max === g) {
|
|
3044
|
-
hue = 2 + (b - r) / chroma;
|
|
3045
|
-
} else {
|
|
3046
|
-
hue = 4 + (r - g) / chroma;
|
|
3047
|
-
}
|
|
3048
|
-
hue /= 6;
|
|
3049
|
-
hue %= 1;
|
|
3050
|
-
return [hue * 360, chroma * 100, grayscale * 100];
|
|
3051
|
-
};
|
|
3052
|
-
convert.hsl.hcg = function(hsl) {
|
|
3053
|
-
const s = hsl[1] / 100;
|
|
3054
|
-
const l = hsl[2] / 100;
|
|
3055
|
-
const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
|
|
3056
|
-
let f = 0;
|
|
3057
|
-
if (c < 1) {
|
|
3058
|
-
f = (l - 0.5 * c) / (1 - c);
|
|
3059
|
-
}
|
|
3060
|
-
return [hsl[0], c * 100, f * 100];
|
|
3061
|
-
};
|
|
3062
|
-
convert.hsv.hcg = function(hsv) {
|
|
3063
|
-
const s = hsv[1] / 100;
|
|
3064
|
-
const v = hsv[2] / 100;
|
|
3065
|
-
const c = s * v;
|
|
3066
|
-
let f = 0;
|
|
3067
|
-
if (c < 1) {
|
|
3068
|
-
f = (v - c) / (1 - c);
|
|
3069
|
-
}
|
|
3070
|
-
return [hsv[0], c * 100, f * 100];
|
|
3071
|
-
};
|
|
3072
|
-
convert.hcg.rgb = function(hcg) {
|
|
3073
|
-
const h = hcg[0] / 360;
|
|
3074
|
-
const c = hcg[1] / 100;
|
|
3075
|
-
const g = hcg[2] / 100;
|
|
3076
|
-
if (c === 0) {
|
|
3077
|
-
return [g * 255, g * 255, g * 255];
|
|
3078
|
-
}
|
|
3079
|
-
const pure = [0, 0, 0];
|
|
3080
|
-
const hi = h % 1 * 6;
|
|
3081
|
-
const v = hi % 1;
|
|
3082
|
-
const w = 1 - v;
|
|
3083
|
-
let mg = 0;
|
|
3084
|
-
switch (Math.floor(hi)) {
|
|
3085
|
-
case 0:
|
|
3086
|
-
pure[0] = 1;
|
|
3087
|
-
pure[1] = v;
|
|
3088
|
-
pure[2] = 0;
|
|
3089
|
-
break;
|
|
3090
|
-
case 1:
|
|
3091
|
-
pure[0] = w;
|
|
3092
|
-
pure[1] = 1;
|
|
3093
|
-
pure[2] = 0;
|
|
3094
|
-
break;
|
|
3095
|
-
case 2:
|
|
3096
|
-
pure[0] = 0;
|
|
3097
|
-
pure[1] = 1;
|
|
3098
|
-
pure[2] = v;
|
|
3099
|
-
break;
|
|
3100
|
-
case 3:
|
|
3101
|
-
pure[0] = 0;
|
|
3102
|
-
pure[1] = w;
|
|
3103
|
-
pure[2] = 1;
|
|
3104
|
-
break;
|
|
3105
|
-
case 4:
|
|
3106
|
-
pure[0] = v;
|
|
3107
|
-
pure[1] = 0;
|
|
3108
|
-
pure[2] = 1;
|
|
3109
|
-
break;
|
|
3110
|
-
default:
|
|
3111
|
-
pure[0] = 1;
|
|
3112
|
-
pure[1] = 0;
|
|
3113
|
-
pure[2] = w;
|
|
3114
|
-
}
|
|
3115
|
-
mg = (1 - c) * g;
|
|
3116
|
-
return [
|
|
3117
|
-
(c * pure[0] + mg) * 255,
|
|
3118
|
-
(c * pure[1] + mg) * 255,
|
|
3119
|
-
(c * pure[2] + mg) * 255
|
|
3120
|
-
];
|
|
3121
|
-
};
|
|
3122
|
-
convert.hcg.hsv = function(hcg) {
|
|
3123
|
-
const c = hcg[1] / 100;
|
|
3124
|
-
const g = hcg[2] / 100;
|
|
3125
|
-
const v = c + g * (1 - c);
|
|
3126
|
-
let f = 0;
|
|
3127
|
-
if (v > 0) {
|
|
3128
|
-
f = c / v;
|
|
3129
|
-
}
|
|
3130
|
-
return [hcg[0], f * 100, v * 100];
|
|
3131
|
-
};
|
|
3132
|
-
convert.hcg.hsl = function(hcg) {
|
|
3133
|
-
const c = hcg[1] / 100;
|
|
3134
|
-
const g = hcg[2] / 100;
|
|
3135
|
-
const l = g * (1 - c) + 0.5 * c;
|
|
3136
|
-
let s = 0;
|
|
3137
|
-
if (l > 0 && l < 0.5) {
|
|
3138
|
-
s = c / (2 * l);
|
|
3139
|
-
} else if (l >= 0.5 && l < 1) {
|
|
3140
|
-
s = c / (2 * (1 - l));
|
|
3141
|
-
}
|
|
3142
|
-
return [hcg[0], s * 100, l * 100];
|
|
3143
|
-
};
|
|
3144
|
-
convert.hcg.hwb = function(hcg) {
|
|
3145
|
-
const c = hcg[1] / 100;
|
|
3146
|
-
const g = hcg[2] / 100;
|
|
3147
|
-
const v = c + g * (1 - c);
|
|
3148
|
-
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
3149
|
-
};
|
|
3150
|
-
convert.hwb.hcg = function(hwb) {
|
|
3151
|
-
const w = hwb[1] / 100;
|
|
3152
|
-
const b = hwb[2] / 100;
|
|
3153
|
-
const v = 1 - b;
|
|
3154
|
-
const c = v - w;
|
|
3155
|
-
let g = 0;
|
|
3156
|
-
if (c < 1) {
|
|
3157
|
-
g = (v - c) / (1 - c);
|
|
3158
|
-
}
|
|
3159
|
-
return [hwb[0], c * 100, g * 100];
|
|
3160
|
-
};
|
|
3161
|
-
convert.apple.rgb = function(apple) {
|
|
3162
|
-
return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
|
|
3163
|
-
};
|
|
3164
|
-
convert.rgb.apple = function(rgb) {
|
|
3165
|
-
return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
|
|
3166
|
-
};
|
|
3167
|
-
convert.gray.rgb = function(args) {
|
|
3168
|
-
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
3169
|
-
};
|
|
3170
|
-
convert.gray.hsl = function(args) {
|
|
3171
|
-
return [0, 0, args[0]];
|
|
3172
|
-
};
|
|
3173
|
-
convert.gray.hsv = convert.gray.hsl;
|
|
3174
|
-
convert.gray.hwb = function(gray) {
|
|
3175
|
-
return [0, 100, gray[0]];
|
|
3176
|
-
};
|
|
3177
|
-
convert.gray.cmyk = function(gray) {
|
|
3178
|
-
return [0, 0, 0, gray[0]];
|
|
3179
|
-
};
|
|
3180
|
-
convert.gray.lab = function(gray) {
|
|
3181
|
-
return [gray[0], 0, 0];
|
|
3182
|
-
};
|
|
3183
|
-
convert.gray.hex = function(gray) {
|
|
3184
|
-
const val = Math.round(gray[0] / 100 * 255) & 255;
|
|
3185
|
-
const integer = (val << 16) + (val << 8) + val;
|
|
3186
|
-
const string = integer.toString(16).toUpperCase();
|
|
3187
|
-
return "000000".substring(string.length) + string;
|
|
3188
|
-
};
|
|
3189
|
-
convert.rgb.gray = function(rgb) {
|
|
3190
|
-
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
3191
|
-
return [val / 255 * 100];
|
|
3192
|
-
};
|
|
3193
|
-
return conversions;
|
|
3194
|
-
}
|
|
3195
|
-
var route;
|
|
3196
|
-
var hasRequiredRoute;
|
|
3197
|
-
function requireRoute() {
|
|
3198
|
-
if (hasRequiredRoute) return route;
|
|
3199
|
-
hasRequiredRoute = 1;
|
|
3200
|
-
const conversions2 = requireConversions();
|
|
3201
|
-
function buildGraph() {
|
|
3202
|
-
const graph = {};
|
|
3203
|
-
const models = Object.keys(conversions2);
|
|
3204
|
-
for (let len = models.length, i = 0; i < len; i++) {
|
|
3205
|
-
graph[models[i]] = {
|
|
3206
|
-
// http://jsperf.com/1-vs-infinity
|
|
3207
|
-
// micro-opt, but this is simple.
|
|
3208
|
-
distance: -1,
|
|
3209
|
-
parent: null
|
|
3210
|
-
};
|
|
3211
|
-
}
|
|
3212
|
-
return graph;
|
|
3213
|
-
}
|
|
3214
|
-
function deriveBFS(fromModel) {
|
|
3215
|
-
const graph = buildGraph();
|
|
3216
|
-
const queue = [fromModel];
|
|
3217
|
-
graph[fromModel].distance = 0;
|
|
3218
|
-
while (queue.length) {
|
|
3219
|
-
const current = queue.pop();
|
|
3220
|
-
const adjacents = Object.keys(conversions2[current]);
|
|
3221
|
-
for (let len = adjacents.length, i = 0; i < len; i++) {
|
|
3222
|
-
const adjacent = adjacents[i];
|
|
3223
|
-
const node = graph[adjacent];
|
|
3224
|
-
if (node.distance === -1) {
|
|
3225
|
-
node.distance = graph[current].distance + 1;
|
|
3226
|
-
node.parent = current;
|
|
3227
|
-
queue.unshift(adjacent);
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3231
|
-
return graph;
|
|
3232
|
-
}
|
|
3233
|
-
function link(from, to) {
|
|
3234
|
-
return function(args) {
|
|
3235
|
-
return to(from(args));
|
|
3236
|
-
};
|
|
3237
|
-
}
|
|
3238
|
-
function wrapConversion(toModel, graph) {
|
|
3239
|
-
const path = [graph[toModel].parent, toModel];
|
|
3240
|
-
let fn = conversions2[graph[toModel].parent][toModel];
|
|
3241
|
-
let cur = graph[toModel].parent;
|
|
3242
|
-
while (graph[cur].parent) {
|
|
3243
|
-
path.unshift(graph[cur].parent);
|
|
3244
|
-
fn = link(conversions2[graph[cur].parent][cur], fn);
|
|
3245
|
-
cur = graph[cur].parent;
|
|
3246
|
-
}
|
|
3247
|
-
fn.conversion = path;
|
|
3248
|
-
return fn;
|
|
3249
|
-
}
|
|
3250
|
-
route = function(fromModel) {
|
|
3251
|
-
const graph = deriveBFS(fromModel);
|
|
3252
|
-
const conversion = {};
|
|
3253
|
-
const models = Object.keys(graph);
|
|
3254
|
-
for (let len = models.length, i = 0; i < len; i++) {
|
|
3255
|
-
const toModel = models[i];
|
|
3256
|
-
const node = graph[toModel];
|
|
3257
|
-
if (node.parent === null) {
|
|
3258
|
-
continue;
|
|
3259
|
-
}
|
|
3260
|
-
conversion[toModel] = wrapConversion(toModel, graph);
|
|
3261
|
-
}
|
|
3262
|
-
return conversion;
|
|
3263
|
-
};
|
|
3264
|
-
return route;
|
|
3265
|
-
}
|
|
3266
|
-
var colorConvert;
|
|
3267
|
-
var hasRequiredColorConvert;
|
|
3268
|
-
function requireColorConvert() {
|
|
3269
|
-
if (hasRequiredColorConvert) return colorConvert;
|
|
3270
|
-
hasRequiredColorConvert = 1;
|
|
3271
|
-
const conversions2 = requireConversions();
|
|
3272
|
-
const route2 = requireRoute();
|
|
3273
|
-
const convert = {};
|
|
3274
|
-
const models = Object.keys(conversions2);
|
|
3275
|
-
function wrapRaw(fn) {
|
|
3276
|
-
const wrappedFn = function(...args) {
|
|
3277
|
-
const arg0 = args[0];
|
|
3278
|
-
if (arg0 === void 0 || arg0 === null) {
|
|
3279
|
-
return arg0;
|
|
3280
|
-
}
|
|
3281
|
-
if (arg0.length > 1) {
|
|
3282
|
-
args = arg0;
|
|
3283
|
-
}
|
|
3284
|
-
return fn(args);
|
|
3285
|
-
};
|
|
3286
|
-
if ("conversion" in fn) {
|
|
3287
|
-
wrappedFn.conversion = fn.conversion;
|
|
3288
|
-
}
|
|
3289
|
-
return wrappedFn;
|
|
3290
|
-
}
|
|
3291
|
-
function wrapRounded(fn) {
|
|
3292
|
-
const wrappedFn = function(...args) {
|
|
3293
|
-
const arg0 = args[0];
|
|
3294
|
-
if (arg0 === void 0 || arg0 === null) {
|
|
3295
|
-
return arg0;
|
|
3296
|
-
}
|
|
3297
|
-
if (arg0.length > 1) {
|
|
3298
|
-
args = arg0;
|
|
3299
|
-
}
|
|
3300
|
-
const result = fn(args);
|
|
3301
|
-
if (typeof result === "object") {
|
|
3302
|
-
for (let len = result.length, i = 0; i < len; i++) {
|
|
3303
|
-
result[i] = Math.round(result[i]);
|
|
3304
|
-
}
|
|
3305
|
-
}
|
|
3306
|
-
return result;
|
|
3307
|
-
};
|
|
3308
|
-
if ("conversion" in fn) {
|
|
3309
|
-
wrappedFn.conversion = fn.conversion;
|
|
3310
|
-
}
|
|
3311
|
-
return wrappedFn;
|
|
3312
|
-
}
|
|
3313
|
-
models.forEach((fromModel) => {
|
|
3314
|
-
convert[fromModel] = {};
|
|
3315
|
-
Object.defineProperty(convert[fromModel], "channels", { value: conversions2[fromModel].channels });
|
|
3316
|
-
Object.defineProperty(convert[fromModel], "labels", { value: conversions2[fromModel].labels });
|
|
3317
|
-
const routes = route2(fromModel);
|
|
3318
|
-
const routeModels = Object.keys(routes);
|
|
3319
|
-
routeModels.forEach((toModel) => {
|
|
3320
|
-
const fn = routes[toModel];
|
|
3321
|
-
convert[fromModel][toModel] = wrapRounded(fn);
|
|
3322
|
-
convert[fromModel][toModel].raw = wrapRaw(fn);
|
|
3323
|
-
});
|
|
3324
|
-
});
|
|
3325
|
-
colorConvert = convert;
|
|
3326
|
-
return colorConvert;
|
|
3327
|
-
}
|
|
3328
|
-
ansiStyles.exports;
|
|
3329
|
-
var hasRequiredAnsiStyles;
|
|
3330
|
-
function requireAnsiStyles() {
|
|
3331
|
-
if (hasRequiredAnsiStyles) return ansiStyles.exports;
|
|
3332
|
-
hasRequiredAnsiStyles = 1;
|
|
3333
|
-
(function(module2) {
|
|
3334
|
-
const wrapAnsi16 = (fn, offset) => (...args) => {
|
|
3335
|
-
const code = fn(...args);
|
|
3336
|
-
return `\x1B[${code + offset}m`;
|
|
3337
|
-
};
|
|
3338
|
-
const wrapAnsi256 = (fn, offset) => (...args) => {
|
|
3339
|
-
const code = fn(...args);
|
|
3340
|
-
return `\x1B[${38 + offset};5;${code}m`;
|
|
3341
|
-
};
|
|
3342
|
-
const wrapAnsi16m = (fn, offset) => (...args) => {
|
|
3343
|
-
const rgb = fn(...args);
|
|
3344
|
-
return `\x1B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
|
3345
|
-
};
|
|
3346
|
-
const ansi2ansi = (n) => n;
|
|
3347
|
-
const rgb2rgb = (r, g, b) => [r, g, b];
|
|
3348
|
-
const setLazyProperty = (object, property, get) => {
|
|
3349
|
-
Object.defineProperty(object, property, {
|
|
3350
|
-
get: () => {
|
|
3351
|
-
const value = get();
|
|
3352
|
-
Object.defineProperty(object, property, {
|
|
3353
|
-
value,
|
|
3354
|
-
enumerable: true,
|
|
3355
|
-
configurable: true
|
|
3356
|
-
});
|
|
3357
|
-
return value;
|
|
3358
|
-
},
|
|
3359
|
-
enumerable: true,
|
|
3360
|
-
configurable: true
|
|
3361
|
-
});
|
|
3362
|
-
};
|
|
3363
|
-
let colorConvert2;
|
|
3364
|
-
const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
|
3365
|
-
if (colorConvert2 === void 0) {
|
|
3366
|
-
colorConvert2 = requireColorConvert();
|
|
3367
|
-
}
|
|
3368
|
-
const offset = isBackground ? 10 : 0;
|
|
3369
|
-
const styles = {};
|
|
3370
|
-
for (const [sourceSpace, suite] of Object.entries(colorConvert2)) {
|
|
3371
|
-
const name = sourceSpace === "ansi16" ? "ansi" : sourceSpace;
|
|
3372
|
-
if (sourceSpace === targetSpace) {
|
|
3373
|
-
styles[name] = wrap(identity, offset);
|
|
3374
|
-
} else if (typeof suite === "object") {
|
|
3375
|
-
styles[name] = wrap(suite[targetSpace], offset);
|
|
3376
|
-
}
|
|
3377
|
-
}
|
|
3378
|
-
return styles;
|
|
3379
|
-
};
|
|
3380
|
-
function assembleStyles() {
|
|
3381
|
-
const codes = /* @__PURE__ */ new Map();
|
|
3382
|
-
const styles = {
|
|
3383
|
-
modifier: {
|
|
3384
|
-
reset: [0, 0],
|
|
3385
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
3386
|
-
bold: [1, 22],
|
|
3387
|
-
dim: [2, 22],
|
|
3388
|
-
italic: [3, 23],
|
|
3389
|
-
underline: [4, 24],
|
|
3390
|
-
inverse: [7, 27],
|
|
3391
|
-
hidden: [8, 28],
|
|
3392
|
-
strikethrough: [9, 29]
|
|
3393
|
-
},
|
|
3394
|
-
color: {
|
|
3395
|
-
black: [30, 39],
|
|
3396
|
-
red: [31, 39],
|
|
3397
|
-
green: [32, 39],
|
|
3398
|
-
yellow: [33, 39],
|
|
3399
|
-
blue: [34, 39],
|
|
3400
|
-
magenta: [35, 39],
|
|
3401
|
-
cyan: [36, 39],
|
|
3402
|
-
white: [37, 39],
|
|
3403
|
-
// Bright color
|
|
3404
|
-
blackBright: [90, 39],
|
|
3405
|
-
redBright: [91, 39],
|
|
3406
|
-
greenBright: [92, 39],
|
|
3407
|
-
yellowBright: [93, 39],
|
|
3408
|
-
blueBright: [94, 39],
|
|
3409
|
-
magentaBright: [95, 39],
|
|
3410
|
-
cyanBright: [96, 39],
|
|
3411
|
-
whiteBright: [97, 39]
|
|
3412
|
-
},
|
|
3413
|
-
bgColor: {
|
|
3414
|
-
bgBlack: [40, 49],
|
|
3415
|
-
bgRed: [41, 49],
|
|
3416
|
-
bgGreen: [42, 49],
|
|
3417
|
-
bgYellow: [43, 49],
|
|
3418
|
-
bgBlue: [44, 49],
|
|
3419
|
-
bgMagenta: [45, 49],
|
|
3420
|
-
bgCyan: [46, 49],
|
|
3421
|
-
bgWhite: [47, 49],
|
|
3422
|
-
// Bright color
|
|
3423
|
-
bgBlackBright: [100, 49],
|
|
3424
|
-
bgRedBright: [101, 49],
|
|
3425
|
-
bgGreenBright: [102, 49],
|
|
3426
|
-
bgYellowBright: [103, 49],
|
|
3427
|
-
bgBlueBright: [104, 49],
|
|
3428
|
-
bgMagentaBright: [105, 49],
|
|
3429
|
-
bgCyanBright: [106, 49],
|
|
3430
|
-
bgWhiteBright: [107, 49]
|
|
3431
|
-
}
|
|
3432
|
-
};
|
|
3433
|
-
styles.color.gray = styles.color.blackBright;
|
|
3434
|
-
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
3435
|
-
styles.color.grey = styles.color.blackBright;
|
|
3436
|
-
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
3437
|
-
for (const [groupName, group] of Object.entries(styles)) {
|
|
3438
|
-
for (const [styleName, style] of Object.entries(group)) {
|
|
3439
|
-
styles[styleName] = {
|
|
3440
|
-
open: `\x1B[${style[0]}m`,
|
|
3441
|
-
close: `\x1B[${style[1]}m`
|
|
3442
|
-
};
|
|
3443
|
-
group[styleName] = styles[styleName];
|
|
3444
|
-
codes.set(style[0], style[1]);
|
|
3445
|
-
}
|
|
3446
|
-
Object.defineProperty(styles, groupName, {
|
|
3447
|
-
value: group,
|
|
3448
|
-
enumerable: false
|
|
3449
|
-
});
|
|
3450
|
-
}
|
|
3451
|
-
Object.defineProperty(styles, "codes", {
|
|
3452
|
-
value: codes,
|
|
3453
|
-
enumerable: false
|
|
3454
|
-
});
|
|
3455
|
-
styles.color.close = "\x1B[39m";
|
|
3456
|
-
styles.bgColor.close = "\x1B[49m";
|
|
3457
|
-
setLazyProperty(styles.color, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, false));
|
|
3458
|
-
setLazyProperty(styles.color, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, false));
|
|
3459
|
-
setLazyProperty(styles.color, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, false));
|
|
3460
|
-
setLazyProperty(styles.bgColor, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, true));
|
|
3461
|
-
setLazyProperty(styles.bgColor, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, true));
|
|
3462
|
-
setLazyProperty(styles.bgColor, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, true));
|
|
3463
|
-
return styles;
|
|
3464
|
-
}
|
|
3465
|
-
Object.defineProperty(module2, "exports", {
|
|
3466
|
-
enumerable: true,
|
|
3467
|
-
get: assembleStyles
|
|
3468
|
-
});
|
|
3469
|
-
})(ansiStyles);
|
|
3470
|
-
return ansiStyles.exports;
|
|
3471
|
-
}
|
|
3472
|
-
var browser;
|
|
3473
|
-
var hasRequiredBrowser;
|
|
3474
|
-
function requireBrowser() {
|
|
3475
|
-
if (hasRequiredBrowser) return browser;
|
|
3476
|
-
hasRequiredBrowser = 1;
|
|
3477
|
-
browser = {
|
|
3478
|
-
stdout: false,
|
|
3479
|
-
stderr: false
|
|
3480
|
-
};
|
|
3481
|
-
return browser;
|
|
3482
|
-
}
|
|
3483
|
-
var util;
|
|
3484
|
-
var hasRequiredUtil;
|
|
3485
|
-
function requireUtil() {
|
|
3486
|
-
if (hasRequiredUtil) return util;
|
|
3487
|
-
hasRequiredUtil = 1;
|
|
3488
|
-
const stringReplaceAll = (string, substring, replacer) => {
|
|
3489
|
-
let index = string.indexOf(substring);
|
|
3490
|
-
if (index === -1) {
|
|
3491
|
-
return string;
|
|
3492
|
-
}
|
|
3493
|
-
const substringLength = substring.length;
|
|
3494
|
-
let endIndex = 0;
|
|
3495
|
-
let returnValue = "";
|
|
3496
|
-
do {
|
|
3497
|
-
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
|
3498
|
-
endIndex = index + substringLength;
|
|
3499
|
-
index = string.indexOf(substring, endIndex);
|
|
3500
|
-
} while (index !== -1);
|
|
3501
|
-
returnValue += string.substr(endIndex);
|
|
3502
|
-
return returnValue;
|
|
3503
|
-
};
|
|
3504
|
-
const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
|
3505
|
-
let endIndex = 0;
|
|
3506
|
-
let returnValue = "";
|
|
3507
|
-
do {
|
|
3508
|
-
const gotCR = string[index - 1] === "\r";
|
|
3509
|
-
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
3510
|
-
endIndex = index + 1;
|
|
3511
|
-
index = string.indexOf("\n", endIndex);
|
|
3512
|
-
} while (index !== -1);
|
|
3513
|
-
returnValue += string.substr(endIndex);
|
|
3514
|
-
return returnValue;
|
|
3515
|
-
};
|
|
3516
|
-
util = {
|
|
3517
|
-
stringReplaceAll,
|
|
3518
|
-
stringEncaseCRLFWithFirstIndex
|
|
3519
|
-
};
|
|
3520
|
-
return util;
|
|
3521
|
-
}
|
|
3522
|
-
var templates;
|
|
3523
|
-
var hasRequiredTemplates;
|
|
3524
|
-
function requireTemplates() {
|
|
3525
|
-
if (hasRequiredTemplates) return templates;
|
|
3526
|
-
hasRequiredTemplates = 1;
|
|
3527
|
-
const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
3528
|
-
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
|
3529
|
-
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
3530
|
-
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
3531
|
-
const ESCAPES = /* @__PURE__ */ new Map([
|
|
3532
|
-
["n", "\n"],
|
|
3533
|
-
["r", "\r"],
|
|
3534
|
-
["t", " "],
|
|
3535
|
-
["b", "\b"],
|
|
3536
|
-
["f", "\f"],
|
|
3537
|
-
["v", "\v"],
|
|
3538
|
-
["0", "\0"],
|
|
3539
|
-
["\\", "\\"],
|
|
3540
|
-
["e", "\x1B"],
|
|
3541
|
-
["a", "\x07"]
|
|
3542
|
-
]);
|
|
3543
|
-
function unescape(c) {
|
|
3544
|
-
const u = c[0] === "u";
|
|
3545
|
-
const bracket = c[1] === "{";
|
|
3546
|
-
if (u && !bracket && c.length === 5 || c[0] === "x" && c.length === 3) {
|
|
3547
|
-
return String.fromCharCode(parseInt(c.slice(1), 16));
|
|
3548
|
-
}
|
|
3549
|
-
if (u && bracket) {
|
|
3550
|
-
return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
|
|
3551
|
-
}
|
|
3552
|
-
return ESCAPES.get(c) || c;
|
|
3553
|
-
}
|
|
3554
|
-
function parseArguments(name, arguments_) {
|
|
3555
|
-
const results = [];
|
|
3556
|
-
const chunks = arguments_.trim().split(/\s*,\s*/g);
|
|
3557
|
-
let matches;
|
|
3558
|
-
for (const chunk of chunks) {
|
|
3559
|
-
const number = Number(chunk);
|
|
3560
|
-
if (!Number.isNaN(number)) {
|
|
3561
|
-
results.push(number);
|
|
3562
|
-
} else if (matches = chunk.match(STRING_REGEX)) {
|
|
3563
|
-
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
|
|
3564
|
-
} else {
|
|
3565
|
-
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3568
|
-
return results;
|
|
3569
|
-
}
|
|
3570
|
-
function parseStyle(style) {
|
|
3571
|
-
STYLE_REGEX.lastIndex = 0;
|
|
3572
|
-
const results = [];
|
|
3573
|
-
let matches;
|
|
3574
|
-
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
|
3575
|
-
const name = matches[1];
|
|
3576
|
-
if (matches[2]) {
|
|
3577
|
-
const args = parseArguments(name, matches[2]);
|
|
3578
|
-
results.push([name].concat(args));
|
|
3579
|
-
} else {
|
|
3580
|
-
results.push([name]);
|
|
3581
|
-
}
|
|
3582
|
-
}
|
|
3583
|
-
return results;
|
|
3584
|
-
}
|
|
3585
|
-
function buildStyle(chalk2, styles) {
|
|
3586
|
-
const enabled = {};
|
|
3587
|
-
for (const layer of styles) {
|
|
3588
|
-
for (const style of layer.styles) {
|
|
3589
|
-
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
|
3590
|
-
}
|
|
3591
|
-
}
|
|
3592
|
-
let current = chalk2;
|
|
3593
|
-
for (const [styleName, styles2] of Object.entries(enabled)) {
|
|
3594
|
-
if (!Array.isArray(styles2)) {
|
|
3595
|
-
continue;
|
|
3596
|
-
}
|
|
3597
|
-
if (!(styleName in current)) {
|
|
3598
|
-
throw new Error(`Unknown Chalk style: ${styleName}`);
|
|
3599
|
-
}
|
|
3600
|
-
current = styles2.length > 0 ? current[styleName](...styles2) : current[styleName];
|
|
3601
|
-
}
|
|
3602
|
-
return current;
|
|
3603
|
-
}
|
|
3604
|
-
templates = (chalk2, temporary) => {
|
|
3605
|
-
const styles = [];
|
|
3606
|
-
const chunks = [];
|
|
3607
|
-
let chunk = [];
|
|
3608
|
-
temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
|
|
3609
|
-
if (escapeCharacter) {
|
|
3610
|
-
chunk.push(unescape(escapeCharacter));
|
|
3611
|
-
} else if (style) {
|
|
3612
|
-
const string = chunk.join("");
|
|
3613
|
-
chunk = [];
|
|
3614
|
-
chunks.push(styles.length === 0 ? string : buildStyle(chalk2, styles)(string));
|
|
3615
|
-
styles.push({ inverse, styles: parseStyle(style) });
|
|
3616
|
-
} else if (close) {
|
|
3617
|
-
if (styles.length === 0) {
|
|
3618
|
-
throw new Error("Found extraneous } in Chalk template literal");
|
|
3619
|
-
}
|
|
3620
|
-
chunks.push(buildStyle(chalk2, styles)(chunk.join("")));
|
|
3621
|
-
chunk = [];
|
|
3622
|
-
styles.pop();
|
|
3623
|
-
} else {
|
|
3624
|
-
chunk.push(character);
|
|
3625
|
-
}
|
|
3626
|
-
});
|
|
3627
|
-
chunks.push(chunk.join(""));
|
|
3628
|
-
if (styles.length > 0) {
|
|
3629
|
-
const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`;
|
|
3630
|
-
throw new Error(errMessage);
|
|
3631
|
-
}
|
|
3632
|
-
return chunks.join("");
|
|
3633
|
-
};
|
|
3634
|
-
return templates;
|
|
3635
|
-
}
|
|
3636
|
-
var source;
|
|
3637
|
-
var hasRequiredSource;
|
|
3638
|
-
function requireSource() {
|
|
3639
|
-
if (hasRequiredSource) return source;
|
|
3640
|
-
hasRequiredSource = 1;
|
|
3641
|
-
const ansiStyles2 = requireAnsiStyles();
|
|
3642
|
-
const { stdout: stdoutColor, stderr: stderrColor } = requireBrowser();
|
|
3643
|
-
const {
|
|
3644
|
-
stringReplaceAll,
|
|
3645
|
-
stringEncaseCRLFWithFirstIndex
|
|
3646
|
-
} = requireUtil();
|
|
3647
|
-
const { isArray } = Array;
|
|
3648
|
-
const levelMapping = [
|
|
3649
|
-
"ansi",
|
|
3650
|
-
"ansi",
|
|
3651
|
-
"ansi256",
|
|
3652
|
-
"ansi16m"
|
|
3653
|
-
];
|
|
3654
|
-
const styles = /* @__PURE__ */ Object.create(null);
|
|
3655
|
-
const applyOptions = (object, options = {}) => {
|
|
3656
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
3657
|
-
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
3658
|
-
}
|
|
3659
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
3660
|
-
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
3661
|
-
};
|
|
3662
|
-
class ChalkClass {
|
|
3663
|
-
constructor(options) {
|
|
3664
|
-
return chalkFactory(options);
|
|
3665
|
-
}
|
|
3666
|
-
}
|
|
3667
|
-
const chalkFactory = (options) => {
|
|
3668
|
-
const chalk3 = {};
|
|
3669
|
-
applyOptions(chalk3, options);
|
|
3670
|
-
chalk3.template = (...arguments_) => chalkTag(chalk3.template, ...arguments_);
|
|
3671
|
-
Object.setPrototypeOf(chalk3, Chalk.prototype);
|
|
3672
|
-
Object.setPrototypeOf(chalk3.template, chalk3);
|
|
3673
|
-
chalk3.template.constructor = () => {
|
|
3674
|
-
throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
|
|
3675
|
-
};
|
|
3676
|
-
chalk3.template.Instance = ChalkClass;
|
|
3677
|
-
return chalk3.template;
|
|
3678
|
-
};
|
|
3679
|
-
function Chalk(options) {
|
|
3680
|
-
return chalkFactory(options);
|
|
3681
|
-
}
|
|
3682
|
-
for (const [styleName, style] of Object.entries(ansiStyles2)) {
|
|
3683
|
-
styles[styleName] = {
|
|
3684
|
-
get() {
|
|
3685
|
-
const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
|
|
3686
|
-
Object.defineProperty(this, styleName, { value: builder });
|
|
3687
|
-
return builder;
|
|
3688
|
-
}
|
|
3689
|
-
};
|
|
3690
|
-
}
|
|
3691
|
-
styles.visible = {
|
|
3692
|
-
get() {
|
|
3693
|
-
const builder = createBuilder(this, this._styler, true);
|
|
3694
|
-
Object.defineProperty(this, "visible", { value: builder });
|
|
3695
|
-
return builder;
|
|
3696
|
-
}
|
|
3697
|
-
};
|
|
3698
|
-
const usedModels = ["rgb", "hex", "keyword", "hsl", "hsv", "hwb", "ansi", "ansi256"];
|
|
3699
|
-
for (const model of usedModels) {
|
|
3700
|
-
styles[model] = {
|
|
3701
|
-
get() {
|
|
3702
|
-
const { level } = this;
|
|
3703
|
-
return function(...arguments_) {
|
|
3704
|
-
const styler = createStyler(ansiStyles2.color[levelMapping[level]][model](...arguments_), ansiStyles2.color.close, this._styler);
|
|
3705
|
-
return createBuilder(this, styler, this._isEmpty);
|
|
3706
|
-
};
|
|
3707
|
-
}
|
|
3708
|
-
};
|
|
3709
|
-
}
|
|
3710
|
-
for (const model of usedModels) {
|
|
3711
|
-
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
3712
|
-
styles[bgModel] = {
|
|
3713
|
-
get() {
|
|
3714
|
-
const { level } = this;
|
|
3715
|
-
return function(...arguments_) {
|
|
3716
|
-
const styler = createStyler(ansiStyles2.bgColor[levelMapping[level]][model](...arguments_), ansiStyles2.bgColor.close, this._styler);
|
|
3717
|
-
return createBuilder(this, styler, this._isEmpty);
|
|
3718
|
-
};
|
|
3719
|
-
}
|
|
3720
|
-
};
|
|
3721
|
-
}
|
|
3722
|
-
const proto = Object.defineProperties(() => {
|
|
3723
|
-
}, {
|
|
3724
|
-
...styles,
|
|
3725
|
-
level: {
|
|
3726
|
-
enumerable: true,
|
|
3727
|
-
get() {
|
|
3728
|
-
return this._generator.level;
|
|
3729
|
-
},
|
|
3730
|
-
set(level) {
|
|
3731
|
-
this._generator.level = level;
|
|
3732
|
-
}
|
|
3733
|
-
}
|
|
3734
|
-
});
|
|
3735
|
-
const createStyler = (open, close, parent) => {
|
|
3736
|
-
let openAll;
|
|
3737
|
-
let closeAll;
|
|
3738
|
-
if (parent === void 0) {
|
|
3739
|
-
openAll = open;
|
|
3740
|
-
closeAll = close;
|
|
3741
|
-
} else {
|
|
3742
|
-
openAll = parent.openAll + open;
|
|
3743
|
-
closeAll = close + parent.closeAll;
|
|
3744
|
-
}
|
|
3745
|
-
return {
|
|
3746
|
-
open,
|
|
3747
|
-
close,
|
|
3748
|
-
openAll,
|
|
3749
|
-
closeAll,
|
|
3750
|
-
parent
|
|
3751
|
-
};
|
|
3752
|
-
};
|
|
3753
|
-
const createBuilder = (self, _styler, _isEmpty) => {
|
|
3754
|
-
const builder = (...arguments_) => {
|
|
3755
|
-
if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
|
|
3756
|
-
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
|
3757
|
-
}
|
|
3758
|
-
return applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
3759
|
-
};
|
|
3760
|
-
Object.setPrototypeOf(builder, proto);
|
|
3761
|
-
builder._generator = self;
|
|
3762
|
-
builder._styler = _styler;
|
|
3763
|
-
builder._isEmpty = _isEmpty;
|
|
3764
|
-
return builder;
|
|
3765
|
-
};
|
|
3766
|
-
const applyStyle = (self, string) => {
|
|
3767
|
-
if (self.level <= 0 || !string) {
|
|
3768
|
-
return self._isEmpty ? "" : string;
|
|
3769
|
-
}
|
|
3770
|
-
let styler = self._styler;
|
|
3771
|
-
if (styler === void 0) {
|
|
3772
|
-
return string;
|
|
3773
|
-
}
|
|
3774
|
-
const { openAll, closeAll } = styler;
|
|
3775
|
-
if (string.indexOf("\x1B") !== -1) {
|
|
3776
|
-
while (styler !== void 0) {
|
|
3777
|
-
string = stringReplaceAll(string, styler.close, styler.open);
|
|
3778
|
-
styler = styler.parent;
|
|
3779
|
-
}
|
|
3780
|
-
}
|
|
3781
|
-
const lfIndex = string.indexOf("\n");
|
|
3782
|
-
if (lfIndex !== -1) {
|
|
3783
|
-
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
3784
|
-
}
|
|
3785
|
-
return openAll + string + closeAll;
|
|
3786
|
-
};
|
|
3787
|
-
let template;
|
|
3788
|
-
const chalkTag = (chalk3, ...strings) => {
|
|
3789
|
-
const [firstString] = strings;
|
|
3790
|
-
if (!isArray(firstString) || !isArray(firstString.raw)) {
|
|
3791
|
-
return strings.join(" ");
|
|
3792
|
-
}
|
|
3793
|
-
const arguments_ = strings.slice(1);
|
|
3794
|
-
const parts = [firstString.raw[0]];
|
|
3795
|
-
for (let i = 1; i < firstString.length; i++) {
|
|
3796
|
-
parts.push(
|
|
3797
|
-
String(arguments_[i - 1]).replace(/[{}\\]/g, "\\$&"),
|
|
3798
|
-
String(firstString.raw[i])
|
|
3799
|
-
);
|
|
3800
|
-
}
|
|
3801
|
-
if (template === void 0) {
|
|
3802
|
-
template = requireTemplates();
|
|
3803
|
-
}
|
|
3804
|
-
return template(chalk3, parts.join(""));
|
|
3805
|
-
};
|
|
3806
|
-
Object.defineProperties(Chalk.prototype, styles);
|
|
3807
|
-
const chalk2 = Chalk();
|
|
3808
|
-
chalk2.supportsColor = stdoutColor;
|
|
3809
|
-
chalk2.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
3810
|
-
chalk2.stderr.supportsColor = stderrColor;
|
|
3811
|
-
source = chalk2;
|
|
3812
|
-
return source;
|
|
3813
|
-
}
|
|
3814
|
-
var sourceExports = requireSource();
|
|
3815
|
-
const chalk = /* @__PURE__ */ getDefaultExportFromCjs(sourceExports);
|
|
3816
|
-
function utf8Count(str) {
|
|
3817
|
-
const strLength = str.length;
|
|
3818
|
-
let byteLength = 0;
|
|
3819
|
-
let pos = 0;
|
|
3820
|
-
while (pos < strLength) {
|
|
3821
|
-
let value = str.charCodeAt(pos++);
|
|
3822
|
-
if ((value & 4294967168) === 0) {
|
|
3823
|
-
byteLength++;
|
|
3824
|
-
continue;
|
|
3825
|
-
} else if ((value & 4294965248) === 0) {
|
|
3826
|
-
byteLength += 2;
|
|
3827
|
-
} else {
|
|
3828
|
-
if (value >= 55296 && value <= 56319) {
|
|
3829
|
-
if (pos < strLength) {
|
|
3830
|
-
const extra = str.charCodeAt(pos);
|
|
3831
|
-
if ((extra & 64512) === 56320) {
|
|
3832
|
-
++pos;
|
|
3833
|
-
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
3834
|
-
}
|
|
3835
|
-
}
|
|
3836
|
-
}
|
|
3837
|
-
if ((value & 4294901760) === 0) {
|
|
3838
|
-
byteLength += 3;
|
|
3839
|
-
} else {
|
|
3840
|
-
byteLength += 4;
|
|
3841
|
-
}
|
|
3842
|
-
}
|
|
3843
|
-
}
|
|
3844
|
-
return byteLength;
|
|
3845
|
-
}
|
|
3846
|
-
function utf8EncodeJs(str, output, outputOffset) {
|
|
3847
|
-
const strLength = str.length;
|
|
3848
|
-
let offset = outputOffset;
|
|
3849
|
-
let pos = 0;
|
|
3850
|
-
while (pos < strLength) {
|
|
3851
|
-
let value = str.charCodeAt(pos++);
|
|
3852
|
-
if ((value & 4294967168) === 0) {
|
|
3853
|
-
output[offset++] = value;
|
|
3854
|
-
continue;
|
|
3855
|
-
} else if ((value & 4294965248) === 0) {
|
|
3856
|
-
output[offset++] = value >> 6 & 31 | 192;
|
|
3857
|
-
} else {
|
|
3858
|
-
if (value >= 55296 && value <= 56319) {
|
|
3859
|
-
if (pos < strLength) {
|
|
3860
|
-
const extra = str.charCodeAt(pos);
|
|
3861
|
-
if ((extra & 64512) === 56320) {
|
|
3862
|
-
++pos;
|
|
3863
|
-
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
3864
|
-
}
|
|
3865
|
-
}
|
|
3866
|
-
}
|
|
3867
|
-
if ((value & 4294901760) === 0) {
|
|
3868
|
-
output[offset++] = value >> 12 & 15 | 224;
|
|
3869
|
-
output[offset++] = value >> 6 & 63 | 128;
|
|
3870
|
-
} else {
|
|
3871
|
-
output[offset++] = value >> 18 & 7 | 240;
|
|
3872
|
-
output[offset++] = value >> 12 & 63 | 128;
|
|
3873
|
-
output[offset++] = value >> 6 & 63 | 128;
|
|
3874
|
-
}
|
|
3875
|
-
}
|
|
3876
|
-
output[offset++] = value & 63 | 128;
|
|
3877
|
-
}
|
|
3878
|
-
}
|
|
3879
|
-
const sharedTextEncoder = new TextEncoder();
|
|
3880
|
-
const TEXT_ENCODER_THRESHOLD = 50;
|
|
3881
|
-
function utf8EncodeTE(str, output, outputOffset) {
|
|
3882
|
-
sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
|
|
3883
|
-
}
|
|
3884
|
-
function utf8Encode(str, output, outputOffset) {
|
|
3885
|
-
if (str.length > TEXT_ENCODER_THRESHOLD) {
|
|
3886
|
-
utf8EncodeTE(str, output, outputOffset);
|
|
3887
|
-
} else {
|
|
3888
|
-
utf8EncodeJs(str, output, outputOffset);
|
|
3889
|
-
}
|
|
3890
|
-
}
|
|
3891
|
-
new TextDecoder();
|
|
3892
|
-
class ExtData {
|
|
3893
|
-
type;
|
|
3894
|
-
data;
|
|
3895
|
-
constructor(type, data) {
|
|
3896
|
-
this.type = type;
|
|
3897
|
-
this.data = data;
|
|
3898
|
-
}
|
|
3899
|
-
}
|
|
3900
|
-
class DecodeError extends Error {
|
|
3901
|
-
constructor(message) {
|
|
3902
|
-
super(message);
|
|
3903
|
-
const proto = Object.create(DecodeError.prototype);
|
|
3904
|
-
Object.setPrototypeOf(this, proto);
|
|
3905
|
-
Object.defineProperty(this, "name", {
|
|
3906
|
-
configurable: true,
|
|
3907
|
-
enumerable: false,
|
|
3908
|
-
value: DecodeError.name
|
|
3909
|
-
});
|
|
3910
|
-
}
|
|
3911
|
-
}
|
|
3912
|
-
function setUint64(view, offset, value) {
|
|
3913
|
-
const high = value / 4294967296;
|
|
3914
|
-
const low = value;
|
|
3915
|
-
view.setUint32(offset, high);
|
|
3916
|
-
view.setUint32(offset + 4, low);
|
|
3917
|
-
}
|
|
3918
|
-
function setInt64(view, offset, value) {
|
|
3919
|
-
const high = Math.floor(value / 4294967296);
|
|
3920
|
-
const low = value;
|
|
3921
|
-
view.setUint32(offset, high);
|
|
3922
|
-
view.setUint32(offset + 4, low);
|
|
3923
|
-
}
|
|
3924
|
-
function getInt64(view, offset) {
|
|
3925
|
-
const high = view.getInt32(offset);
|
|
3926
|
-
const low = view.getUint32(offset + 4);
|
|
3927
|
-
return high * 4294967296 + low;
|
|
3928
|
-
}
|
|
3929
|
-
const EXT_TIMESTAMP = -1;
|
|
3930
|
-
const TIMESTAMP32_MAX_SEC = 4294967296 - 1;
|
|
3931
|
-
const TIMESTAMP64_MAX_SEC = 17179869184 - 1;
|
|
3932
|
-
function encodeTimeSpecToTimestamp({ sec, nsec }) {
|
|
3933
|
-
if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
|
|
3934
|
-
if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
|
|
3935
|
-
const rv = new Uint8Array(4);
|
|
3936
|
-
const view = new DataView(rv.buffer);
|
|
3937
|
-
view.setUint32(0, sec);
|
|
3938
|
-
return rv;
|
|
3939
|
-
} else {
|
|
3940
|
-
const secHigh = sec / 4294967296;
|
|
3941
|
-
const secLow = sec & 4294967295;
|
|
3942
|
-
const rv = new Uint8Array(8);
|
|
3943
|
-
const view = new DataView(rv.buffer);
|
|
3944
|
-
view.setUint32(0, nsec << 2 | secHigh & 3);
|
|
3945
|
-
view.setUint32(4, secLow);
|
|
3946
|
-
return rv;
|
|
3947
|
-
}
|
|
3948
|
-
} else {
|
|
3949
|
-
const rv = new Uint8Array(12);
|
|
3950
|
-
const view = new DataView(rv.buffer);
|
|
3951
|
-
view.setUint32(0, nsec);
|
|
3952
|
-
setInt64(view, 4, sec);
|
|
3953
|
-
return rv;
|
|
3954
|
-
}
|
|
3955
|
-
}
|
|
3956
|
-
function encodeDateToTimeSpec(date) {
|
|
3957
|
-
const msec = date.getTime();
|
|
3958
|
-
const sec = Math.floor(msec / 1e3);
|
|
3959
|
-
const nsec = (msec - sec * 1e3) * 1e6;
|
|
3960
|
-
const nsecInSec = Math.floor(nsec / 1e9);
|
|
3961
|
-
return {
|
|
3962
|
-
sec: sec + nsecInSec,
|
|
3963
|
-
nsec: nsec - nsecInSec * 1e9
|
|
3964
|
-
};
|
|
3965
|
-
}
|
|
3966
|
-
function encodeTimestampExtension(object) {
|
|
3967
|
-
if (object instanceof Date) {
|
|
3968
|
-
const timeSpec = encodeDateToTimeSpec(object);
|
|
3969
|
-
return encodeTimeSpecToTimestamp(timeSpec);
|
|
3970
|
-
} else {
|
|
3971
|
-
return null;
|
|
3972
|
-
}
|
|
3973
|
-
}
|
|
3974
|
-
function decodeTimestampToTimeSpec(data) {
|
|
3975
|
-
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
3976
|
-
switch (data.byteLength) {
|
|
3977
|
-
case 4: {
|
|
3978
|
-
const sec = view.getUint32(0);
|
|
3979
|
-
const nsec = 0;
|
|
3980
|
-
return { sec, nsec };
|
|
3981
|
-
}
|
|
3982
|
-
case 8: {
|
|
3983
|
-
const nsec30AndSecHigh2 = view.getUint32(0);
|
|
3984
|
-
const secLow32 = view.getUint32(4);
|
|
3985
|
-
const sec = (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32;
|
|
3986
|
-
const nsec = nsec30AndSecHigh2 >>> 2;
|
|
3987
|
-
return { sec, nsec };
|
|
3988
|
-
}
|
|
3989
|
-
case 12: {
|
|
3990
|
-
const sec = getInt64(view, 4);
|
|
3991
|
-
const nsec = view.getUint32(0);
|
|
3992
|
-
return { sec, nsec };
|
|
3993
|
-
}
|
|
3994
|
-
default:
|
|
3995
|
-
throw new DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${data.length}`);
|
|
3996
|
-
}
|
|
3997
|
-
}
|
|
3998
|
-
function decodeTimestampExtension(data) {
|
|
3999
|
-
const timeSpec = decodeTimestampToTimeSpec(data);
|
|
4000
|
-
return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
|
|
4001
|
-
}
|
|
4002
|
-
const timestampExtension = {
|
|
4003
|
-
type: EXT_TIMESTAMP,
|
|
4004
|
-
encode: encodeTimestampExtension,
|
|
4005
|
-
decode: decodeTimestampExtension
|
|
4006
|
-
};
|
|
4007
|
-
class ExtensionCodec {
|
|
4008
|
-
static defaultCodec = new ExtensionCodec();
|
|
4009
|
-
// ensures ExtensionCodecType<X> matches ExtensionCodec<X>
|
|
4010
|
-
// this will make type errors a lot more clear
|
|
4011
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4012
|
-
__brand;
|
|
4013
|
-
// built-in extensions
|
|
4014
|
-
builtInEncoders = [];
|
|
4015
|
-
builtInDecoders = [];
|
|
4016
|
-
// custom extensions
|
|
4017
|
-
encoders = [];
|
|
4018
|
-
decoders = [];
|
|
4019
|
-
constructor() {
|
|
4020
|
-
this.register(timestampExtension);
|
|
4021
|
-
}
|
|
4022
|
-
register({ type, encode: encode2, decode }) {
|
|
4023
|
-
if (type >= 0) {
|
|
4024
|
-
this.encoders[type] = encode2;
|
|
4025
|
-
this.decoders[type] = decode;
|
|
4026
|
-
} else {
|
|
4027
|
-
const index = -1 - type;
|
|
4028
|
-
this.builtInEncoders[index] = encode2;
|
|
4029
|
-
this.builtInDecoders[index] = decode;
|
|
4030
|
-
}
|
|
4031
|
-
}
|
|
4032
|
-
tryToEncode(object, context) {
|
|
4033
|
-
for (let i = 0; i < this.builtInEncoders.length; i++) {
|
|
4034
|
-
const encodeExt = this.builtInEncoders[i];
|
|
4035
|
-
if (encodeExt != null) {
|
|
4036
|
-
const data = encodeExt(object, context);
|
|
4037
|
-
if (data != null) {
|
|
4038
|
-
const type = -1 - i;
|
|
4039
|
-
return new ExtData(type, data);
|
|
4040
|
-
}
|
|
4041
|
-
}
|
|
4042
|
-
}
|
|
4043
|
-
for (let i = 0; i < this.encoders.length; i++) {
|
|
4044
|
-
const encodeExt = this.encoders[i];
|
|
4045
|
-
if (encodeExt != null) {
|
|
4046
|
-
const data = encodeExt(object, context);
|
|
4047
|
-
if (data != null) {
|
|
4048
|
-
const type = i;
|
|
4049
|
-
return new ExtData(type, data);
|
|
4050
|
-
}
|
|
4051
|
-
}
|
|
4052
|
-
}
|
|
4053
|
-
if (object instanceof ExtData) {
|
|
4054
|
-
return object;
|
|
4055
|
-
}
|
|
4056
|
-
return null;
|
|
4057
|
-
}
|
|
4058
|
-
decode(data, type, context) {
|
|
4059
|
-
const decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
|
|
4060
|
-
if (decodeExt) {
|
|
4061
|
-
return decodeExt(data, type, context);
|
|
4062
|
-
} else {
|
|
4063
|
-
return new ExtData(type, data);
|
|
4064
|
-
}
|
|
4065
|
-
}
|
|
4066
|
-
}
|
|
4067
|
-
function isArrayBufferLike(buffer) {
|
|
4068
|
-
return buffer instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer;
|
|
4069
|
-
}
|
|
4070
|
-
function ensureUint8Array(buffer) {
|
|
4071
|
-
if (buffer instanceof Uint8Array) {
|
|
4072
|
-
return buffer;
|
|
4073
|
-
} else if (ArrayBuffer.isView(buffer)) {
|
|
4074
|
-
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
4075
|
-
} else if (isArrayBufferLike(buffer)) {
|
|
4076
|
-
return new Uint8Array(buffer);
|
|
4077
|
-
} else {
|
|
4078
|
-
return Uint8Array.from(buffer);
|
|
4079
|
-
}
|
|
4080
|
-
}
|
|
4081
|
-
const DEFAULT_MAX_DEPTH = 100;
|
|
4082
|
-
const DEFAULT_INITIAL_BUFFER_SIZE = 2048;
|
|
4083
|
-
class Encoder {
|
|
4084
|
-
extensionCodec;
|
|
4085
|
-
context;
|
|
4086
|
-
useBigInt64;
|
|
4087
|
-
maxDepth;
|
|
4088
|
-
initialBufferSize;
|
|
4089
|
-
sortKeys;
|
|
4090
|
-
forceFloat32;
|
|
4091
|
-
ignoreUndefined;
|
|
4092
|
-
forceIntegerToFloat;
|
|
4093
|
-
pos;
|
|
4094
|
-
view;
|
|
4095
|
-
bytes;
|
|
4096
|
-
entered = false;
|
|
4097
|
-
constructor(options) {
|
|
4098
|
-
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec.defaultCodec;
|
|
4099
|
-
this.context = options?.context;
|
|
4100
|
-
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
4101
|
-
this.maxDepth = options?.maxDepth ?? DEFAULT_MAX_DEPTH;
|
|
4102
|
-
this.initialBufferSize = options?.initialBufferSize ?? DEFAULT_INITIAL_BUFFER_SIZE;
|
|
4103
|
-
this.sortKeys = options?.sortKeys ?? false;
|
|
4104
|
-
this.forceFloat32 = options?.forceFloat32 ?? false;
|
|
4105
|
-
this.ignoreUndefined = options?.ignoreUndefined ?? false;
|
|
4106
|
-
this.forceIntegerToFloat = options?.forceIntegerToFloat ?? false;
|
|
4107
|
-
this.pos = 0;
|
|
4108
|
-
this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
|
|
4109
|
-
this.bytes = new Uint8Array(this.view.buffer);
|
|
4110
|
-
}
|
|
4111
|
-
clone() {
|
|
4112
|
-
return new Encoder({
|
|
4113
|
-
extensionCodec: this.extensionCodec,
|
|
4114
|
-
context: this.context,
|
|
4115
|
-
useBigInt64: this.useBigInt64,
|
|
4116
|
-
maxDepth: this.maxDepth,
|
|
4117
|
-
initialBufferSize: this.initialBufferSize,
|
|
4118
|
-
sortKeys: this.sortKeys,
|
|
4119
|
-
forceFloat32: this.forceFloat32,
|
|
4120
|
-
ignoreUndefined: this.ignoreUndefined,
|
|
4121
|
-
forceIntegerToFloat: this.forceIntegerToFloat
|
|
4122
|
-
});
|
|
4123
|
-
}
|
|
4124
|
-
reinitializeState() {
|
|
4125
|
-
this.pos = 0;
|
|
4126
|
-
}
|
|
4127
|
-
/**
|
|
4128
|
-
* This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
|
|
4129
|
-
*
|
|
4130
|
-
* @returns Encodes the object and returns a shared reference the encoder's internal buffer.
|
|
4131
|
-
*/
|
|
4132
|
-
encodeSharedRef(object) {
|
|
4133
|
-
if (this.entered) {
|
|
4134
|
-
const instance = this.clone();
|
|
4135
|
-
return instance.encodeSharedRef(object);
|
|
4136
|
-
}
|
|
4137
|
-
try {
|
|
4138
|
-
this.entered = true;
|
|
4139
|
-
this.reinitializeState();
|
|
4140
|
-
this.doEncode(object, 1);
|
|
4141
|
-
return this.bytes.subarray(0, this.pos);
|
|
4142
|
-
} finally {
|
|
4143
|
-
this.entered = false;
|
|
4144
|
-
}
|
|
4145
|
-
}
|
|
4146
|
-
/**
|
|
4147
|
-
* @returns Encodes the object and returns a copy of the encoder's internal buffer.
|
|
4148
|
-
*/
|
|
4149
|
-
encode(object) {
|
|
4150
|
-
if (this.entered) {
|
|
4151
|
-
const instance = this.clone();
|
|
4152
|
-
return instance.encode(object);
|
|
4153
|
-
}
|
|
4154
|
-
try {
|
|
4155
|
-
this.entered = true;
|
|
4156
|
-
this.reinitializeState();
|
|
4157
|
-
this.doEncode(object, 1);
|
|
4158
|
-
return this.bytes.slice(0, this.pos);
|
|
4159
|
-
} finally {
|
|
4160
|
-
this.entered = false;
|
|
4161
|
-
}
|
|
4162
|
-
}
|
|
4163
|
-
doEncode(object, depth) {
|
|
4164
|
-
if (depth > this.maxDepth) {
|
|
4165
|
-
throw new Error(`Too deep objects in depth ${depth}`);
|
|
4166
|
-
}
|
|
4167
|
-
if (object == null) {
|
|
4168
|
-
this.encodeNil();
|
|
4169
|
-
} else if (typeof object === "boolean") {
|
|
4170
|
-
this.encodeBoolean(object);
|
|
4171
|
-
} else if (typeof object === "number") {
|
|
4172
|
-
if (!this.forceIntegerToFloat) {
|
|
4173
|
-
this.encodeNumber(object);
|
|
4174
|
-
} else {
|
|
4175
|
-
this.encodeNumberAsFloat(object);
|
|
4176
|
-
}
|
|
4177
|
-
} else if (typeof object === "string") {
|
|
4178
|
-
this.encodeString(object);
|
|
4179
|
-
} else if (this.useBigInt64 && typeof object === "bigint") {
|
|
4180
|
-
this.encodeBigInt64(object);
|
|
4181
|
-
} else {
|
|
4182
|
-
this.encodeObject(object, depth);
|
|
4183
|
-
}
|
|
4184
|
-
}
|
|
4185
|
-
ensureBufferSizeToWrite(sizeToWrite) {
|
|
4186
|
-
const requiredSize = this.pos + sizeToWrite;
|
|
4187
|
-
if (this.view.byteLength < requiredSize) {
|
|
4188
|
-
this.resizeBuffer(requiredSize * 2);
|
|
4189
|
-
}
|
|
4190
|
-
}
|
|
4191
|
-
resizeBuffer(newSize) {
|
|
4192
|
-
const newBuffer = new ArrayBuffer(newSize);
|
|
4193
|
-
const newBytes = new Uint8Array(newBuffer);
|
|
4194
|
-
const newView = new DataView(newBuffer);
|
|
4195
|
-
newBytes.set(this.bytes);
|
|
4196
|
-
this.view = newView;
|
|
4197
|
-
this.bytes = newBytes;
|
|
4198
|
-
}
|
|
4199
|
-
encodeNil() {
|
|
4200
|
-
this.writeU8(192);
|
|
4201
|
-
}
|
|
4202
|
-
encodeBoolean(object) {
|
|
4203
|
-
if (object === false) {
|
|
4204
|
-
this.writeU8(194);
|
|
4205
|
-
} else {
|
|
4206
|
-
this.writeU8(195);
|
|
4207
|
-
}
|
|
4208
|
-
}
|
|
4209
|
-
encodeNumber(object) {
|
|
4210
|
-
if (!this.forceIntegerToFloat && Number.isSafeInteger(object)) {
|
|
4211
|
-
if (object >= 0) {
|
|
4212
|
-
if (object < 128) {
|
|
4213
|
-
this.writeU8(object);
|
|
4214
|
-
} else if (object < 256) {
|
|
4215
|
-
this.writeU8(204);
|
|
4216
|
-
this.writeU8(object);
|
|
4217
|
-
} else if (object < 65536) {
|
|
4218
|
-
this.writeU8(205);
|
|
4219
|
-
this.writeU16(object);
|
|
4220
|
-
} else if (object < 4294967296) {
|
|
4221
|
-
this.writeU8(206);
|
|
4222
|
-
this.writeU32(object);
|
|
4223
|
-
} else if (!this.useBigInt64) {
|
|
4224
|
-
this.writeU8(207);
|
|
4225
|
-
this.writeU64(object);
|
|
4226
|
-
} else {
|
|
4227
|
-
this.encodeNumberAsFloat(object);
|
|
4228
|
-
}
|
|
4229
|
-
} else {
|
|
4230
|
-
if (object >= -32) {
|
|
4231
|
-
this.writeU8(224 | object + 32);
|
|
4232
|
-
} else if (object >= -128) {
|
|
4233
|
-
this.writeU8(208);
|
|
4234
|
-
this.writeI8(object);
|
|
4235
|
-
} else if (object >= -32768) {
|
|
4236
|
-
this.writeU8(209);
|
|
4237
|
-
this.writeI16(object);
|
|
4238
|
-
} else if (object >= -2147483648) {
|
|
4239
|
-
this.writeU8(210);
|
|
4240
|
-
this.writeI32(object);
|
|
4241
|
-
} else if (!this.useBigInt64) {
|
|
4242
|
-
this.writeU8(211);
|
|
4243
|
-
this.writeI64(object);
|
|
4244
|
-
} else {
|
|
4245
|
-
this.encodeNumberAsFloat(object);
|
|
4246
|
-
}
|
|
4247
|
-
}
|
|
4248
|
-
} else {
|
|
4249
|
-
this.encodeNumberAsFloat(object);
|
|
4250
|
-
}
|
|
4251
|
-
}
|
|
4252
|
-
encodeNumberAsFloat(object) {
|
|
4253
|
-
if (this.forceFloat32) {
|
|
4254
|
-
this.writeU8(202);
|
|
4255
|
-
this.writeF32(object);
|
|
4256
|
-
} else {
|
|
4257
|
-
this.writeU8(203);
|
|
4258
|
-
this.writeF64(object);
|
|
4259
|
-
}
|
|
4260
|
-
}
|
|
4261
|
-
encodeBigInt64(object) {
|
|
4262
|
-
if (object >= BigInt(0)) {
|
|
4263
|
-
this.writeU8(207);
|
|
4264
|
-
this.writeBigUint64(object);
|
|
4265
|
-
} else {
|
|
4266
|
-
this.writeU8(211);
|
|
4267
|
-
this.writeBigInt64(object);
|
|
4268
|
-
}
|
|
4269
|
-
}
|
|
4270
|
-
writeStringHeader(byteLength) {
|
|
4271
|
-
if (byteLength < 32) {
|
|
4272
|
-
this.writeU8(160 + byteLength);
|
|
4273
|
-
} else if (byteLength < 256) {
|
|
4274
|
-
this.writeU8(217);
|
|
4275
|
-
this.writeU8(byteLength);
|
|
4276
|
-
} else if (byteLength < 65536) {
|
|
4277
|
-
this.writeU8(218);
|
|
4278
|
-
this.writeU16(byteLength);
|
|
4279
|
-
} else if (byteLength < 4294967296) {
|
|
4280
|
-
this.writeU8(219);
|
|
4281
|
-
this.writeU32(byteLength);
|
|
4282
|
-
} else {
|
|
4283
|
-
throw new Error(`Too long string: ${byteLength} bytes in UTF-8`);
|
|
4284
|
-
}
|
|
4285
|
-
}
|
|
4286
|
-
encodeString(object) {
|
|
4287
|
-
const maxHeaderSize = 1 + 4;
|
|
4288
|
-
const byteLength = utf8Count(object);
|
|
4289
|
-
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
4290
|
-
this.writeStringHeader(byteLength);
|
|
4291
|
-
utf8Encode(object, this.bytes, this.pos);
|
|
4292
|
-
this.pos += byteLength;
|
|
4293
|
-
}
|
|
4294
|
-
encodeObject(object, depth) {
|
|
4295
|
-
const ext = this.extensionCodec.tryToEncode(object, this.context);
|
|
4296
|
-
if (ext != null) {
|
|
4297
|
-
this.encodeExtension(ext);
|
|
4298
|
-
} else if (Array.isArray(object)) {
|
|
4299
|
-
this.encodeArray(object, depth);
|
|
4300
|
-
} else if (ArrayBuffer.isView(object)) {
|
|
4301
|
-
this.encodeBinary(object);
|
|
4302
|
-
} else if (typeof object === "object") {
|
|
4303
|
-
this.encodeMap(object, depth);
|
|
4304
|
-
} else {
|
|
4305
|
-
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`);
|
|
4306
|
-
}
|
|
4307
|
-
}
|
|
4308
|
-
encodeBinary(object) {
|
|
4309
|
-
const size = object.byteLength;
|
|
4310
|
-
if (size < 256) {
|
|
4311
|
-
this.writeU8(196);
|
|
4312
|
-
this.writeU8(size);
|
|
4313
|
-
} else if (size < 65536) {
|
|
4314
|
-
this.writeU8(197);
|
|
4315
|
-
this.writeU16(size);
|
|
4316
|
-
} else if (size < 4294967296) {
|
|
4317
|
-
this.writeU8(198);
|
|
4318
|
-
this.writeU32(size);
|
|
4319
|
-
} else {
|
|
4320
|
-
throw new Error(`Too large binary: ${size}`);
|
|
4321
|
-
}
|
|
4322
|
-
const bytes = ensureUint8Array(object);
|
|
4323
|
-
this.writeU8a(bytes);
|
|
4324
|
-
}
|
|
4325
|
-
encodeArray(object, depth) {
|
|
4326
|
-
const size = object.length;
|
|
4327
|
-
if (size < 16) {
|
|
4328
|
-
this.writeU8(144 + size);
|
|
4329
|
-
} else if (size < 65536) {
|
|
4330
|
-
this.writeU8(220);
|
|
4331
|
-
this.writeU16(size);
|
|
4332
|
-
} else if (size < 4294967296) {
|
|
4333
|
-
this.writeU8(221);
|
|
4334
|
-
this.writeU32(size);
|
|
4335
|
-
} else {
|
|
4336
|
-
throw new Error(`Too large array: ${size}`);
|
|
4337
|
-
}
|
|
4338
|
-
for (const item of object) {
|
|
4339
|
-
this.doEncode(item, depth + 1);
|
|
4340
|
-
}
|
|
4341
|
-
}
|
|
4342
|
-
countWithoutUndefined(object, keys) {
|
|
4343
|
-
let count = 0;
|
|
4344
|
-
for (const key of keys) {
|
|
4345
|
-
if (object[key] !== void 0) {
|
|
4346
|
-
count++;
|
|
4347
|
-
}
|
|
4348
|
-
}
|
|
4349
|
-
return count;
|
|
4350
|
-
}
|
|
4351
|
-
encodeMap(object, depth) {
|
|
4352
|
-
const keys = Object.keys(object);
|
|
4353
|
-
if (this.sortKeys) {
|
|
4354
|
-
keys.sort();
|
|
4355
|
-
}
|
|
4356
|
-
const size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
|
|
4357
|
-
if (size < 16) {
|
|
4358
|
-
this.writeU8(128 + size);
|
|
4359
|
-
} else if (size < 65536) {
|
|
4360
|
-
this.writeU8(222);
|
|
4361
|
-
this.writeU16(size);
|
|
4362
|
-
} else if (size < 4294967296) {
|
|
4363
|
-
this.writeU8(223);
|
|
4364
|
-
this.writeU32(size);
|
|
4365
|
-
} else {
|
|
4366
|
-
throw new Error(`Too large map object: ${size}`);
|
|
4367
|
-
}
|
|
4368
|
-
for (const key of keys) {
|
|
4369
|
-
const value = object[key];
|
|
4370
|
-
if (!(this.ignoreUndefined && value === void 0)) {
|
|
4371
|
-
this.encodeString(key);
|
|
4372
|
-
this.doEncode(value, depth + 1);
|
|
4373
|
-
}
|
|
4374
|
-
}
|
|
4375
|
-
}
|
|
4376
|
-
encodeExtension(ext) {
|
|
4377
|
-
if (typeof ext.data === "function") {
|
|
4378
|
-
const data = ext.data(this.pos + 6);
|
|
4379
|
-
const size2 = data.length;
|
|
4380
|
-
if (size2 >= 4294967296) {
|
|
4381
|
-
throw new Error(`Too large extension object: ${size2}`);
|
|
4382
|
-
}
|
|
4383
|
-
this.writeU8(201);
|
|
4384
|
-
this.writeU32(size2);
|
|
4385
|
-
this.writeI8(ext.type);
|
|
4386
|
-
this.writeU8a(data);
|
|
4387
|
-
return;
|
|
4388
|
-
}
|
|
4389
|
-
const size = ext.data.length;
|
|
4390
|
-
if (size === 1) {
|
|
4391
|
-
this.writeU8(212);
|
|
4392
|
-
} else if (size === 2) {
|
|
4393
|
-
this.writeU8(213);
|
|
4394
|
-
} else if (size === 4) {
|
|
4395
|
-
this.writeU8(214);
|
|
4396
|
-
} else if (size === 8) {
|
|
4397
|
-
this.writeU8(215);
|
|
4398
|
-
} else if (size === 16) {
|
|
4399
|
-
this.writeU8(216);
|
|
4400
|
-
} else if (size < 256) {
|
|
4401
|
-
this.writeU8(199);
|
|
4402
|
-
this.writeU8(size);
|
|
4403
|
-
} else if (size < 65536) {
|
|
4404
|
-
this.writeU8(200);
|
|
4405
|
-
this.writeU16(size);
|
|
4406
|
-
} else if (size < 4294967296) {
|
|
4407
|
-
this.writeU8(201);
|
|
4408
|
-
this.writeU32(size);
|
|
4409
|
-
} else {
|
|
4410
|
-
throw new Error(`Too large extension object: ${size}`);
|
|
4411
|
-
}
|
|
4412
|
-
this.writeI8(ext.type);
|
|
4413
|
-
this.writeU8a(ext.data);
|
|
4414
|
-
}
|
|
4415
|
-
writeU8(value) {
|
|
4416
|
-
this.ensureBufferSizeToWrite(1);
|
|
4417
|
-
this.view.setUint8(this.pos, value);
|
|
4418
|
-
this.pos++;
|
|
4419
|
-
}
|
|
4420
|
-
writeU8a(values) {
|
|
4421
|
-
const size = values.length;
|
|
4422
|
-
this.ensureBufferSizeToWrite(size);
|
|
4423
|
-
this.bytes.set(values, this.pos);
|
|
4424
|
-
this.pos += size;
|
|
4425
|
-
}
|
|
4426
|
-
writeI8(value) {
|
|
4427
|
-
this.ensureBufferSizeToWrite(1);
|
|
4428
|
-
this.view.setInt8(this.pos, value);
|
|
4429
|
-
this.pos++;
|
|
4430
|
-
}
|
|
4431
|
-
writeU16(value) {
|
|
4432
|
-
this.ensureBufferSizeToWrite(2);
|
|
4433
|
-
this.view.setUint16(this.pos, value);
|
|
4434
|
-
this.pos += 2;
|
|
4435
|
-
}
|
|
4436
|
-
writeI16(value) {
|
|
4437
|
-
this.ensureBufferSizeToWrite(2);
|
|
4438
|
-
this.view.setInt16(this.pos, value);
|
|
4439
|
-
this.pos += 2;
|
|
4440
|
-
}
|
|
4441
|
-
writeU32(value) {
|
|
4442
|
-
this.ensureBufferSizeToWrite(4);
|
|
4443
|
-
this.view.setUint32(this.pos, value);
|
|
4444
|
-
this.pos += 4;
|
|
4445
|
-
}
|
|
4446
|
-
writeI32(value) {
|
|
4447
|
-
this.ensureBufferSizeToWrite(4);
|
|
4448
|
-
this.view.setInt32(this.pos, value);
|
|
4449
|
-
this.pos += 4;
|
|
4450
|
-
}
|
|
4451
|
-
writeF32(value) {
|
|
4452
|
-
this.ensureBufferSizeToWrite(4);
|
|
4453
|
-
this.view.setFloat32(this.pos, value);
|
|
4454
|
-
this.pos += 4;
|
|
4455
|
-
}
|
|
4456
|
-
writeF64(value) {
|
|
4457
|
-
this.ensureBufferSizeToWrite(8);
|
|
4458
|
-
this.view.setFloat64(this.pos, value);
|
|
4459
|
-
this.pos += 8;
|
|
4460
|
-
}
|
|
4461
|
-
writeU64(value) {
|
|
4462
|
-
this.ensureBufferSizeToWrite(8);
|
|
4463
|
-
setUint64(this.view, this.pos, value);
|
|
4464
|
-
this.pos += 8;
|
|
4465
|
-
}
|
|
4466
|
-
writeI64(value) {
|
|
4467
|
-
this.ensureBufferSizeToWrite(8);
|
|
4468
|
-
setInt64(this.view, this.pos, value);
|
|
4469
|
-
this.pos += 8;
|
|
4470
|
-
}
|
|
4471
|
-
writeBigUint64(value) {
|
|
4472
|
-
this.ensureBufferSizeToWrite(8);
|
|
4473
|
-
this.view.setBigUint64(this.pos, value);
|
|
4474
|
-
this.pos += 8;
|
|
4475
|
-
}
|
|
4476
|
-
writeBigInt64(value) {
|
|
4477
|
-
this.ensureBufferSizeToWrite(8);
|
|
4478
|
-
this.view.setBigInt64(this.pos, value);
|
|
4479
|
-
this.pos += 8;
|
|
4480
|
-
}
|
|
4481
|
-
}
|
|
4482
|
-
function encode(value, options) {
|
|
4483
|
-
const encoder = new Encoder(options);
|
|
4484
|
-
return encoder.encodeSharedRef(value);
|
|
4485
|
-
}
|
|
4486
|
-
class PublishTransportRESTServer extends stsutils.STSOptionsBase {
|
|
4487
|
-
constructor(options) {
|
|
4488
|
-
super(options);
|
|
4489
|
-
}
|
|
4490
|
-
get options() {
|
|
4491
|
-
return super.options;
|
|
4492
|
-
}
|
|
4493
|
-
// Returns true for success or false for failure.
|
|
4494
|
-
Publish = async (payload) => {
|
|
4495
|
-
try {
|
|
4496
|
-
if (this.options.showPublishPayload) {
|
|
4497
|
-
console.log(chalk.grey(`PublishTransportRESTServer::Publish() url: [${this.options.url}]`));
|
|
4498
|
-
console.log(payload);
|
|
4499
|
-
}
|
|
4500
|
-
const encodedData = encode(payload, { ignoreUndefined: true });
|
|
4501
|
-
const headers = { "Content-Type": "application/octet-stream" };
|
|
4502
|
-
let retVal = null;
|
|
4503
|
-
if (this.options.socketPath) {
|
|
4504
|
-
retVal = await axios({
|
|
4505
|
-
method: "post",
|
|
4506
|
-
data: Buffer.from(encodedData),
|
|
4507
|
-
headers,
|
|
4508
|
-
socketPath: this.options.socketPath
|
|
4509
|
-
});
|
|
4510
|
-
} else {
|
|
4511
|
-
if (isNode) {
|
|
4512
|
-
if (this.options.agentManager) {
|
|
4513
|
-
retVal = await axios(new stsutils.STSAxiosConfig(this.options.url, "post", headers).withData(Buffer.from(encodedData)).withAgentManager(this.options.agentManager).config);
|
|
4514
|
-
} else {
|
|
4515
|
-
retVal = await axios(new stsutils.STSAxiosConfig(this.options.url, "post", headers).withData(Buffer.from(encodedData)).config);
|
|
4516
|
-
}
|
|
4517
|
-
} else {
|
|
4518
|
-
const blob = new Blob([new Uint8Array(encodedData)], { type: "application/octet-stream" });
|
|
4519
|
-
retVal = await axios(new stsutils.STSAxiosConfig(this.options.url, "post", headers).withData(blob).config);
|
|
4520
|
-
}
|
|
4521
|
-
}
|
|
4522
|
-
if (retVal.status !== 200) {
|
|
4523
|
-
if (this.options.showPublishPayload) {
|
|
4524
|
-
console.log(chalk.red(`PublishTransportRESTServer::Publish() Error (_PerformPublishRESTAPI:_PerformPublish:#publishmessage): Invalid response from server: [${retVal.status}]`));
|
|
4525
|
-
}
|
|
4526
|
-
this.options.logger.debug(chalk.red(`Error (_PerformPublishRESTAPI:_PerformPublish:#publishmessage): Invalid response from server: [${retVal.status}]`));
|
|
4527
|
-
return false;
|
|
4528
|
-
} else {
|
|
4529
|
-
if (this.options.showPublishPayload) {
|
|
4530
|
-
console.log(chalk.grey(`PublishTransportRESTServer::Publish() _PerformPublishRESTAPI:_PerformPublish:#publishmessage: [${this.options.url}] - Valid response from server: [${retVal.status}]`));
|
|
4531
|
-
}
|
|
4532
|
-
}
|
|
4533
|
-
return true;
|
|
4534
|
-
} catch (error) {
|
|
4535
|
-
if (this.options.showPublishPayload) {
|
|
4536
|
-
console.log(chalk.red(`PublishTransportRESTServer::Publish() Error (PublishRESTServer:_PerformPublishRESTAPI:Error: [${error}]`));
|
|
4537
|
-
}
|
|
4538
|
-
return false;
|
|
4539
|
-
}
|
|
4540
|
-
};
|
|
4541
|
-
async Close() {
|
|
4542
|
-
if (this.options.agentManager) {
|
|
4543
|
-
this.options.agentManager.Terminate();
|
|
4544
|
-
}
|
|
4545
|
-
return true;
|
|
4546
|
-
}
|
|
4547
|
-
}
|
|
4548
|
-
class PublishInstruments extends stsutils.STSOptionsBase {
|
|
4549
|
-
#inPublish = false;
|
|
4550
|
-
#observer = null;
|
|
4551
|
-
#publishState = 0;
|
|
4552
|
-
#publisherTransport = null;
|
|
4553
|
-
constructor(options) {
|
|
4554
|
-
super(options);
|
|
4555
|
-
this.#publisherTransport = null;
|
|
4556
|
-
switch (options.publishTransportBaseOptions.transportType) {
|
|
4557
|
-
case TransportType.RESTAPI:
|
|
4558
|
-
this.#publisherTransport = new PublishTransportRESTServer(options.publishTransportBaseOptions);
|
|
4559
|
-
break;
|
|
4560
|
-
}
|
|
4561
|
-
this.#UpdateState(0, "constructor()");
|
|
4562
|
-
}
|
|
4563
|
-
get options() {
|
|
4564
|
-
return super.options;
|
|
4565
|
-
}
|
|
4566
|
-
async Publish() {
|
|
4567
|
-
if (this.#inPublish) {
|
|
4568
|
-
return false;
|
|
4569
|
-
}
|
|
4570
|
-
if (this.#publisherTransport) {
|
|
4571
|
-
try {
|
|
4572
|
-
this.#inPublish = true;
|
|
4573
|
-
if (this.options.publishInstrumentController) {
|
|
4574
|
-
const instrumentPayload = this.options.publishInstrumentController.GetPayloadData();
|
|
4575
|
-
return await this.#publisherTransport.Publish(instrumentPayload);
|
|
4576
|
-
}
|
|
4577
|
-
return false;
|
|
4578
|
-
} catch (error) {
|
|
4579
|
-
return false;
|
|
4580
|
-
} finally {
|
|
4581
|
-
this.#inPublish = false;
|
|
4582
|
-
}
|
|
4583
|
-
} else {
|
|
4584
|
-
return false;
|
|
4585
|
-
}
|
|
4586
|
-
}
|
|
4587
|
-
#PublishTimeoutLoop(publishInterval) {
|
|
4588
|
-
this.#observer = setTimeout(async () => {
|
|
4589
|
-
const start = performance.now();
|
|
4590
|
-
const result = await this.Publish();
|
|
4591
|
-
const end = performance.now();
|
|
4592
|
-
const diff = end - start;
|
|
4593
|
-
if (this.#publishState === 1) {
|
|
4594
|
-
if (result === true) {
|
|
4595
|
-
this.#PublishTimeoutLoop(this.options.publishInterval - diff);
|
|
4596
|
-
} else {
|
|
4597
|
-
this.#PublishTimeoutLoop(this.options.publishPostFailInterval - diff);
|
|
4598
|
-
}
|
|
4599
|
-
}
|
|
4600
|
-
}, publishInterval);
|
|
4601
|
-
if (isNode) this.#observer.unref();
|
|
4602
|
-
}
|
|
4603
|
-
async StartPublish() {
|
|
4604
|
-
if (this.#publishState !== 0) {
|
|
4605
|
-
this.options.logger.debug(chalk.yellow(`StartPublish:${this.options.processContext.nid}: StartPublish called when not currently in the init state. Current State: [${this.#publishState}]`));
|
|
4606
|
-
return false;
|
|
4607
|
-
}
|
|
4608
|
-
this.#UpdateState(1, "StartPublish()");
|
|
4609
|
-
this.#PublishTimeoutLoop(this.options.publishInterval);
|
|
4610
|
-
return true;
|
|
4611
|
-
}
|
|
4612
|
-
#UpdateState(newState, comment) {
|
|
4613
|
-
const previousState = this.#publishState;
|
|
4614
|
-
this.#publishState = newState;
|
|
4615
|
-
this.options.logger.debug(chalk.yellow(`#UpdateState:${this.options.processContext.nid}: Previous State: [${previousState}]. Current State: [${this.#publishState}]. Comment: [${comment}]`));
|
|
4616
|
-
}
|
|
4617
|
-
async EndPublish() {
|
|
4618
|
-
if (this.#publishState !== 1) {
|
|
4619
|
-
this.options.logger.debug(chalk.yellow(`EndPublish:${this.options.processContext.nid}: EndPublish called when not within the started state. Current State: [${this.#publishState}]`));
|
|
4620
|
-
return false;
|
|
4621
|
-
}
|
|
4622
|
-
this.#UpdateState(2, "EndPublish() (1)");
|
|
4623
|
-
if (this.#observer !== null) {
|
|
4624
|
-
clearTimeout(this.#observer);
|
|
4625
|
-
this.#observer = null;
|
|
4626
|
-
await this.Publish();
|
|
4627
|
-
}
|
|
4628
|
-
if (this.#publisherTransport) {
|
|
4629
|
-
await this.#publisherTransport.Close();
|
|
4630
|
-
}
|
|
4631
|
-
this.#UpdateState(0, "EndPublish() (2)");
|
|
4632
|
-
return true;
|
|
4633
|
-
}
|
|
4634
|
-
}
|
|
4635
|
-
var ePublishState = /* @__PURE__ */ ((ePublishState2) => {
|
|
4636
|
-
ePublishState2[ePublishState2["init"] = 0] = "init";
|
|
4637
|
-
ePublishState2[ePublishState2["started"] = 1] = "started";
|
|
4638
|
-
ePublishState2[ePublishState2["stopping"] = 2] = "stopping";
|
|
4639
|
-
return ePublishState2;
|
|
4640
|
-
})(ePublishState || {});
|
|
4641
|
-
class PublishInstrumentController extends stsutils.STSOptionsBase {
|
|
4642
|
-
#instruments = {};
|
|
4643
|
-
#publisher = null;
|
|
4644
|
-
constructor(options) {
|
|
4645
|
-
super(options);
|
|
4646
|
-
this.SetupInstrumentation();
|
|
4647
|
-
const publishInstrumentsOptions = {
|
|
4648
|
-
logger: options.logger,
|
|
4649
|
-
processContext: { ...options.processContext },
|
|
4650
|
-
publishInterval: options.publishInterval,
|
|
4651
|
-
publishPostFailInterval: options.publishPostFailInterval,
|
|
4652
|
-
publishInstrumentController: this,
|
|
4653
|
-
publishTransportBaseOptions: { ...options.publishTransportBaseOptions }
|
|
4654
|
-
};
|
|
4655
|
-
this.#publisher = new PublishInstruments(publishInstrumentsOptions);
|
|
4656
|
-
if (this.options.autoStart === true) {
|
|
4657
|
-
this.StartPublish();
|
|
4658
|
-
}
|
|
4659
|
-
}
|
|
4660
|
-
get options() {
|
|
4661
|
-
return super.options;
|
|
4662
|
-
}
|
|
4663
|
-
async StartPublish() {
|
|
4664
|
-
return this.#publisher.StartPublish();
|
|
4665
|
-
}
|
|
4666
|
-
async EndPublish() {
|
|
4667
|
-
return this.#publisher.EndPublish();
|
|
4668
|
-
}
|
|
4669
|
-
async Publish() {
|
|
4670
|
-
return this.#publisher.Publish();
|
|
4671
|
-
}
|
|
4672
|
-
LogEx = (message) => {
|
|
4673
|
-
this.UpdateInstrument(Gauge.LOGGER, {
|
|
4674
|
-
LogMessage: message
|
|
4675
|
-
});
|
|
4676
|
-
};
|
|
4677
|
-
#GetInstrument(instrumentName) {
|
|
4678
|
-
return this.#instruments[instrumentName];
|
|
4679
|
-
}
|
|
4680
|
-
#ProcessTelemetryCommand(instrumentName, telemetry) {
|
|
4681
|
-
const instrument = this.#GetInstrument(instrumentName);
|
|
4682
|
-
if (instrument) {
|
|
4683
|
-
instrument.ProcessTelemetry(telemetry);
|
|
4684
|
-
}
|
|
4685
|
-
}
|
|
4686
|
-
// Instrument factory
|
|
4687
|
-
#CreateInstrument(instrumentType, options) {
|
|
4688
|
-
let instrument;
|
|
4689
|
-
switch (instrumentType) {
|
|
4690
|
-
case GaugeTypes.INSTRUMENT_GAUGE:
|
|
4691
|
-
instrument = new InstrumentGauge(options);
|
|
4692
|
-
break;
|
|
4693
|
-
case GaugeTypes.INSTRUMENT_HISTOGRAM:
|
|
4694
|
-
instrument = new InstrumentHistogram(options);
|
|
4695
|
-
break;
|
|
4696
|
-
case GaugeTypes.INSTRUMENT_LOG:
|
|
4697
|
-
instrument = new InstrumentLog(options);
|
|
4698
|
-
break;
|
|
4699
|
-
case GaugeTypes.INSTRUMENT_OBJECT:
|
|
4700
|
-
instrument = new InstrumentObject(options);
|
|
4701
|
-
break;
|
|
4702
|
-
case GaugeTypes.INSTRUMENT_TIMER:
|
|
4703
|
-
instrument = new InstrumentTimerGauge(options);
|
|
4704
|
-
break;
|
|
4705
|
-
case GaugeTypes.INSTRUMENT_VELOCITY:
|
|
4706
|
-
instrument = new InstrumentVelocity(options);
|
|
4707
|
-
break;
|
|
4708
|
-
default:
|
|
4709
|
-
throw new Error(`Gauge type: [${instrumentType} not known.]`);
|
|
4710
|
-
}
|
|
4711
|
-
return instrument;
|
|
4712
|
-
}
|
|
4713
|
-
#CreateInstruments(payload) {
|
|
4714
|
-
payload.forEach((instrumentDefinition) => {
|
|
4715
|
-
const g = instrumentDefinition[0];
|
|
4716
|
-
const gt = instrumentDefinition[1];
|
|
4717
|
-
const instrumentBaseOptions = instrumentDefinition[2];
|
|
4718
|
-
const instrument = this.#CreateInstrument(gt, instrumentBaseOptions);
|
|
4719
|
-
this.#instruments[g] = instrument;
|
|
4720
|
-
});
|
|
4721
|
-
}
|
|
4722
|
-
GetPayloadData() {
|
|
4723
|
-
const context = this.options.processContext;
|
|
4724
|
-
const instruments = this.#instruments;
|
|
4725
|
-
const payloadInstruments = {};
|
|
4726
|
-
for (const [key, value] of Object.entries(instruments)) {
|
|
4727
|
-
if (value instanceof InstrumentLog) {
|
|
4728
|
-
payloadInstruments[key] = { ...value.WithUseLatestMessages(true) };
|
|
4729
|
-
} else {
|
|
4730
|
-
payloadInstruments[key] = { ...value };
|
|
4731
|
-
}
|
|
4732
|
-
}
|
|
4733
|
-
return {
|
|
4734
|
-
context,
|
|
4735
|
-
instruments: payloadInstruments
|
|
4736
|
-
};
|
|
4737
|
-
}
|
|
4738
|
-
SetupInstrumentation() {
|
|
4739
|
-
if (!this.options.instrumentDefinitions) {
|
|
4740
|
-
this.options.logger.debug(chalk.yellow(`SetupInstrumentation:${this.options.processContext.nid}: No instrument(s) defined within supplied options.`));
|
|
4741
|
-
return;
|
|
4742
|
-
}
|
|
4743
|
-
if (!this.options.processContext) {
|
|
4744
|
-
this.options.logger.debug(chalk.yellow(`SetupInstrumentation: No context defined within supplied options.`));
|
|
4745
|
-
return;
|
|
4746
|
-
}
|
|
4747
|
-
this.#CreateInstruments(this.options.instrumentDefinitions);
|
|
4748
|
-
}
|
|
4749
|
-
/**
|
|
4750
|
-
* Check if an instrument exists within the managed instrument collection
|
|
4751
|
-
* @param instrumentName
|
|
4752
|
-
* @returns
|
|
4753
|
-
*/
|
|
4754
|
-
InstrumentExists(instrumentName) {
|
|
4755
|
-
if (this.#instruments[instrumentName]) {
|
|
4756
|
-
return true;
|
|
4757
|
-
}
|
|
4758
|
-
return false;
|
|
4759
|
-
}
|
|
4760
|
-
/**
|
|
4761
|
-
* Update instrument telemetry.
|
|
4762
|
-
* @param instrumentName
|
|
4763
|
-
* @param telemetry
|
|
4764
|
-
*/
|
|
4765
|
-
UpdateInstrument(instrumentName, telemetry) {
|
|
4766
|
-
if (this.#instruments[instrumentName]) {
|
|
4767
|
-
this.#ProcessTelemetryCommand(instrumentName, telemetry);
|
|
4768
|
-
} else {
|
|
4769
|
-
this.options.logger.debug(chalk.red(`UpdateInstrument:${this.options.processContext.nid}: Attempted to UpdateInstrument before initialised.`));
|
|
4770
|
-
}
|
|
4771
|
-
}
|
|
4772
|
-
/**
|
|
4773
|
-
* Add additional instrument publishers. Usually invoked when adding workers to the app and/or async runners within a worker.
|
|
4774
|
-
* @param processContext
|
|
4775
|
-
* @returns Returns the newly created PublishInstrumentController
|
|
4776
|
-
*/
|
|
4777
|
-
AddPublishInstrumentController(processContext) {
|
|
4778
|
-
const options = { ...this.options };
|
|
4779
|
-
options.processContext = processContext;
|
|
4780
|
-
return new PublishInstrumentController(options);
|
|
4781
|
-
}
|
|
4782
|
-
}
|
|
4783
|
-
const STSInstrumentControllerPluginKey = /* @__PURE__ */ Symbol("instrumentController");
|
|
4784
|
-
const GetSTSInstrumentControllerPluginKey = () => STSInstrumentControllerPluginKey;
|
|
4785
|
-
const CompareSTSInstrumentControllerPluginKey = (val) => val === STSInstrumentControllerPluginKey;
|
|
4786
|
-
const useSTSInstrumentControllerPlugin = () => vue.inject(STSInstrumentControllerPluginKey);
|
|
4787
|
-
const GetSTSInstrumentController = (app) => {
|
|
4788
|
-
return app.config.globalProperties.$sts[STSInstrumentControllerPluginKey];
|
|
4789
|
-
};
|
|
4790
|
-
const STSInstrumentControllerPlugin = {
|
|
4791
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4792
|
-
install: (app, options) => {
|
|
4793
|
-
options.logger.debug(chalk.yellow(`STSInstrumentControllerPlugin:install:Start`));
|
|
4794
|
-
const aic = new PublishInstrumentController(options);
|
|
4795
|
-
if (!app.config.globalProperties.$sts) {
|
|
4796
|
-
options.logger.debug(chalk.cyan(`STSInstrumentControllerPlugin:install: [app.config.globalProperties.$sts] does not exist.`));
|
|
4797
|
-
app.config.globalProperties.$sts = {};
|
|
4798
|
-
options.logger.debug(chalk.cyan(`STSInstrumentControllerPlugin:install: created empty [app.config.globalProperties.$sts].`));
|
|
4799
|
-
} else {
|
|
4800
|
-
options.logger.debug(chalk.cyan(`STSInstrumentControllerPlugin:install: [app.config.globalProperties.$sts] already exists.`));
|
|
4801
|
-
}
|
|
4802
|
-
app.config.globalProperties.$sts.aic = aic;
|
|
4803
|
-
app.config.globalProperties.$sts[STSInstrumentControllerPluginKey] = aic;
|
|
4804
|
-
options.logger.debug(chalk.cyan(`STSInstrumentControllerPlugin:install: AgentInstrumentController installed into [app.config.globalProperties.$sts] using: [${String(STSInstrumentControllerPluginKey)}].`));
|
|
4805
|
-
app.provide(STSInstrumentControllerPluginKey, aic);
|
|
4806
|
-
options.logger.debug(chalk.cyan(`STSInstrumentControllerPlugin:install: AgentInstrumentController installed into 'provide' using: [${String(STSInstrumentControllerPluginKey)}].`));
|
|
4807
|
-
options.logger.debug(chalk.green(`STSInstrumentControllerPlugin:install:End`));
|
|
4808
|
-
}
|
|
4809
|
-
};
|
|
4810
|
-
var SubscriptionTopic = /* @__PURE__ */ ((SubscriptionTopic2) => {
|
|
4811
|
-
SubscriptionTopic2["AllServicesCombined"] = "AllServicesCombined";
|
|
4812
|
-
SubscriptionTopic2["Services"] = "Services";
|
|
4813
|
-
SubscriptionTopic2["ServiceInstances"] = "ServiceInstances";
|
|
4814
|
-
SubscriptionTopic2["ServiceInstance"] = "ServiceInstance";
|
|
4815
|
-
SubscriptionTopic2["AllAgentsCombined"] = "AllAgentsCombined";
|
|
4816
|
-
SubscriptionTopic2["Agents"] = "Agents";
|
|
4817
|
-
SubscriptionTopic2["AgentWorkers"] = "AgentWorkers";
|
|
4818
|
-
SubscriptionTopic2["AgentWorker"] = "AgentWorker";
|
|
4819
|
-
SubscriptionTopic2["AllLambdasCombined"] = "AllLambdasCombined";
|
|
4820
|
-
SubscriptionTopic2["LambdaTechnologies"] = "LambdaTechnologies";
|
|
4821
|
-
SubscriptionTopic2["LambdaSubTechnologies"] = "LambdaSubTechnologies";
|
|
4822
|
-
SubscriptionTopic2["LambdaSubTechnologiesInstance"] = "LambdaSubTechnologiesInstance";
|
|
4823
|
-
SubscriptionTopic2["LogProcessing"] = "LogProcessing";
|
|
4824
|
-
return SubscriptionTopic2;
|
|
4825
|
-
})(SubscriptionTopic || {});
|
|
4826
|
-
const GetSocketIOSubscriptionKey = (subscriptionKey) => {
|
|
4827
|
-
return `SubscriptionData_${subscriptionKey.id}`;
|
|
4828
|
-
};
|
|
4829
|
-
const KAFKA_PREFIX = "__STS__";
|
|
4830
|
-
var influxDBDataType = /* @__PURE__ */ ((influxDBDataType2) => {
|
|
4831
|
-
influxDBDataType2["intField"] = "intField";
|
|
4832
|
-
influxDBDataType2["floatField"] = "floatField";
|
|
4833
|
-
influxDBDataType2["stringField"] = "stringField";
|
|
4834
|
-
return influxDBDataType2;
|
|
4835
|
-
})(influxDBDataType || {});
|
|
4836
|
-
const instrumentationObservationInterval = 1e3;
|
|
4837
|
-
const instrumentationTimeWindow = 600;
|
|
4838
|
-
const consoleLogging = false;
|
|
4839
|
-
const instrumentLogging = true;
|
|
4840
|
-
const globalServiceDefinitions = {
|
|
4841
|
-
coreFieldList: [
|
|
4842
|
-
{ fieldName: "requestCount", gauge: Gauge.REQUEST_COUNT_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4843
|
-
{ fieldName: "errorCount", gauge: Gauge.ERROR_COUNT_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4844
|
-
{ fieldName: "retryCount", gauge: Gauge.RETRY_COUNT_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4845
|
-
{ fieldName: "authenticationCount", gauge: Gauge.AUTHENTICATION_COUNT_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4846
|
-
{ fieldName: "authenticationErrorCount", gauge: Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4847
|
-
{ fieldName: "authenticationRetryCount", gauge: Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4848
|
-
{ fieldName: "velocity", gauge: Gauge.VELOCITY_GAUGE, instrumentProperty: "va", dataType: "number", influxdbDataType: "floatField", gaugeType: GaugeTypes.INSTRUMENT_VELOCITY },
|
|
4849
|
-
{
|
|
4850
|
-
fieldName: "activeRequestCount",
|
|
4851
|
-
gauge: Gauge.ACTIVE_REQUEST_GAUGE,
|
|
4852
|
-
instrumentProperty: "val",
|
|
4853
|
-
dataType: "number",
|
|
4854
|
-
timeSeriesIndex: true,
|
|
4855
|
-
quantile: true,
|
|
4856
|
-
influxdbDataType: "intField",
|
|
4857
|
-
gaugeType: GaugeTypes.INSTRUMENT_GAUGE,
|
|
4858
|
-
instrumentOptions: {
|
|
4859
|
-
interval: instrumentationObservationInterval,
|
|
4860
|
-
sampleSize: instrumentationTimeWindow
|
|
4861
|
-
}
|
|
4862
|
-
},
|
|
4863
|
-
{ fieldName: "coreCount", gauge: Gauge.CORE_COUNT_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4864
|
-
{ fieldName: "rx", gauge: Gauge.NETWORK_RX_GAUGE, instrumentProperty: "va", dataType: "number", influxdbDataType: "floatField", gaugeType: GaugeTypes.INSTRUMENT_VELOCITY },
|
|
4865
|
-
{ fieldName: "tx", gauge: Gauge.NETWORK_TX_GAUGE, instrumentProperty: "va", dataType: "number", influxdbDataType: "floatField", gaugeType: GaugeTypes.INSTRUMENT_VELOCITY },
|
|
4866
|
-
{ fieldName: "timer", gauge: Gauge.TIMER_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "floatField", gaugeType: GaugeTypes.INSTRUMENT_TIMER },
|
|
4867
|
-
{
|
|
4868
|
-
fieldName: "duration",
|
|
4869
|
-
gauge: Gauge.DURATION_GAUGE,
|
|
4870
|
-
instrumentProperty: "val",
|
|
4871
|
-
dataType: "number",
|
|
4872
|
-
timeSeriesIndex: true,
|
|
4873
|
-
quantile: true,
|
|
4874
|
-
influxdbDataType: "floatField",
|
|
4875
|
-
gaugeType: GaugeTypes.INSTRUMENT_GAUGE,
|
|
4876
|
-
instrumentOptions: {
|
|
4877
|
-
interval: instrumentationObservationInterval,
|
|
4878
|
-
sampleSize: instrumentationTimeWindow
|
|
4879
|
-
},
|
|
4880
|
-
histo: [
|
|
4881
|
-
{ label: "B10", bucketLimit: 10 },
|
|
4882
|
-
{ label: "B20", bucketLimit: 20 },
|
|
4883
|
-
{ label: "B50", bucketLimit: 50 },
|
|
4884
|
-
{ label: "B100", bucketLimit: 100 },
|
|
4885
|
-
{ label: "B1000", bucketLimit: 1e3 },
|
|
4886
|
-
{ label: "B50000", bucketLimit: 5e4 },
|
|
4887
|
-
{ label: "BInfinity", bucketLimit: -1 }
|
|
4888
|
-
],
|
|
4889
|
-
histoGauge: Gauge.DURATION_HISTOGRAM_GAUGE
|
|
4890
|
-
},
|
|
4891
|
-
{
|
|
4892
|
-
fieldName: "latency",
|
|
4893
|
-
gauge: Gauge.LATENCY_GAUGE,
|
|
4894
|
-
instrumentProperty: "val",
|
|
4895
|
-
dataType: "number",
|
|
4896
|
-
timeSeriesIndex: true,
|
|
4897
|
-
quantile: true,
|
|
4898
|
-
influxdbDataType: "floatField",
|
|
4899
|
-
gaugeType: GaugeTypes.INSTRUMENT_GAUGE,
|
|
4900
|
-
instrumentOptions: {
|
|
4901
|
-
interval: instrumentationObservationInterval,
|
|
4902
|
-
sampleSize: instrumentationTimeWindow
|
|
4903
|
-
},
|
|
4904
|
-
histo: [
|
|
4905
|
-
{ label: "B10", bucketLimit: 10 },
|
|
4906
|
-
{ label: "B20", bucketLimit: 20 },
|
|
4907
|
-
{ label: "B50", bucketLimit: 50 },
|
|
4908
|
-
{ label: "B100", bucketLimit: 100 },
|
|
4909
|
-
{ label: "B1000", bucketLimit: 1e3 },
|
|
4910
|
-
{ label: "B50000", bucketLimit: 5e4 },
|
|
4911
|
-
{ label: "BInfinity", bucketLimit: -1 }
|
|
4912
|
-
],
|
|
4913
|
-
histoGauge: Gauge.LATENCY_HISTOGRAM_GAUGE
|
|
4914
|
-
}
|
|
4915
|
-
],
|
|
4916
|
-
logFieldList: [
|
|
4917
|
-
{
|
|
4918
|
-
fieldName: "log",
|
|
4919
|
-
gauge: Gauge.LOGGER,
|
|
4920
|
-
instrumentProperty: "val",
|
|
4921
|
-
dataType: "string",
|
|
4922
|
-
timeSeriesIndex: false,
|
|
4923
|
-
quantile: false,
|
|
4924
|
-
influxdbDataType: "stringField",
|
|
4925
|
-
gaugeType: GaugeTypes.INSTRUMENT_LOG,
|
|
4926
|
-
instrumentOptions: {
|
|
4927
|
-
consoleLogging,
|
|
4928
|
-
instrumentLogging
|
|
4929
|
-
}
|
|
4930
|
-
}
|
|
4931
|
-
],
|
|
4932
|
-
services: {
|
|
4933
|
-
["service"]: {
|
|
4934
|
-
influxDBContextTags: [
|
|
4935
|
-
"serviceId",
|
|
4936
|
-
"serviceName",
|
|
4937
|
-
"serviceVersion",
|
|
4938
|
-
"serviceInstanceId",
|
|
4939
|
-
"serviceInstanceProcessId",
|
|
4940
|
-
"hostName",
|
|
4941
|
-
"pid",
|
|
4942
|
-
"ppid"
|
|
4943
|
-
],
|
|
4944
|
-
redisIndexPrefixDefinitions: {
|
|
4945
|
-
timeSeriesIndex: "idx:serviceIndexTimeSeries",
|
|
4946
|
-
timeSeriesPrefix: "/serviceTimeSeries:",
|
|
4947
|
-
instantIndex: "idx:serviceIndexInstant",
|
|
4948
|
-
instantPrefix: "/serviceInstant:"
|
|
4949
|
-
},
|
|
4950
|
-
fieldList: [
|
|
4951
|
-
{
|
|
4952
|
-
fieldName: "cpu",
|
|
4953
|
-
gauge: Gauge.CPU_LOAD_GAUGE,
|
|
4954
|
-
instrumentProperty: "val",
|
|
4955
|
-
dataType: "number",
|
|
4956
|
-
timeSeriesIndex: true,
|
|
4957
|
-
quantile: true,
|
|
4958
|
-
influxdbDataType: "floatField",
|
|
4959
|
-
gaugeType: GaugeTypes.INSTRUMENT_GAUGE,
|
|
4960
|
-
instrumentOptions: {
|
|
4961
|
-
interval: instrumentationObservationInterval,
|
|
4962
|
-
sampleSize: instrumentationTimeWindow
|
|
4963
|
-
}
|
|
4964
|
-
},
|
|
4965
|
-
{
|
|
4966
|
-
fieldName: "connectionCount",
|
|
4967
|
-
gauge: Gauge.CONNECTION_COUNT_GAUGE,
|
|
4968
|
-
instrumentProperty: "val",
|
|
4969
|
-
dataType: "number",
|
|
4970
|
-
timeSeriesIndex: true,
|
|
4971
|
-
quantile: true,
|
|
4972
|
-
influxdbDataType: "intField",
|
|
4973
|
-
gaugeType: GaugeTypes.INSTRUMENT_GAUGE,
|
|
4974
|
-
instrumentOptions: {
|
|
4975
|
-
interval: instrumentationObservationInterval,
|
|
4976
|
-
sampleSize: instrumentationTimeWindow
|
|
4977
|
-
}
|
|
4978
|
-
},
|
|
4979
|
-
{ fieldName: "connectionPoolCount", gauge: Gauge.CONNECTION_POOL_TOTAL_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4980
|
-
{ fieldName: "connectionIdleCount", gauge: Gauge.CONNECTION_POOL_IDLE_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4981
|
-
{ fieldName: "connectionWaitingCount", gauge: Gauge.CONNECTION_POOL_WAITING_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4982
|
-
{ fieldName: "systemcpu", gauge: Gauge.CPU_SYSTEM_LOAD_GAUGE, instrumentProperty: "val", dataType: "number", timeSeriesIndex: true, quantile: true, influxdbDataType: "floatField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
4983
|
-
{
|
|
4984
|
-
fieldName: "memory",
|
|
4985
|
-
gauge: Gauge.OBJECT_GAUGE,
|
|
4986
|
-
instrumentProperty: "val",
|
|
4987
|
-
dataType: "JSON",
|
|
4988
|
-
influxdbDataType: "stringField",
|
|
4989
|
-
gaugeType: GaugeTypes.INSTRUMENT_OBJECT,
|
|
4990
|
-
instrumentOptions: {
|
|
4991
|
-
label: "InstrumentObjectMaster"
|
|
4992
|
-
}
|
|
4993
|
-
}
|
|
4994
|
-
],
|
|
4995
|
-
GetPathFromContext(context) {
|
|
4996
|
-
const { serviceId, serviceInstanceId, serviceInstanceProcessId } = context;
|
|
4997
|
-
return `/${serviceId}/${serviceInstanceId}/${serviceInstanceProcessId}`;
|
|
4998
|
-
},
|
|
4999
|
-
redisQueryFilters: {
|
|
5000
|
-
level1ContextField: "serviceType",
|
|
5001
|
-
level2ContextField: "appid",
|
|
5002
|
-
level3ContextField: "appinstanceid"
|
|
5003
|
-
},
|
|
5004
|
-
subscriptionTopics: [
|
|
5005
|
-
{
|
|
5006
|
-
subscriptionTopic: SubscriptionTopic.AllServicesCombined,
|
|
5007
|
-
route: "/metrics"
|
|
5008
|
-
},
|
|
5009
|
-
{
|
|
5010
|
-
subscriptionTopic: SubscriptionTopic.Services,
|
|
5011
|
-
route: "/metrics/services"
|
|
5012
|
-
},
|
|
5013
|
-
{
|
|
5014
|
-
subscriptionTopic: SubscriptionTopic.ServiceInstances,
|
|
5015
|
-
route: "/metrics/services/:key"
|
|
5016
|
-
},
|
|
5017
|
-
{
|
|
5018
|
-
subscriptionTopic: SubscriptionTopic.ServiceInstance,
|
|
5019
|
-
route: "/metrics/services/:key/:subkey"
|
|
5020
|
-
}
|
|
5021
|
-
]
|
|
5022
|
-
},
|
|
5023
|
-
["agent"]: {
|
|
5024
|
-
influxDBContextTags: [
|
|
5025
|
-
"id",
|
|
5026
|
-
"hostName",
|
|
5027
|
-
"agentName",
|
|
5028
|
-
"threadId",
|
|
5029
|
-
"asyncRunnerId"
|
|
5030
|
-
],
|
|
5031
|
-
redisIndexPrefixDefinitions: {
|
|
5032
|
-
timeSeriesIndex: "idx:agentIndexTimeSeries",
|
|
5033
|
-
timeSeriesPrefix: "/agentTimeSeries:",
|
|
5034
|
-
instantIndex: "idx:agentIndexInstant",
|
|
5035
|
-
instantPrefix: "/agentInstant:"
|
|
5036
|
-
},
|
|
5037
|
-
fieldList: [
|
|
5038
|
-
{ fieldName: "childCount", gauge: Gauge.CHILD_COUNT, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE }
|
|
5039
|
-
],
|
|
5040
|
-
//@@ need type declare in appframework ?? agent does not use appframework ... perhaps stspublisher
|
|
5041
|
-
GetPathFromContext(context) {
|
|
5042
|
-
const { agentName, threadId, asyncRunnerId } = context;
|
|
5043
|
-
return `/${agentName}/${threadId}/${asyncRunnerId}`;
|
|
5044
|
-
},
|
|
5045
|
-
redisQueryFilters: {
|
|
5046
|
-
level1ContextField: "serviceType",
|
|
5047
|
-
level2ContextField: "appid",
|
|
5048
|
-
//@@ this should be named something else
|
|
5049
|
-
level3ContextField: "appinstanceid"
|
|
5050
|
-
//@@ this should be named something else
|
|
5051
|
-
},
|
|
5052
|
-
subscriptionTopics: [
|
|
5053
|
-
{
|
|
5054
|
-
subscriptionTopic: SubscriptionTopic.AllAgentsCombined,
|
|
5055
|
-
route: "/metrics"
|
|
5056
|
-
},
|
|
5057
|
-
{
|
|
5058
|
-
subscriptionTopic: SubscriptionTopic.Agents,
|
|
5059
|
-
route: "/metrics/agents"
|
|
5060
|
-
},
|
|
5061
|
-
{
|
|
5062
|
-
subscriptionTopic: SubscriptionTopic.AgentWorkers,
|
|
5063
|
-
route: "/metrics/agents/:key"
|
|
5064
|
-
},
|
|
5065
|
-
{
|
|
5066
|
-
subscriptionTopic: SubscriptionTopic.AgentWorker,
|
|
5067
|
-
route: "/metrics/agents/:key/:subkey"
|
|
5068
|
-
}
|
|
5069
|
-
]
|
|
5070
|
-
},
|
|
5071
|
-
["lambda"]: {
|
|
5072
|
-
influxDBContextTags: [
|
|
5073
|
-
"technology",
|
|
5074
|
-
"subTechnology",
|
|
5075
|
-
"lambdaFunctionName",
|
|
5076
|
-
"lambdaInstance",
|
|
5077
|
-
"hostName",
|
|
5078
|
-
"processId",
|
|
5079
|
-
"parentProcessId",
|
|
5080
|
-
"useCase",
|
|
5081
|
-
"pattern"
|
|
5082
|
-
],
|
|
5083
|
-
redisIndexPrefixDefinitions: {
|
|
5084
|
-
timeSeriesIndex: "idx:lambdaIndexTimeSeries",
|
|
5085
|
-
timeSeriesPrefix: "/lambdaTimeSeries:",
|
|
5086
|
-
instantIndex: "idx:lambdaIndexInstant",
|
|
5087
|
-
instantPrefix: "/lambdaInstant:"
|
|
5088
|
-
},
|
|
5089
|
-
fieldList: [
|
|
5090
|
-
{ fieldName: "cpu", gauge: Gauge.CPU_LOAD_GAUGE, instrumentProperty: "val", dataType: "number", timeSeriesIndex: true, quantile: true, influxdbDataType: "floatField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
5091
|
-
{ fieldName: "connectionCount", gauge: Gauge.CONNECTION_COUNT_GAUGE, instrumentProperty: "val", dataType: "number", timeSeriesIndex: true, quantile: true, influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
5092
|
-
{ fieldName: "connectionPoolCount", gauge: Gauge.CONNECTION_POOL_TOTAL_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
5093
|
-
{ fieldName: "connectionIdleCount", gauge: Gauge.CONNECTION_POOL_IDLE_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
5094
|
-
{ fieldName: "connectionWaitingCount", gauge: Gauge.CONNECTION_POOL_WAITING_GAUGE, instrumentProperty: "val", dataType: "number", influxdbDataType: "intField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
5095
|
-
{ fieldName: "systemcpu", gauge: Gauge.CPU_SYSTEM_LOAD_GAUGE, instrumentProperty: "val", dataType: "number", timeSeriesIndex: true, quantile: true, influxdbDataType: "floatField", gaugeType: GaugeTypes.INSTRUMENT_GAUGE },
|
|
5096
|
-
{ fieldName: "memory", gauge: Gauge.OBJECT_GAUGE, instrumentProperty: "val", dataType: "JSON", influxdbDataType: "stringField", gaugeType: GaugeTypes.INSTRUMENT_OBJECT }
|
|
5097
|
-
],
|
|
5098
|
-
//@@ need type declare in appframework
|
|
5099
|
-
GetPathFromContext(context) {
|
|
5100
|
-
const { technology, subTechnology, lambdaInstance } = context;
|
|
5101
|
-
return `/${technology}/${subTechnology}/${lambdaInstance}`;
|
|
5102
|
-
},
|
|
5103
|
-
redisQueryFilters: {
|
|
5104
|
-
level1ContextField: "serviceType",
|
|
5105
|
-
level2ContextField: "technology",
|
|
5106
|
-
level3ContextField: "subTechnology"
|
|
5107
|
-
},
|
|
5108
|
-
subscriptionTopics: [
|
|
5109
|
-
{
|
|
5110
|
-
subscriptionTopic: SubscriptionTopic.AllLambdasCombined,
|
|
5111
|
-
// uicontrollerlanding
|
|
5112
|
-
route: "/metrics"
|
|
5113
|
-
},
|
|
5114
|
-
{
|
|
5115
|
-
subscriptionTopic: SubscriptionTopic.LambdaTechnologies,
|
|
5116
|
-
// uicontrollerlambda
|
|
5117
|
-
route: "/metrics/lambdas"
|
|
5118
|
-
},
|
|
5119
|
-
{
|
|
5120
|
-
subscriptionTopic: SubscriptionTopic.LambdaSubTechnologies,
|
|
5121
|
-
// uicontrollerlambdasubtechnologies
|
|
5122
|
-
route: "/metrics/lambdas/:key"
|
|
5123
|
-
},
|
|
5124
|
-
{
|
|
5125
|
-
subscriptionTopic: SubscriptionTopic.LambdaSubTechnologiesInstance,
|
|
5126
|
-
// uicontrollerlambdasubtechnologiesinstance
|
|
5127
|
-
route: "/metrics/lambdas/:key/:subkey"
|
|
5128
|
-
}
|
|
5129
|
-
]
|
|
5130
|
-
}
|
|
5131
|
-
}
|
|
5132
|
-
};
|
|
5133
|
-
const GetInstruments = (service) => {
|
|
5134
|
-
const fieldList = [
|
|
5135
|
-
...globalServiceDefinitions.coreFieldList,
|
|
5136
|
-
...globalServiceDefinitions.logFieldList,
|
|
5137
|
-
...globalServiceDefinitions.services[service].fieldList
|
|
5138
|
-
];
|
|
5139
|
-
const retVal = [];
|
|
5140
|
-
fieldList.forEach((v) => {
|
|
5141
|
-
if (v.instrumentOptions) {
|
|
5142
|
-
retVal.push([v.gauge, v.gaugeType, v.instrumentOptions]);
|
|
5143
|
-
} else {
|
|
5144
|
-
retVal.push([v.gauge, v.gaugeType]);
|
|
5145
|
-
}
|
|
5146
|
-
if (v.histo) {
|
|
5147
|
-
retVal.push([v.histoGauge, GaugeTypes.INSTRUMENT_HISTOGRAM]);
|
|
5148
|
-
}
|
|
5149
|
-
});
|
|
5150
|
-
return retVal;
|
|
5151
|
-
};
|
|
5152
|
-
class ObservabilityModelUtils {
|
|
5153
|
-
static GetModelNode(data) {
|
|
5154
|
-
const fixedSize = 2;
|
|
5155
|
-
const padLength = 9;
|
|
5156
|
-
try {
|
|
5157
|
-
return {
|
|
5158
|
-
val: data,
|
|
5159
|
-
vf: parseFloat(data.toString()).toFixed(fixedSize).padStart(padLength, " "),
|
|
5160
|
-
value: parseFloat(data.toString()).toFixed(fixedSize)
|
|
5161
|
-
};
|
|
5162
|
-
} catch (error) {
|
|
5163
|
-
return {
|
|
5164
|
-
val: 0,
|
|
5165
|
-
vf: "",
|
|
5166
|
-
value: ""
|
|
5167
|
-
};
|
|
5168
|
-
}
|
|
5169
|
-
}
|
|
5170
|
-
static GetModelNodeRawStringArray(data) {
|
|
5171
|
-
try {
|
|
5172
|
-
return {
|
|
5173
|
-
val: data
|
|
5174
|
-
};
|
|
5175
|
-
} catch (error) {
|
|
5176
|
-
return {
|
|
5177
|
-
val: []
|
|
5178
|
-
};
|
|
5179
|
-
}
|
|
5180
|
-
}
|
|
5181
|
-
static GetModelNodeObject(data) {
|
|
5182
|
-
try {
|
|
5183
|
-
return {
|
|
5184
|
-
val: JSON.parse(data)
|
|
5185
|
-
};
|
|
5186
|
-
} catch (error) {
|
|
5187
|
-
return {
|
|
5188
|
-
val: null
|
|
5189
|
-
};
|
|
5190
|
-
}
|
|
5191
|
-
}
|
|
5192
|
-
static GetModelNodeWithQuantile(data, quantileData) {
|
|
5193
|
-
let quantile2 = "";
|
|
5194
|
-
const quantileDataElementArray = [];
|
|
5195
|
-
for (const [key, val] of Object.entries(quantileData)) {
|
|
5196
|
-
quantile2 += parseFloat(val.toFixed(2)).toString().padStart(8, " ");
|
|
5197
|
-
quantileDataElementArray.push([
|
|
5198
|
-
key,
|
|
5199
|
-
val
|
|
5200
|
-
]);
|
|
5201
|
-
}
|
|
5202
|
-
const fixedSize = 2;
|
|
5203
|
-
const padLength = 9;
|
|
5204
|
-
try {
|
|
5205
|
-
return {
|
|
5206
|
-
val: data,
|
|
5207
|
-
vf: parseFloat(data.toString()).toFixed(fixedSize).padStart(padLength, " "),
|
|
5208
|
-
value: parseFloat(data.toString()).toFixed(fixedSize),
|
|
5209
|
-
percentile: quantileDataElementArray,
|
|
5210
|
-
percentileFormatted: quantile2
|
|
5211
|
-
};
|
|
5212
|
-
} catch (error) {
|
|
5213
|
-
return {
|
|
5214
|
-
val: 0,
|
|
5215
|
-
vf: "",
|
|
5216
|
-
value: "",
|
|
5217
|
-
percentile: [],
|
|
5218
|
-
percentileFormatted: ""
|
|
5219
|
-
};
|
|
5220
|
-
}
|
|
5221
|
-
}
|
|
5222
|
-
static GetModelNodeHistFromInfluxData(data) {
|
|
5223
|
-
try {
|
|
5224
|
-
const histVal = [];
|
|
5225
|
-
if (data) {
|
|
5226
|
-
for (const [key, val] of Object.entries(data)) {
|
|
5227
|
-
const dataElement = [
|
|
5228
|
-
val,
|
|
5229
|
-
key,
|
|
5230
|
-
parseInt(key)
|
|
5231
|
-
];
|
|
5232
|
-
histVal.push(dataElement);
|
|
5233
|
-
}
|
|
5234
|
-
}
|
|
5235
|
-
try {
|
|
5236
|
-
return {
|
|
5237
|
-
hist: histVal
|
|
5238
|
-
};
|
|
5239
|
-
} catch (error) {
|
|
5240
|
-
return {
|
|
5241
|
-
hist: []
|
|
5242
|
-
};
|
|
5243
|
-
}
|
|
5244
|
-
} catch (error) {
|
|
5245
|
-
return {
|
|
5246
|
-
hist: []
|
|
5247
|
-
};
|
|
5248
|
-
}
|
|
5249
|
-
}
|
|
5250
|
-
static ParseModelNode = (model, data, parseLog, gaugeName, fieldName) => {
|
|
5251
|
-
if (fieldName in data) {
|
|
5252
|
-
model.instruments[gaugeName] = this.GetModelNode(data[fieldName]);
|
|
5253
|
-
} else {
|
|
5254
|
-
parseLog.push(`ObservabilityModelUtils:ParseModelNode(): Field not present: [${fieldName}], default to [0]`);
|
|
5255
|
-
model.instruments[gaugeName] = this.GetModelNode(0);
|
|
5256
|
-
}
|
|
5257
|
-
};
|
|
5258
|
-
static ParseModelNodeWithQuantile = (model, data, parseLog, gaugeName, fieldName, quantileFieldName) => {
|
|
5259
|
-
if (fieldName in data && quantileFieldName in data) {
|
|
5260
|
-
model.instruments[gaugeName] = this.GetModelNodeWithQuantile(data[fieldName], data[quantileFieldName]);
|
|
5261
|
-
} else if (fieldName in data) {
|
|
5262
|
-
const dataVal = data[fieldName];
|
|
5263
|
-
parseLog.push(`ObservabilityModelUtils:ParseModelNodeWithQuantile(): QuantileFieldName not present: [${quantileFieldName}], default to [${dataVal},{}]`);
|
|
5264
|
-
model.instruments[gaugeName] = this.GetModelNodeWithQuantile(dataVal, {});
|
|
5265
|
-
} else {
|
|
5266
|
-
parseLog.push(`ObservabilityModelUtils:ParseModelNodeWithQuantile(): Field not present: [${fieldName}], QuantileFieldName not present: [${quantileFieldName}], default to [0,{}]`);
|
|
5267
|
-
model.instruments[gaugeName] = this.GetModelNodeWithQuantile(0, {});
|
|
5268
|
-
}
|
|
5269
|
-
};
|
|
5270
|
-
static ParseModelNodeHisto = (model, data, parseLog, gaugeName, fieldName) => {
|
|
5271
|
-
if (fieldName in data) {
|
|
5272
|
-
model.instruments[gaugeName] = this.GetModelNodeHistFromInfluxData(data[fieldName]);
|
|
5273
|
-
} else {
|
|
5274
|
-
parseLog.push(`ObservabilityModelUtils:ParseModelNodeHisto(): Field not present: [${fieldName}], default to [{}]`);
|
|
5275
|
-
model.instruments[gaugeName] = this.GetModelNodeHistFromInfluxData({});
|
|
5276
|
-
}
|
|
5277
|
-
};
|
|
5278
|
-
static ParseModelNodeObject = (model, data, parseLog, gaugeName, fieldName) => {
|
|
5279
|
-
if (fieldName in data) {
|
|
5280
|
-
model.instruments[gaugeName] = this.GetModelNodeObject(data[fieldName]);
|
|
5281
|
-
} else {
|
|
5282
|
-
parseLog.push(`ObservabilityModelUtils:ParseModelNodeObject(): Field not present: [${fieldName}], default to [{}]`);
|
|
5283
|
-
model.instruments[gaugeName] = this.GetModelNodeObject({});
|
|
5284
|
-
}
|
|
5285
|
-
};
|
|
5286
|
-
static GetModelData(serviceType, model, data, parseLog) {
|
|
5287
|
-
const fieldList = [
|
|
5288
|
-
...globalServiceDefinitions.coreFieldList,
|
|
5289
|
-
...globalServiceDefinitions.services[serviceType].fieldList
|
|
5290
|
-
];
|
|
5291
|
-
fieldList.forEach((field) => {
|
|
5292
|
-
if (field.quantile) {
|
|
5293
|
-
ObservabilityModelUtils.ParseModelNodeWithQuantile(model, data, parseLog, field.gauge, field.fieldName, `${field.fieldName}_quantile`);
|
|
5294
|
-
} else if (field.gaugeType.localeCompare(GaugeTypes.INSTRUMENT_OBJECT) === 0) {
|
|
5295
|
-
ObservabilityModelUtils.ParseModelNodeObject(model, data, parseLog, field.gauge, field.fieldName);
|
|
5296
|
-
} else {
|
|
5297
|
-
ObservabilityModelUtils.ParseModelNode(model, data, parseLog, field.gauge, field.fieldName);
|
|
5298
|
-
}
|
|
5299
|
-
if (field.histo) {
|
|
5300
|
-
ObservabilityModelUtils.ParseModelNodeHisto(model, data, parseLog, field.histoGauge, `${field.fieldName}_histo`);
|
|
5301
|
-
}
|
|
5302
|
-
});
|
|
5303
|
-
}
|
|
5304
|
-
static GetModelForService(id, data, logger) {
|
|
5305
|
-
try {
|
|
5306
|
-
const parseLog = [];
|
|
5307
|
-
const model = {
|
|
5308
|
-
id,
|
|
5309
|
-
instruments: {}
|
|
5310
|
-
};
|
|
5311
|
-
this.GetModelData("service", model, data, parseLog);
|
|
5312
|
-
model.instruments[Gauge.LOGGER] = ObservabilityModelUtils.GetModelNodeRawStringArray(data["logMessages"]);
|
|
5313
|
-
if (parseLog.length > 0) {
|
|
5314
|
-
parseLog.forEach((logEntry) => logger.debug(logEntry));
|
|
5315
|
-
}
|
|
5316
|
-
return model;
|
|
5317
|
-
} catch (error) {
|
|
5318
|
-
return null;
|
|
5319
|
-
}
|
|
5320
|
-
}
|
|
5321
|
-
static GetModelForLambda(id, data, logger) {
|
|
5322
|
-
try {
|
|
5323
|
-
const parseLog = [];
|
|
5324
|
-
const model = {
|
|
5325
|
-
id,
|
|
5326
|
-
instruments: {}
|
|
5327
|
-
};
|
|
5328
|
-
this.GetModelData("lambda", model, data, parseLog);
|
|
5329
|
-
model.instruments[Gauge.LOGGER] = ObservabilityModelUtils.GetModelNodeRawStringArray(data["logMessages"]);
|
|
5330
|
-
if (parseLog.length > 0) {
|
|
5331
|
-
parseLog.forEach((logEntry) => logger.debug(logEntry));
|
|
5332
|
-
}
|
|
5333
|
-
return model;
|
|
5334
|
-
} catch (error) {
|
|
5335
|
-
return null;
|
|
5336
|
-
}
|
|
5337
|
-
}
|
|
5338
|
-
static GetModelForAgent(id, data, logger) {
|
|
5339
|
-
try {
|
|
5340
|
-
if (Object.keys(data).length === 0) {
|
|
5341
|
-
return null;
|
|
5342
|
-
}
|
|
5343
|
-
const parseLog = [];
|
|
5344
|
-
const model = {
|
|
5345
|
-
id,
|
|
5346
|
-
instruments: {}
|
|
5347
|
-
};
|
|
5348
|
-
this.GetModelData("agent", model, data, parseLog);
|
|
5349
|
-
model.instruments[Gauge.LOGGER] = ObservabilityModelUtils.GetModelNodeRawStringArray(data["logMessages"]);
|
|
5350
|
-
if (parseLog.length > 0) {
|
|
5351
|
-
parseLog.forEach((logEntry) => logger.debug(logEntry));
|
|
5352
|
-
}
|
|
5353
|
-
return model;
|
|
5354
|
-
} catch (error) {
|
|
5355
|
-
return null;
|
|
5356
|
-
}
|
|
5357
|
-
}
|
|
5358
|
-
}
|
|
5359
|
-
class ObservabilityRESTAPISubscriber {
|
|
5360
|
-
#socketSubscribeKeepAlive = {};
|
|
5361
|
-
#options;
|
|
5362
|
-
// This is required becuase each call to .bind create a new replica bound function - so we need the same instance for on/off event bindings.
|
|
5363
|
-
KeepAliveAckBoundFunction;
|
|
5364
|
-
constructor(options) {
|
|
5365
|
-
this.#options = options;
|
|
5366
|
-
}
|
|
5367
|
-
#LogDebugMessage(message) {
|
|
5368
|
-
this.#options.logger.debug(message);
|
|
5369
|
-
}
|
|
5370
|
-
#LogErrorMessage(message) {
|
|
5371
|
-
this.#options.logger.error(message);
|
|
5372
|
-
}
|
|
5373
|
-
async Subscribe(subscriptions) {
|
|
5374
|
-
subscriptions.map(async (subId) => {
|
|
5375
|
-
this.#RemoveKeepAlive(subId);
|
|
5376
|
-
this.#LogDebugMessage(chalk.yellow(`ObservabilityRESTAPISubscriber:Subscribe(): Sending subscribe: subscriptionKey: [${subId.subscriptionKey.id}]`));
|
|
5377
|
-
try {
|
|
5378
|
-
this.#AddKeepAlive(subId);
|
|
5379
|
-
} catch (error) {
|
|
5380
|
-
this.#LogErrorMessage(chalk.red(`ObservabilityRESTAPISubscriber:Subscribe(): Error: response: [${JSON.stringify(error)}]`));
|
|
5381
|
-
this.#RemoveKeepAlive(subId);
|
|
5382
|
-
}
|
|
5383
|
-
});
|
|
5384
|
-
}
|
|
5385
|
-
UnSubscribe(subscriptions) {
|
|
5386
|
-
subscriptions.map(async (subId) => {
|
|
5387
|
-
this.#RemoveKeepAlive(subId);
|
|
5388
|
-
this.#LogDebugMessage(chalk.yellow(`ObservabilityRESTAPISubscriber:UnSubscribe(): Sending unsubscribe: subscriptionKey: [${subId.subscriptionKey.id}]`));
|
|
5389
|
-
});
|
|
5390
|
-
}
|
|
5391
|
-
async #InvokeRESTAPI(subscription) {
|
|
5392
|
-
const { subscriptionKey } = subscription;
|
|
5393
|
-
let url = "";
|
|
5394
|
-
switch (subscriptionKey.topic) {
|
|
5395
|
-
// Services -------------------------------------------------------------------------------------------
|
|
5396
|
-
case SubscriptionTopic.AllServicesCombined:
|
|
5397
|
-
url = `/metrics`;
|
|
5398
|
-
break;
|
|
5399
|
-
case SubscriptionTopic.Services:
|
|
5400
|
-
url = `/metrics/services`;
|
|
5401
|
-
break;
|
|
5402
|
-
case SubscriptionTopic.ServiceInstances:
|
|
5403
|
-
if (subscriptionKey.key) {
|
|
5404
|
-
url = `/metrics/services/${subscriptionKey.key}`;
|
|
5405
|
-
break;
|
|
5406
|
-
} else {
|
|
5407
|
-
throw new Error(`#OutputSubscription(Services): key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
5408
|
-
}
|
|
5409
|
-
case SubscriptionTopic.ServiceInstance:
|
|
5410
|
-
url = `/metrics/services/${subscriptionKey.key}`;
|
|
5411
|
-
if (subscriptionKey.key && subscriptionKey.subkey) {
|
|
5412
|
-
url = `/metrics/services/${subscriptionKey.key}/${subscriptionKey.subkey}`;
|
|
5413
|
-
break;
|
|
5414
|
-
} else {
|
|
5415
|
-
throw new Error(`#OutputSubscription(Services): key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
5416
|
-
}
|
|
5417
|
-
// Lambdas -------------------------------------------------------------------------------------------
|
|
5418
|
-
case SubscriptionTopic.AllLambdasCombined:
|
|
5419
|
-
url = `/metrics`;
|
|
5420
|
-
break;
|
|
5421
|
-
case SubscriptionTopic.LambdaTechnologies:
|
|
5422
|
-
url = `/metrics/lambdas`;
|
|
5423
|
-
break;
|
|
5424
|
-
case SubscriptionTopic.LambdaSubTechnologies:
|
|
5425
|
-
if (subscriptionKey.key) {
|
|
5426
|
-
url = `/metrics/lambdas/${subscriptionKey.key}`;
|
|
5427
|
-
break;
|
|
5428
|
-
} else {
|
|
5429
|
-
throw new Error(`#OutputSubscription(Lambdas): key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
5430
|
-
}
|
|
5431
|
-
case SubscriptionTopic.LambdaSubTechnologiesInstance:
|
|
5432
|
-
url = `/metrics/lambdas/${subscriptionKey.key}`;
|
|
5433
|
-
if (subscriptionKey.key && subscriptionKey.subkey) {
|
|
5434
|
-
url = `/metrics/lambdas/${subscriptionKey.key}/${subscriptionKey.subkey}`;
|
|
5435
|
-
break;
|
|
5436
|
-
} else {
|
|
5437
|
-
throw new Error(`#OutputSubscription(Lambdas): key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
5438
|
-
}
|
|
5439
|
-
// User Agents -------------------------------------------------------------------------------------------
|
|
5440
|
-
case SubscriptionTopic.AllAgentsCombined:
|
|
5441
|
-
url = `/metrics`;
|
|
5442
|
-
break;
|
|
5443
|
-
case SubscriptionTopic.Agents:
|
|
5444
|
-
url = `/metrics/agents`;
|
|
5445
|
-
break;
|
|
5446
|
-
case SubscriptionTopic.AgentWorkers:
|
|
5447
|
-
if (subscriptionKey.key) {
|
|
5448
|
-
url = `/metrics/agents/${subscriptionKey.key}`;
|
|
5449
|
-
break;
|
|
5450
|
-
} else {
|
|
5451
|
-
throw new Error(`#OutputSubscription(Agents): key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
5452
|
-
}
|
|
5453
|
-
case SubscriptionTopic.AgentWorker:
|
|
5454
|
-
if (subscriptionKey.key && subscriptionKey.subkey) {
|
|
5455
|
-
url = `/metrics/agents/${subscriptionKey.key}/${subscriptionKey.subkey}`;
|
|
5456
|
-
break;
|
|
5457
|
-
} else {
|
|
5458
|
-
throw new Error(`#OutputSubscription(Agents): key and/or subkey not provided for subscription: [${JSON.stringify(subscriptionKey.topic)}]`);
|
|
5459
|
-
}
|
|
5460
|
-
}
|
|
5461
|
-
if (url.localeCompare("") !== 0) {
|
|
5462
|
-
const endPointUrl = `${this.#options.urlBase}${url}`;
|
|
5463
|
-
let retVal;
|
|
5464
|
-
const start = performance.now();
|
|
5465
|
-
try {
|
|
5466
|
-
if (isNode && this.#options.agentManager) {
|
|
5467
|
-
retVal = await axios(new stsutils.STSAxiosConfig(endPointUrl, "get").withDefaultHeaders().withAgentManager(this.#options.agentManager).config);
|
|
5468
|
-
} else {
|
|
5469
|
-
retVal = await axios(new stsutils.STSAxiosConfig(endPointUrl, "get").withDefaultHeaders().config);
|
|
5470
|
-
}
|
|
5471
|
-
const end = performance.now();
|
|
5472
|
-
const diff = end - start;
|
|
5473
|
-
if (subscriptionKey.topic.localeCompare(SubscriptionTopic.AllServicesCombined) === 0) {
|
|
5474
|
-
return retVal.data["services"].data;
|
|
5475
|
-
}
|
|
5476
|
-
if (subscriptionKey.topic.localeCompare(SubscriptionTopic.AllAgentsCombined) === 0) {
|
|
5477
|
-
return retVal.data["agents"].data;
|
|
5478
|
-
}
|
|
5479
|
-
if (subscriptionKey.topic.localeCompare(SubscriptionTopic.AllLambdasCombined) === 0) {
|
|
5480
|
-
return retVal.data["lambdas"].data;
|
|
5481
|
-
}
|
|
5482
|
-
return retVal.data;
|
|
5483
|
-
} catch (error) {
|
|
5484
|
-
return null;
|
|
5485
|
-
}
|
|
5486
|
-
} else {
|
|
5487
|
-
return null;
|
|
5488
|
-
}
|
|
5489
|
-
}
|
|
5490
|
-
#GetData = async (subscription) => {
|
|
5491
|
-
try {
|
|
5492
|
-
const retVal = await this.#InvokeRESTAPI(subscription);
|
|
5493
|
-
if (retVal) {
|
|
5494
|
-
const payload = {
|
|
5495
|
-
subscriptionKey: subscription.subscriptionKey,
|
|
5496
|
-
data: retVal
|
|
5497
|
-
};
|
|
5498
|
-
subscription.cb(payload);
|
|
5499
|
-
}
|
|
5500
|
-
} catch (error) {
|
|
5501
|
-
this.#LogErrorMessage(chalk.red(`ObservabilityRESTAPISubscriber:#AddKeepAlive(): Error response: [${JSON.stringify(error)}]`));
|
|
5502
|
-
this.#RemoveKeepAlive(subscription);
|
|
5503
|
-
}
|
|
5504
|
-
};
|
|
5505
|
-
#SetupTimeout(socketSubscribeKeepAlive, subscription, timeout) {
|
|
5506
|
-
return setTimeout(async () => {
|
|
5507
|
-
try {
|
|
5508
|
-
const start = performance.now();
|
|
5509
|
-
await this.#GetData(subscription);
|
|
5510
|
-
if (socketSubscribeKeepAlive.timeout) {
|
|
5511
|
-
const end = performance.now();
|
|
5512
|
-
const diff = end - start;
|
|
5513
|
-
let timeoutDuration = (this.#options.keepAlive ?? 1e3) - diff;
|
|
5514
|
-
if (timeoutDuration < 500) {
|
|
5515
|
-
timeoutDuration = 500;
|
|
5516
|
-
}
|
|
5517
|
-
socketSubscribeKeepAlive.timeout = this.#SetupTimeout(socketSubscribeKeepAlive, subscription, timeoutDuration);
|
|
5518
|
-
} else {
|
|
5519
|
-
this.#LogDebugMessage(chalk.yellow(`Subscription removed: [${socketSubscribeKeepAlive.id}]. Processing terminate.`));
|
|
5520
|
-
}
|
|
5521
|
-
} catch (error) {
|
|
5522
|
-
this.#LogErrorMessage(chalk.red(`ObservabilityRESTAPISubscriber:#AddKeepAlive(): Error response: [${JSON.stringify(error)}]`));
|
|
5523
|
-
this.#RemoveKeepAlive(subscription);
|
|
5524
|
-
}
|
|
5525
|
-
}, timeout);
|
|
5526
|
-
}
|
|
5527
|
-
#AddKeepAlive(subscription) {
|
|
5528
|
-
this.#RemoveKeepAlive(subscription);
|
|
5529
|
-
const socketSubscribeKeepAlive = {
|
|
5530
|
-
id: subscription.subscriptionKey.id
|
|
5531
|
-
};
|
|
5532
|
-
socketSubscribeKeepAlive.timeout = this.#SetupTimeout(socketSubscribeKeepAlive, subscription, this.#options.keepAlive ?? 1e3);
|
|
5533
|
-
this.#socketSubscribeKeepAlive[subscription.subscriptionKey.id] = socketSubscribeKeepAlive;
|
|
5534
|
-
this.#GetData(subscription);
|
|
5535
|
-
}
|
|
5536
|
-
#RemoveKeepAlive(subscription) {
|
|
5537
|
-
if (this.#socketSubscribeKeepAlive[subscription.subscriptionKey.id]) {
|
|
5538
|
-
this.#LogDebugMessage(chalk.gray(`ObservabilityRESTAPISubscriber:#RemoveKeepAlive(): subscriptionKey: [${subscription.subscriptionKey.id}]`));
|
|
5539
|
-
clearTimeout(this.#socketSubscribeKeepAlive[subscription.subscriptionKey.id].timeout);
|
|
5540
|
-
delete this.#socketSubscribeKeepAlive[subscription.subscriptionKey.id].timeout;
|
|
5541
|
-
delete this.#socketSubscribeKeepAlive[subscription.subscriptionKey.id];
|
|
5542
|
-
}
|
|
5543
|
-
}
|
|
5544
|
-
}
|
|
5545
|
-
class ObservabilitySocketIOSubscriber {
|
|
5546
|
-
#socket;
|
|
5547
|
-
#options;
|
|
5548
|
-
subscriptions = {};
|
|
5549
|
-
#LogDebugMessage(message) {
|
|
5550
|
-
this.#options.logger.debug(message);
|
|
5551
|
-
}
|
|
5552
|
-
#LogErrorMessage(message) {
|
|
5553
|
-
this.#options.logger.error(message);
|
|
5554
|
-
}
|
|
5555
|
-
constructor(options) {
|
|
5556
|
-
this.#options = options;
|
|
5557
|
-
this.#socket = options.socket;
|
|
5558
|
-
}
|
|
5559
|
-
get socket() {
|
|
5560
|
-
return this.#socket;
|
|
5561
|
-
}
|
|
5562
|
-
set socket(socket) {
|
|
5563
|
-
this.#LogDebugMessage(chalk.cyan(`ObservabilitySocketIOSubscriber:set socket(): new socket assigned`));
|
|
5564
|
-
this.#socket.off("subscriptionData");
|
|
5565
|
-
this.subscriptions = {};
|
|
5566
|
-
if (this.#socket.connected) {
|
|
5567
|
-
this.#socket.disconnect();
|
|
5568
|
-
}
|
|
5569
|
-
this.#socket = socket;
|
|
5570
|
-
this.#socket.on("subscriptionData", (data, cb) => {
|
|
5571
|
-
const subId = data.subscriptionKey.id;
|
|
5572
|
-
const currentSubscriptions = Object.keys(this.subscriptions).toString();
|
|
5573
|
-
if (this.subscriptions[subId]) {
|
|
5574
|
-
this.subscriptions[subId].cb(data);
|
|
5575
|
-
cb(`sstsobservability:subscriptionData Response: [${JSON.stringify(data.subscriptionKey)}], Current Subscriptions: [${currentSubscriptions}]`);
|
|
5576
|
-
} else {
|
|
5577
|
-
cb(`sstsobservability:subscriptionData Response: No subscription found in subscriptions: [${JSON.stringify(data.subscriptionKey)}], Current Subscriptions: [${currentSubscriptions}]`);
|
|
5578
|
-
}
|
|
5579
|
-
});
|
|
5580
|
-
}
|
|
5581
|
-
async Subscribe(subscriptions) {
|
|
5582
|
-
subscriptions.map(async (subId) => {
|
|
5583
|
-
try {
|
|
5584
|
-
this.#LogDebugMessage(chalk.yellow(`ObservabilitySocketIOSubscriber:Subscribe(): Sending subscribe: subscriptionKey: [${subId.subscriptionKey.id}]`));
|
|
5585
|
-
this.#socket.timeout(1e3).emit("subscribe", subId.subscriptionKey, (error, data) => {
|
|
5586
|
-
if (error) {
|
|
5587
|
-
this.#LogErrorMessage(chalk.red(`ObservabilitySocketIOSubscriber:Subscribe(): Error: [${error}], data: [${data}]`));
|
|
5588
|
-
} else {
|
|
5589
|
-
this.#LogDebugMessage(chalk.green(`ObservabilitySocketIOSubscriber:Subscribe(): Response: [${JSON.stringify(data)}]`));
|
|
5590
|
-
this.subscriptions[subId.subscriptionKey.id] = subId;
|
|
5591
|
-
}
|
|
5592
|
-
});
|
|
5593
|
-
} catch (error) {
|
|
5594
|
-
this.#LogErrorMessage(chalk.red(`ObservabilitySocketIOSubscriber:Subscribe(): Error: response: [${JSON.stringify(error)}]`));
|
|
5595
|
-
}
|
|
5596
|
-
});
|
|
5597
|
-
}
|
|
5598
|
-
UnSubscribe(subscriptions) {
|
|
5599
|
-
subscriptions.map(async (subId) => {
|
|
5600
|
-
try {
|
|
5601
|
-
this.#LogDebugMessage(chalk.yellow(`ObservabilitySocketIOSubscriber:UnSubscribe(): Sending unsubscribe: subscriptionKey: [${subId.subscriptionKey.id}]`));
|
|
5602
|
-
this.#socket.timeout(1e3).emit("unsubscribe", subId.subscriptionKey, (error, data) => {
|
|
5603
|
-
if (error) {
|
|
5604
|
-
this.#LogErrorMessage(chalk.red(`ObservabilitySocketIOSubscriber:UnSubscribe(): Error: [${error}], data: [${data}]`));
|
|
5605
|
-
} else {
|
|
5606
|
-
this.#LogDebugMessage(chalk.green(`ObservabilitySocketIOSubscriber:UnSubscribe(): Response: [${JSON.stringify(data)}]`));
|
|
5607
|
-
delete this.subscriptions[subId.subscriptionKey.id];
|
|
5608
|
-
}
|
|
5609
|
-
});
|
|
5610
|
-
} catch (error) {
|
|
5611
|
-
this.#LogErrorMessage(chalk.red(`ObservabilitySocketIOSubscriber:UnSubscribe(): Error response: [${JSON.stringify(error)}]`));
|
|
5612
|
-
}
|
|
5613
|
-
});
|
|
5614
|
-
}
|
|
5615
|
-
}
|
|
5616
|
-
var runStates = /* @__PURE__ */ ((runStates2) => {
|
|
5617
|
-
runStates2["idle"] = "idle";
|
|
5618
|
-
runStates2["started"] = "started";
|
|
5619
|
-
runStates2["stopped"] = "stopped";
|
|
5620
|
-
return runStates2;
|
|
5621
|
-
})(runStates || {});
|
|
5622
|
-
class ObservabilitySubscriptionManager {
|
|
5623
|
-
#serviceModel = {};
|
|
5624
|
-
#agentModel = {};
|
|
5625
|
-
#lambdaModel = {};
|
|
5626
|
-
#options;
|
|
5627
|
-
#LogDebugMessage(message) {
|
|
5628
|
-
this.#options.logger.debug(message);
|
|
5629
|
-
}
|
|
5630
|
-
#LogErrorMessage(message) {
|
|
5631
|
-
this.#options.logger.error(message);
|
|
5632
|
-
}
|
|
5633
|
-
constructor(options) {
|
|
5634
|
-
this.#options = options;
|
|
5635
|
-
}
|
|
5636
|
-
get serviceModel() {
|
|
5637
|
-
return this.#serviceModel;
|
|
5638
|
-
}
|
|
5639
|
-
get agentModel() {
|
|
5640
|
-
return this.#agentModel;
|
|
5641
|
-
}
|
|
5642
|
-
get lambdaModel() {
|
|
5643
|
-
return this.#lambdaModel;
|
|
5644
|
-
}
|
|
5645
|
-
TransformSubscriptionPayloadCallback(subscriptionPayload) {
|
|
5646
|
-
switch (subscriptionPayload.subscriptionKey.topic) {
|
|
5647
|
-
// Services -----------------------------------------------------------------------------
|
|
5648
|
-
case SubscriptionTopic.AllServicesCombined:
|
|
5649
|
-
this.CreateModelAllServicesCombined(subscriptionPayload);
|
|
5650
|
-
break;
|
|
5651
|
-
case SubscriptionTopic.Services:
|
|
5652
|
-
this.CreateModelServices(subscriptionPayload);
|
|
5653
|
-
break;
|
|
5654
|
-
case SubscriptionTopic.ServiceInstances:
|
|
5655
|
-
this.CreateModelServiceInstances(subscriptionPayload);
|
|
5656
|
-
break;
|
|
5657
|
-
case SubscriptionTopic.ServiceInstance:
|
|
5658
|
-
this.CreateModelServiceInstance(subscriptionPayload);
|
|
5659
|
-
break;
|
|
5660
|
-
// Lambda -----------------------------------------------------------------------------
|
|
5661
|
-
case SubscriptionTopic.AllLambdasCombined:
|
|
5662
|
-
this.CreateModelAllLambdasCombined(subscriptionPayload);
|
|
5663
|
-
break;
|
|
5664
|
-
case SubscriptionTopic.LambdaTechnologies:
|
|
5665
|
-
this.CreateModelLambdaTechnologies(subscriptionPayload);
|
|
5666
|
-
break;
|
|
5667
|
-
case SubscriptionTopic.LambdaSubTechnologies:
|
|
5668
|
-
this.CreateModelLambdaSubTechnologies(subscriptionPayload);
|
|
5669
|
-
break;
|
|
5670
|
-
case SubscriptionTopic.LambdaSubTechnologiesInstance:
|
|
5671
|
-
this.CreateModelLambdaSubTechnologiesInstance(subscriptionPayload);
|
|
5672
|
-
break;
|
|
5673
|
-
// Agents -----------------------------------------------------------------------------
|
|
5674
|
-
case SubscriptionTopic.AllAgentsCombined:
|
|
5675
|
-
this.CreateModelAllAgentsCombined(subscriptionPayload);
|
|
5676
|
-
break;
|
|
5677
|
-
case SubscriptionTopic.Agents:
|
|
5678
|
-
this.CreateModelAgents(subscriptionPayload);
|
|
5679
|
-
break;
|
|
5680
|
-
case SubscriptionTopic.AgentWorkers:
|
|
5681
|
-
this.CreateModelAgentWorkers(subscriptionPayload);
|
|
5682
|
-
break;
|
|
5683
|
-
case SubscriptionTopic.AgentWorker:
|
|
5684
|
-
this.CreateModelAgentWorker(subscriptionPayload);
|
|
5685
|
-
break;
|
|
5686
|
-
}
|
|
5687
|
-
}
|
|
5688
|
-
// --- [ Services ] ------------------------------------------------------------------------------------------------------------------------------------------------
|
|
5689
|
-
// /
|
|
5690
|
-
CreateModelAllServicesCombined(subscriptionPayload) {
|
|
5691
|
-
try {
|
|
5692
|
-
this.#serviceModel = {};
|
|
5693
|
-
if (subscriptionPayload.subscriptionKey.topic.localeCompare(SubscriptionTopic.AllServicesCombined.toString()) === 0) {
|
|
5694
|
-
this.#serviceModel["STS-Service"] = ObservabilityModelUtils.GetModelForService("STS-Service", subscriptionPayload.data, this.#options.logger);
|
|
5695
|
-
if (this.#serviceModel["STS-Service"] === null) {
|
|
5696
|
-
this.#LogDebugMessage(chalk.red(`CreateModelAllServicesCombined():Error: GetModelForService() returned null`));
|
|
5697
|
-
}
|
|
5698
|
-
}
|
|
5699
|
-
} catch (error) {
|
|
5700
|
-
this.#LogErrorMessage(error);
|
|
5701
|
-
return;
|
|
5702
|
-
}
|
|
5703
|
-
}
|
|
5704
|
-
// /serviceId
|
|
5705
|
-
CreateModelServices(subscriptionPayload) {
|
|
5706
|
-
try {
|
|
5707
|
-
this.#serviceModel = {};
|
|
5708
|
-
for (const [serviceId, serviceTelemetry] of Object.entries(subscriptionPayload.data)) {
|
|
5709
|
-
this.#serviceModel[serviceId] = ObservabilityModelUtils.GetModelForService(serviceId, serviceTelemetry, this.#options.logger);
|
|
5710
|
-
if (this.#serviceModel[serviceId] === null) {
|
|
5711
|
-
this.#LogDebugMessage(chalk.red(`CreateModelServices():Error: GetModelForService() returned null`));
|
|
5712
|
-
}
|
|
5713
|
-
}
|
|
5714
|
-
} catch (error) {
|
|
5715
|
-
return;
|
|
5716
|
-
}
|
|
5717
|
-
}
|
|
5718
|
-
// /serviceId/serviceInstanceId
|
|
5719
|
-
CreateModelServiceInstances(subscriptionPayload) {
|
|
5720
|
-
try {
|
|
5721
|
-
this.#serviceModel = {};
|
|
5722
|
-
for (const [serviceId, service] of Object.entries(subscriptionPayload.data)) {
|
|
5723
|
-
for (const [serviceInstanceId, serviceInstanceTelemetry] of Object.entries(service)) {
|
|
5724
|
-
if (serviceInstanceTelemetry.cpu && serviceInstanceTelemetry.cpu > 0) {
|
|
5725
|
-
this.#serviceModel[serviceInstanceId] = ObservabilityModelUtils.GetModelForService(serviceInstanceId, serviceInstanceTelemetry, this.#options.logger);
|
|
5726
|
-
if (this.#serviceModel[serviceInstanceId] !== null) {
|
|
5727
|
-
this.#serviceModel[serviceInstanceId].options = { serviceId };
|
|
5728
|
-
} else {
|
|
5729
|
-
this.#LogDebugMessage(chalk.red(`CreateModelServiceInstances():Error: GetModelForService() returned null`));
|
|
5730
|
-
}
|
|
5731
|
-
}
|
|
5732
|
-
}
|
|
5733
|
-
}
|
|
5734
|
-
} catch (error) {
|
|
5735
|
-
return;
|
|
5736
|
-
}
|
|
5737
|
-
}
|
|
5738
|
-
// serviceId/serviceInstanceId/serviceInstanceProcessId
|
|
5739
|
-
CreateModelServiceInstance(subscriptionPayload) {
|
|
5740
|
-
try {
|
|
5741
|
-
this.#serviceModel = {};
|
|
5742
|
-
for (const [serviceId, service] of Object.entries(subscriptionPayload.data)) {
|
|
5743
|
-
for (const [serviceInstanceId, serviceInstance] of Object.entries(service)) {
|
|
5744
|
-
for (const [serviceInstanceProcessId, serviceInstanceProcessTelemetry] of Object.entries(serviceInstance)) {
|
|
5745
|
-
if (serviceInstanceProcessTelemetry.cpu && serviceInstanceProcessTelemetry.cpu > 0) {
|
|
5746
|
-
this.#serviceModel[serviceInstanceProcessId] = ObservabilityModelUtils.GetModelForService(serviceInstanceProcessId, serviceInstanceProcessTelemetry, this.#options.logger);
|
|
5747
|
-
if (this.#serviceModel[serviceInstanceProcessId] !== null) {
|
|
5748
|
-
this.#serviceModel[serviceInstanceProcessId].options = { serviceId, serviceInstanceId };
|
|
5749
|
-
} else {
|
|
5750
|
-
this.#LogDebugMessage(chalk.red(`CreateModelServiceInstance():Error: GetModelForService() returned null`));
|
|
5751
|
-
}
|
|
5752
|
-
}
|
|
5753
|
-
}
|
|
5754
|
-
}
|
|
5755
|
-
}
|
|
5756
|
-
} catch (error) {
|
|
5757
|
-
return;
|
|
5758
|
-
}
|
|
5759
|
-
}
|
|
5760
|
-
// --- [ Agents ] ------------------------------------------------------------------------------------------------------------------------------------------------
|
|
5761
|
-
// /
|
|
5762
|
-
CreateModelAllAgentsCombined(subscriptionPayload) {
|
|
5763
|
-
try {
|
|
5764
|
-
this.#agentModel = {};
|
|
5765
|
-
if (subscriptionPayload.subscriptionKey.topic.localeCompare(SubscriptionTopic.AllAgentsCombined.toString()) === 0) {
|
|
5766
|
-
if (Object.keys(subscriptionPayload.data).length !== 0) {
|
|
5767
|
-
this.#agentModel["STS-Agent"] = ObservabilityModelUtils.GetModelForAgent("STS-Agent", subscriptionPayload.data, this.#options.logger);
|
|
5768
|
-
if (this.#agentModel["STS-Agent"] === null) {
|
|
5769
|
-
this.#LogDebugMessage(chalk.red(`CreateModelAllAgentsCombined():Error: GetModelForAgent() returned null`));
|
|
5770
|
-
}
|
|
5771
|
-
}
|
|
5772
|
-
}
|
|
5773
|
-
} catch (error) {
|
|
5774
|
-
this.#LogErrorMessage(error);
|
|
5775
|
-
return;
|
|
5776
|
-
}
|
|
5777
|
-
}
|
|
5778
|
-
// /agentId
|
|
5779
|
-
CreateModelAgents(subscriptionPayload) {
|
|
5780
|
-
try {
|
|
5781
|
-
this.#agentModel = {};
|
|
5782
|
-
for (const [agentId, agentInstanceTelemetry] of Object.entries(subscriptionPayload.data)) {
|
|
5783
|
-
if (agentInstanceTelemetry.timer) {
|
|
5784
|
-
this.#agentModel[agentId] = ObservabilityModelUtils.GetModelForAgent(agentId, agentInstanceTelemetry, this.#options.logger);
|
|
5785
|
-
if (this.#agentModel[agentId] !== null) {
|
|
5786
|
-
} else {
|
|
5787
|
-
this.#LogDebugMessage(chalk.red(`CreateModelAgents():Error: GetModelForAgent() returned null`));
|
|
5788
|
-
}
|
|
5789
|
-
}
|
|
5790
|
-
}
|
|
5791
|
-
} catch (error) {
|
|
5792
|
-
this.#LogErrorMessage(chalk.red(`UIControllerAgent:CreateModel(): Error: [${error}]`));
|
|
5793
|
-
}
|
|
5794
|
-
}
|
|
5795
|
-
// /agentId/agentWorkerId
|
|
5796
|
-
CreateModelAgentWorkers(subscriptionPayload) {
|
|
5797
|
-
try {
|
|
5798
|
-
this.#agentModel = {};
|
|
5799
|
-
for (const [agentId, agentWorker] of Object.entries(subscriptionPayload.data)) {
|
|
5800
|
-
for (const [agentWorkerId, agentInstanceTelemetry] of Object.entries(agentWorker)) {
|
|
5801
|
-
if (agentInstanceTelemetry.timer) {
|
|
5802
|
-
const threadKey = `${agentWorkerId}`;
|
|
5803
|
-
this.#agentModel[threadKey] = ObservabilityModelUtils.GetModelForAgent(threadKey, agentInstanceTelemetry, this.#options.logger);
|
|
5804
|
-
if (this.#agentModel[threadKey] !== null) {
|
|
5805
|
-
const coreCount = this.#agentModel[threadKey].instruments[Gauge.CORE_COUNT_GAUGE].val;
|
|
5806
|
-
this.#agentModel[threadKey].canNavigate = coreCount > 0;
|
|
5807
|
-
this.#agentModel[threadKey].options = { agentId };
|
|
5808
|
-
} else {
|
|
5809
|
-
this.#LogDebugMessage(chalk.red(`CreateModelAgentWorkers():Error: GetModelForAgent() returned null`));
|
|
5810
|
-
}
|
|
5811
|
-
}
|
|
5812
|
-
}
|
|
5813
|
-
}
|
|
5814
|
-
} catch (error) {
|
|
5815
|
-
this.#LogErrorMessage(chalk.red(`UIControllerAgentThreads:CreateModel(): Error: [${error}]`));
|
|
5816
|
-
}
|
|
5817
|
-
}
|
|
5818
|
-
// /agentId/agentWorkerId/asyncRunnerId
|
|
5819
|
-
CreateModelAgentWorker(subscriptionPayload) {
|
|
5820
|
-
try {
|
|
5821
|
-
this.#agentModel = {};
|
|
5822
|
-
for (const [agentId, agentWorker] of Object.entries(subscriptionPayload.data)) {
|
|
5823
|
-
for (const [agentWorkerId, asyncRunnerData] of Object.entries(agentWorker)) {
|
|
5824
|
-
for (const [asyncRunnerId, agentInstanceTelemetry] of Object.entries(asyncRunnerData)) {
|
|
5825
|
-
if (agentInstanceTelemetry.timer) {
|
|
5826
|
-
this.#agentModel[asyncRunnerId] = ObservabilityModelUtils.GetModelForAgent(asyncRunnerId, agentInstanceTelemetry, this.#options.logger);
|
|
5827
|
-
}
|
|
5828
|
-
}
|
|
5829
|
-
}
|
|
5830
|
-
}
|
|
5831
|
-
} catch (error) {
|
|
5832
|
-
this.#LogErrorMessage(chalk.red(`UIControllerAgentThread:CreateModel(): Error: [${error}]`));
|
|
5833
|
-
}
|
|
5834
|
-
}
|
|
5835
|
-
// --- [ Lambdas ] ------------------------------------------------------------------------------------------------------------------------------------------------
|
|
5836
|
-
// /
|
|
5837
|
-
CreateModelAllLambdasCombined(subscriptionPayload) {
|
|
5838
|
-
try {
|
|
5839
|
-
this.#lambdaModel = {};
|
|
5840
|
-
if (subscriptionPayload.subscriptionKey.topic.localeCompare(SubscriptionTopic.AllLambdasCombined.toString()) === 0) {
|
|
5841
|
-
this.#lambdaModel["STS-Lambda"] = ObservabilityModelUtils.GetModelForLambda("STS-Lambda", subscriptionPayload.data, this.#options.logger);
|
|
5842
|
-
if (this.#lambdaModel["STS-Lambda"] === null) {
|
|
5843
|
-
this.#LogDebugMessage(chalk.red(`CreateModelAllLambdasCombined():Error: GetModelForLambda() returned null`));
|
|
5844
|
-
}
|
|
5845
|
-
}
|
|
5846
|
-
} catch (error) {
|
|
5847
|
-
this.#LogErrorMessage(error);
|
|
5848
|
-
return;
|
|
5849
|
-
}
|
|
5850
|
-
}
|
|
5851
|
-
// /technologyId
|
|
5852
|
-
CreateModelLambdaTechnologies(subscriptionPayload) {
|
|
5853
|
-
try {
|
|
5854
|
-
this.#lambdaModel = {};
|
|
5855
|
-
for (const [technologyId, technologyTelemetry] of Object.entries(subscriptionPayload.data)) {
|
|
5856
|
-
this.#lambdaModel[technologyId] = ObservabilityModelUtils.GetModelForLambda(technologyId, technologyTelemetry, this.#options.logger);
|
|
5857
|
-
if (this.#lambdaModel[technologyId] === null) {
|
|
5858
|
-
this.#LogDebugMessage(chalk.red(`CreateModelLambdaTechnologies():Error: GetModelForLambda() returned null`));
|
|
5859
|
-
}
|
|
5860
|
-
}
|
|
5861
|
-
} catch (error) {
|
|
5862
|
-
return;
|
|
5863
|
-
}
|
|
5864
|
-
}
|
|
5865
|
-
// /technologyId/subTechnologyId
|
|
5866
|
-
CreateModelLambdaSubTechnologies(subscriptionPayload) {
|
|
5867
|
-
try {
|
|
5868
|
-
this.#lambdaModel = {};
|
|
5869
|
-
for (const [technologyId, technologyTelemetry] of Object.entries(subscriptionPayload.data)) {
|
|
5870
|
-
for (const [subTechnologyId, subTechnologyTelemetry] of Object.entries(technologyTelemetry)) {
|
|
5871
|
-
if (subTechnologyTelemetry.cpu && subTechnologyTelemetry.cpu > 0) {
|
|
5872
|
-
this.#lambdaModel[subTechnologyId] = ObservabilityModelUtils.GetModelForLambda(subTechnologyId, subTechnologyTelemetry, this.#options.logger);
|
|
5873
|
-
if (this.#lambdaModel[subTechnologyId] !== null) {
|
|
5874
|
-
this.#lambdaModel[subTechnologyId].options = { technologyId };
|
|
5875
|
-
} else {
|
|
5876
|
-
this.#LogDebugMessage(chalk.red(`CreateModelLambdaSubTechnologies():Error: GetModelForLambda() returned null`));
|
|
5877
|
-
}
|
|
5878
|
-
}
|
|
5879
|
-
}
|
|
5880
|
-
}
|
|
5881
|
-
} catch (error) {
|
|
5882
|
-
return;
|
|
5883
|
-
}
|
|
5884
|
-
}
|
|
5885
|
-
// /technologyId/subTechnologyId/subTechnologyInstanceId
|
|
5886
|
-
CreateModelLambdaSubTechnologiesInstance(subscriptionPayload) {
|
|
5887
|
-
try {
|
|
5888
|
-
this.#lambdaModel = {};
|
|
5889
|
-
for (const [technologyId, technologyTelemetry] of Object.entries(subscriptionPayload.data)) {
|
|
5890
|
-
for (const [subTechnologyId, subTechnologyTelemetry] of Object.entries(technologyTelemetry)) {
|
|
5891
|
-
for (const [subTechnologyInstanceId, subTechnologyInstanceTelemetry] of Object.entries(subTechnologyTelemetry)) {
|
|
5892
|
-
if (subTechnologyInstanceTelemetry.cpu && subTechnologyInstanceTelemetry.cpu > 0) {
|
|
5893
|
-
this.#lambdaModel[subTechnologyInstanceId] = ObservabilityModelUtils.GetModelForLambda(subTechnologyInstanceId, subTechnologyInstanceTelemetry, this.#options.logger);
|
|
5894
|
-
if (this.#lambdaModel[subTechnologyInstanceId] !== null) {
|
|
5895
|
-
this.#lambdaModel[subTechnologyInstanceId].options = { technologyId, subTechnologyId };
|
|
5896
|
-
} else {
|
|
5897
|
-
this.#LogDebugMessage(chalk.red(`CreateModelLambdaSubTechnologiesInstance():Error: GetModelForLambda() returned null`));
|
|
5898
|
-
}
|
|
5899
|
-
}
|
|
5900
|
-
}
|
|
5901
|
-
}
|
|
5902
|
-
}
|
|
5903
|
-
} catch (error) {
|
|
5904
|
-
return;
|
|
5905
|
-
}
|
|
5906
|
-
}
|
|
5907
|
-
}
|
|
5908
|
-
exports.CompareSTSInstrumentControllerPluginKey = CompareSTSInstrumentControllerPluginKey;
|
|
5909
2179
|
exports.CreateInstrument = CreateInstrument;
|
|
5910
2180
|
exports.Gauge = Gauge;
|
|
5911
2181
|
exports.GaugeTypes = GaugeTypes;
|
|
5912
2182
|
exports.GetInstrumentName = GetInstrumentName;
|
|
5913
|
-
exports.GetInstruments = GetInstruments;
|
|
5914
|
-
exports.GetSTSInstrumentController = GetSTSInstrumentController;
|
|
5915
|
-
exports.GetSTSInstrumentControllerPluginKey = GetSTSInstrumentControllerPluginKey;
|
|
5916
|
-
exports.GetSocketIOSubscriptionKey = GetSocketIOSubscriptionKey;
|
|
5917
|
-
exports.GetTransportMode = GetTransportMode;
|
|
5918
2183
|
exports.HistogramDataElementPos = HistogramDataElementPos;
|
|
5919
2184
|
exports.InstrumentBase = InstrumentBase;
|
|
5920
2185
|
exports.InstrumentBaseOptions = InstrumentBaseOptions;
|
|
@@ -5931,30 +2196,11 @@ exports.InstrumentLogTelemetry = InstrumentLogTelemetry;
|
|
|
5931
2196
|
exports.InstrumentObject = InstrumentObject;
|
|
5932
2197
|
exports.InstrumentObjectOptions = InstrumentObjectOptions;
|
|
5933
2198
|
exports.InstrumentObjectTelemetry = InstrumentObjectTelemetry;
|
|
5934
|
-
exports.InstrumentPayloadType = InstrumentPayloadType;
|
|
5935
2199
|
exports.InstrumentTimerGauge = InstrumentTimerGauge;
|
|
5936
2200
|
exports.InstrumentTimerOptions = InstrumentTimerOptions;
|
|
5937
2201
|
exports.InstrumentTimerTelemetry = InstrumentTimerTelemetry;
|
|
5938
2202
|
exports.InstrumentVelocity = InstrumentVelocity;
|
|
5939
2203
|
exports.InstrumentVelocityOptions = InstrumentVelocityOptions;
|
|
5940
2204
|
exports.InstrumentVelocityTelemetry = InstrumentVelocityTelemetry;
|
|
5941
|
-
exports.KAFKA_PREFIX = KAFKA_PREFIX;
|
|
5942
|
-
exports.ObservabilityModelUtils = ObservabilityModelUtils;
|
|
5943
|
-
exports.ObservabilityRESTAPISubscriber = ObservabilityRESTAPISubscriber;
|
|
5944
|
-
exports.ObservabilitySocketIOSubscriber = ObservabilitySocketIOSubscriber;
|
|
5945
|
-
exports.ObservabilitySubscriptionManager = ObservabilitySubscriptionManager;
|
|
5946
|
-
exports.PublishInstrumentController = PublishInstrumentController;
|
|
5947
|
-
exports.PublishTransportRESTServer = PublishTransportRESTServer;
|
|
5948
|
-
exports.RequestLoggerMiddleware = RequestLoggerMiddleware;
|
|
5949
|
-
exports.RequestLoggerMiddlewareEventName = RequestLoggerMiddlewareEventName;
|
|
5950
|
-
exports.STSInstrumentControllerPlugin = STSInstrumentControllerPlugin;
|
|
5951
|
-
exports.STSInstrumentControllerPluginKey = STSInstrumentControllerPluginKey;
|
|
5952
2205
|
exports.StopInstruments = StopInstruments;
|
|
5953
|
-
exports.SubscriptionTopic = SubscriptionTopic;
|
|
5954
|
-
exports.TransportType = TransportType;
|
|
5955
|
-
exports.ePublishState = ePublishState;
|
|
5956
|
-
exports.globalServiceDefinitions = globalServiceDefinitions;
|
|
5957
|
-
exports.influxDBDataType = influxDBDataType;
|
|
5958
|
-
exports.runStates = runStates;
|
|
5959
|
-
exports.useSTSInstrumentControllerPlugin = useSTSInstrumentControllerPlugin;
|
|
5960
2206
|
//# sourceMappingURL=index.cjs.map
|