@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,184 @@
|
|
|
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.SBPlugins = void 0;
|
|
30
|
+
const node_fs_1 = require("node:fs");
|
|
31
|
+
const node_path_1 = require("node:path");
|
|
32
|
+
const interfaces_1 = require("../interfaces");
|
|
33
|
+
/**
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
36
|
+
function internalTrace(span) {
|
|
37
|
+
return (0, interfaces_1.createFakeDTrace)("serviceBase/SBPlugins", span);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* BSB Plugins Controller
|
|
41
|
+
*
|
|
42
|
+
* This class is responsible for loading the plugins in the BSB framework.
|
|
43
|
+
* If you have a specific way of loading plugins, you can extend this class and then use your own class when creating the ServiceBase instance.
|
|
44
|
+
*
|
|
45
|
+
* @group Plugins
|
|
46
|
+
* @category Core
|
|
47
|
+
*/
|
|
48
|
+
class SBPlugins {
|
|
49
|
+
/**
|
|
50
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBPlugins.html | API: SBPlugins}
|
|
51
|
+
*/
|
|
52
|
+
cwd;
|
|
53
|
+
nodeModulesPluginDir;
|
|
54
|
+
referencedPluginDir = null;
|
|
55
|
+
devMode;
|
|
56
|
+
constructor(cwd, devMode) {
|
|
57
|
+
this.cwd = cwd;
|
|
58
|
+
this.devMode = devMode;
|
|
59
|
+
this.nodeModulesPluginDir = (0, node_path_1.join)(this.cwd, "./node_modules/");
|
|
60
|
+
if (typeof process.env.BSB_PLUGIN_DIR == "string" &&
|
|
61
|
+
process.env.BSB_PLUGIN_DIR.length > 3) {
|
|
62
|
+
if (!(0, node_fs_1.existsSync)(process.env.BSB_PLUGIN_DIR)) {
|
|
63
|
+
throw new Error(`Plugin directory ${process.env.BSB_PLUGIN_DIR} does not exist`);
|
|
64
|
+
}
|
|
65
|
+
this.referencedPluginDir = process.env.BSB_PLUGIN_DIR;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async loadPlugin(log, npmPackage, plugin, name) {
|
|
69
|
+
const tTrace = internalTrace(`loadPlugin:${npmPackage}:${plugin}`);
|
|
70
|
+
log.debug(tTrace, `Plugin {name} from {package} try load as {pluginName}`, {
|
|
71
|
+
name: plugin,
|
|
72
|
+
pluginName: name,
|
|
73
|
+
package: npmPackage ?? "self",
|
|
74
|
+
});
|
|
75
|
+
const nodeModulesLib = npmPackage !== null;
|
|
76
|
+
let pluginPath = "";
|
|
77
|
+
let packageCwd = this.cwd;
|
|
78
|
+
let version = "1.0.0";
|
|
79
|
+
if (!nodeModulesLib) {
|
|
80
|
+
// If no package is defined in the config, we will not look anywhere else except for the local plugins
|
|
81
|
+
if (this.devMode) {
|
|
82
|
+
pluginPath = (0, node_path_1.join)(this.cwd, "./src/plugins/" + plugin);
|
|
83
|
+
if (!(0, node_fs_1.existsSync)(pluginPath)) {
|
|
84
|
+
pluginPath = "";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (pluginPath == "") {
|
|
88
|
+
pluginPath = (0, node_path_1.join)(this.cwd, "./lib/plugins/" + plugin);
|
|
89
|
+
}
|
|
90
|
+
const packageJsonPath = (0, node_path_1.join)(packageCwd, "./package.json");
|
|
91
|
+
if ((0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
92
|
+
const packageJSON = JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, "utf-8")
|
|
93
|
+
.toString());
|
|
94
|
+
version = packageJSON.version ?? '0.0.0';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// If a package is defined in the config, we will look for the plugin in the BSB_PLUGIN_DIR env, followed by the node_modules directory. Local plugins are not used.
|
|
99
|
+
if (this.referencedPluginDir) {
|
|
100
|
+
const T1packageCwd = (0, node_path_1.join)(this.referencedPluginDir, npmPackage, version);
|
|
101
|
+
const T1pluginPath = (0, node_path_1.join)(this.referencedPluginDir, npmPackage, version, "./lib/plugins/" + plugin);
|
|
102
|
+
if ((0, node_fs_1.existsSync)(T1pluginPath)) {
|
|
103
|
+
pluginPath = T1pluginPath;
|
|
104
|
+
packageCwd = T1packageCwd;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const T2pluginPath = (0, node_path_1.join)(this.referencedPluginDir, npmPackage, "latest", "./lib/plugins/" + plugin);
|
|
108
|
+
const T2packageCwd = (0, node_path_1.join)(this.referencedPluginDir, npmPackage, "latest");
|
|
109
|
+
if ((0, node_fs_1.existsSync)(T2pluginPath)) {
|
|
110
|
+
pluginPath = T2pluginPath;
|
|
111
|
+
packageCwd = T2packageCwd;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (pluginPath == '') {
|
|
116
|
+
const T3pluginPath = (0, node_path_1.join)(this.nodeModulesPluginDir, npmPackage, "./lib/plugins/" + plugin);
|
|
117
|
+
const T3packageCwd = (0, node_path_1.join)(this.nodeModulesPluginDir, npmPackage);
|
|
118
|
+
if ((0, node_fs_1.existsSync)(T3pluginPath)) {
|
|
119
|
+
pluginPath = T3pluginPath;
|
|
120
|
+
packageCwd = T3packageCwd;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if ((0, node_fs_1.existsSync)(packageCwd) && (0, node_fs_1.existsSync)((0, node_path_1.join)(packageCwd, "./package.json"))) {
|
|
124
|
+
const packageJSON = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(packageCwd, "./package.json"), "utf-8")
|
|
125
|
+
.toString());
|
|
126
|
+
version = packageJSON.version ?? '0.0.0';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!(0, node_fs_1.existsSync)(pluginPath)) {
|
|
130
|
+
log.error(tTrace, `Plugin {name} in {package} not found`, {
|
|
131
|
+
name: plugin,
|
|
132
|
+
package: npmPackage ?? "self",
|
|
133
|
+
});
|
|
134
|
+
return (0, interfaces_1.Err)(new Error(`Plugin ${plugin} in ${npmPackage ?? "self"} not found`));
|
|
135
|
+
}
|
|
136
|
+
log.debug(tTrace, `Plugin {name}: attempt to load from {path} as {pluginName}`, {
|
|
137
|
+
name: plugin,
|
|
138
|
+
path: pluginPath,
|
|
139
|
+
pluginName: name,
|
|
140
|
+
});
|
|
141
|
+
const loadResult = await (0, interfaces_1.fromPromise)(this.loadPluginFile(pluginPath, name, packageCwd, version));
|
|
142
|
+
if (!loadResult.success) {
|
|
143
|
+
log.error(tTrace, `Failed to load plugin {name}: {error}`, {
|
|
144
|
+
name: plugin,
|
|
145
|
+
error: loadResult.error.message,
|
|
146
|
+
});
|
|
147
|
+
return (0, interfaces_1.Err)(new Error(`Failed to load plugin ${name}: ${loadResult.error.message}`));
|
|
148
|
+
}
|
|
149
|
+
log.info(tTrace, `Successfully loaded plugin {name}`, { name: plugin });
|
|
150
|
+
return (0, interfaces_1.Ok)(loadResult.data);
|
|
151
|
+
}
|
|
152
|
+
async loadPluginFile(pluginPath, pluginName, packageCwd, version) {
|
|
153
|
+
let pluginFile = (0, node_path_1.join)(pluginPath, './index.js');
|
|
154
|
+
if (this.devMode) {
|
|
155
|
+
const tsPluginFile = (0, node_path_1.join)(pluginPath, './index.ts');
|
|
156
|
+
if ((0, node_fs_1.existsSync)(tsPluginFile)) {
|
|
157
|
+
pluginFile = tsPluginFile;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!(0, node_fs_1.existsSync)(pluginFile)) {
|
|
161
|
+
throw new Error(`Plugin ${pluginName} not found at ${pluginFile}`);
|
|
162
|
+
}
|
|
163
|
+
const pluginExports = await Promise.resolve(`${pluginFile}`).then(s => require(s));
|
|
164
|
+
if (!pluginExports.Plugin) {
|
|
165
|
+
throw new Error(`Plugin ${pluginName} does not export a Plugin class`);
|
|
166
|
+
}
|
|
167
|
+
let serviceConfigDef = null;
|
|
168
|
+
if (pluginExports.Config) {
|
|
169
|
+
serviceConfigDef = new pluginExports.Config(process.cwd(), packageCwd, pluginPath, pluginName);
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
name: pluginName,
|
|
173
|
+
ref: pluginName,
|
|
174
|
+
version: version,
|
|
175
|
+
serviceConfig: serviceConfigDef,
|
|
176
|
+
plugin: pluginExports.Plugin,
|
|
177
|
+
packageCwd: packageCwd,
|
|
178
|
+
pluginCwd: pluginPath,
|
|
179
|
+
pluginPath: pluginPath,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.SBPlugins = SBPlugins;
|
|
184
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/serviceBase/plugins.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,qCAAmD;AACnD,yCAAiC;AAEjC,8CAA0J;AAE1J;;GAEG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAA,6BAAgB,EAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAa,SAAS;IACpB;;OAEG;IACO,GAAG,CAAS;IACZ,oBAAoB,CAAS;IAC7B,mBAAmB,GAAkB,IAAI,CAAC;IAC1C,OAAO,CAAU;IAE3B,YAAY,GAAW,EAAE,OAAgB;QACvC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,oBAAoB,GAAG,IAAA,gBAAI,EAAC,IAAI,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QAC9D,IACE,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,QAAQ;YAC7C,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EACrC,CAAC;YACD,IAAI,CAAC,IAAA,oBAAU,EAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,oBAAqB,OAAO,CAAC,GAAG,CAAC,cAAe,iBA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xE,OAAO,CAAC,GAAG,EAAE,EACb,UAAU,EACV,UAAU,EACV,UAAU,CACX,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,GAAG,EAAE,UAAU;YACf,OAAO,EAAE,OAAO;YAChB,aAAa,EAAE,gBAAgB;YAC/B,MAAM,EAAE,aAAa,CAAC,MAAM;YAC5B,UAAU,EAAE,UAAU;YACtB,SAAS,EAAE,UAAU;YACrB,UAAU,EAAE,UAAU;SACvB,CAAC;IACJ,CAAC;CACF;AAlLD,8BAkLC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
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 { BSBService } from "../base";
|
|
28
|
+
import { BSBOptions, SimpleBSBOptions, BSBPreset } from "../interfaces";
|
|
29
|
+
/**
|
|
30
|
+
* @hidden
|
|
31
|
+
*/
|
|
32
|
+
export declare const BOOT_STAT_KEYS: {
|
|
33
|
+
readonly BSB: "BSB";
|
|
34
|
+
readonly SELF: "SELF";
|
|
35
|
+
readonly CONFIG: "CONFIG";
|
|
36
|
+
readonly OBSERVABLE: "OBSERVABLE";
|
|
37
|
+
readonly EVENTS: "EVENTS";
|
|
38
|
+
readonly SERVICES: "SERVICES";
|
|
39
|
+
readonly INIT: "INIT";
|
|
40
|
+
readonly RUN: "RUN";
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* @hidden
|
|
44
|
+
*/
|
|
45
|
+
export type BootStatKeys = (typeof BOOT_STAT_KEYS)[keyof typeof BOOT_STAT_KEYS];
|
|
46
|
+
/**
|
|
47
|
+
* Main entry point for the BSB framework.
|
|
48
|
+
*
|
|
49
|
+
* This class is responsible for initializing and running the BSB framework.
|
|
50
|
+
* You can override the default behaviour of the framework by passing in your own classes for the plugins, logging, metrics, events and services.
|
|
51
|
+
* The passed in classes are not the plugins themselves, but rather the classes that handle the plugin creation, setup and running.
|
|
52
|
+
*
|
|
53
|
+
* @group Main
|
|
54
|
+
* @category Core
|
|
55
|
+
*/
|
|
56
|
+
export declare class ServiceBase {
|
|
57
|
+
/**
|
|
58
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html | API: ServiceBase}
|
|
59
|
+
*/
|
|
60
|
+
private readonly mode;
|
|
61
|
+
/**
|
|
62
|
+
* Create a ServiceBase instance with simple configuration
|
|
63
|
+
*
|
|
64
|
+
* @param simple - Simple configuration options
|
|
65
|
+
* @returns New ServiceBase instance
|
|
66
|
+
*
|
|
67
|
+
* @group Main
|
|
68
|
+
* @category Factory
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const app = ServiceBase.create({
|
|
72
|
+
* cwd: './my-app',
|
|
73
|
+
* plugins: ['logging-default', 'events-default']
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
static create(simple?: SimpleBSBOptions): ServiceBase;
|
|
78
|
+
/**
|
|
79
|
+
* Create a ServiceBase instance from a preset
|
|
80
|
+
*
|
|
81
|
+
* @param preset - Preset configuration type
|
|
82
|
+
* @param overrides - Additional options to override preset defaults
|
|
83
|
+
* @returns New ServiceBase instance
|
|
84
|
+
*
|
|
85
|
+
* @group Main
|
|
86
|
+
* @category Factory
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const app = ServiceBase.fromPreset(BSBPreset.DEVELOPMENT, {
|
|
90
|
+
* cwd: './my-app'
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
static fromPreset(preset: BSBPreset, overrides?: Partial<BSBOptions>): ServiceBase;
|
|
95
|
+
/**
|
|
96
|
+
* Create a minimal ServiceBase instance for quick prototyping
|
|
97
|
+
*
|
|
98
|
+
* @param cwd - Working directory (defaults to process.cwd())
|
|
99
|
+
* @returns New ServiceBase instance with minimal configuration
|
|
100
|
+
*
|
|
101
|
+
* @group Main
|
|
102
|
+
* @category Factory
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const app = ServiceBase.minimal('./my-app');
|
|
106
|
+
* await app.init();
|
|
107
|
+
* await app.run();
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
static minimal(cwd?: string): ServiceBase;
|
|
111
|
+
/**
|
|
112
|
+
* Create a development ServiceBase instance with debug logging
|
|
113
|
+
*
|
|
114
|
+
* @param cwd - Working directory (defaults to process.cwd())
|
|
115
|
+
* @returns New ServiceBase instance configured for development
|
|
116
|
+
*
|
|
117
|
+
* @group Main
|
|
118
|
+
* @category Factory
|
|
119
|
+
*/
|
|
120
|
+
static development(cwd?: string): ServiceBase;
|
|
121
|
+
/**
|
|
122
|
+
* Create a production ServiceBase instance with optimized settings
|
|
123
|
+
*
|
|
124
|
+
* @param cwd - Working directory (defaults to process.cwd())
|
|
125
|
+
* @returns New ServiceBase instance configured for production
|
|
126
|
+
*
|
|
127
|
+
* @group Main
|
|
128
|
+
* @category Factory
|
|
129
|
+
*/
|
|
130
|
+
static production(cwd?: string): ServiceBase;
|
|
131
|
+
private readonly _CORE_PLUGIN_NAME;
|
|
132
|
+
private readonly _appId;
|
|
133
|
+
private readonly observable;
|
|
134
|
+
private readonly plugins;
|
|
135
|
+
private readonly config;
|
|
136
|
+
private readonly events;
|
|
137
|
+
private readonly observableBackend;
|
|
138
|
+
private readonly services;
|
|
139
|
+
private readonly cwd;
|
|
140
|
+
private coreMetrics;
|
|
141
|
+
private heartBeatMetric;
|
|
142
|
+
private bsbBootTimeMetric;
|
|
143
|
+
private _keeps?;
|
|
144
|
+
private _heartbeat;
|
|
145
|
+
private _startKeep;
|
|
146
|
+
private _outputKeep;
|
|
147
|
+
/**
|
|
148
|
+
* Creates a new ServiceBase instance to orchestrate the BSB framework.
|
|
149
|
+
*
|
|
150
|
+
* The ServiceBase is the main entry point for running BSB applications. It initializes
|
|
151
|
+
* and coordinates all subsystems including configuration, logging, metrics, events,
|
|
152
|
+
* and service plugins.
|
|
153
|
+
*
|
|
154
|
+
* @param options - Configuration options for the ServiceBase instance
|
|
155
|
+
* @param options.debug - Enable debug mode with verbose logging (default: true)
|
|
156
|
+
* @param options.live - Enable production/live mode optimizations (default: false)
|
|
157
|
+
* @param options.cwd - Working directory for the application (default: process.cwd())
|
|
158
|
+
* @param options.config - Custom configuration controller class
|
|
159
|
+
* @param options.plugins - Custom plugin loader class
|
|
160
|
+
* @param options.logging - Custom logging controller class
|
|
161
|
+
* @param options.metrics - Custom metrics controller class
|
|
162
|
+
* @param options.events - Custom events controller class
|
|
163
|
+
* @param options.services - Custom services controller class
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* // Basic usage with defaults
|
|
168
|
+
* const app = new ServiceBase();
|
|
169
|
+
* await app.init();
|
|
170
|
+
* await app.run();
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* // Production configuration
|
|
176
|
+
* const app = new ServiceBase({
|
|
177
|
+
* debug: false,
|
|
178
|
+
* live: true,
|
|
179
|
+
* cwd: '/app'
|
|
180
|
+
* });
|
|
181
|
+
* await app.init();
|
|
182
|
+
* await app.run();
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* // Development configuration
|
|
188
|
+
* const app = new ServiceBase({
|
|
189
|
+
* debug: true,
|
|
190
|
+
* live: false,
|
|
191
|
+
* cwd: process.cwd()
|
|
192
|
+
* });
|
|
193
|
+
* await app.init();
|
|
194
|
+
* await app.run();
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* @see {@link ServiceBase.create} for factory method with simple options
|
|
198
|
+
* @see {@link ServiceBase.fromPreset} for preset-based configuration
|
|
199
|
+
* @see {@link ServiceBase.init} for initialization
|
|
200
|
+
* @see {@link ServiceBase.run} for starting the application
|
|
201
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html | API: ServiceBase}
|
|
202
|
+
*/
|
|
203
|
+
private readonly _region?;
|
|
204
|
+
constructor(options?: BSBOptions);
|
|
205
|
+
/**
|
|
206
|
+
* Initialize all subsystems and plugins
|
|
207
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html#init | API: ServiceBase.init}
|
|
208
|
+
*/
|
|
209
|
+
init(): Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
* Run the application after initialization
|
|
212
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html#run | API: ServiceBase.run}
|
|
213
|
+
*/
|
|
214
|
+
run(): Promise<void>;
|
|
215
|
+
private heartBeat;
|
|
216
|
+
private _disposing;
|
|
217
|
+
/**
|
|
218
|
+
* Dispose all subsystems and exit process with code
|
|
219
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html#dispose | API: ServiceBase.dispose}
|
|
220
|
+
*/
|
|
221
|
+
dispose(eCode: number | undefined, reason: string, extraData?: any): Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* Add a service plugin programmatically
|
|
224
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html#addService | API: ServiceBase.addService}
|
|
225
|
+
*/
|
|
226
|
+
addService(name: string, plugin: typeof BSBService<any, any>, config: object | any): Promise<import("../base").BSBServiceRef>;
|
|
227
|
+
}
|
|
228
|
+
export default ServiceBase;
|