@bsb/base 9.0.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/LICENSE +665 -0
- package/LICENSE.commercial +32 -0
- package/README.md +263 -0
- package/bsb-plugin.json +62 -0
- package/lib/base/BSBConfig.d.ts +130 -0
- package/lib/base/BSBConfig.js +95 -0
- package/lib/base/BSBConfig.js.map +1 -0
- package/lib/base/BSBEvents.d.ts +207 -0
- package/lib/base/BSBEvents.js +101 -0
- package/lib/base/BSBEvents.js.map +1 -0
- package/lib/base/BSBObservable.d.ts +178 -0
- package/lib/base/BSBObservable.js +91 -0
- package/lib/base/BSBObservable.js.map +1 -0
- package/lib/base/BSBService.d.ts +277 -0
- package/lib/base/BSBService.js +366 -0
- package/lib/base/BSBService.js.map +1 -0
- package/lib/base/BSBServiceClient.d.ts +135 -0
- package/lib/base/BSBServiceClient.js +130 -0
- package/lib/base/BSBServiceClient.js.map +1 -0
- package/lib/base/EventValidator.d.ts +137 -0
- package/lib/base/EventValidator.js +210 -0
- package/lib/base/EventValidator.js.map +1 -0
- package/lib/base/ObservableBackend.d.ts +281 -0
- package/lib/base/ObservableBackend.js +515 -0
- package/lib/base/ObservableBackend.js.map +1 -0
- package/lib/base/PluginConfig.d.ts +196 -0
- package/lib/base/PluginConfig.js +96 -0
- package/lib/base/PluginConfig.js.map +1 -0
- package/lib/base/PluginEvents.d.ts +140 -0
- package/lib/base/PluginEvents.js +268 -0
- package/lib/base/PluginEvents.js.map +1 -0
- package/lib/base/PluginObservable.d.ts +196 -0
- package/lib/base/PluginObservable.js +250 -0
- package/lib/base/PluginObservable.js.map +1 -0
- package/lib/base/ResourceContext.d.ts +70 -0
- package/lib/base/ResourceContext.js +54 -0
- package/lib/base/ResourceContext.js.map +1 -0
- package/lib/base/base.d.ts +264 -0
- package/lib/base/base.js +182 -0
- package/lib/base/base.js.map +1 -0
- package/lib/base/errorMessages.d.ts +56 -0
- package/lib/base/errorMessages.js +70 -0
- package/lib/base/errorMessages.js.map +1 -0
- package/lib/base/factory.d.ts +58 -0
- package/lib/base/factory.js +167 -0
- package/lib/base/factory.js.map +1 -0
- package/lib/base/functions.d.ts +117 -0
- package/lib/base/functions.js +152 -0
- package/lib/base/functions.js.map +1 -0
- package/lib/base/index.d.ts +44 -0
- package/lib/base/index.js +64 -0
- package/lib/base/index.js.map +1 -0
- package/lib/base/logFormatter.d.ts +50 -0
- package/lib/base/logFormatter.js +105 -0
- package/lib/base/logFormatter.js.map +1 -0
- package/lib/base/tools.d.ts +316 -0
- package/lib/base/tools.js +666 -0
- package/lib/base/tools.js.map +1 -0
- package/lib/cli.d.ts +28 -0
- package/lib/cli.js +254 -0
- package/lib/cli.js.map +1 -0
- package/lib/dev.d.ts +27 -0
- package/lib/dev.js +200 -0
- package/lib/dev.js.map +1 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.js +49 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces/events.d.ts +67 -0
- package/lib/interfaces/events.js +44 -0
- package/lib/interfaces/events.js.map +1 -0
- package/lib/interfaces/index.d.ts +38 -0
- package/lib/interfaces/index.js +59 -0
- package/lib/interfaces/index.js.map +1 -0
- package/lib/interfaces/logging.d.ts +106 -0
- package/lib/interfaces/logging.js +39 -0
- package/lib/interfaces/logging.js.map +1 -0
- package/lib/interfaces/metrics.d.ts +365 -0
- package/lib/interfaces/metrics.js +46 -0
- package/lib/interfaces/metrics.js.map +1 -0
- package/lib/interfaces/observable-types.d.ts +63 -0
- package/lib/interfaces/observable-types.js +49 -0
- package/lib/interfaces/observable-types.js.map +1 -0
- package/lib/interfaces/observable.d.ts +297 -0
- package/lib/interfaces/observable.js +29 -0
- package/lib/interfaces/observable.js.map +1 -0
- package/lib/interfaces/options.d.ts +164 -0
- package/lib/interfaces/options.js +56 -0
- package/lib/interfaces/options.js.map +1 -0
- package/lib/interfaces/plugins.d.ts +143 -0
- package/lib/interfaces/plugins.js +45 -0
- package/lib/interfaces/plugins.js.map +1 -0
- package/lib/interfaces/result.d.ts +129 -0
- package/lib/interfaces/result.js +162 -0
- package/lib/interfaces/result.js.map +1 -0
- package/lib/interfaces/schema-events.d.ts +378 -0
- package/lib/interfaces/schema-events.js +247 -0
- package/lib/interfaces/schema-events.js.map +1 -0
- package/lib/interfaces/schema-types.d.ts +407 -0
- package/lib/interfaces/schema-types.js +581 -0
- package/lib/interfaces/schema-types.js.map +1 -0
- package/lib/interfaces/service.d.ts +48 -0
- package/lib/interfaces/service.js +29 -0
- package/lib/interfaces/service.js.map +1 -0
- package/lib/interfaces/tools.d.ts +65 -0
- package/lib/interfaces/tools.js +50 -0
- package/lib/interfaces/tools.js.map +1 -0
- package/lib/plugins/config-default/index.d.ts +59 -0
- package/lib/plugins/config-default/index.js +197 -0
- package/lib/plugins/config-default/index.js.map +1 -0
- package/lib/plugins/config-default/interfaces.d.ts +92 -0
- package/lib/plugins/config-default/interfaces.js +36 -0
- package/lib/plugins/config-default/interfaces.js.map +1 -0
- package/lib/plugins/events-default/events/broadcast.d.ts +36 -0
- package/lib/plugins/events-default/events/broadcast.js +85 -0
- package/lib/plugins/events-default/events/broadcast.js.map +1 -0
- package/lib/plugins/events-default/events/emit.d.ts +38 -0
- package/lib/plugins/events-default/events/emit.js +104 -0
- package/lib/plugins/events-default/events/emit.js.map +1 -0
- package/lib/plugins/events-default/events/emitAndReturn.d.ts +36 -0
- package/lib/plugins/events-default/events/emitAndReturn.js +100 -0
- package/lib/plugins/events-default/events/emitAndReturn.js.map +1 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.d.ts +38 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js +134 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js.map +1 -0
- package/lib/plugins/events-default/events/index.d.ts +30 -0
- package/lib/plugins/events-default/events/index.js +38 -0
- package/lib/plugins/events-default/events/index.js.map +1 -0
- package/lib/plugins/events-default/index.d.ts +57 -0
- package/lib/plugins/events-default/index.js +86 -0
- package/lib/plugins/events-default/index.js.map +1 -0
- package/lib/plugins/observable-default/index.d.ts +43 -0
- package/lib/plugins/observable-default/index.js +151 -0
- package/lib/plugins/observable-default/index.js.map +1 -0
- package/lib/schemas/config-default.json +34 -0
- package/lib/schemas/config-default.plugin.json +36 -0
- package/lib/schemas/events-default.json +18 -0
- package/lib/schemas/events-default.plugin.json +17 -0
- package/lib/schemas/observable-default.json +33 -0
- package/lib/schemas/observable-default.plugin.json +24 -0
- package/lib/scripts/bsb-client-cli.d.ts +21 -0
- package/lib/scripts/bsb-client-cli.js +701 -0
- package/lib/scripts/bsb-client-cli.js.map +1 -0
- package/lib/scripts/bsb-plugin-cli.d.ts +15 -0
- package/lib/scripts/bsb-plugin-cli.js +547 -0
- package/lib/scripts/bsb-plugin-cli.js.map +1 -0
- package/lib/scripts/export-schemas.d.ts +17 -0
- package/lib/scripts/export-schemas.js +205 -0
- package/lib/scripts/export-schemas.js.map +1 -0
- package/lib/scripts/extract-schemas-from-source.d.ts +23 -0
- package/lib/scripts/extract-schemas-from-source.js +604 -0
- package/lib/scripts/extract-schemas-from-source.js.map +1 -0
- package/lib/scripts/generate-client-types.d.ts +22 -0
- package/lib/scripts/generate-client-types.js +537 -0
- package/lib/scripts/generate-client-types.js.map +1 -0
- package/lib/scripts/generate-plugin-json.d.ts +17 -0
- package/lib/scripts/generate-plugin-json.js +219 -0
- package/lib/scripts/generate-plugin-json.js.map +1 -0
- package/lib/serviceBase/config.d.ts +83 -0
- package/lib/serviceBase/config.js +236 -0
- package/lib/serviceBase/config.js.map +1 -0
- package/lib/serviceBase/events.d.ts +91 -0
- package/lib/serviceBase/events.js +519 -0
- package/lib/serviceBase/events.js.map +1 -0
- package/lib/serviceBase/index.d.ts +33 -0
- package/lib/serviceBase/index.js +50 -0
- package/lib/serviceBase/index.js.map +1 -0
- package/lib/serviceBase/observable.d.ts +249 -0
- package/lib/serviceBase/observable.js +551 -0
- package/lib/serviceBase/observable.js.map +1 -0
- package/lib/serviceBase/plugins.d.ts +48 -0
- package/lib/serviceBase/plugins.js +184 -0
- package/lib/serviceBase/plugins.js.map +1 -0
- package/lib/serviceBase/serviceBase.d.ts +228 -0
- package/lib/serviceBase/serviceBase.js +420 -0
- package/lib/serviceBase/serviceBase.js.map +1 -0
- package/lib/serviceBase/services.d.ts +63 -0
- package/lib/serviceBase/services.js +346 -0
- package/lib/serviceBase/services.js.map +1 -0
- package/lib/tests.d.ts +27 -0
- package/lib/tests.js +44 -0
- package/lib/tests.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { EventEmitter } from "node:events";
|
|
28
|
+
import { Observable, IPluginLogging } from "../../../index";
|
|
29
|
+
export declare class emit extends EventEmitter {
|
|
30
|
+
private _lastReceivedMessageIds;
|
|
31
|
+
private set lastReceivedMessageIds(value);
|
|
32
|
+
constructor(_log: IPluginLogging);
|
|
33
|
+
dispose(): void;
|
|
34
|
+
onEvent(obs: Observable, pluginName: string, event: string, listener: {
|
|
35
|
+
(obs: Observable, args: Array<any>): Promise<void>;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
emitEvent(obs: Observable, pluginName: string, event: string, args: Array<any>): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.emit = void 0;
|
|
30
|
+
const node_events_1 = require("node:events");
|
|
31
|
+
const node_crypto_1 = require("node:crypto");
|
|
32
|
+
class emit extends node_events_1.EventEmitter {
|
|
33
|
+
_lastReceivedMessageIds = [];
|
|
34
|
+
set lastReceivedMessageIds(value) {
|
|
35
|
+
// remove after 50 messages
|
|
36
|
+
if (this._lastReceivedMessageIds.length > 50) {
|
|
37
|
+
this._lastReceivedMessageIds.shift();
|
|
38
|
+
}
|
|
39
|
+
this._lastReceivedMessageIds.push(value);
|
|
40
|
+
}
|
|
41
|
+
constructor(_log) {
|
|
42
|
+
super();
|
|
43
|
+
}
|
|
44
|
+
dispose() {
|
|
45
|
+
this.removeAllListeners();
|
|
46
|
+
}
|
|
47
|
+
async onEvent(obs, pluginName, event, listener) {
|
|
48
|
+
obs.log.debug("onEvent: listening to {pluginName}-{event}", {
|
|
49
|
+
pluginName,
|
|
50
|
+
event,
|
|
51
|
+
});
|
|
52
|
+
this.on(`${pluginName}-${event}`, async (eobs, args) => {
|
|
53
|
+
if (this._lastReceivedMessageIds.includes(args.msgID)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.lastReceivedMessageIds = args.msgID;
|
|
57
|
+
// Create child observable for receiving the event
|
|
58
|
+
const receiveObs = eobs.startSpan("onEvent:receive", {
|
|
59
|
+
pluginName,
|
|
60
|
+
event,
|
|
61
|
+
messageId: args.msgID
|
|
62
|
+
});
|
|
63
|
+
try {
|
|
64
|
+
await listener(receiveObs, args.data);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const errorObj = error instanceof Error ? error : new Error(error?.message || String(error));
|
|
68
|
+
receiveObs.error(errorObj);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
receiveObs.end();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async emitEvent(obs, pluginName, event, args) {
|
|
77
|
+
const msgID = (0, node_crypto_1.randomUUID)();
|
|
78
|
+
// Create child observable for sending the event
|
|
79
|
+
const sendObs = obs.startSpan("emitEvent:send", {
|
|
80
|
+
pluginName,
|
|
81
|
+
event,
|
|
82
|
+
messageId: msgID
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
sendObs.log.debug("emitEvent: emitting {pluginName}-{event}", {
|
|
86
|
+
pluginName, event,
|
|
87
|
+
});
|
|
88
|
+
this.emit(`${pluginName}-${event}`, sendObs, {
|
|
89
|
+
msgID,
|
|
90
|
+
data: args,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const errorObj = error instanceof Error ? error : new Error(error?.message || String(error));
|
|
95
|
+
sendObs.error(errorObj);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
sendObs.end();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.emit = emit;
|
|
104
|
+
//# sourceMappingURL=emit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../../../src/plugins/events-default/events/emit.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,6CAA2C;AAE3C,6CAAyC;AAEzC,MAAa,IACX,SAAQ,0BAAY;IACZ,uBAAuB,GAAkB,EAAE,CAAC;IACpD,IAAY,sBAAsB,CAAC,KAAa;QAC9C,2BAA2B;QAC3B,IAAI,IAAI,CAAC,uBAAuB,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;YAC7C,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,YAAY,IAAoB;QAC9B,KAAK,E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IAAgB;QAEhB,MAAM,KAAK,GAAG,IAAA,wBAAU,GAAE,CAAC;QAE3B,gDAAgD;QAChD,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE;YAC9C,UAAU;YACV,KAAK;YACL,SAAS,EAAE,KAAK;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,0CAA0C,EAAE;gBAC5D,UAAU,EAAE,KAAK;aAClB,CAAC,CAAC;YAEH,IAAI,CAAC,IAAI,CAAC,GAAI,UAAW,IAAK,KAAM,EAAE,EAAE,OAAO,EAAE;gBAC/C,KAAK;gBACL,IAAI,EAAE,IAAI;aACX,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,QAAQ,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7F,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACxB,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;CACF;AAtFD,oBAsFC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { EventEmitter } from "node:events";
|
|
28
|
+
import { Observable, IPluginLogging } from "../../../index";
|
|
29
|
+
export declare class emitAndReturn extends EventEmitter {
|
|
30
|
+
constructor(_log: IPluginLogging);
|
|
31
|
+
dispose(): void;
|
|
32
|
+
onReturnableEvent(obs: Observable, pluginName: string, event: string, listener: {
|
|
33
|
+
(obs: Observable, args: Array<any>): Promise<any>;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
emitEventAndReturn(obs: Observable, pluginName: string, event: string, timeoutSeconds: number, args: Array<any>): Promise<any>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.emitAndReturn = void 0;
|
|
30
|
+
const node_events_1 = require("node:events");
|
|
31
|
+
const index_1 = require("../../../index");
|
|
32
|
+
class emitAndReturn extends node_events_1.EventEmitter {
|
|
33
|
+
constructor(_log) {
|
|
34
|
+
super();
|
|
35
|
+
}
|
|
36
|
+
dispose() {
|
|
37
|
+
this.removeAllListeners();
|
|
38
|
+
}
|
|
39
|
+
async onReturnableEvent(obs, pluginName, event, listener) {
|
|
40
|
+
obs.log.debug("onReturnableEvent: listening to {pluginName}-{event}", {
|
|
41
|
+
pluginName,
|
|
42
|
+
event,
|
|
43
|
+
});
|
|
44
|
+
this.on(`${pluginName}-${event}`, async (eobs, resolve, reject, data) => {
|
|
45
|
+
// Create child observable for receiving and handling the returnable event
|
|
46
|
+
const receiveObs = eobs.startSpan("onReturnableEvent:receive", {
|
|
47
|
+
pluginName,
|
|
48
|
+
event,
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
const result = await listener(receiveObs, data);
|
|
52
|
+
resolve(result);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const errorObj = error instanceof Error ? error : new Error(error?.message || String(error));
|
|
56
|
+
receiveObs.error(errorObj);
|
|
57
|
+
reject(error);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
receiveObs.end();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async emitEventAndReturn(obs, pluginName, event, timeoutSeconds, args) {
|
|
65
|
+
// Create child observable for sending the returnable event
|
|
66
|
+
const sendObs = obs.startSpan("emitEventAndReturn:send", {
|
|
67
|
+
pluginName,
|
|
68
|
+
event,
|
|
69
|
+
timeoutSeconds
|
|
70
|
+
});
|
|
71
|
+
sendObs.log.debug("emitReturnableEvent: emitting {pluginName}-{event}", {
|
|
72
|
+
pluginName, event,
|
|
73
|
+
});
|
|
74
|
+
const self = this;
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
const timeoutHandler = setTimeout(() => {
|
|
77
|
+
const timeoutError = new index_1.BSBError(sendObs.trace, "Timeout: {pluginName}-{event}", {
|
|
78
|
+
pluginName,
|
|
79
|
+
event,
|
|
80
|
+
});
|
|
81
|
+
sendObs.error(timeoutError);
|
|
82
|
+
sendObs.end();
|
|
83
|
+
reject(timeoutError);
|
|
84
|
+
}, timeoutSeconds * 1000);
|
|
85
|
+
self.emit(`${pluginName}-${event}`, sendObs, (result) => {
|
|
86
|
+
clearTimeout(timeoutHandler);
|
|
87
|
+
resolve(result);
|
|
88
|
+
sendObs.end();
|
|
89
|
+
}, (error) => {
|
|
90
|
+
clearTimeout(timeoutHandler);
|
|
91
|
+
const errorObj = error instanceof Error ? error : new Error(error?.message || String(error));
|
|
92
|
+
sendObs.error(errorObj);
|
|
93
|
+
reject(error);
|
|
94
|
+
sendObs.end();
|
|
95
|
+
}, args);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.emitAndReturn = emitAndReturn;
|
|
100
|
+
//# sourceMappingURL=emitAndReturn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC7F,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBACxB,MAAM,CAAC,KAAK,CAAC,CAAC;gBACd,OAAO,CAAC,GAAG,EAAE,CAAC;YAChB,CAAC,EACD,IAAI,CACL,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzFD,sCAyFC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { EventEmitter } from "node:events";
|
|
28
|
+
import { Readable } from "node:stream";
|
|
29
|
+
import { Observable, IPluginLogging } from "../../../index";
|
|
30
|
+
export declare class emitStreamAndReceiveStream extends EventEmitter {
|
|
31
|
+
private readonly staticCommsTimeout;
|
|
32
|
+
constructor(_log: IPluginLogging);
|
|
33
|
+
dispose(): void;
|
|
34
|
+
receiveStream(obs: Observable, pluginName: string, event: string, listener: {
|
|
35
|
+
(eobs: Observable, error: Error | null, stream: Readable): Promise<void>;
|
|
36
|
+
}, timeoutSeconds?: number): Promise<string>;
|
|
37
|
+
sendStream(obs: Observable, pluginName: string, event: string, streamId: string, stream: Readable): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.emitStreamAndReceiveStream = void 0;
|
|
30
|
+
const node_events_1 = require("node:events");
|
|
31
|
+
const node_crypto_1 = require("node:crypto");
|
|
32
|
+
const index_1 = require("../../../index");
|
|
33
|
+
class emitStreamAndReceiveStream extends node_events_1.EventEmitter {
|
|
34
|
+
// If we try receive or send a stream and the other party is not ready for some reason, we will automatically timeout in 5s.
|
|
35
|
+
staticCommsTimeout = 1000;
|
|
36
|
+
constructor(_log) {
|
|
37
|
+
super();
|
|
38
|
+
}
|
|
39
|
+
dispose() {
|
|
40
|
+
this.removeAllListeners();
|
|
41
|
+
}
|
|
42
|
+
async receiveStream(obs, pluginName, event, listener, timeoutSeconds = 60) {
|
|
43
|
+
// Create child observable for receiving stream
|
|
44
|
+
const receiveObs = obs.startSpan("receiveStream:receive", {
|
|
45
|
+
event,
|
|
46
|
+
pluginName,
|
|
47
|
+
timeoutSeconds,
|
|
48
|
+
});
|
|
49
|
+
const streamId = `${(0, node_crypto_1.randomUUID)()}=${timeoutSeconds}`;
|
|
50
|
+
receiveObs.log.debug("receiveStream: listening to {streamId} ({pluginName}-{event})", {
|
|
51
|
+
streamId,
|
|
52
|
+
pluginName,
|
|
53
|
+
event,
|
|
54
|
+
});
|
|
55
|
+
const self = this;
|
|
56
|
+
return new Promise((resolve) => {
|
|
57
|
+
const receiptTimeoutHandler = setTimeout(() => {
|
|
58
|
+
const timeoutError = new index_1.BSBError(receiveObs.trace, "Receive Receipt Timeout");
|
|
59
|
+
receiveObs.error(timeoutError);
|
|
60
|
+
listener(receiveObs, timeoutError, null);
|
|
61
|
+
self.emit(`${streamId}-error`, receiveObs, timeoutError);
|
|
62
|
+
self.removeAllListeners(streamId);
|
|
63
|
+
receiveObs.end();
|
|
64
|
+
}, self.staticCommsTimeout);
|
|
65
|
+
self.once(streamId, (eobs, stream) => {
|
|
66
|
+
clearTimeout(receiptTimeoutHandler);
|
|
67
|
+
self.emit(`${streamId}-emit`);
|
|
68
|
+
stream.on("error", (error) => {
|
|
69
|
+
const errorObj = error instanceof Error ? error : new Error(error?.message || String(error));
|
|
70
|
+
receiveObs.error(errorObj);
|
|
71
|
+
self.emit(`${streamId}-error`, errorObj);
|
|
72
|
+
});
|
|
73
|
+
stream.on("end", () => {
|
|
74
|
+
self.emit(`${streamId}-end`);
|
|
75
|
+
receiveObs.end();
|
|
76
|
+
});
|
|
77
|
+
listener(receiveObs, null, stream);
|
|
78
|
+
});
|
|
79
|
+
resolve(streamId);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async sendStream(obs, pluginName, event, streamId, stream) {
|
|
83
|
+
// Create child observable for sending stream
|
|
84
|
+
const sendObs = obs.startSpan("sendStream:send", {
|
|
85
|
+
event,
|
|
86
|
+
pluginName,
|
|
87
|
+
streamId
|
|
88
|
+
});
|
|
89
|
+
sendObs.log.debug("sendStream: emitting {streamId}", { streamId });
|
|
90
|
+
const self = this;
|
|
91
|
+
return new Promise((resolve, rejectI) => {
|
|
92
|
+
const timeout = Number.parseInt(streamId.split("=")[1]);
|
|
93
|
+
const clearSessions = (e) => {
|
|
94
|
+
stream.destroy(e);
|
|
95
|
+
if (receiptTimeoutHandler !== null) {
|
|
96
|
+
clearTimeout(receiptTimeoutHandler);
|
|
97
|
+
}
|
|
98
|
+
receiptTimeoutHandler = null;
|
|
99
|
+
clearTimeout(timeoutHandler);
|
|
100
|
+
self.removeAllListeners(`${streamId}-emit`);
|
|
101
|
+
self.removeAllListeners(`${streamId}-end`);
|
|
102
|
+
self.removeAllListeners(`${streamId}-error`);
|
|
103
|
+
sendObs.end();
|
|
104
|
+
};
|
|
105
|
+
const reject = (e) => {
|
|
106
|
+
clearSessions(e);
|
|
107
|
+
sendObs.error(e);
|
|
108
|
+
rejectI(e);
|
|
109
|
+
};
|
|
110
|
+
let receiptTimeoutHandler = setTimeout(() => {
|
|
111
|
+
const timeoutError = new index_1.BSBError(sendObs.trace, "Send Receipt Timeout");
|
|
112
|
+
reject(timeoutError);
|
|
113
|
+
}, self.staticCommsTimeout);
|
|
114
|
+
const timeoutHandler = setTimeout(() => {
|
|
115
|
+
const timeoutError = new index_1.BSBError(sendObs.trace, "Stream Timeout");
|
|
116
|
+
reject(timeoutError);
|
|
117
|
+
}, timeout * 1000);
|
|
118
|
+
self.once(`${streamId}-emit`, () => {
|
|
119
|
+
if (receiptTimeoutHandler !== null) {
|
|
120
|
+
clearTimeout(receiptTimeoutHandler);
|
|
121
|
+
}
|
|
122
|
+
receiptTimeoutHandler = null;
|
|
123
|
+
});
|
|
124
|
+
self.once(`${streamId}-end`, () => {
|
|
125
|
+
clearSessions();
|
|
126
|
+
resolve();
|
|
127
|
+
});
|
|
128
|
+
self.once(`${streamId}-error`, (error) => reject(error));
|
|
129
|
+
self.emit(streamId, sendObs, stream);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.emitStreamAndReceiveStream = emitStreamAndReceiveStream;
|
|
134
|
+
//# sourceMappingURL=emitStreamAndReceiveStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitStreamAndReceiveStream.js","sourceRoot":"","sources":["../../../../src/plugins/events-default/events/emitStreamAndReceiveStream.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,6CAA2C;AAE3C,6CAAyC;AACzC,0CAAsE;AAEtE,MAAa,0BACX,SAAQ,0BAAY;IACpB,4HAA4H;IAC3G,kBAAkB,GAAG,IAAI,CAAC;IAE3C,YAAY,IAAoB;QAC9B,KAAK,EAAE,CAAC;IACV,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,GAAe,EACf,UAAkB,EAClB,KAAa,EACb,QAAsF,EACtF,iBAAyB,EAAE;QAE3B,+CAA+C;QAC/C,MAAM,UAAU,GAAG,GAAG,CAAC,SAAS,CAAC,uBAAuB,EAA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AM,EAAE,GAAG,EAAE;gBAChC,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,QAAQ,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAEhE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArID,gEAqIC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
export { emit } from "./emit";
|
|
28
|
+
export { emitAndReturn } from "./emitAndReturn";
|
|
29
|
+
export { emitStreamAndReceiveStream } from "./emitStreamAndReceiveStream";
|
|
30
|
+
export { broadcast } from "./broadcast";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.broadcast = exports.emitStreamAndReceiveStream = exports.emitAndReturn = exports.emit = void 0;
|
|
30
|
+
var emit_1 = require("./emit");
|
|
31
|
+
Object.defineProperty(exports, "emit", { enumerable: true, get: function () { return emit_1.emit; } });
|
|
32
|
+
var emitAndReturn_1 = require("./emitAndReturn");
|
|
33
|
+
Object.defineProperty(exports, "emitAndReturn", { enumerable: true, get: function () { return emitAndReturn_1.emitAndReturn; } });
|
|
34
|
+
var emitStreamAndReceiveStream_1 = require("./emitStreamAndReceiveStream");
|
|
35
|
+
Object.defineProperty(exports, "emitStreamAndReceiveStream", { enumerable: true, get: function () { return emitStreamAndReceiveStream_1.emitStreamAndReceiveStream; } });
|
|
36
|
+
var broadcast_1 = require("./broadcast");
|
|
37
|
+
Object.defineProperty(exports, "broadcast", { enumerable: true, get: function () { return broadcast_1.broadcast; } });
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/events-default/events/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,2EAA0E;AAAjE,wIAAA,0BAA0B,OAAA;AACnC,yCAAwC;AAA/B,sGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { Readable } from "node:stream";
|
|
28
|
+
import { emit, broadcast, emitAndReturn, emitStreamAndReceiveStream } from "../../plugins/events-default/events/index";
|
|
29
|
+
import { Observable } from "../../index";
|
|
30
|
+
import { BSBEvents, BSBEventsConstructor } from "../../base/BSBEvents";
|
|
31
|
+
export declare const Config: import("../../index").BSBPluginConfigClass<undefined>;
|
|
32
|
+
export declare class Plugin extends BSBEvents<InstanceType<typeof Config>> {
|
|
33
|
+
static Config: import("../../index").BSBPluginConfigClass<undefined>;
|
|
34
|
+
init?(): void;
|
|
35
|
+
protected broadcast: broadcast;
|
|
36
|
+
protected emit: emit;
|
|
37
|
+
protected ear: emitAndReturn;
|
|
38
|
+
protected eas: emitStreamAndReceiveStream;
|
|
39
|
+
constructor(config: BSBEventsConstructor<InstanceType<typeof Config>>);
|
|
40
|
+
dispose(): void;
|
|
41
|
+
onBroadcast(obs: Observable, pluginName: string, event: string, listener: {
|
|
42
|
+
(obs: Observable, args: Array<any>): Promise<void>;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
emitBroadcast(obs: Observable, pluginName: string, event: string, args: Array<any>): Promise<void>;
|
|
45
|
+
onEvent(obs: Observable, pluginName: string, event: string, listener: {
|
|
46
|
+
(obs: Observable, args: Array<any>): Promise<void>;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
emitEvent(obs: Observable, pluginName: string, event: string, args: Array<any>): Promise<void>;
|
|
49
|
+
onReturnableEvent(obs: Observable, pluginName: string, event: string, listener: {
|
|
50
|
+
(obs: Observable, args: Array<any>): Promise<any>;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
emitEventAndReturn(obs: Observable, pluginName: string, event: string, timeoutSeconds: number, args: Array<any>): Promise<any>;
|
|
53
|
+
receiveStream(obs: Observable, pluginName: string, event: string, listener: {
|
|
54
|
+
(obs: Observable, error: Error | null, stream: Readable): Promise<void>;
|
|
55
|
+
}, timeoutSeconds?: number): Promise<string>;
|
|
56
|
+
sendStream(obs: Observable, pluginName: string, event: string, streamId: string, stream: Readable): Promise<void>;
|
|
57
|
+
}
|