@nsshunt/stsvueutils 1.0.22 → 1.0.24
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/stsvueutils.mjs +738 -460
- package/dist/stsvueutils.mjs.map +1 -1
- package/dist/stsvueutils.umd.js +955 -1
- package/dist/stsvueutils.umd.js.map +1 -1
- package/package.json +6 -6
package/dist/stsvueutils.mjs
CHANGED
|
@@ -1,453 +1,651 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
if (
|
|
7
|
+
var __accessCheck = (obj, member, msg) => {
|
|
8
|
+
if (!member.has(obj))
|
|
9
|
+
throw TypeError("Cannot " + msg);
|
|
10
|
+
};
|
|
11
|
+
var __privateGet = (obj, member, getter) => {
|
|
12
|
+
__accessCheck(obj, member, "read from private field");
|
|
13
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
14
|
+
};
|
|
15
|
+
var __privateAdd = (obj, member, value) => {
|
|
16
|
+
if (member.has(obj))
|
|
9
17
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
19
|
+
};
|
|
20
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
21
|
+
__accessCheck(obj, member, "write to private field");
|
|
22
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
26
|
+
set _(value) {
|
|
27
|
+
__privateSet(obj, member, value, setter);
|
|
14
28
|
},
|
|
15
29
|
get _() {
|
|
16
|
-
return
|
|
30
|
+
return __privateGet(obj, member, getter);
|
|
17
31
|
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
});
|
|
33
|
+
var __privateMethod = (obj, member, method) => {
|
|
34
|
+
__accessCheck(obj, member, "access private method");
|
|
35
|
+
return method;
|
|
36
|
+
};
|
|
37
|
+
var _store, _storage, _workersEx, _runner, _workerId, _options, _STSInstrumentController, _app, _CreateRunnerCopy, CreateRunnerCopy_fn, _SetRunnerIntoWorker, _ProcessTelemetry, _CreateAsyncRunner, _PostMessageToWorker, _TerminateWorker, _StopRunner, _StopWorker, _requestResponseMessages, _requestResponseMessageTimeout, _port, _SetupListener, _collectorCollectorPort, _requestResponseHelper, _runners, _options2, _SetMessagePort, _AddAsyncRunner, _StopRunners;
|
|
38
|
+
import { inject } from "vue";
|
|
39
|
+
import debugModule from "debug";
|
|
40
|
+
import { STSInstrumentControllerPluginKey, GetSTSInstrumentController, PublishMessageCommands, GetSTSInstrumentControllerPluginKey } from "@nsshunt/stspublisherserver";
|
|
41
|
+
import { Gauge } from "@nsshunt/stsinstrumentation";
|
|
42
|
+
import { ModelDelimeter } from "@nsshunt/stsmodels";
|
|
43
|
+
import { defineStore } from "pinia";
|
|
44
|
+
import { Sleep } from "@nsshunt/stsutils";
|
|
45
|
+
const STSStoragePluginKey = Symbol("storage");
|
|
46
|
+
const STSEmitterPluginKey = Symbol("emitter");
|
|
47
|
+
const STSWorkerManagerPluginKey = Symbol("workerManager");
|
|
48
|
+
var tinyEmitterExports = {};
|
|
49
|
+
var tinyEmitter = {
|
|
28
50
|
get exports() {
|
|
29
|
-
return
|
|
51
|
+
return tinyEmitterExports;
|
|
30
52
|
},
|
|
31
|
-
set exports(
|
|
32
|
-
|
|
53
|
+
set exports(v) {
|
|
54
|
+
tinyEmitterExports = v;
|
|
33
55
|
}
|
|
34
56
|
};
|
|
35
|
-
function
|
|
57
|
+
function E() {
|
|
36
58
|
}
|
|
37
|
-
|
|
38
|
-
on: function(
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
fn:
|
|
42
|
-
ctx
|
|
43
|
-
})
|
|
59
|
+
E.prototype = {
|
|
60
|
+
on: function(name, callback, ctx) {
|
|
61
|
+
var e = this.e || (this.e = {});
|
|
62
|
+
(e[name] || (e[name] = [])).push({
|
|
63
|
+
fn: callback,
|
|
64
|
+
ctx
|
|
65
|
+
});
|
|
66
|
+
return this;
|
|
44
67
|
},
|
|
45
|
-
once: function(
|
|
46
|
-
var
|
|
47
|
-
function
|
|
48
|
-
|
|
68
|
+
once: function(name, callback, ctx) {
|
|
69
|
+
var self = this;
|
|
70
|
+
function listener() {
|
|
71
|
+
self.off(name, listener);
|
|
72
|
+
callback.apply(ctx, arguments);
|
|
49
73
|
}
|
|
50
|
-
|
|
74
|
+
listener._ = callback;
|
|
75
|
+
return this.on(name, listener, ctx);
|
|
51
76
|
},
|
|
52
|
-
emit: function(
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
77
|
+
emit: function(name) {
|
|
78
|
+
var data = [].slice.call(arguments, 1);
|
|
79
|
+
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
|
|
80
|
+
var i = 0;
|
|
81
|
+
var len = evtArr.length;
|
|
82
|
+
for (i; i < len; i++) {
|
|
83
|
+
evtArr[i].fn.apply(evtArr[i].ctx, data);
|
|
84
|
+
}
|
|
56
85
|
return this;
|
|
57
86
|
},
|
|
58
|
-
off: function(
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
87
|
+
off: function(name, callback) {
|
|
88
|
+
var e = this.e || (this.e = {});
|
|
89
|
+
var evts = e[name];
|
|
90
|
+
var liveEvents = [];
|
|
91
|
+
if (evts && callback) {
|
|
92
|
+
for (var i = 0, len = evts.length; i < len; i++) {
|
|
93
|
+
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
|
|
94
|
+
liveEvents.push(evts[i]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
liveEvents.length ? e[name] = liveEvents : delete e[name];
|
|
98
|
+
return this;
|
|
64
99
|
}
|
|
65
100
|
};
|
|
66
|
-
|
|
67
|
-
var
|
|
68
|
-
const
|
|
101
|
+
tinyEmitter.exports = E;
|
|
102
|
+
var TinyEmitter = tinyEmitterExports.TinyEmitter = E;
|
|
103
|
+
const useSTSEmitterPlugin = () => inject(STSEmitterPluginKey);
|
|
104
|
+
const STSEmitterPlugin = {
|
|
69
105
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
-
install: (
|
|
71
|
-
const
|
|
72
|
-
|
|
106
|
+
install: (app) => {
|
|
107
|
+
const tinyEmitter2 = new TinyEmitter();
|
|
108
|
+
if (!app.config.globalProperties.$sts) {
|
|
109
|
+
app.config.globalProperties.$sts = {};
|
|
110
|
+
}
|
|
111
|
+
app.config.globalProperties.$sts[STSEmitterPluginKey] = tinyEmitter2;
|
|
112
|
+
app.provide(STSEmitterPluginKey, tinyEmitter2);
|
|
73
113
|
}
|
|
74
114
|
};
|
|
75
115
|
/*! js-cookie v3.0.1 | MIT */
|
|
76
|
-
function
|
|
77
|
-
for (var
|
|
78
|
-
var
|
|
79
|
-
for (var
|
|
80
|
-
|
|
116
|
+
function assign(target) {
|
|
117
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
118
|
+
var source = arguments[i];
|
|
119
|
+
for (var key in source) {
|
|
120
|
+
target[key] = source[key];
|
|
121
|
+
}
|
|
81
122
|
}
|
|
82
|
-
return
|
|
123
|
+
return target;
|
|
83
124
|
}
|
|
84
|
-
var
|
|
85
|
-
read: function(
|
|
86
|
-
|
|
125
|
+
var defaultConverter = {
|
|
126
|
+
read: function(value) {
|
|
127
|
+
if (value[0] === '"') {
|
|
128
|
+
value = value.slice(1, -1);
|
|
129
|
+
}
|
|
130
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
87
131
|
},
|
|
88
|
-
write: function(
|
|
89
|
-
return encodeURIComponent(
|
|
132
|
+
write: function(value) {
|
|
133
|
+
return encodeURIComponent(value).replace(
|
|
90
134
|
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
91
135
|
decodeURIComponent
|
|
92
136
|
);
|
|
93
137
|
}
|
|
94
138
|
};
|
|
95
|
-
function
|
|
96
|
-
function
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
139
|
+
function init(converter, defaultAttributes) {
|
|
140
|
+
function set(key, value, attributes) {
|
|
141
|
+
if (typeof document === "undefined") {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
attributes = assign({}, defaultAttributes, attributes);
|
|
145
|
+
if (typeof attributes.expires === "number") {
|
|
146
|
+
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
103
147
|
}
|
|
148
|
+
if (attributes.expires) {
|
|
149
|
+
attributes.expires = attributes.expires.toUTCString();
|
|
150
|
+
}
|
|
151
|
+
key = encodeURIComponent(key).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
|
|
152
|
+
var stringifiedAttributes = "";
|
|
153
|
+
for (var attributeName in attributes) {
|
|
154
|
+
if (!attributes[attributeName]) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
stringifiedAttributes += "; " + attributeName;
|
|
158
|
+
if (attributes[attributeName] === true) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
stringifiedAttributes += "=" + attributes[attributeName].split(";")[0];
|
|
162
|
+
}
|
|
163
|
+
return document.cookie = key + "=" + converter.write(value, key) + stringifiedAttributes;
|
|
104
164
|
}
|
|
105
|
-
function
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
165
|
+
function get(key) {
|
|
166
|
+
if (typeof document === "undefined" || arguments.length && !key) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
var cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
170
|
+
var jar = {};
|
|
171
|
+
for (var i = 0; i < cookies.length; i++) {
|
|
172
|
+
var parts = cookies[i].split("=");
|
|
173
|
+
var value = parts.slice(1).join("=");
|
|
174
|
+
try {
|
|
175
|
+
var foundKey = decodeURIComponent(parts[0]);
|
|
176
|
+
jar[foundKey] = converter.read(value, foundKey);
|
|
177
|
+
if (key === foundKey) {
|
|
178
|
+
break;
|
|
114
179
|
}
|
|
180
|
+
} catch (e) {
|
|
115
181
|
}
|
|
116
|
-
return o ? a[o] : a;
|
|
117
182
|
}
|
|
183
|
+
return key ? jar[key] : jar;
|
|
118
184
|
}
|
|
119
185
|
return Object.create(
|
|
120
186
|
{
|
|
121
|
-
set
|
|
122
|
-
get
|
|
123
|
-
remove: function(
|
|
124
|
-
|
|
125
|
-
|
|
187
|
+
set,
|
|
188
|
+
get,
|
|
189
|
+
remove: function(key, attributes) {
|
|
190
|
+
set(
|
|
191
|
+
key,
|
|
126
192
|
"",
|
|
127
|
-
|
|
193
|
+
assign({}, attributes, {
|
|
128
194
|
expires: -1
|
|
129
195
|
})
|
|
130
196
|
);
|
|
131
197
|
},
|
|
132
|
-
withAttributes: function(
|
|
133
|
-
return
|
|
198
|
+
withAttributes: function(attributes) {
|
|
199
|
+
return init(this.converter, assign({}, this.attributes, attributes));
|
|
134
200
|
},
|
|
135
|
-
withConverter: function(
|
|
136
|
-
return
|
|
201
|
+
withConverter: function(converter2) {
|
|
202
|
+
return init(assign({}, this.converter, converter2), this.attributes);
|
|
137
203
|
}
|
|
138
204
|
},
|
|
139
205
|
{
|
|
140
|
-
attributes: { value: Object.freeze(
|
|
141
|
-
converter: { value: Object.freeze(
|
|
206
|
+
attributes: { value: Object.freeze(defaultAttributes) },
|
|
207
|
+
converter: { value: Object.freeze(converter) }
|
|
142
208
|
}
|
|
143
209
|
);
|
|
144
210
|
}
|
|
145
|
-
var
|
|
146
|
-
const
|
|
147
|
-
let
|
|
148
|
-
var
|
|
149
|
-
|
|
211
|
+
var api = init(defaultConverter, { path: "/" });
|
|
212
|
+
const debug$3 = debugModule(`proc:${process.pid}:storage.ts`);
|
|
213
|
+
let PREFIX = "_ststra_";
|
|
214
|
+
var ClientStorageType = /* @__PURE__ */ ((ClientStorageType2) => {
|
|
215
|
+
ClientStorageType2["LOCAL_STORAGE"] = "LocalStorage";
|
|
216
|
+
ClientStorageType2["SESSION_STORAGE"] = "SessionStorage";
|
|
217
|
+
ClientStorageType2["COOKIE_STORAGE"] = "CookieStorage";
|
|
218
|
+
ClientStorageType2["MEMORY_STORAGE"] = "MemoryStorage";
|
|
219
|
+
return ClientStorageType2;
|
|
220
|
+
})(ClientStorageType || {});
|
|
221
|
+
class CookieStorage {
|
|
150
222
|
constructor() {
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
223
|
+
__publicField(this, "get", (key) => {
|
|
224
|
+
const raw = api.get(PREFIX + key);
|
|
225
|
+
if (raw) {
|
|
226
|
+
return JSON.parse(raw);
|
|
227
|
+
} else {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
154
230
|
});
|
|
155
|
-
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
231
|
+
__publicField(this, "set", (key, value, options = {}) => {
|
|
232
|
+
let cookieAttributes = {};
|
|
233
|
+
if ("https:" === window.location.protocol) {
|
|
234
|
+
cookieAttributes = {
|
|
235
|
+
secure: true,
|
|
236
|
+
sameSite: "none"
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (options && options.daysUntilExpire) {
|
|
240
|
+
cookieAttributes.expires = options.daysUntilExpire;
|
|
241
|
+
} else {
|
|
242
|
+
cookieAttributes.expires = 1;
|
|
243
|
+
}
|
|
244
|
+
debug$3(`CookieStorage.set: key: ${key}, value: [${value}]`);
|
|
245
|
+
api.set(PREFIX + key, JSON.stringify(value), cookieAttributes);
|
|
161
246
|
});
|
|
162
|
-
|
|
163
|
-
|
|
247
|
+
__publicField(this, "remove", (key) => {
|
|
248
|
+
api.remove(PREFIX + key);
|
|
164
249
|
});
|
|
165
250
|
}
|
|
166
251
|
}
|
|
167
|
-
class
|
|
252
|
+
class SessionStorage {
|
|
168
253
|
constructor() {
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
|
|
254
|
+
__publicField(this, "get", (key) => {
|
|
255
|
+
const value = sessionStorage.getItem(PREFIX + key);
|
|
256
|
+
if (value) {
|
|
257
|
+
return JSON.parse(value);
|
|
258
|
+
} else {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
172
261
|
});
|
|
173
|
-
|
|
174
|
-
|
|
262
|
+
__publicField(this, "set", (key, value) => {
|
|
263
|
+
debug$3(`SessionStorage.set: key: ${key}, value: [${value}]`);
|
|
264
|
+
sessionStorage.setItem(PREFIX + key, JSON.stringify(value));
|
|
175
265
|
});
|
|
176
|
-
|
|
177
|
-
sessionStorage.removeItem(
|
|
266
|
+
__publicField(this, "remove", (key) => {
|
|
267
|
+
sessionStorage.removeItem(PREFIX + key);
|
|
178
268
|
});
|
|
179
269
|
}
|
|
180
270
|
}
|
|
181
|
-
class
|
|
271
|
+
class LocalStorage {
|
|
182
272
|
constructor() {
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
273
|
+
__publicField(this, "get", (key) => {
|
|
274
|
+
const value = localStorage.getItem(PREFIX + key);
|
|
275
|
+
if (value) {
|
|
276
|
+
return JSON.parse(value);
|
|
277
|
+
} else {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
186
280
|
});
|
|
187
|
-
|
|
188
|
-
|
|
281
|
+
__publicField(this, "set", (key, value) => {
|
|
282
|
+
debug$3(`LocalStorage.set: key: ${key}, value: [${value}]`);
|
|
283
|
+
localStorage.setItem(PREFIX + key, JSON.stringify(value));
|
|
189
284
|
});
|
|
190
|
-
|
|
191
|
-
localStorage.removeItem(
|
|
285
|
+
__publicField(this, "remove", (key) => {
|
|
286
|
+
localStorage.removeItem(PREFIX + key);
|
|
192
287
|
});
|
|
193
288
|
}
|
|
194
289
|
}
|
|
195
|
-
|
|
196
|
-
class Ie {
|
|
290
|
+
class MemoryStorage {
|
|
197
291
|
constructor() {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
292
|
+
__privateAdd(this, _store, {});
|
|
293
|
+
__publicField(this, "get", (key) => {
|
|
294
|
+
const value = __privateGet(this, _store)[PREFIX + key];
|
|
295
|
+
if (value) {
|
|
296
|
+
return value;
|
|
297
|
+
} else {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
202
300
|
});
|
|
203
|
-
|
|
204
|
-
|
|
301
|
+
__publicField(this, "set", (key, value) => {
|
|
302
|
+
debug$3(`MemoryStorage.set: key: ${key}, value: [${value}]`);
|
|
303
|
+
__privateGet(this, _store)[PREFIX + key] = value;
|
|
205
304
|
});
|
|
206
|
-
|
|
207
|
-
delete
|
|
305
|
+
__publicField(this, "remove", (key) => {
|
|
306
|
+
delete __privateGet(this, _store)[PREFIX + key];
|
|
208
307
|
});
|
|
209
308
|
}
|
|
210
309
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
310
|
+
_store = new WeakMap();
|
|
311
|
+
class ClientStorageFactory {
|
|
312
|
+
constructor(options) {
|
|
313
|
+
__privateAdd(this, _storage, void 0);
|
|
314
|
+
if (options.usePrefix === false) {
|
|
315
|
+
PREFIX = "";
|
|
316
|
+
}
|
|
317
|
+
switch (options.clientStorageType) {
|
|
217
318
|
case "SessionStorage":
|
|
218
|
-
|
|
319
|
+
__privateSet(this, _storage, new SessionStorage());
|
|
219
320
|
break;
|
|
220
321
|
case "LocalStorage":
|
|
221
|
-
|
|
322
|
+
__privateSet(this, _storage, new LocalStorage());
|
|
222
323
|
break;
|
|
223
324
|
case "CookieStorage":
|
|
224
|
-
|
|
325
|
+
__privateSet(this, _storage, new CookieStorage());
|
|
225
326
|
break;
|
|
226
327
|
case "MemoryStorage":
|
|
227
|
-
|
|
328
|
+
__privateSet(this, _storage, new MemoryStorage());
|
|
228
329
|
break;
|
|
229
330
|
default:
|
|
230
|
-
throw new Error(`Unknown [${
|
|
331
|
+
throw new Error(`Unknown [${options.clientStorageType}] storage type.`);
|
|
231
332
|
}
|
|
333
|
+
return;
|
|
232
334
|
}
|
|
233
335
|
GetStorage() {
|
|
234
|
-
return
|
|
336
|
+
return __privateGet(this, _storage);
|
|
235
337
|
}
|
|
236
338
|
}
|
|
237
|
-
|
|
238
|
-
const
|
|
339
|
+
_storage = new WeakMap();
|
|
340
|
+
const useSTSStoragePlugin = () => inject(STSStoragePluginKey);
|
|
341
|
+
const STSStoragePlugin = {
|
|
239
342
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
240
|
-
install: (
|
|
241
|
-
const
|
|
242
|
-
|
|
343
|
+
install: (app, options) => {
|
|
344
|
+
const cs = new ClientStorageFactory({ clientStorageType: options.clientStorageType, usePrefix: true });
|
|
345
|
+
const pluginInstance = cs.GetStorage();
|
|
346
|
+
if (!app.config.globalProperties.$sts) {
|
|
347
|
+
app.config.globalProperties.$sts = {};
|
|
348
|
+
}
|
|
349
|
+
app.config.globalProperties.$sts[STSStoragePluginKey] = pluginInstance;
|
|
350
|
+
app.provide(STSStoragePluginKey, pluginInstance);
|
|
243
351
|
}
|
|
244
|
-
}
|
|
352
|
+
};
|
|
353
|
+
const TelemetryStore = defineStore("__sts__TelemetryStore", {
|
|
245
354
|
// State
|
|
246
355
|
// https://pinia.vuejs.org/core-concepts/state.html
|
|
247
|
-
state: () =>
|
|
248
|
-
|
|
249
|
-
|
|
356
|
+
state: () => {
|
|
357
|
+
return {
|
|
358
|
+
workers: {}
|
|
359
|
+
};
|
|
360
|
+
},
|
|
250
361
|
// Getters
|
|
251
362
|
// https://pinia.vuejs.org/core-concepts/getters.html
|
|
252
363
|
// Actions
|
|
253
364
|
// https://pinia.vuejs.org/core-concepts/actions.html
|
|
254
365
|
actions: {
|
|
255
|
-
RemoveWorker(
|
|
256
|
-
delete this.workers[
|
|
366
|
+
RemoveWorker(workerEx) {
|
|
367
|
+
delete this.workers[workerEx.id];
|
|
257
368
|
},
|
|
258
|
-
RemoveRunner(
|
|
259
|
-
const
|
|
260
|
-
|
|
369
|
+
RemoveRunner(workerEx, runnerEx) {
|
|
370
|
+
const worker = this.workers[workerEx.id];
|
|
371
|
+
if (worker && worker.runners) {
|
|
372
|
+
delete worker.runners[runnerEx.id];
|
|
373
|
+
}
|
|
261
374
|
},
|
|
262
|
-
Update(
|
|
263
|
-
|
|
264
|
-
id
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
instrumentData: { ...e.instrumentData }
|
|
375
|
+
Update(workerEx, runnerEx) {
|
|
376
|
+
if (!this.workers[workerEx.id]) {
|
|
377
|
+
this.workers[workerEx.id] = {
|
|
378
|
+
id: workerEx.id,
|
|
379
|
+
state: workerEx.state,
|
|
380
|
+
primaryThreadWorkerOptions: { ...workerEx.primaryThreadWorkerOptions },
|
|
381
|
+
workerThreadWorkerOptions: { ...workerEx.workerThreadWorkerOptions },
|
|
382
|
+
runners: {}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
const worker = this.workers[workerEx.id];
|
|
386
|
+
if (worker.runners) {
|
|
387
|
+
if (!worker.runners[runnerEx.id]) {
|
|
388
|
+
const runner = {
|
|
389
|
+
id: runnerEx.id,
|
|
390
|
+
asyncRunnerContext: { ...runnerEx.asyncRunnerContext },
|
|
391
|
+
options: { ...runnerEx.options },
|
|
392
|
+
state: runnerEx.state,
|
|
393
|
+
instrumentData: { ...runnerEx.instrumentData }
|
|
282
394
|
};
|
|
283
|
-
|
|
395
|
+
worker.runners[runner.id] = runner;
|
|
396
|
+
} else {
|
|
397
|
+
const runner = worker.runners[runnerEx.id];
|
|
398
|
+
runner.instrumentData = { ...runnerEx.instrumentData };
|
|
284
399
|
}
|
|
400
|
+
}
|
|
285
401
|
}
|
|
286
402
|
}
|
|
287
403
|
});
|
|
288
|
-
var
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
404
|
+
var IRunnerState = /* @__PURE__ */ ((IRunnerState2) => {
|
|
405
|
+
IRunnerState2["created"] = "created";
|
|
406
|
+
IRunnerState2["running"] = "running";
|
|
407
|
+
IRunnerState2["stopped"] = "stopped";
|
|
408
|
+
IRunnerState2["paused"] = "paused";
|
|
409
|
+
IRunnerState2["error"] = "error";
|
|
410
|
+
return IRunnerState2;
|
|
411
|
+
})(IRunnerState || {});
|
|
412
|
+
var IWorkerState = /* @__PURE__ */ ((IWorkerState2) => {
|
|
413
|
+
IWorkerState2["starting"] = "starting";
|
|
414
|
+
IWorkerState2["started"] = "started";
|
|
415
|
+
IWorkerState2["stopped"] = "stopped";
|
|
416
|
+
return IWorkerState2;
|
|
417
|
+
})(IWorkerState || {});
|
|
418
|
+
const debug$2 = debugModule(`proc:${process.pid}:workerManager`);
|
|
419
|
+
class STSWorkerManager {
|
|
292
420
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
293
|
-
constructor(
|
|
294
|
-
|
|
421
|
+
constructor(app, options) {
|
|
422
|
+
__privateAdd(this, _CreateRunnerCopy);
|
|
295
423
|
//#agentSession: string = null;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
424
|
+
__privateAdd(this, _workersEx, {});
|
|
425
|
+
__privateAdd(this, _runner, 0);
|
|
426
|
+
__privateAdd(this, _workerId, 0);
|
|
427
|
+
__privateAdd(this, _options, void 0);
|
|
428
|
+
__privateAdd(this, _STSInstrumentController, void 0);
|
|
301
429
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
let
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
430
|
+
__privateAdd(this, _app, void 0);
|
|
431
|
+
__publicField(this, "AddWorker", async (useWorkerFactory) => {
|
|
432
|
+
let workerFactory;
|
|
433
|
+
if (useWorkerFactory) {
|
|
434
|
+
workerFactory = useWorkerFactory;
|
|
435
|
+
} else {
|
|
436
|
+
workerFactory = __privateGet(this, _options).workerFactory;
|
|
437
|
+
}
|
|
438
|
+
const stsWorkerEx = {
|
|
439
|
+
id: __privateWrapper(this, _workerId)._++,
|
|
308
440
|
// uuidv4()
|
|
309
|
-
worker:
|
|
310
|
-
primaryWorker:
|
|
311
|
-
state:
|
|
312
|
-
workerThreadWorkerOptions:
|
|
313
|
-
primaryThreadWorkerOptions:
|
|
441
|
+
worker: workerFactory.createWorkerThreadWorker(),
|
|
442
|
+
primaryWorker: workerFactory.createPrimaryThreadWorker(__privateGet(this, _app), workerFactory.primaryThreadWorkerOptions),
|
|
443
|
+
state: IWorkerState.starting,
|
|
444
|
+
workerThreadWorkerOptions: workerFactory.workerThreadWorkerOptions,
|
|
445
|
+
primaryThreadWorkerOptions: workerFactory.primaryThreadWorkerOptions,
|
|
314
446
|
runnersEx: {},
|
|
315
|
-
AddRunner: (
|
|
316
|
-
StopRunner: (
|
|
317
|
-
Stop: async () =>
|
|
447
|
+
AddRunner: (runnerOptions) => this.AddRunnerToWorker(stsWorkerEx, runnerOptions),
|
|
448
|
+
StopRunner: (runner) => __privateGet(this, _StopRunner).call(this, stsWorkerEx, runner),
|
|
449
|
+
Stop: async () => __privateGet(this, _StopWorker).call(this, stsWorkerEx)
|
|
318
450
|
};
|
|
319
|
-
console.log(`Adding worker: [${
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
451
|
+
console.log(`Adding worker: [${stsWorkerEx.id}]`);
|
|
452
|
+
stsWorkerEx.worker.onmessage = function(data) {
|
|
453
|
+
console.log(data.data);
|
|
454
|
+
};
|
|
455
|
+
stsWorkerEx.worker.onerror = function(error) {
|
|
456
|
+
console.log(error);
|
|
323
457
|
};
|
|
324
458
|
const {
|
|
325
|
-
port1
|
|
459
|
+
port1,
|
|
326
460
|
// process message port
|
|
327
|
-
port2
|
|
461
|
+
port2
|
|
328
462
|
// collector message port
|
|
329
|
-
} = new MessageChannel()
|
|
330
|
-
|
|
331
|
-
|
|
463
|
+
} = new MessageChannel();
|
|
464
|
+
const workerPort = port1;
|
|
465
|
+
console.log(`STSWorkerManager::AddWorker::workerThreadWorkerOptions: [${JSON.stringify(stsWorkerEx.workerThreadWorkerOptions)}]`);
|
|
466
|
+
__privateGet(this, _PostMessageToWorker).call(this, stsWorkerEx, PublishMessageCommands.MessagePort, {
|
|
467
|
+
port: port2,
|
|
332
468
|
//applicationStoreState: stateCopy,
|
|
333
|
-
options: { ...
|
|
334
|
-
},
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
469
|
+
options: { ...stsWorkerEx.workerThreadWorkerOptions }
|
|
470
|
+
}, port2);
|
|
471
|
+
workerPort.onmessage = async (data) => {
|
|
472
|
+
const publishMessagePayload = data.data;
|
|
473
|
+
switch (publishMessagePayload.command) {
|
|
474
|
+
case PublishMessageCommands.MessagePortResponse:
|
|
475
|
+
stsWorkerEx.state = IWorkerState.started;
|
|
339
476
|
break;
|
|
340
|
-
case
|
|
341
|
-
|
|
477
|
+
case PublishMessageCommands.InstrumentTelemetry:
|
|
478
|
+
__privateGet(this, _ProcessTelemetry).call(this, stsWorkerEx, publishMessagePayload.payload);
|
|
342
479
|
break;
|
|
343
480
|
default:
|
|
344
|
-
|
|
481
|
+
stsWorkerEx.primaryWorker.ProcessMessageFromWorker(workerPort, publishMessagePayload);
|
|
345
482
|
}
|
|
346
|
-
}, n(this, O)[r.id] = r, console.log(`Added worker: [${r.id}]`), r;
|
|
347
|
-
});
|
|
348
|
-
c(this, "AddRunnerToWorker", (e, t) => {
|
|
349
|
-
const r = n(this, H).call(this, e, t);
|
|
350
|
-
return e.runnersEx[r.id] = r, n(this, E).call(this, e, r), r;
|
|
351
|
-
});
|
|
352
|
-
l(this, E, (e, t) => {
|
|
353
|
-
const r = {
|
|
354
|
-
runner: ee(this, N, ce).call(this, t)
|
|
355
483
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
484
|
+
__privateGet(this, _workersEx)[stsWorkerEx.id] = stsWorkerEx;
|
|
485
|
+
console.log(`Added worker: [${stsWorkerEx.id}]`);
|
|
486
|
+
return stsWorkerEx;
|
|
487
|
+
});
|
|
488
|
+
__publicField(this, "AddRunnerToWorker", (stsWorkerEx, runnerOptions) => {
|
|
489
|
+
const runnerEx = __privateGet(this, _CreateAsyncRunner).call(this, stsWorkerEx, runnerOptions);
|
|
490
|
+
stsWorkerEx.runnersEx[runnerEx.id] = runnerEx;
|
|
491
|
+
__privateGet(this, _SetRunnerIntoWorker).call(this, stsWorkerEx, runnerEx);
|
|
492
|
+
return runnerEx;
|
|
493
|
+
});
|
|
494
|
+
__privateAdd(this, _SetRunnerIntoWorker, (workerEx, runnerEx) => {
|
|
495
|
+
const payload = {
|
|
496
|
+
runner: __privateMethod(this, _CreateRunnerCopy, CreateRunnerCopy_fn).call(this, runnerEx)
|
|
497
|
+
};
|
|
498
|
+
__privateGet(this, _PostMessageToWorker).call(this, workerEx, PublishMessageCommands.Add, payload);
|
|
499
|
+
});
|
|
500
|
+
__privateAdd(this, _ProcessTelemetry, (workerEx, payloadContents) => {
|
|
501
|
+
const store = TelemetryStore();
|
|
502
|
+
const { runner } = payloadContents;
|
|
503
|
+
if (workerEx.runnersEx[runner.id]) {
|
|
504
|
+
const runnerEx = workerEx.runnersEx[runner.id];
|
|
505
|
+
let update = false;
|
|
506
|
+
runnerEx.instrumentData.count = runner.instrumentData.count;
|
|
507
|
+
runnerEx.instrumentData.velocity = runner.instrumentData.velocity;
|
|
508
|
+
if (runner.instrumentData.message) {
|
|
509
|
+
runnerEx.instrumentData.message = [...runner.instrumentData.message];
|
|
510
|
+
} else {
|
|
511
|
+
runnerEx.instrumentData.message = [];
|
|
512
|
+
}
|
|
513
|
+
if (runner.instrumentData.message) {
|
|
514
|
+
runner.instrumentData.message.forEach((message) => {
|
|
515
|
+
runnerEx.publishInstrumentController.LogEx(message);
|
|
516
|
+
});
|
|
517
|
+
update = true;
|
|
518
|
+
}
|
|
519
|
+
if (runner.instrumentData.count) {
|
|
520
|
+
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.REQUEST_COUNT_GAUGE, {
|
|
521
|
+
val: runnerEx.instrumentData.count
|
|
522
|
+
});
|
|
523
|
+
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.VELOCITY_GAUGE, {
|
|
524
|
+
Inc: runnerEx.instrumentData.velocity
|
|
525
|
+
});
|
|
526
|
+
update = true;
|
|
527
|
+
}
|
|
528
|
+
if (update) {
|
|
529
|
+
store.Update(workerEx, runnerEx);
|
|
530
|
+
}
|
|
370
531
|
}
|
|
371
532
|
});
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
nid: `${
|
|
376
|
-
id:
|
|
377
|
-
hostName:
|
|
378
|
-
agentName: `${
|
|
379
|
-
threadId: `worker${
|
|
380
|
-
asyncRunnerId:
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
533
|
+
__privateAdd(this, _CreateAsyncRunner, (workerEx, runnerOptions) => {
|
|
534
|
+
__privateWrapper(this, _runner)._++;
|
|
535
|
+
const asyncRunnerContext = {
|
|
536
|
+
nid: `${workerEx.workerThreadWorkerOptions.hostName}${ModelDelimeter.COMPONENT_SEPERATOR}${workerEx.workerThreadWorkerOptions.agentId}-${workerEx.workerThreadWorkerOptions.userAgent}${ModelDelimeter.NID_SEPERATOR}worker${workerEx.id}${ModelDelimeter.SEPERATOR}${__privateGet(this, _runner)}`,
|
|
537
|
+
id: __privateGet(this, _runner).toString(),
|
|
538
|
+
hostName: workerEx.workerThreadWorkerOptions.hostName ? workerEx.workerThreadWorkerOptions.hostName : "host",
|
|
539
|
+
agentName: `${workerEx.workerThreadWorkerOptions.agentId}-${workerEx.workerThreadWorkerOptions.userAgent}`,
|
|
540
|
+
threadId: `worker${workerEx.id}`,
|
|
541
|
+
asyncRunnerId: __privateGet(this, _runner)
|
|
542
|
+
};
|
|
543
|
+
const runnerEx = {
|
|
544
|
+
id: __privateGet(this, _runner),
|
|
545
|
+
publishInstrumentController: __privateGet(this, _STSInstrumentController).AddPublishInstrumentController(asyncRunnerContext),
|
|
546
|
+
asyncRunnerContext,
|
|
547
|
+
state: IRunnerState.created,
|
|
548
|
+
options: runnerOptions,
|
|
387
549
|
instrumentData: {
|
|
388
550
|
count: 0,
|
|
389
551
|
velocity: 0,
|
|
390
552
|
message: []
|
|
391
553
|
},
|
|
392
|
-
Stop: async () =>
|
|
554
|
+
Stop: async () => __privateGet(this, _StopRunner).call(this, workerEx, runnerEx)
|
|
393
555
|
};
|
|
394
|
-
return
|
|
556
|
+
return runnerEx;
|
|
395
557
|
});
|
|
396
558
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
397
|
-
|
|
398
|
-
|
|
559
|
+
__privateAdd(this, _PostMessageToWorker, (workerEx, command, payload, transferObject) => {
|
|
560
|
+
if (transferObject) {
|
|
561
|
+
console.log(`#PostMessageToWorker with transfer object`);
|
|
562
|
+
workerEx.worker.postMessage({ command, payload }, [transferObject]);
|
|
563
|
+
console.log(`#PostMessageToWorker with transfer object - done...`);
|
|
564
|
+
} else {
|
|
565
|
+
console.log(`#PostMessageToWorker`);
|
|
566
|
+
workerEx.worker.postMessage({ command, payload });
|
|
567
|
+
}
|
|
399
568
|
});
|
|
400
|
-
|
|
401
|
-
if (
|
|
402
|
-
const
|
|
403
|
-
|
|
569
|
+
__privateAdd(this, _TerminateWorker, (workerEx) => {
|
|
570
|
+
if (workerEx.worker) {
|
|
571
|
+
const store = TelemetryStore();
|
|
572
|
+
workerEx.worker.terminate();
|
|
573
|
+
console.log(`Terminated worker: [${workerEx.id}]`);
|
|
574
|
+
store.RemoveWorker(workerEx);
|
|
575
|
+
delete __privateGet(this, _workersEx)[workerEx.id];
|
|
404
576
|
}
|
|
405
577
|
});
|
|
406
|
-
|
|
407
|
-
if (
|
|
408
|
-
const
|
|
409
|
-
if (
|
|
410
|
-
const
|
|
411
|
-
|
|
578
|
+
__privateAdd(this, _StopRunner, async (workerEx, runnerEx = null) => {
|
|
579
|
+
if (runnerEx === null) {
|
|
580
|
+
const ids = Object.keys(workerEx.runnersEx);
|
|
581
|
+
if (ids.length > 0) {
|
|
582
|
+
const id = ids[0];
|
|
583
|
+
runnerEx = workerEx.runnersEx[id];
|
|
412
584
|
}
|
|
413
585
|
}
|
|
414
|
-
if (
|
|
415
|
-
|
|
416
|
-
runner:
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
586
|
+
if (runnerEx !== null) {
|
|
587
|
+
__privateGet(this, _PostMessageToWorker).call(this, workerEx, PublishMessageCommands.Stop, {
|
|
588
|
+
runner: __privateMethod(this, _CreateRunnerCopy, CreateRunnerCopy_fn).call(this, runnerEx)
|
|
589
|
+
});
|
|
590
|
+
runnerEx.publishInstrumentController.LogEx(`Terminating runner: [${runnerEx.id}]`);
|
|
591
|
+
const promArray = [];
|
|
592
|
+
promArray.push((async () => {
|
|
593
|
+
await Sleep(100);
|
|
594
|
+
return runnerEx.publishInstrumentController.InstrumentTerminate();
|
|
595
|
+
})());
|
|
596
|
+
const store = TelemetryStore();
|
|
597
|
+
store.RemoveRunner(workerEx, runnerEx);
|
|
598
|
+
delete workerEx.runnersEx[runnerEx.id];
|
|
599
|
+
const retVal = await Promise.all(promArray);
|
|
600
|
+
console.log(`Removed instrument workers: [${retVal}]`);
|
|
422
601
|
}
|
|
423
|
-
return
|
|
602
|
+
return true;
|
|
424
603
|
});
|
|
425
|
-
|
|
604
|
+
__privateAdd(this, _StopWorker, async (workerEx) => {
|
|
426
605
|
try {
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
606
|
+
if (workerEx.state !== IWorkerState.stopped) {
|
|
607
|
+
__privateGet(this, _PostMessageToWorker).call(this, workerEx, PublishMessageCommands.Stop, null);
|
|
608
|
+
console.log(`Terminating worker: [${workerEx.id}]`);
|
|
609
|
+
const promArray = [];
|
|
610
|
+
const ids = Object.keys(workerEx.runnersEx);
|
|
611
|
+
ids.forEach((id) => {
|
|
612
|
+
const runnerEx = workerEx.runnersEx[id];
|
|
613
|
+
promArray.push(__privateGet(this, _StopRunner).call(this, workerEx, runnerEx));
|
|
614
|
+
});
|
|
615
|
+
await Promise.all(promArray);
|
|
616
|
+
__privateGet(this, _TerminateWorker).call(this, workerEx);
|
|
434
617
|
}
|
|
435
|
-
return
|
|
436
|
-
} catch (
|
|
437
|
-
|
|
618
|
+
return true;
|
|
619
|
+
} catch (error) {
|
|
620
|
+
console.log(`Error in STSTestWorker:StopWorker: [${error}]`);
|
|
621
|
+
return false;
|
|
438
622
|
}
|
|
439
623
|
});
|
|
440
|
-
|
|
441
|
-
let
|
|
442
|
-
for (const [,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
624
|
+
__publicField(this, "GetNextAvailableWorker", () => {
|
|
625
|
+
let leastRunnerWorker = null;
|
|
626
|
+
for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
|
|
627
|
+
if (leastRunnerWorker) {
|
|
628
|
+
if (Object.keys(stsWorker.runnersEx).length < Object.keys(leastRunnerWorker.runnersEx).length) {
|
|
629
|
+
leastRunnerWorker = stsWorker;
|
|
630
|
+
}
|
|
631
|
+
} else {
|
|
632
|
+
leastRunnerWorker = stsWorker;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return leastRunnerWorker;
|
|
636
|
+
});
|
|
637
|
+
__publicField(this, "GetBusyWorker", () => {
|
|
638
|
+
let busyWorker = null;
|
|
639
|
+
for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
|
|
640
|
+
if (busyWorker) {
|
|
641
|
+
if (Object.keys(stsWorker.runnersEx).length > Object.keys(busyWorker.runnersEx).length) {
|
|
642
|
+
busyWorker = stsWorker;
|
|
643
|
+
}
|
|
644
|
+
} else {
|
|
645
|
+
busyWorker = stsWorker;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return busyWorker;
|
|
451
649
|
});
|
|
452
650
|
/*
|
|
453
651
|
StopRunner = async () => {
|
|
@@ -481,201 +679,281 @@ class be {
|
|
|
481
679
|
if (largestRunnerWorker) largestRunnerWorker.Stop();
|
|
482
680
|
}
|
|
483
681
|
*/
|
|
484
|
-
|
|
485
|
-
const
|
|
486
|
-
for (const [,
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
682
|
+
__publicField(this, "StopAllWorkers", async () => {
|
|
683
|
+
const promArray = [];
|
|
684
|
+
for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
|
|
685
|
+
promArray.push(stsWorker.Stop());
|
|
686
|
+
}
|
|
687
|
+
await Promise.all(promArray);
|
|
688
|
+
});
|
|
689
|
+
__privateSet(this, _app, app);
|
|
690
|
+
if (options) {
|
|
691
|
+
__privateSet(this, _options, options);
|
|
692
|
+
} else {
|
|
693
|
+
__privateSet(this, _options, {});
|
|
694
|
+
}
|
|
695
|
+
debug$2(`CompareSTSInstrumentControllerPluginKeyWMEx(): [${CompareSTSInstrumentControllerPluginKeyWMEx()}]`);
|
|
696
|
+
debug$2(`Attempting to get STSInstrumentControllerPlugin using symbol: [${String(STSInstrumentControllerPluginKey)}]`);
|
|
697
|
+
__privateSet(this, _STSInstrumentController, GetSTSInstrumentController(app));
|
|
698
|
+
debug$2(__privateGet(this, _STSInstrumentController));
|
|
699
|
+
debug$2("keys within app.config.globalProperties.$sts");
|
|
700
|
+
for (const [key, value] of Object.entries(app.config.globalProperties.$sts)) {
|
|
701
|
+
debug$2(`${key}`);
|
|
702
|
+
}
|
|
703
|
+
if (!__privateGet(this, _STSInstrumentController)) {
|
|
704
|
+
debug$2(`Failed to get STSInstrumentControllerPlugin using symbol: [${String(STSInstrumentControllerPluginKey)}]`);
|
|
705
|
+
}
|
|
494
706
|
}
|
|
495
707
|
get WorkersEx() {
|
|
496
|
-
return
|
|
708
|
+
return __privateGet(this, _workersEx);
|
|
497
709
|
}
|
|
498
710
|
get Options() {
|
|
499
|
-
return
|
|
711
|
+
return __privateGet(this, _options);
|
|
500
712
|
}
|
|
501
|
-
set Options(
|
|
502
|
-
|
|
713
|
+
set Options(options) {
|
|
714
|
+
__privateSet(this, _options, options);
|
|
503
715
|
}
|
|
504
716
|
}
|
|
505
|
-
|
|
717
|
+
_workersEx = new WeakMap();
|
|
718
|
+
_runner = new WeakMap();
|
|
719
|
+
_workerId = new WeakMap();
|
|
720
|
+
_options = new WeakMap();
|
|
721
|
+
_STSInstrumentController = new WeakMap();
|
|
722
|
+
_app = new WeakMap();
|
|
723
|
+
_CreateRunnerCopy = new WeakSet();
|
|
724
|
+
CreateRunnerCopy_fn = function(runnerEx) {
|
|
506
725
|
return {
|
|
507
|
-
id:
|
|
508
|
-
asyncRunnerContext: { ...
|
|
509
|
-
options: { ...
|
|
510
|
-
state:
|
|
511
|
-
instrumentData: { ...
|
|
726
|
+
id: runnerEx.id,
|
|
727
|
+
asyncRunnerContext: { ...runnerEx.asyncRunnerContext },
|
|
728
|
+
options: { ...runnerEx.options },
|
|
729
|
+
state: runnerEx.state,
|
|
730
|
+
instrumentData: { ...runnerEx.instrumentData }
|
|
512
731
|
};
|
|
513
|
-
}
|
|
514
|
-
|
|
732
|
+
};
|
|
733
|
+
_SetRunnerIntoWorker = new WeakMap();
|
|
734
|
+
_ProcessTelemetry = new WeakMap();
|
|
735
|
+
_CreateAsyncRunner = new WeakMap();
|
|
736
|
+
_PostMessageToWorker = new WeakMap();
|
|
737
|
+
_TerminateWorker = new WeakMap();
|
|
738
|
+
_StopRunner = new WeakMap();
|
|
739
|
+
_StopWorker = new WeakMap();
|
|
740
|
+
const GetSTSInstrumentControllerPluginKeyWM = () => STSInstrumentControllerPluginKey;
|
|
741
|
+
const CompareSTSInstrumentControllerPluginKeyWM = (val) => val === STSInstrumentControllerPluginKey;
|
|
742
|
+
const CompareSTSInstrumentControllerPluginKeyWMEx = () => STSInstrumentControllerPluginKey === GetSTSInstrumentControllerPluginKey();
|
|
743
|
+
const useSTSWorkerManager = () => inject(STSWorkerManagerPluginKey);
|
|
744
|
+
const STSWorkerManagerPlugin = {
|
|
515
745
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
516
|
-
install: (
|
|
517
|
-
const
|
|
518
|
-
|
|
746
|
+
install: (app, options) => {
|
|
747
|
+
const wm = new STSWorkerManager(app, options);
|
|
748
|
+
if (!app.config.globalProperties.$sts) {
|
|
749
|
+
app.config.globalProperties.$sts = {};
|
|
750
|
+
}
|
|
751
|
+
app.config.globalProperties.$sts[STSWorkerManagerPluginKey] = wm;
|
|
752
|
+
app.provide(STSWorkerManagerPluginKey, wm);
|
|
519
753
|
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
class
|
|
523
|
-
constructor(
|
|
524
|
-
|
|
525
|
-
|
|
754
|
+
};
|
|
755
|
+
const debug$1 = debugModule(`proc:${process.pid}`);
|
|
756
|
+
class RequestResponseHelper {
|
|
757
|
+
constructor(port) {
|
|
758
|
+
__privateAdd(this, _requestResponseMessages, {});
|
|
759
|
+
__privateAdd(this, _requestResponseMessageTimeout, 1e4);
|
|
526
760
|
//@@ config
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
761
|
+
__privateAdd(this, _port, void 0);
|
|
762
|
+
__publicField(this, "PostMessage", (message) => {
|
|
763
|
+
return new Promise((resolve, reject) => {
|
|
764
|
+
const { messageId } = message.payload;
|
|
765
|
+
if (messageId) {
|
|
766
|
+
if (__privateGet(this, _requestResponseMessages)[messageId]) {
|
|
767
|
+
reject(`RequestResponseHelper: Message with id: [${messageId}] already exists within the Request/Response record structure`);
|
|
768
|
+
} else {
|
|
769
|
+
__privateGet(this, _requestResponseMessages)[messageId] = {
|
|
770
|
+
publishMessagePayload: { ...message },
|
|
771
|
+
cb: () => {
|
|
772
|
+
const detail = __privateGet(this, _requestResponseMessages)[messageId].publishMessagePayloadResponse;
|
|
773
|
+
clearTimeout(__privateGet(this, _requestResponseMessages)[messageId].timeout);
|
|
774
|
+
setTimeout(() => {
|
|
775
|
+
delete __privateGet(this, _requestResponseMessages)[messageId];
|
|
776
|
+
}, 0);
|
|
777
|
+
if (detail) {
|
|
778
|
+
debug$1(`RequestResponseHelper: Resolving response message with id: [${messageId}] from target worker port. Details: [${JSON.stringify(detail)}]`);
|
|
779
|
+
resolve(detail);
|
|
780
|
+
} else {
|
|
781
|
+
const msg = `Could not get detail from this.#requestResponseMessages[messageId].publishMessagePayloadResponse`;
|
|
782
|
+
debug$1(msg);
|
|
783
|
+
reject(msg);
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
timeout: setTimeout(() => {
|
|
787
|
+
setTimeout(() => {
|
|
788
|
+
delete __privateGet(this, _requestResponseMessages)[messageId];
|
|
789
|
+
}, 0);
|
|
790
|
+
debug$1(`RequestResponseHelper: Timeout has occurred after: [${__privateGet(this, _requestResponseMessageTimeout)}]ms with message id: [${messageId}]. Details: [${JSON.stringify(__privateGet(this, _requestResponseMessages)[messageId].publishMessagePayload)}]`);
|
|
791
|
+
reject("RequestResponseHelper: Did not receive response form parent process.");
|
|
792
|
+
}, __privateGet(this, _requestResponseMessageTimeout))
|
|
793
|
+
// max message timeout allowed
|
|
794
|
+
};
|
|
795
|
+
debug$1(`RequestResponseHelper: Sending message with id: [${messageId}] to target worker port. Details: [${JSON.stringify(__privateGet(this, _requestResponseMessages)[messageId].publishMessagePayload)}]`);
|
|
796
|
+
__privateGet(this, _port).postMessage(message);
|
|
797
|
+
}
|
|
798
|
+
} else {
|
|
799
|
+
const msg = `RequestResponseHelper: Response did not include a message id`;
|
|
800
|
+
debug$1(msg);
|
|
801
|
+
reject(msg);
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
});
|
|
805
|
+
__privateAdd(this, _SetupListener, () => {
|
|
806
|
+
__privateGet(this, _port).onmessage = async (msg) => {
|
|
807
|
+
const publishMessagePayload = msg.data;
|
|
808
|
+
if (publishMessagePayload.payload.messageId) {
|
|
809
|
+
const messageId = publishMessagePayload.payload.messageId;
|
|
810
|
+
if (messageId && messageId !== "") {
|
|
811
|
+
if (__privateGet(this, _requestResponseMessages)[messageId]) {
|
|
812
|
+
const requestResponseMessage = __privateGet(this, _requestResponseMessages)[messageId];
|
|
813
|
+
requestResponseMessage.publishMessagePayloadResponse = { ...publishMessagePayload };
|
|
814
|
+
requestResponseMessage.cb();
|
|
815
|
+
} else {
|
|
816
|
+
throw new Error(`RequestResponseHelper: Could not find Request/Response message with id: [${messageId}]`);
|
|
542
817
|
}
|
|
543
|
-
}
|
|
544
|
-
timeout: setTimeout(() => {
|
|
545
|
-
setTimeout(() => {
|
|
546
|
-
delete n(this, d)[o];
|
|
547
|
-
}, 0), w(`RequestResponseHelper: Timeout has occurred after: [${n(this, G)}]ms with message id: [${o}]. Details: [${JSON.stringify(n(this, d)[o].publishMessagePayload)}]`), r("RequestResponseHelper: Did not receive response form parent process.");
|
|
548
|
-
}, n(this, G))
|
|
549
|
-
// max message timeout allowed
|
|
550
|
-
}, w(`RequestResponseHelper: Sending message with id: [${o}] to target worker port. Details: [${JSON.stringify(n(this, d)[o].publishMessagePayload)}]`), n(this, I).postMessage(e));
|
|
551
|
-
else {
|
|
552
|
-
const i = "RequestResponseHelper: Response did not include a message id";
|
|
553
|
-
w(i), r(i);
|
|
554
|
-
}
|
|
555
|
-
}));
|
|
556
|
-
l(this, K, () => {
|
|
557
|
-
n(this, I).onmessage = async (e) => {
|
|
558
|
-
const t = e.data;
|
|
559
|
-
if (t.payload.messageId) {
|
|
560
|
-
const r = t.payload.messageId;
|
|
561
|
-
if (r && r !== "")
|
|
562
|
-
if (n(this, d)[r]) {
|
|
563
|
-
const o = n(this, d)[r];
|
|
564
|
-
o.publishMessagePayloadResponse = { ...t }, o.cb();
|
|
565
|
-
} else
|
|
566
|
-
throw new Error(`RequestResponseHelper: Could not find Request/Response message with id: [${r}]`);
|
|
818
|
+
}
|
|
567
819
|
}
|
|
568
820
|
};
|
|
569
821
|
});
|
|
570
|
-
|
|
822
|
+
__privateSet(this, _port, port);
|
|
823
|
+
__privateGet(this, _SetupListener).call(this);
|
|
571
824
|
}
|
|
572
825
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
826
|
+
_requestResponseMessages = new WeakMap();
|
|
827
|
+
_requestResponseMessageTimeout = new WeakMap();
|
|
828
|
+
_port = new WeakMap();
|
|
829
|
+
_SetupListener = new WeakMap();
|
|
830
|
+
const debug = debugModule(`proc:${process.pid}:workerInstance`);
|
|
831
|
+
class WorkerInstance {
|
|
577
832
|
constructor() {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
f("WorkerInstance::StartWork");
|
|
833
|
+
__privateAdd(this, _collectorCollectorPort, null);
|
|
834
|
+
__privateAdd(this, _requestResponseHelper, null);
|
|
835
|
+
__privateAdd(this, _runners, {});
|
|
836
|
+
__privateAdd(this, _options2, null);
|
|
837
|
+
__publicField(this, "GetRandomInt", (max) => {
|
|
838
|
+
debug(`WorkerInstance::GetRandomInt`);
|
|
839
|
+
return Math.floor(Math.random() * Math.floor(max));
|
|
586
840
|
});
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
841
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
842
|
+
__publicField(this, "StartWork", async (runner) => {
|
|
843
|
+
debug(`WorkerInstance::StartWork`);
|
|
844
|
+
return;
|
|
845
|
+
});
|
|
846
|
+
__publicField(this, "PostTelemetry", (runner) => {
|
|
847
|
+
if (__privateGet(this, _collectorCollectorPort)) {
|
|
848
|
+
const message = {
|
|
849
|
+
command: PublishMessageCommands.InstrumentTelemetry,
|
|
591
850
|
payload: {
|
|
592
|
-
runner
|
|
851
|
+
runner
|
|
593
852
|
}
|
|
594
853
|
};
|
|
595
|
-
|
|
854
|
+
__privateGet(this, _collectorCollectorPort).postMessage(message);
|
|
596
855
|
}
|
|
597
856
|
});
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
857
|
+
__privateAdd(this, _SetMessagePort, (workerMessagePort) => {
|
|
858
|
+
debug(`WorkerInstance::SetMessagePort`);
|
|
859
|
+
__privateSet(this, _collectorCollectorPort, workerMessagePort.port);
|
|
860
|
+
__privateGet(this, _collectorCollectorPort).onmessage = function(data) {
|
|
861
|
+
console.log(`collectorCollectorPort onmessage: ${data.data}`);
|
|
862
|
+
};
|
|
863
|
+
__privateSet(this, _requestResponseHelper, new RequestResponseHelper(__privateGet(this, _collectorCollectorPort)));
|
|
864
|
+
const response = {
|
|
865
|
+
command: PublishMessageCommands.MessagePortResponse,
|
|
604
866
|
payload: {}
|
|
605
867
|
};
|
|
606
|
-
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
868
|
+
__privateGet(this, _collectorCollectorPort).postMessage(response);
|
|
869
|
+
});
|
|
870
|
+
__publicField(this, "StartRunner", async (runner) => {
|
|
871
|
+
debug(`WorkerInstance::StartRunner`);
|
|
872
|
+
console.log(`StartTests: [${JSON.stringify(runner)}]`);
|
|
873
|
+
runner.state = IRunnerState.running;
|
|
874
|
+
this.StartWork(runner);
|
|
875
|
+
});
|
|
876
|
+
__privateAdd(this, _AddAsyncRunner, (testRunnerTelemetryPayload) => {
|
|
877
|
+
debug(`WorkerInstance::AddAsyncRunner`);
|
|
878
|
+
const { runner } = testRunnerTelemetryPayload;
|
|
879
|
+
__privateGet(this, _runners)[runner.id] = runner;
|
|
880
|
+
this.StartRunner(runner);
|
|
881
|
+
});
|
|
882
|
+
__privateAdd(this, _StopRunners, (testRunnerTelemetryPayload) => {
|
|
883
|
+
debug(`WorkerInstance::StopRunners`);
|
|
884
|
+
if (testRunnerTelemetryPayload === null) {
|
|
885
|
+
for (const [, testRunner] of Object.entries(__privateGet(this, _runners))) {
|
|
886
|
+
testRunner.state = IRunnerState.stopped;
|
|
887
|
+
}
|
|
888
|
+
} else {
|
|
889
|
+
const runner = __privateGet(this, _runners)[testRunnerTelemetryPayload.runner.id];
|
|
890
|
+
if (runner) {
|
|
891
|
+
runner.state = IRunnerState.stopped;
|
|
892
|
+
}
|
|
623
893
|
}
|
|
624
894
|
});
|
|
625
|
-
|
|
626
|
-
|
|
895
|
+
__publicField(this, "ProcessMessage", async (data) => {
|
|
896
|
+
debug(`WorkerInstance::ProcessMessage`);
|
|
627
897
|
try {
|
|
628
|
-
const
|
|
629
|
-
switch (
|
|
630
|
-
case
|
|
631
|
-
|
|
898
|
+
const payloadMessage = data.data;
|
|
899
|
+
switch (payloadMessage.command) {
|
|
900
|
+
case PublishMessageCommands.MessagePort:
|
|
901
|
+
__privateGet(this, _SetMessagePort).call(this, payloadMessage.payload);
|
|
902
|
+
__privateSet(this, _options2, payloadMessage.payload.options);
|
|
903
|
+
debug(`WorkerInstance::ProcessMessage::#options: [${JSON.stringify(__privateGet(this, _options2))}]`);
|
|
632
904
|
break;
|
|
633
|
-
case
|
|
634
|
-
|
|
905
|
+
case PublishMessageCommands.Add:
|
|
906
|
+
__privateGet(this, _AddAsyncRunner).call(this, payloadMessage.payload);
|
|
635
907
|
break;
|
|
636
|
-
case
|
|
637
|
-
|
|
908
|
+
case PublishMessageCommands.Stop:
|
|
909
|
+
__privateGet(this, _StopRunners).call(this, payloadMessage.payload);
|
|
638
910
|
break;
|
|
639
911
|
default:
|
|
640
|
-
|
|
912
|
+
debug(`Invalid payloadMessage.command: [${payloadMessage.command}] - Ignoring`);
|
|
641
913
|
}
|
|
642
|
-
} catch (
|
|
643
|
-
console.log(
|
|
914
|
+
} catch (error) {
|
|
915
|
+
console.log(error);
|
|
644
916
|
}
|
|
645
917
|
});
|
|
646
|
-
|
|
918
|
+
debug(`WorkerInstance::constructor`);
|
|
647
919
|
}
|
|
648
920
|
get RequestResponseHelper() {
|
|
649
|
-
return
|
|
921
|
+
return __privateGet(this, _requestResponseHelper);
|
|
650
922
|
}
|
|
651
923
|
get CollectorCollectorPort() {
|
|
652
|
-
return
|
|
924
|
+
return __privateGet(this, _collectorCollectorPort);
|
|
653
925
|
}
|
|
654
926
|
get Options() {
|
|
655
|
-
return
|
|
927
|
+
return __privateGet(this, _options2);
|
|
656
928
|
}
|
|
657
929
|
}
|
|
658
|
-
|
|
930
|
+
_collectorCollectorPort = new WeakMap();
|
|
931
|
+
_requestResponseHelper = new WeakMap();
|
|
932
|
+
_runners = new WeakMap();
|
|
933
|
+
_options2 = new WeakMap();
|
|
934
|
+
_SetMessagePort = new WeakMap();
|
|
935
|
+
_AddAsyncRunner = new WeakMap();
|
|
936
|
+
_StopRunners = new WeakMap();
|
|
659
937
|
export {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
938
|
+
ClientStorageFactory,
|
|
939
|
+
ClientStorageType,
|
|
940
|
+
CompareSTSInstrumentControllerPluginKeyWM,
|
|
941
|
+
CompareSTSInstrumentControllerPluginKeyWMEx,
|
|
942
|
+
GetSTSInstrumentControllerPluginKeyWM,
|
|
943
|
+
IRunnerState,
|
|
944
|
+
IWorkerState,
|
|
945
|
+
RequestResponseHelper,
|
|
946
|
+
STSEmitterPlugin,
|
|
947
|
+
STSEmitterPluginKey,
|
|
948
|
+
STSStoragePlugin,
|
|
949
|
+
STSStoragePluginKey,
|
|
950
|
+
STSWorkerManager,
|
|
951
|
+
STSWorkerManagerPlugin,
|
|
952
|
+
STSWorkerManagerPluginKey,
|
|
953
|
+
TelemetryStore,
|
|
954
|
+
WorkerInstance,
|
|
955
|
+
useSTSEmitterPlugin,
|
|
956
|
+
useSTSStoragePlugin,
|
|
957
|
+
useSTSWorkerManager
|
|
680
958
|
};
|
|
681
959
|
//# sourceMappingURL=stsvueutils.mjs.map
|