@module-federation/dts-plugin 2.0.0 → 2.1.0
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/Action-CzhPMw2i.js +153 -0
- package/dist/Broker-DRlzScTT.js +800 -0
- package/dist/CHANGELOG.md +26 -0
- package/dist/DtsWorker-Dtem3-FM.d.ts +166 -0
- package/dist/constant-BwEkyidO.d.ts +42 -0
- package/dist/consumeTypes-AD2ig87l.js +237 -0
- package/dist/core.d.ts +3 -68
- package/dist/core.js +26 -2380
- package/dist/dynamic-remote-type-hints-plugin.d.ts +622 -3
- package/dist/dynamic-remote-type-hints-plugin.js +65 -187
- package/dist/esm/Action-DNNg2YDh.mjs +47 -0
- package/dist/esm/Broker-BU4gToNr.mjs +736 -0
- package/dist/esm/consumeTypes-D51rVbSt.mjs +204 -0
- package/dist/esm/core.mjs +5 -0
- package/dist/esm/dynamic-remote-type-hints-plugin.mjs +73 -0
- package/dist/esm/expose-rpc-DMhY1i8A.mjs +1301 -0
- package/dist/esm/fork-dev-worker.mjs +103 -0
- package/dist/esm/fork-generate-dts.mjs +14 -0
- package/dist/esm/index.mjs +465 -0
- package/dist/esm/start-broker.mjs +22 -0
- package/dist/esm/utils-CkPvDGOy.mjs +13 -0
- package/dist/expose-rpc-BLAH20uj.js +1415 -0
- package/dist/fork-dev-worker.d.ts +10 -9
- package/dist/fork-dev-worker.js +100 -2869
- package/dist/fork-generate-dts.d.ts +4 -8
- package/dist/fork-generate-dts.js +11 -2040
- package/dist/iife/launch-web-client.iife.js +117 -0
- package/dist/index.d.ts +57 -46
- package/dist/index.js +449 -2980
- package/dist/package.json +27 -12
- package/dist/start-broker.d.ts +41 -39
- package/dist/start-broker.js +17 -952
- package/dist/utils-7KqCZHbb.js +19 -0
- package/package.json +32 -17
- package/dist/DTSManager-b15Gfat3.d.ts +0 -53
- package/dist/DTSManagerOptions-QVchWb0x.d.ts +0 -32
- package/dist/DtsWorker-BrHsGz8C.d.ts +0 -56
- package/dist/core.d.mts +0 -68
- package/dist/dynamic-remote-type-hints-plugin.d.mts +0 -5
- package/dist/esm/chunk-647HGGGS.js +0 -241
- package/dist/esm/chunk-G65LOFTY.js +0 -24
- package/dist/esm/chunk-N7GTIQUA.js +0 -282
- package/dist/esm/chunk-RWXNVNFM.js +0 -1579
- package/dist/esm/chunk-WWV5RWOP.js +0 -902
- package/dist/esm/core.js +0 -44
- package/dist/esm/dynamic-remote-type-hints-plugin.js +0 -73
- package/dist/esm/fork-dev-worker.js +0 -145
- package/dist/esm/fork-generate-dts.js +0 -27
- package/dist/esm/index.js +0 -646
- package/dist/esm/start-broker.js +0 -36
- package/dist/fork-dev-worker.d.mts +0 -15
- package/dist/fork-generate-dts.d.mts +0 -10
- package/dist/iife/launch-web-client.js +0 -152
- package/dist/index.d.mts +0 -56
- package/dist/start-broker.d.mts +0 -42
- package/dist/utils-C4sQemLR.d.ts +0 -15
package/dist/start-broker.js
CHANGED
|
@@ -1,958 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var __publicField = (obj, key, value) => {
|
|
31
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
-
return value;
|
|
33
|
-
};
|
|
34
|
-
var __async = (__this, __arguments, generator) => {
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
var fulfilled = (value) => {
|
|
37
|
-
try {
|
|
38
|
-
step(generator.next(value));
|
|
39
|
-
} catch (e) {
|
|
40
|
-
reject(e);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var rejected = (value) => {
|
|
44
|
-
try {
|
|
45
|
-
step(generator.throw(value));
|
|
46
|
-
} catch (e) {
|
|
47
|
-
reject(e);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
51
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
52
|
-
});
|
|
53
|
-
};
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_Broker = require('./Broker-DRlzScTT.js');
|
|
54
3
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
__export(startBroker_exports, {
|
|
58
|
-
getBroker: () => getBroker
|
|
59
|
-
});
|
|
60
|
-
module.exports = __toCommonJS(startBroker_exports);
|
|
61
|
-
|
|
62
|
-
// src/server/broker/Broker.ts
|
|
63
|
-
var import_http = require("http");
|
|
64
|
-
|
|
65
|
-
// src/server/constant.ts
|
|
66
|
-
var DEFAULT_WEB_SOCKET_PORT = 16322;
|
|
67
|
-
var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
|
|
68
|
-
var MF_SERVER_IDENTIFIER = "Module Federation DTS";
|
|
69
|
-
var UpdateMode;
|
|
70
|
-
(function(UpdateMode2) {
|
|
71
|
-
UpdateMode2["POSITIVE"] = "POSITIVE";
|
|
72
|
-
UpdateMode2["PASSIVE"] = "PASSIVE";
|
|
73
|
-
})(UpdateMode || (UpdateMode = {}));
|
|
74
|
-
|
|
75
|
-
// src/server/broker/Broker.ts
|
|
76
|
-
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
77
|
-
var import_node_schedule = __toESM(require("node-schedule"));
|
|
78
|
-
var import_url = require("url");
|
|
79
|
-
|
|
80
|
-
// src/server/message/Message.ts
|
|
81
|
-
var _Message = class _Message {
|
|
82
|
-
constructor(type, kind) {
|
|
83
|
-
__publicField(this, "type");
|
|
84
|
-
__publicField(this, "kind");
|
|
85
|
-
__publicField(this, "time");
|
|
86
|
-
this.type = type;
|
|
87
|
-
this.kind = kind;
|
|
88
|
-
this.time = Date.now();
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
__name(_Message, "Message");
|
|
92
|
-
var Message = _Message;
|
|
93
|
-
|
|
94
|
-
// src/server/message/API/API.ts
|
|
95
|
-
var APIKind;
|
|
96
|
-
(function(APIKind2) {
|
|
97
|
-
APIKind2["UPDATE_SUBSCRIBER"] = "UPDATE_SUBSCRIBER";
|
|
98
|
-
APIKind2["RELOAD_WEB_CLIENT"] = "RELOAD_WEB_CLIENT";
|
|
99
|
-
APIKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
100
|
-
})(APIKind || (APIKind = {}));
|
|
101
|
-
var _API = class _API extends Message {
|
|
102
|
-
constructor(content, kind) {
|
|
103
|
-
super("API", kind);
|
|
104
|
-
__publicField(this, "code");
|
|
105
|
-
__publicField(this, "payload");
|
|
106
|
-
const { code, payload } = content;
|
|
107
|
-
this.code = code;
|
|
108
|
-
this.payload = payload;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
__name(_API, "API");
|
|
112
|
-
var API = _API;
|
|
113
|
-
|
|
114
|
-
// src/server/message/API/UpdateSubscriber.ts
|
|
115
|
-
var _UpdateSubscriberAPI = class _UpdateSubscriberAPI extends API {
|
|
116
|
-
constructor(payload) {
|
|
117
|
-
super({
|
|
118
|
-
code: 0,
|
|
119
|
-
payload
|
|
120
|
-
}, APIKind.UPDATE_SUBSCRIBER);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
__name(_UpdateSubscriberAPI, "UpdateSubscriberAPI");
|
|
124
|
-
var UpdateSubscriberAPI = _UpdateSubscriberAPI;
|
|
125
|
-
|
|
126
|
-
// src/server/message/API/ReloadWebClient.ts
|
|
127
|
-
var _ReloadWebClientAPI = class _ReloadWebClientAPI extends API {
|
|
128
|
-
constructor(payload) {
|
|
129
|
-
super({
|
|
130
|
-
code: 0,
|
|
131
|
-
payload
|
|
132
|
-
}, APIKind.RELOAD_WEB_CLIENT);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
__name(_ReloadWebClientAPI, "ReloadWebClientAPI");
|
|
136
|
-
var ReloadWebClientAPI = _ReloadWebClientAPI;
|
|
137
|
-
|
|
138
|
-
// src/server/message/API/FetchTypes.ts
|
|
139
|
-
var _FetchTypesAPI = class _FetchTypesAPI extends API {
|
|
140
|
-
constructor(payload) {
|
|
141
|
-
super({
|
|
142
|
-
code: 0,
|
|
143
|
-
payload
|
|
144
|
-
}, APIKind.FETCH_TYPES);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
__name(_FetchTypesAPI, "FetchTypesAPI");
|
|
148
|
-
var FetchTypesAPI = _FetchTypesAPI;
|
|
149
|
-
|
|
150
|
-
// src/server/utils/index.ts
|
|
151
|
-
var import_sdk2 = require("@module-federation/sdk");
|
|
152
|
-
|
|
153
|
-
// src/server/utils/logTransform.ts
|
|
154
|
-
var import_chalk = __toESM(require("chalk"));
|
|
155
|
-
|
|
156
|
-
// src/server/message/Log/Log.ts
|
|
157
|
-
var LogLevel;
|
|
158
|
-
(function(LogLevel2) {
|
|
159
|
-
LogLevel2["LOG"] = "LOG";
|
|
160
|
-
LogLevel2["WARN"] = "WARN";
|
|
161
|
-
LogLevel2["ERROR"] = "ERROR";
|
|
162
|
-
})(LogLevel || (LogLevel = {}));
|
|
163
|
-
var LogKind;
|
|
164
|
-
(function(LogKind2) {
|
|
165
|
-
LogKind2["BrokerExitLog"] = "BrokerExitLog";
|
|
166
|
-
LogKind2["PublisherRegisteredLog"] = "PublisherRegisteredLog";
|
|
167
|
-
})(LogKind || (LogKind = {}));
|
|
168
|
-
var _Log = class _Log extends Message {
|
|
169
|
-
constructor(level, kind, ignoreVerbose = false) {
|
|
170
|
-
super("Log", kind);
|
|
171
|
-
__publicField(this, "level");
|
|
172
|
-
__publicField(this, "ignoreVerbose", false);
|
|
173
|
-
this.level = level;
|
|
174
|
-
this.ignoreVerbose = ignoreVerbose;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
__name(_Log, "Log");
|
|
178
|
-
var Log = _Log;
|
|
179
|
-
|
|
180
|
-
// src/server/message/Log/BrokerExitLog.ts
|
|
181
|
-
var _BrokerExitLog = class _BrokerExitLog extends Log {
|
|
182
|
-
constructor() {
|
|
183
|
-
super(LogLevel.LOG, LogKind.BrokerExitLog);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
__name(_BrokerExitLog, "BrokerExitLog");
|
|
187
|
-
var BrokerExitLog = _BrokerExitLog;
|
|
188
|
-
|
|
189
|
-
// src/server/utils/log.ts
|
|
190
|
-
var import_sdk = require("@module-federation/sdk");
|
|
191
|
-
var log4js = __toESM(require("log4js"));
|
|
192
|
-
var logger = (0, import_sdk.createLogger)(`[ ${MF_SERVER_IDENTIFIER} ]`);
|
|
193
|
-
function fileLog(msg, module2, level) {
|
|
194
|
-
var _a, _b;
|
|
195
|
-
if (!((_a = process == null ? void 0 : process.env) == null ? void 0 : _a["FEDERATION_DEBUG"])) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
log4js.configure({
|
|
199
|
-
appenders: {
|
|
200
|
-
[module2]: {
|
|
201
|
-
type: "file",
|
|
202
|
-
filename: ".mf/typesGenerate.log"
|
|
203
|
-
},
|
|
204
|
-
default: {
|
|
205
|
-
type: "file",
|
|
206
|
-
filename: ".mf/typesGenerate.log"
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
categories: {
|
|
210
|
-
[module2]: {
|
|
211
|
-
appenders: [
|
|
212
|
-
module2
|
|
213
|
-
],
|
|
214
|
-
level: "error"
|
|
215
|
-
},
|
|
216
|
-
default: {
|
|
217
|
-
appenders: [
|
|
218
|
-
"default"
|
|
219
|
-
],
|
|
220
|
-
level: "trace"
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
const logger4 = log4js.getLogger(module2);
|
|
225
|
-
logger4.level = "debug";
|
|
226
|
-
(_b = logger4[level]) == null ? void 0 : _b.call(logger4, msg);
|
|
227
|
-
}
|
|
228
|
-
__name(fileLog, "fileLog");
|
|
229
|
-
function error(error2, action, from) {
|
|
230
|
-
const err = error2 instanceof Error ? error2 : new Error(`${action} error`);
|
|
231
|
-
fileLog(`[${action}] error: ${err}`, from, "fatal");
|
|
232
|
-
return err.toString();
|
|
233
|
-
}
|
|
234
|
-
__name(error, "error");
|
|
235
|
-
|
|
236
|
-
// src/server/utils/index.ts
|
|
237
|
-
function getIdentifier(options) {
|
|
238
|
-
const { ip, name } = options;
|
|
239
|
-
return `mf ${import_sdk2.SEPARATOR}${name}${ip ? `${import_sdk2.SEPARATOR}${ip}` : ""}`;
|
|
240
|
-
}
|
|
241
|
-
__name(getIdentifier, "getIdentifier");
|
|
242
|
-
|
|
243
|
-
// src/server/Publisher.ts
|
|
244
|
-
var _Publisher = class _Publisher {
|
|
245
|
-
constructor(ctx) {
|
|
246
|
-
__publicField(this, "_ip");
|
|
247
|
-
__publicField(this, "_name");
|
|
248
|
-
__publicField(this, "_remoteTypeTarPath");
|
|
249
|
-
__publicField(this, "_subscribers");
|
|
250
|
-
__publicField(this, "_ws");
|
|
251
|
-
__publicField(this, "dynamicRemoteMap");
|
|
252
|
-
this._name = ctx.name;
|
|
253
|
-
this._ip = ctx.ip;
|
|
254
|
-
this._remoteTypeTarPath = ctx.remoteTypeTarPath;
|
|
255
|
-
this._subscribers = /* @__PURE__ */ new Map();
|
|
256
|
-
this._ws = ctx.ws;
|
|
257
|
-
this.dynamicRemoteMap = /* @__PURE__ */ new Map();
|
|
258
|
-
}
|
|
259
|
-
get identifier() {
|
|
260
|
-
return getIdentifier({
|
|
261
|
-
name: this._name,
|
|
262
|
-
ip: this._ip
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
get name() {
|
|
266
|
-
return this._name;
|
|
267
|
-
}
|
|
268
|
-
get ip() {
|
|
269
|
-
return this._ip;
|
|
270
|
-
}
|
|
271
|
-
get remoteTypeTarPath() {
|
|
272
|
-
return this._remoteTypeTarPath;
|
|
273
|
-
}
|
|
274
|
-
get hasSubscribes() {
|
|
275
|
-
return Boolean(this._subscribers.size);
|
|
276
|
-
}
|
|
277
|
-
get subscribers() {
|
|
278
|
-
return this._subscribers;
|
|
279
|
-
}
|
|
280
|
-
addSubscriber(identifier, subscriber) {
|
|
281
|
-
fileLog(`${this.name} set subscriber: ${identifier}`, "Publisher", "info");
|
|
282
|
-
this._subscribers.set(identifier, subscriber);
|
|
283
|
-
}
|
|
284
|
-
removeSubscriber(identifier) {
|
|
285
|
-
if (this._subscribers.has(identifier)) {
|
|
286
|
-
fileLog(`${this.name} removeSubscriber: ${identifier}`, "Publisher", "warn");
|
|
287
|
-
this._subscribers.delete(identifier);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
notifySubscriber(subscriberIdentifier, options) {
|
|
291
|
-
const subscriber = this._subscribers.get(subscriberIdentifier);
|
|
292
|
-
if (!subscriber) {
|
|
293
|
-
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`, "Publisher", "error");
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const api = new UpdateSubscriberAPI(options);
|
|
297
|
-
subscriber.send(JSON.stringify(api));
|
|
298
|
-
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${JSON.stringify(subscriberIdentifier)}, message: ${JSON.stringify(api)}`, "Publisher", "info");
|
|
299
|
-
}
|
|
300
|
-
fetchRemoteTypes(options) {
|
|
301
|
-
fileLog(`[fetchRemoteTypes] ${this.name} fetchRemoteTypes, options: ${JSON.stringify(options)}, ws: ${Boolean(this._ws)}`, "Publisher", "info");
|
|
302
|
-
if (!this._ws) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const api = new FetchTypesAPI(options);
|
|
306
|
-
this._ws.send(JSON.stringify(api));
|
|
307
|
-
}
|
|
308
|
-
notifySubscribers(options) {
|
|
309
|
-
const api = new UpdateSubscriberAPI(options);
|
|
310
|
-
this.broadcast(api);
|
|
311
|
-
}
|
|
312
|
-
broadcast(message) {
|
|
313
|
-
if (this.hasSubscribes) {
|
|
314
|
-
this._subscribers.forEach((subscriber, key) => {
|
|
315
|
-
fileLog(`[BroadCast] ${this.name} notifySubscriber: ${key}, PID: ${process.pid}, message: ${JSON.stringify(message)}`, "Publisher", "info");
|
|
316
|
-
subscriber.send(JSON.stringify(message));
|
|
317
|
-
});
|
|
318
|
-
} else {
|
|
319
|
-
fileLog(`[BroadCast] ${this.name}'s subscribe is empty`, "Publisher", "warn");
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
close() {
|
|
323
|
-
this._ws = void 0;
|
|
324
|
-
this._subscribers.forEach((_subscriber, identifier) => {
|
|
325
|
-
fileLog(`[BroadCast] close ${this.name} remove: ${identifier}`, "Publisher", "warn");
|
|
326
|
-
this.removeSubscriber(identifier);
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
__name(_Publisher, "Publisher");
|
|
331
|
-
var Publisher = _Publisher;
|
|
332
|
-
|
|
333
|
-
// src/server/message/Action/Action.ts
|
|
334
|
-
var ActionKind;
|
|
335
|
-
(function(ActionKind2) {
|
|
336
|
-
ActionKind2["ADD_SUBSCRIBER"] = "ADD_SUBSCRIBER";
|
|
337
|
-
ActionKind2["EXIT_SUBSCRIBER"] = "EXIT_SUBSCRIBER";
|
|
338
|
-
ActionKind2["ADD_PUBLISHER"] = "ADD_PUBLISHER";
|
|
339
|
-
ActionKind2["UPDATE_PUBLISHER"] = "UPDATE_PUBLISHER";
|
|
340
|
-
ActionKind2["NOTIFY_SUBSCRIBER"] = "NOTIFY_SUBSCRIBER";
|
|
341
|
-
ActionKind2["EXIT_PUBLISHER"] = "EXIT_PUBLISHER";
|
|
342
|
-
ActionKind2["ADD_WEB_CLIENT"] = "ADD_WEB_CLIENT";
|
|
343
|
-
ActionKind2["NOTIFY_WEB_CLIENT"] = "NOTIFY_WEB_CLIENT";
|
|
344
|
-
ActionKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
345
|
-
ActionKind2["ADD_DYNAMIC_REMOTE"] = "ADD_DYNAMIC_REMOTE";
|
|
346
|
-
})(ActionKind || (ActionKind = {}));
|
|
347
|
-
|
|
348
|
-
// src/server/message/Action/Update.ts
|
|
349
|
-
var UpdateKind;
|
|
350
|
-
(function(UpdateKind2) {
|
|
351
|
-
UpdateKind2["UPDATE_TYPE"] = "UPDATE_TYPE";
|
|
352
|
-
UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
|
|
353
|
-
})(UpdateKind || (UpdateKind = {}));
|
|
354
|
-
|
|
355
|
-
// src/server/broker/Broker.ts
|
|
356
|
-
var _Broker = class _Broker {
|
|
357
|
-
constructor() {
|
|
358
|
-
__publicField(this, "_publisherMap", /* @__PURE__ */ new Map());
|
|
359
|
-
__publicField(this, "_webClientMap", /* @__PURE__ */ new Map());
|
|
360
|
-
__publicField(this, "_webSocketServer");
|
|
361
|
-
__publicField(this, "_secureWebSocketServer");
|
|
362
|
-
__publicField(this, "_tmpSubscriberShelter", /* @__PURE__ */ new Map());
|
|
363
|
-
__publicField(this, "_scheduleJob", null);
|
|
364
|
-
this._setSchedule();
|
|
365
|
-
this._startWsServer();
|
|
366
|
-
this._stopWhenSIGTERMOrSIGINT();
|
|
367
|
-
this._handleUnexpectedExit();
|
|
368
|
-
}
|
|
369
|
-
get hasPublishers() {
|
|
370
|
-
return Boolean(this._publisherMap.size);
|
|
371
|
-
}
|
|
372
|
-
_startWsServer() {
|
|
373
|
-
return __async(this, null, function* () {
|
|
374
|
-
const wsHandler = /* @__PURE__ */ __name((ws, req) => {
|
|
375
|
-
const { url: reqUrl = "" } = req;
|
|
376
|
-
const { query } = (0, import_url.parse)(reqUrl, true);
|
|
377
|
-
const { WEB_SOCKET_CONNECT_MAGIC_ID: WEB_SOCKET_CONNECT_MAGIC_ID2 } = query;
|
|
378
|
-
if (WEB_SOCKET_CONNECT_MAGIC_ID2 === _Broker.WEB_SOCKET_CONNECT_MAGIC_ID) {
|
|
379
|
-
ws.on("message", (message) => {
|
|
380
|
-
try {
|
|
381
|
-
const text = message.toString();
|
|
382
|
-
const action = JSON.parse(text);
|
|
383
|
-
fileLog(`${action == null ? void 0 : action.kind} action received `, "Broker", "info");
|
|
384
|
-
this._takeAction(action, ws);
|
|
385
|
-
} catch (error2) {
|
|
386
|
-
fileLog(`parse action message error: ${error2}`, "Broker", "error");
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
ws.on("error", (e) => {
|
|
390
|
-
fileLog(`parse action message error: ${e}`, "Broker", "error");
|
|
391
|
-
});
|
|
392
|
-
} else {
|
|
393
|
-
ws.send("Invalid CONNECT ID.");
|
|
394
|
-
fileLog("Invalid CONNECT ID.", "Broker", "warn");
|
|
395
|
-
ws.close();
|
|
396
|
-
}
|
|
397
|
-
}, "wsHandler");
|
|
398
|
-
const server = (0, import_http.createServer)();
|
|
399
|
-
this._webSocketServer = new import_isomorphic_ws.default.Server({
|
|
400
|
-
noServer: true
|
|
401
|
-
});
|
|
402
|
-
this._webSocketServer.on("error", (err) => {
|
|
403
|
-
fileLog(`ws error:
|
|
404
|
-
${err.message}
|
|
405
|
-
${err.stack}`, "Broker", "error");
|
|
406
|
-
});
|
|
407
|
-
this._webSocketServer.on("listening", () => {
|
|
408
|
-
fileLog(`WebSocket server is listening on port ${_Broker.DEFAULT_WEB_SOCKET_PORT}`, "Broker", "info");
|
|
409
|
-
});
|
|
410
|
-
this._webSocketServer.on("connection", wsHandler);
|
|
411
|
-
this._webSocketServer.on("close", (code) => {
|
|
412
|
-
fileLog(`WebSocket Server Close with Code ${code}`, "Broker", "warn");
|
|
413
|
-
this._webSocketServer && this._webSocketServer.close();
|
|
414
|
-
this._webSocketServer = void 0;
|
|
415
|
-
});
|
|
416
|
-
server.on("upgrade", (req, socket, head) => {
|
|
417
|
-
var _a;
|
|
418
|
-
if (req.url) {
|
|
419
|
-
const { pathname } = (0, import_url.parse)(req.url);
|
|
420
|
-
if (pathname === "/") {
|
|
421
|
-
(_a = this._webSocketServer) == null ? void 0 : _a.handleUpgrade(req, socket, head, (ws) => {
|
|
422
|
-
var _a2;
|
|
423
|
-
(_a2 = this._webSocketServer) == null ? void 0 : _a2.emit("connection", ws, req);
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
_takeAction(action, client) {
|
|
432
|
-
return __async(this, null, function* () {
|
|
433
|
-
const { kind, payload } = action;
|
|
434
|
-
if (kind === ActionKind.ADD_PUBLISHER) {
|
|
435
|
-
yield this._addPublisher(payload, client);
|
|
436
|
-
}
|
|
437
|
-
if (kind === ActionKind.UPDATE_PUBLISHER) {
|
|
438
|
-
yield this._updatePublisher(payload, client);
|
|
439
|
-
}
|
|
440
|
-
if (kind === ActionKind.ADD_SUBSCRIBER) {
|
|
441
|
-
yield this._addSubscriber(payload, client);
|
|
442
|
-
}
|
|
443
|
-
if (kind === ActionKind.EXIT_SUBSCRIBER) {
|
|
444
|
-
yield this._removeSubscriber(payload, client);
|
|
445
|
-
}
|
|
446
|
-
if (kind === ActionKind.EXIT_PUBLISHER) {
|
|
447
|
-
yield this._removePublisher(payload, client);
|
|
448
|
-
}
|
|
449
|
-
if (kind === ActionKind.ADD_WEB_CLIENT) {
|
|
450
|
-
yield this._addWebClient(payload, client);
|
|
451
|
-
}
|
|
452
|
-
if (kind === ActionKind.NOTIFY_WEB_CLIENT) {
|
|
453
|
-
yield this._notifyWebClient(payload, client);
|
|
454
|
-
}
|
|
455
|
-
if (kind === ActionKind.FETCH_TYPES) {
|
|
456
|
-
yield this._fetchTypes(payload, client);
|
|
457
|
-
}
|
|
458
|
-
if (kind === ActionKind.ADD_DYNAMIC_REMOTE) {
|
|
459
|
-
this._addDynamicRemote(payload);
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
_addPublisher(context, client) {
|
|
464
|
-
return __async(this, null, function* () {
|
|
465
|
-
const { name, ip, remoteTypeTarPath } = context != null ? context : {};
|
|
466
|
-
const identifier = getIdentifier({
|
|
467
|
-
name,
|
|
468
|
-
ip
|
|
469
|
-
});
|
|
470
|
-
if (this._publisherMap.has(identifier)) {
|
|
471
|
-
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} has been added, this action will be ignored`, "Broker", "warn");
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
try {
|
|
475
|
-
const publisher = new Publisher({
|
|
476
|
-
name,
|
|
477
|
-
ip,
|
|
478
|
-
remoteTypeTarPath,
|
|
479
|
-
ws: client
|
|
480
|
-
});
|
|
481
|
-
this._publisherMap.set(identifier, publisher);
|
|
482
|
-
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} Adding Publisher Succeed`, "Broker", "info");
|
|
483
|
-
const tmpSubScribers = this._getTmpSubScribers(identifier);
|
|
484
|
-
if (tmpSubScribers) {
|
|
485
|
-
fileLog(`[${ActionKind.ADD_PUBLISHER}] consumeTmpSubscriber set ${publisher.name}\u2019s subscribers `, "Broker", "info");
|
|
486
|
-
this._consumeTmpSubScribers(publisher, tmpSubScribers);
|
|
487
|
-
this._clearTmpSubScriberRelation(identifier);
|
|
488
|
-
}
|
|
489
|
-
} catch (err) {
|
|
490
|
-
const msg = error(err, ActionKind.ADD_PUBLISHER, "Broker");
|
|
491
|
-
client.send(msg);
|
|
492
|
-
client.close();
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
_updatePublisher(context, client) {
|
|
497
|
-
return __async(this, null, function* () {
|
|
498
|
-
const { name, updateMode, updateKind, updateSourcePaths, remoteTypeTarPath, ip } = context != null ? context : {};
|
|
499
|
-
const identifier = getIdentifier({
|
|
500
|
-
name,
|
|
501
|
-
ip
|
|
502
|
-
});
|
|
503
|
-
if (!this._publisherMap.has(identifier)) {
|
|
504
|
-
fileLog(`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} has not been started, this action will be ignored
|
|
505
|
-
this._publisherMap: ${JSON.stringify(this._publisherMap.entries())}
|
|
506
|
-
`, "Broker", "warn");
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
try {
|
|
510
|
-
const publisher = this._publisherMap.get(identifier);
|
|
511
|
-
fileLog(
|
|
512
|
-
// eslint-disable-next-line max-len
|
|
513
|
-
`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} update, and notify subscribers to update`,
|
|
514
|
-
"Broker",
|
|
515
|
-
"info"
|
|
516
|
-
);
|
|
517
|
-
if (publisher) {
|
|
518
|
-
publisher.notifySubscribers({
|
|
519
|
-
remoteTypeTarPath,
|
|
520
|
-
name,
|
|
521
|
-
updateMode,
|
|
522
|
-
updateKind,
|
|
523
|
-
updateSourcePaths: updateSourcePaths || []
|
|
524
|
-
});
|
|
525
|
-
this._publisherMap.forEach((p) => {
|
|
526
|
-
if (p.name === publisher.name) {
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
const dynamicRemoteInfo = p.dynamicRemoteMap.get(identifier);
|
|
530
|
-
if (dynamicRemoteInfo) {
|
|
531
|
-
fileLog(
|
|
532
|
-
// eslint-disable-next-line max-len
|
|
533
|
-
`dynamicRemoteInfo: ${JSON.stringify(dynamicRemoteInfo)}, identifier:${identifier} publish: ${p.name}`,
|
|
534
|
-
"Broker",
|
|
535
|
-
"info"
|
|
536
|
-
);
|
|
537
|
-
p.fetchRemoteTypes({
|
|
538
|
-
remoteInfo: dynamicRemoteInfo,
|
|
539
|
-
once: false
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
} catch (err) {
|
|
545
|
-
const msg = error(err, ActionKind.UPDATE_PUBLISHER, "Broker");
|
|
546
|
-
client.send(msg);
|
|
547
|
-
client.close();
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
_fetchTypes(context, _client) {
|
|
552
|
-
return __async(this, null, function* () {
|
|
553
|
-
const { name, ip, remoteInfo } = context != null ? context : {};
|
|
554
|
-
const identifier = getIdentifier({
|
|
555
|
-
name,
|
|
556
|
-
ip
|
|
557
|
-
});
|
|
558
|
-
try {
|
|
559
|
-
const publisher = this._publisherMap.get(identifier);
|
|
560
|
-
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types`, "Broker", "info");
|
|
561
|
-
if (publisher) {
|
|
562
|
-
publisher.fetchRemoteTypes({
|
|
563
|
-
remoteInfo,
|
|
564
|
-
once: true
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
} catch (err) {
|
|
568
|
-
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types fail , error info: ${err}`, "Broker", "error");
|
|
569
|
-
}
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
_addDynamicRemote(context) {
|
|
573
|
-
const { name, ip, remoteInfo, remoteIp } = context != null ? context : {};
|
|
574
|
-
const identifier = getIdentifier({
|
|
575
|
-
name,
|
|
576
|
-
ip
|
|
577
|
-
});
|
|
578
|
-
const publisher = this._publisherMap.get(identifier);
|
|
579
|
-
const remoteId = getIdentifier({
|
|
580
|
-
name: remoteInfo.name,
|
|
581
|
-
ip: remoteIp
|
|
582
|
-
});
|
|
583
|
-
fileLog(`[${ActionKind.ADD_DYNAMIC_REMOTE}] identifier:${identifier},publisher: ${publisher.name}, remoteId:${remoteId}`, "Broker", "error");
|
|
584
|
-
if (!publisher || publisher.dynamicRemoteMap.has(remoteId)) {
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
publisher.dynamicRemoteMap.set(remoteId, remoteInfo);
|
|
588
|
-
}
|
|
589
|
-
// app1 consumes provider1,provider2. Dependencies at this time: publishers: [provider1, provider2], subscriberName: app1
|
|
590
|
-
// provider1 is app1's remote
|
|
591
|
-
_addSubscriber(context, client) {
|
|
592
|
-
return __async(this, null, function* () {
|
|
593
|
-
const { publishers, name: subscriberName } = context != null ? context : {};
|
|
594
|
-
publishers.forEach((publisher) => {
|
|
595
|
-
const { name, ip } = publisher;
|
|
596
|
-
const identifier = getIdentifier({
|
|
597
|
-
name,
|
|
598
|
-
ip
|
|
599
|
-
});
|
|
600
|
-
if (!this._publisherMap.has(identifier)) {
|
|
601
|
-
fileLog(`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has not been started, ${subscriberName} will add the relation to tmp shelter`, "Broker", "warn");
|
|
602
|
-
this._addTmpSubScriberRelation({
|
|
603
|
-
name: getIdentifier({
|
|
604
|
-
name: context.name,
|
|
605
|
-
ip: context.ip
|
|
606
|
-
}),
|
|
607
|
-
client
|
|
608
|
-
}, publisher);
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
try {
|
|
612
|
-
const registeredPublisher = this._publisherMap.get(identifier);
|
|
613
|
-
if (registeredPublisher) {
|
|
614
|
-
registeredPublisher.addSubscriber(getIdentifier({
|
|
615
|
-
name: subscriberName,
|
|
616
|
-
ip: context.ip
|
|
617
|
-
}), client);
|
|
618
|
-
fileLog(
|
|
619
|
-
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
620
|
-
`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has been started, Adding Subscriber ${subscriberName} Succeed, this.__publisherMap are: ${JSON.stringify(Array.from(this._publisherMap.entries()))}`,
|
|
621
|
-
"Broker",
|
|
622
|
-
"info"
|
|
623
|
-
);
|
|
624
|
-
registeredPublisher.notifySubscriber(getIdentifier({
|
|
625
|
-
name: subscriberName,
|
|
626
|
-
ip: context.ip
|
|
627
|
-
}), {
|
|
628
|
-
updateKind: UpdateKind.UPDATE_TYPE,
|
|
629
|
-
updateMode: UpdateMode.PASSIVE,
|
|
630
|
-
updateSourcePaths: [
|
|
631
|
-
registeredPublisher.name
|
|
632
|
-
],
|
|
633
|
-
remoteTypeTarPath: registeredPublisher.remoteTypeTarPath,
|
|
634
|
-
name: registeredPublisher.name
|
|
635
|
-
});
|
|
636
|
-
fileLog(
|
|
637
|
-
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
638
|
-
`[${ActionKind.ADD_SUBSCRIBER}]: notifySubscriber Subscriber ${subscriberName}, updateMode: "PASSIVE", updateSourcePaths: ${registeredPublisher.name}`,
|
|
639
|
-
"Broker",
|
|
640
|
-
"info"
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
} catch (err) {
|
|
644
|
-
const msg = error(err, ActionKind.ADD_SUBSCRIBER, "Broker");
|
|
645
|
-
client.send(msg);
|
|
646
|
-
client.close();
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
// Trigger while consumer exit
|
|
652
|
-
_removeSubscriber(context, client) {
|
|
653
|
-
return __async(this, null, function* () {
|
|
654
|
-
const { publishers } = context != null ? context : {};
|
|
655
|
-
const subscriberIdentifier = getIdentifier({
|
|
656
|
-
name: context == null ? void 0 : context.name,
|
|
657
|
-
ip: context == null ? void 0 : context.ip
|
|
658
|
-
});
|
|
659
|
-
publishers.forEach((publisher) => {
|
|
660
|
-
const { name, ip } = publisher;
|
|
661
|
-
const identifier = getIdentifier({
|
|
662
|
-
name,
|
|
663
|
-
ip
|
|
664
|
-
});
|
|
665
|
-
const registeredPublisher = this._publisherMap.get(identifier);
|
|
666
|
-
if (!registeredPublisher) {
|
|
667
|
-
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} does not exit `, "Broker", "warn");
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
try {
|
|
671
|
-
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} will exit `, "Broker", "INFO");
|
|
672
|
-
registeredPublisher.removeSubscriber(subscriberIdentifier);
|
|
673
|
-
this._clearTmpSubScriberRelation(identifier);
|
|
674
|
-
if (!registeredPublisher.hasSubscribes) {
|
|
675
|
-
this._publisherMap.delete(identifier);
|
|
676
|
-
}
|
|
677
|
-
if (!this.hasPublishers) {
|
|
678
|
-
this.exit();
|
|
679
|
-
}
|
|
680
|
-
} catch (err) {
|
|
681
|
-
const msg = error(err, ActionKind.EXIT_SUBSCRIBER, "Broker");
|
|
682
|
-
client.send(msg);
|
|
683
|
-
client.close();
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
_removePublisher(context, client) {
|
|
689
|
-
return __async(this, null, function* () {
|
|
690
|
-
const { name, ip } = context != null ? context : {};
|
|
691
|
-
const identifier = getIdentifier({
|
|
692
|
-
name,
|
|
693
|
-
ip
|
|
694
|
-
});
|
|
695
|
-
const publisher = this._publisherMap.get(identifier);
|
|
696
|
-
if (!publisher) {
|
|
697
|
-
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier}} has not been added, this action will be ingored`, "Broker", "warn");
|
|
698
|
-
return;
|
|
699
|
-
}
|
|
700
|
-
try {
|
|
701
|
-
const { subscribers } = publisher;
|
|
702
|
-
subscribers.forEach((subscriber, subscriberIdentifier) => {
|
|
703
|
-
this._addTmpSubScriberRelation({
|
|
704
|
-
name: subscriberIdentifier,
|
|
705
|
-
client: subscriber
|
|
706
|
-
}, {
|
|
707
|
-
name: publisher.name,
|
|
708
|
-
ip: publisher.ip
|
|
709
|
-
});
|
|
710
|
-
fileLog(
|
|
711
|
-
// eslint-disable-next-line max-len
|
|
712
|
-
`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
|
|
713
|
-
"Broker",
|
|
714
|
-
"info"
|
|
715
|
-
);
|
|
716
|
-
});
|
|
717
|
-
this._publisherMap.delete(identifier);
|
|
718
|
-
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removed `, "Broker", "info");
|
|
719
|
-
if (!this.hasPublishers) {
|
|
720
|
-
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: _publisherMap is empty, all server will exit `, "Broker", "warn");
|
|
721
|
-
this.exit();
|
|
722
|
-
}
|
|
723
|
-
} catch (err) {
|
|
724
|
-
const msg = error(err, ActionKind.EXIT_PUBLISHER, "Broker");
|
|
725
|
-
client.send(msg);
|
|
726
|
-
client.close();
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
_addWebClient(context, client) {
|
|
731
|
-
return __async(this, null, function* () {
|
|
732
|
-
const { name } = context != null ? context : {};
|
|
733
|
-
const identifier = getIdentifier({
|
|
734
|
-
name
|
|
735
|
-
});
|
|
736
|
-
if (this._webClientMap.has(identifier)) {
|
|
737
|
-
fileLog(`${identifier}} has been added, this action will override prev WebClient`, "Broker", "warn");
|
|
738
|
-
}
|
|
739
|
-
try {
|
|
740
|
-
this._webClientMap.set(identifier, client);
|
|
741
|
-
fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
|
|
742
|
-
} catch (err) {
|
|
743
|
-
const msg = error(err, ActionKind.ADD_WEB_CLIENT, "Broker");
|
|
744
|
-
client.send(msg);
|
|
745
|
-
client.close();
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
_notifyWebClient(context, client) {
|
|
750
|
-
return __async(this, null, function* () {
|
|
751
|
-
const { name, updateMode } = context != null ? context : {};
|
|
752
|
-
const identifier = getIdentifier({
|
|
753
|
-
name
|
|
754
|
-
});
|
|
755
|
-
const webClient = this._webClientMap.get(identifier);
|
|
756
|
-
if (!webClient) {
|
|
757
|
-
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] ${identifier} has not been added, this action will be ignored`, "Broker", "warn");
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
try {
|
|
761
|
-
const api = new ReloadWebClientAPI({
|
|
762
|
-
name,
|
|
763
|
-
updateMode
|
|
764
|
-
});
|
|
765
|
-
webClient.send(JSON.stringify(api));
|
|
766
|
-
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] Notify ${name} WebClient Succeed`, "Broker", "info");
|
|
767
|
-
} catch (err) {
|
|
768
|
-
const msg = error(err, ActionKind.NOTIFY_WEB_CLIENT, "Broker");
|
|
769
|
-
client.send(msg);
|
|
770
|
-
client.close();
|
|
771
|
-
}
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
// app1 consumes provider1, and provider1 not launch. this._tmpSubscriberShelter at this time: {provider1: Map{subscribers: Map{app1: app1+ip+client'}, timestamp: 'xx'} }
|
|
775
|
-
_addTmpSubScriberRelation(subscriber, publisher) {
|
|
776
|
-
const publisherIdentifier = getIdentifier({
|
|
777
|
-
name: publisher.name,
|
|
778
|
-
ip: publisher.ip
|
|
779
|
-
});
|
|
780
|
-
const subscriberIdentifier = subscriber.name;
|
|
781
|
-
const shelter = this._tmpSubscriberShelter.get(publisherIdentifier);
|
|
782
|
-
if (!shelter) {
|
|
783
|
-
const map = /* @__PURE__ */ new Map();
|
|
784
|
-
map.set(subscriberIdentifier, subscriber);
|
|
785
|
-
this._tmpSubscriberShelter.set(publisherIdentifier, {
|
|
786
|
-
subscribers: map,
|
|
787
|
-
timestamp: Date.now()
|
|
788
|
-
});
|
|
789
|
-
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `, "Broker", "info");
|
|
790
|
-
return;
|
|
791
|
-
}
|
|
792
|
-
const tmpSubScriberShelterSubscriber = shelter.subscribers.get(subscriberIdentifier);
|
|
793
|
-
if (tmpSubScriberShelterSubscriber) {
|
|
794
|
-
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`, "Broker", "warn");
|
|
795
|
-
shelter.subscribers.set(subscriberIdentifier, subscriber);
|
|
796
|
-
shelter.timestamp = Date.now();
|
|
797
|
-
} else {
|
|
798
|
-
fileLog(
|
|
799
|
-
// eslint-disable-next-line max-len
|
|
800
|
-
`AddTmpSubscriberLog ${publisherIdentifier}'s shelter has been added, update shelter.subscribers ${subscriberIdentifier}`,
|
|
801
|
-
"Broker",
|
|
802
|
-
"warn"
|
|
803
|
-
);
|
|
804
|
-
shelter.subscribers.set(subscriberIdentifier, subscriber);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
_getTmpSubScribers(publisherIdentifier) {
|
|
808
|
-
var _a;
|
|
809
|
-
return (_a = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a.subscribers;
|
|
810
|
-
}
|
|
811
|
-
// after adding publisher, it will change the temp subscriber to regular subscriber
|
|
812
|
-
_consumeTmpSubScribers(publisher, tmpSubScribers) {
|
|
813
|
-
tmpSubScribers.forEach((tmpSubScriber, identifier) => {
|
|
814
|
-
fileLog(`notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `, "Broker", "warn");
|
|
815
|
-
publisher.addSubscriber(identifier, tmpSubScriber.client);
|
|
816
|
-
publisher.notifySubscriber(identifier, {
|
|
817
|
-
updateKind: UpdateKind.UPDATE_TYPE,
|
|
818
|
-
updateMode: UpdateMode.PASSIVE,
|
|
819
|
-
updateSourcePaths: [
|
|
820
|
-
publisher.name
|
|
821
|
-
],
|
|
822
|
-
remoteTypeTarPath: publisher.remoteTypeTarPath,
|
|
823
|
-
name: publisher.name
|
|
824
|
-
});
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
_clearTmpSubScriberRelation(identifier) {
|
|
828
|
-
this._tmpSubscriberShelter.delete(identifier);
|
|
829
|
-
}
|
|
830
|
-
_clearTmpSubScriberRelations() {
|
|
831
|
-
this._tmpSubscriberShelter.clear();
|
|
832
|
-
}
|
|
833
|
-
_disconnect() {
|
|
834
|
-
this._publisherMap.forEach((publisher) => {
|
|
835
|
-
publisher.close();
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
// Every day on 0/6/9/12/15//18, Publishers that have not been connected within 1.5 hours will be cleared regularly.
|
|
839
|
-
// If process.env.FEDERATION_SERVER_TEST is set, it will be read at a specified time.
|
|
840
|
-
_setSchedule() {
|
|
841
|
-
const rule = new import_node_schedule.default.RecurrenceRule();
|
|
842
|
-
if (Number(process.env["FEDERATION_SERVER_TEST"])) {
|
|
843
|
-
const interval = Number(process.env["FEDERATION_SERVER_TEST"]) / 1e3;
|
|
844
|
-
const second = [];
|
|
845
|
-
for (let i = 0; i < 60; i = i + interval) {
|
|
846
|
-
second.push(i);
|
|
847
|
-
}
|
|
848
|
-
rule.second = second;
|
|
849
|
-
} else {
|
|
850
|
-
rule.second = 0;
|
|
851
|
-
rule.hour = [
|
|
852
|
-
0,
|
|
853
|
-
3,
|
|
854
|
-
6,
|
|
855
|
-
9,
|
|
856
|
-
12,
|
|
857
|
-
15,
|
|
858
|
-
18
|
|
859
|
-
];
|
|
860
|
-
rule.minute = 0;
|
|
861
|
-
}
|
|
862
|
-
const serverTest = Number(process.env["FEDERATION_SERVER_TEST"]);
|
|
863
|
-
this._scheduleJob = import_node_schedule.default.scheduleJob(rule, () => {
|
|
864
|
-
this._tmpSubscriberShelter.forEach((tmpSubscriber, identifier) => {
|
|
865
|
-
fileLog(` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`, "Broker", "info");
|
|
866
|
-
if (Date.now() - tmpSubscriber.timestamp >= (process.env["FEDERATION_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)) {
|
|
867
|
-
this._clearTmpSubScriberRelation(identifier);
|
|
868
|
-
}
|
|
869
|
-
});
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
_clearSchedule() {
|
|
873
|
-
if (!this._scheduleJob) {
|
|
874
|
-
return;
|
|
875
|
-
}
|
|
876
|
-
this._scheduleJob.cancel();
|
|
877
|
-
this._scheduleJob = null;
|
|
878
|
-
}
|
|
879
|
-
_stopWhenSIGTERMOrSIGINT() {
|
|
880
|
-
process.on("SIGTERM", () => {
|
|
881
|
-
this.exit();
|
|
882
|
-
});
|
|
883
|
-
process.on("SIGINT", () => {
|
|
884
|
-
this.exit();
|
|
885
|
-
});
|
|
886
|
-
}
|
|
887
|
-
_handleUnexpectedExit() {
|
|
888
|
-
process.on("unhandledRejection", (error2) => {
|
|
889
|
-
console.error("Unhandled Rejection Error: ", error2);
|
|
890
|
-
fileLog(`Unhandled Rejection Error: ${error2}`, "Broker", "fatal");
|
|
891
|
-
process.exit(1);
|
|
892
|
-
});
|
|
893
|
-
process.on("uncaughtException", (error2) => {
|
|
894
|
-
console.error("Unhandled Exception Error: ", error2);
|
|
895
|
-
fileLog(`Unhandled Rejection Error: ${error2}`, "Broker", "fatal");
|
|
896
|
-
process.exit(1);
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
start() {
|
|
900
|
-
return __async(this, null, function* () {
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
exit() {
|
|
904
|
-
const brokerExitLog = new BrokerExitLog();
|
|
905
|
-
this.broadcast(JSON.stringify(brokerExitLog));
|
|
906
|
-
this._disconnect();
|
|
907
|
-
this._clearSchedule();
|
|
908
|
-
this._clearTmpSubScriberRelations();
|
|
909
|
-
this._webSocketServer && this._webSocketServer.close();
|
|
910
|
-
this._secureWebSocketServer && this._secureWebSocketServer.close();
|
|
911
|
-
process.exit(0);
|
|
912
|
-
}
|
|
913
|
-
broadcast(message) {
|
|
914
|
-
var _a, _b;
|
|
915
|
-
fileLog(`[broadcast] exit info : ${JSON.stringify(message)}`, "Broker", "warn");
|
|
916
|
-
(_a = this._webSocketServer) == null ? void 0 : _a.clients.forEach((client) => {
|
|
917
|
-
client.send(JSON.stringify(message));
|
|
918
|
-
});
|
|
919
|
-
(_b = this._secureWebSocketServer) == null ? void 0 : _b.clients.forEach((client) => {
|
|
920
|
-
client.send(JSON.stringify(message));
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
__name(_Broker, "Broker");
|
|
925
|
-
__publicField(_Broker, "WEB_SOCKET_CONNECT_MAGIC_ID", WEB_SOCKET_CONNECT_MAGIC_ID);
|
|
926
|
-
__publicField(_Broker, "DEFAULT_WEB_SOCKET_PORT", DEFAULT_WEB_SOCKET_PORT);
|
|
927
|
-
__publicField(_Broker, "DEFAULT_SECURE_WEB_SOCKET_PORT", 16324);
|
|
928
|
-
__publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
929
|
-
var Broker = _Broker;
|
|
930
|
-
|
|
931
|
-
// src/server/broker/startBroker.ts
|
|
932
|
-
var broker;
|
|
4
|
+
//#region src/server/broker/startBroker.ts
|
|
5
|
+
let broker;
|
|
933
6
|
function getBroker() {
|
|
934
|
-
|
|
7
|
+
return broker;
|
|
935
8
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
return;
|
|
942
|
-
}
|
|
943
|
-
broker = new Broker();
|
|
944
|
-
yield broker.start();
|
|
945
|
-
(_a = process.send) == null ? void 0 : _a.call(process, "ready");
|
|
946
|
-
});
|
|
9
|
+
async function startBroker() {
|
|
10
|
+
if (getBroker()) return;
|
|
11
|
+
broker = new require_Broker.Broker();
|
|
12
|
+
await broker.start();
|
|
13
|
+
process.send?.("ready");
|
|
947
14
|
}
|
|
948
|
-
__name(startBroker, "startBroker");
|
|
949
15
|
process.on("message", (message) => {
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
});
|
|
955
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
956
|
-
0 && (module.exports = {
|
|
957
|
-
getBroker
|
|
16
|
+
if (message === "start") {
|
|
17
|
+
require_Broker.fileLog(`startBroker... ${process.pid}`, "StartBroker", "info");
|
|
18
|
+
startBroker();
|
|
19
|
+
}
|
|
958
20
|
});
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.getBroker = getBroker;
|