@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,420 @@
|
|
|
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.ServiceBase = exports.BOOT_STAT_KEYS = void 0;
|
|
30
|
+
const base_1 = require("../base");
|
|
31
|
+
const factory_1 = require("../base/factory");
|
|
32
|
+
const interfaces_1 = require("../interfaces");
|
|
33
|
+
/**
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
36
|
+
exports.BOOT_STAT_KEYS = {
|
|
37
|
+
BSB: "BSB",
|
|
38
|
+
SELF: "SELF",
|
|
39
|
+
CONFIG: "CONFIG",
|
|
40
|
+
OBSERVABLE: "OBSERVABLE",
|
|
41
|
+
EVENTS: "EVENTS",
|
|
42
|
+
SERVICES: "SERVICES",
|
|
43
|
+
INIT: "INIT",
|
|
44
|
+
RUN: "RUN",
|
|
45
|
+
};
|
|
46
|
+
const TIMEKEEPLOG = "[TIMER] {timerName} took ({nsTime}ns) ({msTime}ms)";
|
|
47
|
+
/**
|
|
48
|
+
* @hidden
|
|
49
|
+
*/
|
|
50
|
+
function internalTrace(span) {
|
|
51
|
+
return (0, interfaces_1.createFakeDTrace)("serviceBase/ServiceBase", span);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Main entry point for the BSB framework.
|
|
55
|
+
*
|
|
56
|
+
* This class is responsible for initializing and running the BSB framework.
|
|
57
|
+
* You can override the default behaviour of the framework by passing in your own classes for the plugins, logging, metrics, events and services.
|
|
58
|
+
* The passed in classes are not the plugins themselves, but rather the classes that handle the plugin creation, setup and running.
|
|
59
|
+
*
|
|
60
|
+
* @group Main
|
|
61
|
+
* @category Core
|
|
62
|
+
*/
|
|
63
|
+
class ServiceBase {
|
|
64
|
+
/**
|
|
65
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html | API: ServiceBase}
|
|
66
|
+
*/
|
|
67
|
+
mode = "development";
|
|
68
|
+
/**
|
|
69
|
+
* Create a ServiceBase instance with simple configuration
|
|
70
|
+
*
|
|
71
|
+
* @param simple - Simple configuration options
|
|
72
|
+
* @returns New ServiceBase instance
|
|
73
|
+
*
|
|
74
|
+
* @group Main
|
|
75
|
+
* @category Factory
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const app = ServiceBase.create({
|
|
79
|
+
* cwd: './my-app',
|
|
80
|
+
* plugins: ['logging-default', 'events-default']
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
static create(simple) {
|
|
85
|
+
const options = (0, factory_1.fromSimpleOptions)(simple);
|
|
86
|
+
return new ServiceBase(options);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a ServiceBase instance from a preset
|
|
90
|
+
*
|
|
91
|
+
* @param preset - Preset configuration type
|
|
92
|
+
* @param overrides - Additional options to override preset defaults
|
|
93
|
+
* @returns New ServiceBase instance
|
|
94
|
+
*
|
|
95
|
+
* @group Main
|
|
96
|
+
* @category Factory
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const app = ServiceBase.fromPreset(BSBPreset.DEVELOPMENT, {
|
|
100
|
+
* cwd: './my-app'
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
static fromPreset(preset, overrides) {
|
|
105
|
+
const options = (0, factory_1.fromPreset)(preset, overrides);
|
|
106
|
+
return new ServiceBase(options);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create a minimal ServiceBase instance for quick prototyping
|
|
110
|
+
*
|
|
111
|
+
* @param cwd - Working directory (defaults to process.cwd())
|
|
112
|
+
* @returns New ServiceBase instance with minimal configuration
|
|
113
|
+
*
|
|
114
|
+
* @group Main
|
|
115
|
+
* @category Factory
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const app = ServiceBase.minimal('./my-app');
|
|
119
|
+
* await app.init();
|
|
120
|
+
* await app.run();
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
static minimal(cwd) {
|
|
124
|
+
return ServiceBase.fromPreset(interfaces_1.BSBPreset.MINIMAL, { cwd });
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a development ServiceBase instance with debug logging
|
|
128
|
+
*
|
|
129
|
+
* @param cwd - Working directory (defaults to process.cwd())
|
|
130
|
+
* @returns New ServiceBase instance configured for development
|
|
131
|
+
*
|
|
132
|
+
* @group Main
|
|
133
|
+
* @category Factory
|
|
134
|
+
*/
|
|
135
|
+
static development(cwd) {
|
|
136
|
+
return ServiceBase.fromPreset(interfaces_1.BSBPreset.DEVELOPMENT, { cwd });
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create a production ServiceBase instance with optimized settings
|
|
140
|
+
*
|
|
141
|
+
* @param cwd - Working directory (defaults to process.cwd())
|
|
142
|
+
* @returns New ServiceBase instance configured for production
|
|
143
|
+
*
|
|
144
|
+
* @group Main
|
|
145
|
+
* @category Factory
|
|
146
|
+
*/
|
|
147
|
+
static production(cwd) {
|
|
148
|
+
return ServiceBase.fromPreset(interfaces_1.BSBPreset.PRODUCTION, { cwd });
|
|
149
|
+
}
|
|
150
|
+
_CORE_PLUGIN_NAME = "core";
|
|
151
|
+
_appId;
|
|
152
|
+
observable;
|
|
153
|
+
plugins;
|
|
154
|
+
config;
|
|
155
|
+
events;
|
|
156
|
+
observableBackend;
|
|
157
|
+
services;
|
|
158
|
+
cwd;
|
|
159
|
+
coreMetrics;
|
|
160
|
+
heartBeatMetric;
|
|
161
|
+
bsbBootTimeMetric;
|
|
162
|
+
_keeps = {
|
|
163
|
+
BSB: process.hrtime(),
|
|
164
|
+
};
|
|
165
|
+
_heartbeat;
|
|
166
|
+
_startKeep(stepName) {
|
|
167
|
+
if (this._keeps === undefined) {
|
|
168
|
+
throw new base_1.BSBError(internalTrace("TIMEKEEPER"), "Internal error with timekeeper!");
|
|
169
|
+
}
|
|
170
|
+
if (this.observableBackend !== undefined) {
|
|
171
|
+
this.observableBackend.debug(internalTrace("TIMEKEEPER"), "Starting timer for {log}", { log: stepName });
|
|
172
|
+
}
|
|
173
|
+
this._keeps[stepName] = process.hrtime();
|
|
174
|
+
}
|
|
175
|
+
_outputKeep(stepName) {
|
|
176
|
+
if (this._keeps === undefined) {
|
|
177
|
+
throw new base_1.BSBError(internalTrace("TIMEKEEPER"), "Internal error with timekeeper!");
|
|
178
|
+
}
|
|
179
|
+
if (typeof this._keeps[stepName] === "number") {
|
|
180
|
+
throw new base_1.BSBError(internalTrace("TIMEKEEPER"), "Internal error with timekeeper!");
|
|
181
|
+
}
|
|
182
|
+
const diff = process.hrtime((this._keeps[stepName] || undefined));
|
|
183
|
+
this._keeps[stepName] = (diff[0] * base_1.NS_PER_SEC + diff[1]) * base_1.MS_PER_NS;
|
|
184
|
+
const logMeta = {
|
|
185
|
+
nsTime: diff[0] * base_1.NS_PER_SEC + diff[1],
|
|
186
|
+
msTime: this._keeps[stepName],
|
|
187
|
+
timerName: stepName,
|
|
188
|
+
};
|
|
189
|
+
this.observableBackend.info(internalTrace("TIMEKEEPER"), TIMEKEEPLOG, logMeta);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Creates a new ServiceBase instance to orchestrate the BSB framework.
|
|
193
|
+
*
|
|
194
|
+
* The ServiceBase is the main entry point for running BSB applications. It initializes
|
|
195
|
+
* and coordinates all subsystems including configuration, logging, metrics, events,
|
|
196
|
+
* and service plugins.
|
|
197
|
+
*
|
|
198
|
+
* @param options - Configuration options for the ServiceBase instance
|
|
199
|
+
* @param options.debug - Enable debug mode with verbose logging (default: true)
|
|
200
|
+
* @param options.live - Enable production/live mode optimizations (default: false)
|
|
201
|
+
* @param options.cwd - Working directory for the application (default: process.cwd())
|
|
202
|
+
* @param options.config - Custom configuration controller class
|
|
203
|
+
* @param options.plugins - Custom plugin loader class
|
|
204
|
+
* @param options.logging - Custom logging controller class
|
|
205
|
+
* @param options.metrics - Custom metrics controller class
|
|
206
|
+
* @param options.events - Custom events controller class
|
|
207
|
+
* @param options.services - Custom services controller class
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // Basic usage with defaults
|
|
212
|
+
* const app = new ServiceBase();
|
|
213
|
+
* await app.init();
|
|
214
|
+
* await app.run();
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* // Production configuration
|
|
220
|
+
* const app = new ServiceBase({
|
|
221
|
+
* debug: false,
|
|
222
|
+
* live: true,
|
|
223
|
+
* cwd: '/app'
|
|
224
|
+
* });
|
|
225
|
+
* await app.init();
|
|
226
|
+
* await app.run();
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* // Development configuration
|
|
232
|
+
* const app = new ServiceBase({
|
|
233
|
+
* debug: true,
|
|
234
|
+
* live: false,
|
|
235
|
+
* cwd: process.cwd()
|
|
236
|
+
* });
|
|
237
|
+
* await app.init();
|
|
238
|
+
* await app.run();
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @see {@link ServiceBase.create} for factory method with simple options
|
|
242
|
+
* @see {@link ServiceBase.fromPreset} for preset-based configuration
|
|
243
|
+
* @see {@link ServiceBase.init} for initialization
|
|
244
|
+
* @see {@link ServiceBase.run} for starting the application
|
|
245
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html | API: ServiceBase}
|
|
246
|
+
*/
|
|
247
|
+
_region;
|
|
248
|
+
constructor(options = {}) {
|
|
249
|
+
const resolvedOptions = (0, factory_1.resolveBSBOptions)(options);
|
|
250
|
+
// Set instance properties from resolved options
|
|
251
|
+
this.cwd = resolvedOptions.cwd;
|
|
252
|
+
this.mode = resolvedOptions.mode;
|
|
253
|
+
this._appId = resolvedOptions.appId;
|
|
254
|
+
this._region = resolvedOptions.region;
|
|
255
|
+
this._startKeep(exports.BOOT_STAT_KEYS.SELF);
|
|
256
|
+
// Initialize subsystems with resolved dependencies
|
|
257
|
+
this.plugins = new resolvedOptions.plugins(this.cwd, this.mode === "development");
|
|
258
|
+
this.observable = new resolvedOptions.observable(this._appId, this.mode, this.cwd, this.plugins);
|
|
259
|
+
// Initialize unified observable backend BEFORE config and events
|
|
260
|
+
this.observableBackend = new base_1.ObservableBackend(this.mode, this._appId, this._CORE_PLUGIN_NAME, this.observable);
|
|
261
|
+
// Create Observable factory for subsystems
|
|
262
|
+
const createObservableFromTrace = (trace, pluginName, attributes) => {
|
|
263
|
+
const resource = base_1.ResourceContextBuilder.build({
|
|
264
|
+
appId: this._appId,
|
|
265
|
+
mode: this.mode,
|
|
266
|
+
pluginName: pluginName,
|
|
267
|
+
cwd: this.cwd,
|
|
268
|
+
packageCwd: this.cwd,
|
|
269
|
+
pluginCwd: this.cwd,
|
|
270
|
+
pluginVersion: "1.0.0"
|
|
271
|
+
}, this._region);
|
|
272
|
+
return new base_1.PluginObservable(trace, resource, this.observableBackend, attributes || {});
|
|
273
|
+
};
|
|
274
|
+
this.events = new resolvedOptions.events(this._appId, this.mode, this.cwd, this.plugins, this.observable, createObservableFromTrace);
|
|
275
|
+
this.config = new resolvedOptions.config(this._appId, this.mode, this.cwd, this.observable, this.plugins, createObservableFromTrace);
|
|
276
|
+
this.observableBackend.info(internalTrace("CONSTRUCTOR"), "Starting BSB [{mode}]", {
|
|
277
|
+
mode: this.mode,
|
|
278
|
+
});
|
|
279
|
+
this.services = new resolvedOptions.services(this._appId, this.mode, this.cwd, this.plugins, this.observable, this._region);
|
|
280
|
+
process.stdin.resume(); //so the program will not close instantly
|
|
281
|
+
const self = this;
|
|
282
|
+
//do something when app is closing
|
|
283
|
+
process.on("exit", () => self.dispose(0, "app exit"));
|
|
284
|
+
//catches ctrl+c event
|
|
285
|
+
process.on("SIGINT", () => self.dispose(0, "manual exit"));
|
|
286
|
+
// catches "kill pid" (for example: nodemon restart)
|
|
287
|
+
process.on("SIGUSR1", () => self.dispose(1, "sig kill user 1"));
|
|
288
|
+
process.on("SIGUSR2", () => self.dispose(2, "sig kill user 2"));
|
|
289
|
+
//catches uncaught exceptions
|
|
290
|
+
process.on("uncaughtException", (error) => {
|
|
291
|
+
self.observableBackend.error(internalTrace("UNCAUGHT_EXCEPTION"), "Uncaught exception: {error}\n Stack: {stack}", { error: error.message, stack: error.stack ?? 'no stack trace' });
|
|
292
|
+
self.dispose(3, "uncaught exception", error);
|
|
293
|
+
});
|
|
294
|
+
this._outputKeep(exports.BOOT_STAT_KEYS.SELF);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Initialize all subsystems and plugins
|
|
298
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html#init | API: ServiceBase.init}
|
|
299
|
+
*/
|
|
300
|
+
async init() {
|
|
301
|
+
this._startKeep(exports.BOOT_STAT_KEYS.INIT);
|
|
302
|
+
this._startKeep(exports.BOOT_STAT_KEYS.CONFIG);
|
|
303
|
+
await this.config.init();
|
|
304
|
+
this._outputKeep(exports.BOOT_STAT_KEYS.CONFIG);
|
|
305
|
+
this._startKeep(exports.BOOT_STAT_KEYS.OBSERVABLE);
|
|
306
|
+
await this.observable.init(internalTrace("OBSERVABLE_INIT"), this.config);
|
|
307
|
+
this._outputKeep(exports.BOOT_STAT_KEYS.OBSERVABLE);
|
|
308
|
+
this._startKeep(exports.BOOT_STAT_KEYS.EVENTS);
|
|
309
|
+
await this.events.init(this.config, this.observable);
|
|
310
|
+
this._outputKeep(exports.BOOT_STAT_KEYS.EVENTS);
|
|
311
|
+
// SERVICES ORDERING
|
|
312
|
+
this._startKeep(exports.BOOT_STAT_KEYS.SERVICES);
|
|
313
|
+
await this.services.setup(this.config, this.observable, this.events);
|
|
314
|
+
await this.services.init();
|
|
315
|
+
this._outputKeep(exports.BOOT_STAT_KEYS.SERVICES);
|
|
316
|
+
this.coreMetrics = this.observableBackend;
|
|
317
|
+
this.heartBeatMetric = this.coreMetrics.createCounter("heartbeat", "Heartbeat", "Heartbeat", [this._appId]);
|
|
318
|
+
this.bsbBootTimeMetric = this.coreMetrics.createGauge("bsbBootTime", "BSB Boot Time", "BSB Boot Time", [this._appId]);
|
|
319
|
+
this._outputKeep(exports.BOOT_STAT_KEYS.INIT);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Run the application after initialization
|
|
323
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html#run | API: ServiceBase.run}
|
|
324
|
+
*/
|
|
325
|
+
async run() {
|
|
326
|
+
this._startKeep(exports.BOOT_STAT_KEYS.RUN);
|
|
327
|
+
await this.observable.run(internalTrace("OBSERVABLE_RUN"));
|
|
328
|
+
await this.events.run();
|
|
329
|
+
await this.services.run();
|
|
330
|
+
this.observableBackend.info(internalTrace("RUN"), "Disposing config for memory cleanup and safety");
|
|
331
|
+
this.config.dispose();
|
|
332
|
+
this._outputKeep(exports.BOOT_STAT_KEYS.RUN);
|
|
333
|
+
this._heartbeat = setInterval(() => this.heartBeat(), 60 * 60 * 1000);
|
|
334
|
+
this.heartBeat();
|
|
335
|
+
this._outputKeep(exports.BOOT_STAT_KEYS.BSB);
|
|
336
|
+
this.bsbBootTimeMetric.set(this._keeps[exports.BOOT_STAT_KEYS.BSB]);
|
|
337
|
+
this._keeps = undefined;
|
|
338
|
+
}
|
|
339
|
+
heartBeat() {
|
|
340
|
+
this.observableBackend.debug(internalTrace("HEARTBEAT"), "Heartbeat");
|
|
341
|
+
this.heartBeatMetric.increment();
|
|
342
|
+
}
|
|
343
|
+
_disposing = false;
|
|
344
|
+
/**
|
|
345
|
+
* Dispose all subsystems and exit process with code
|
|
346
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html#dispose | API: ServiceBase.dispose}
|
|
347
|
+
*/
|
|
348
|
+
async dispose(eCode = 0, reason, extraData) {
|
|
349
|
+
if (this._disposing) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
this._disposing = true;
|
|
353
|
+
const trace = this.observableBackend.createTrace("dispose", { reason });
|
|
354
|
+
const span = this.observableBackend.createSpan(trace.trace, "dispose", { reason });
|
|
355
|
+
try {
|
|
356
|
+
this.observableBackend.info(span.trace, "Disposing BSB: {reason}", { reason });
|
|
357
|
+
if (extraData !== undefined) {
|
|
358
|
+
this.observableBackend.error(span.trace, "Extra data: {data} {trace}", { data: extraData, trace: extraData.stack });
|
|
359
|
+
console.error(extraData);
|
|
360
|
+
}
|
|
361
|
+
if (this._heartbeat !== undefined) {
|
|
362
|
+
clearInterval(this._heartbeat);
|
|
363
|
+
}
|
|
364
|
+
if (this.services !== undefined) {
|
|
365
|
+
this.observableBackend.debug(span.trace, "Disposing services");
|
|
366
|
+
this.services.dispose();
|
|
367
|
+
}
|
|
368
|
+
if (this.events !== undefined) {
|
|
369
|
+
this.observableBackend.debug(span.trace, "Disposing events");
|
|
370
|
+
this.events.dispose();
|
|
371
|
+
}
|
|
372
|
+
if (this.observable !== undefined) {
|
|
373
|
+
this.observableBackend.debug(span.trace, "Disposing observable");
|
|
374
|
+
this.observable.dispose();
|
|
375
|
+
}
|
|
376
|
+
if (this.config !== undefined) {
|
|
377
|
+
this.observableBackend.debug(span.trace, "Disposing config");
|
|
378
|
+
this.config.dispose();
|
|
379
|
+
}
|
|
380
|
+
this._keeps = undefined;
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
span.error(error instanceof Error ? error : new Error(String(error)));
|
|
384
|
+
throw error;
|
|
385
|
+
}
|
|
386
|
+
finally {
|
|
387
|
+
span.end();
|
|
388
|
+
trace.end();
|
|
389
|
+
console.log(`APP EXIT CODE ${eCode} REASON ${reason}`);
|
|
390
|
+
process.exit(eCode);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Add a service plugin programmatically
|
|
395
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ServiceBase.html#addService | API: ServiceBase.addService}
|
|
396
|
+
*/
|
|
397
|
+
async addService(name, plugin, config) {
|
|
398
|
+
if (this._keeps[exports.BOOT_STAT_KEYS.SERVICES] !== undefined) {
|
|
399
|
+
throw new base_1.BSBError(internalTrace("ADD_SERVICE"), "Cannot add service plugin as service already called");
|
|
400
|
+
}
|
|
401
|
+
return await this.services.addPlugin(this.config, this.observable, this.events, {
|
|
402
|
+
name,
|
|
403
|
+
plugin: name,
|
|
404
|
+
package: null,
|
|
405
|
+
version: "0.0.0",
|
|
406
|
+
}, {
|
|
407
|
+
serviceConfig: config,
|
|
408
|
+
plugin: plugin,
|
|
409
|
+
packageCwd: this.cwd,
|
|
410
|
+
pluginCwd: this.cwd,
|
|
411
|
+
pluginPath: "",
|
|
412
|
+
version: "0.0.0",
|
|
413
|
+
ref: name,
|
|
414
|
+
name,
|
|
415
|
+
}, config);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
exports.ServiceBase = ServiceBase;
|
|
419
|
+
exports.default = ServiceBase;
|
|
420
|
+
//# sourceMappingURL=serviceBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceBase.js","sourceRoot":"","sources":["../../src/serviceBase/serviceBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,kCAIiB;AACjB,6CAAmF;AACnF,8CAA4K;AAO5K;;GAEG;AACU,QAAA,cAAc,GAAG;IAC5B,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;CACF,CAAC;AAMX,MAAM,WAAW,GAAG,oDAAoD,CAAC;AAEzE;;GAEG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAA,6BAAgB,EAAC,yBAAyB,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;;;GASG;AACH,MA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AC;QACJ,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAClC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,MAAM,EACX;YACE,IAAI;YACJ,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,OAAO;SACjB,EACD;YACE,aAAa,EAAE,MAAM;YACrB,MAAM,EAAE,MAAuD;YAC/D,UAAU,EAAE,IAAI,CAAC,GAAG;YACpB,SAAS,EAAE,IAAI,CAAC,GAAG;YACnB,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,OAAO;YAChB,GAAG,EAAE,IAAI;YACT,IAAI;SACL,EACD,MAAM,CACP,CAAC;IACJ,CAAC;CACF;AAjcD,kCAicC;AAED,kBAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 { DEBUG_MODE, IPluginDefinition, LoadedPlugin } from "../interfaces";
|
|
28
|
+
import { SBConfig } from "./config";
|
|
29
|
+
import { SBEvents } from "./events";
|
|
30
|
+
import { SBObservable } from "./observable";
|
|
31
|
+
import { SBPlugins } from "./plugins";
|
|
32
|
+
/**
|
|
33
|
+
* BSB Services Controller
|
|
34
|
+
*
|
|
35
|
+
* This class is responsible for managing the services in the BSB framework.
|
|
36
|
+
* If you have a specific way of managing services, you can extend this class and then use your own class when creating the ServiceBase instance.
|
|
37
|
+
*
|
|
38
|
+
* @group Services
|
|
39
|
+
* @category Core
|
|
40
|
+
*/
|
|
41
|
+
export declare class SBServices {
|
|
42
|
+
private _activeServices;
|
|
43
|
+
private readonly mode;
|
|
44
|
+
private readonly appId;
|
|
45
|
+
private readonly cwd;
|
|
46
|
+
private sbPlugins;
|
|
47
|
+
private readonly observableBackend;
|
|
48
|
+
private readonly region?;
|
|
49
|
+
constructor(appId: string, mode: DEBUG_MODE, cwd: string, sbPlugins: SBPlugins, sbObservable: SBObservable, region?: string);
|
|
50
|
+
dispose(): void;
|
|
51
|
+
private remapDeps;
|
|
52
|
+
setup(sbConfig: SBConfig, sbObservable: SBObservable, sbEvents: SBEvents): Promise<void>;
|
|
53
|
+
private setupPluginClient;
|
|
54
|
+
private mapServicePlugins;
|
|
55
|
+
addPlugin(sbConfig: SBConfig, sbObservable: SBObservable, sbEvents: SBEvents, plugin: IPluginDefinition, reference: LoadedPlugin<"service">, config: any): Promise<import("../base").BSBServiceRef>;
|
|
56
|
+
private addService;
|
|
57
|
+
private sortByInitDependencies;
|
|
58
|
+
sortAndRunOrInitPlugins(type: "init" | "run"): Promise<void>;
|
|
59
|
+
private getTextReportedDeps;
|
|
60
|
+
private gatherListOfPlugins;
|
|
61
|
+
init(): Promise<void>;
|
|
62
|
+
run(): Promise<void>;
|
|
63
|
+
}
|