@bsb/base 9.0.0 → 9.0.1
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/README.md +6 -41
- package/lib/plugins/config-default/interfaces.d.ts +3 -2
- package/lib/plugins/service-benchmarkify/index.d.ts +312 -0
- package/lib/plugins/service-benchmarkify/index.js +138 -0
- package/lib/plugins/service-benchmarkify/index.js.map +1 -0
- package/lib/plugins/service-default0/index.d.ts +287 -0
- package/lib/plugins/service-default0/index.js +118 -0
- package/lib/plugins/service-default0/index.js.map +1 -0
- package/lib/{tests.d.ts → plugins/service-default1/client.d.ts} +16 -1
- package/lib/plugins/service-default1/client.js +70 -0
- package/lib/plugins/service-default1/client.js.map +1 -0
- package/lib/plugins/service-default1/index.d.ts +304 -0
- package/lib/plugins/service-default1/index.js +179 -0
- package/lib/plugins/service-default1/index.js.map +1 -0
- package/lib/plugins/service-default2/index.d.ts +359 -0
- package/lib/plugins/service-default2/index.js +137 -0
- package/lib/plugins/service-default2/index.js.map +1 -0
- package/lib/plugins/service-default3/index.d.ts +119 -0
- package/lib/plugins/service-default3/index.js +88 -0
- package/lib/plugins/service-default3/index.js.map +1 -0
- package/lib/plugins/service-default4/index.d.ts +81 -0
- package/lib/{tests.js → plugins/service-default4/index.js} +35 -16
- package/lib/plugins/service-default4/index.js.map +1 -0
- package/lib/schemas/config-default.plugin.json +1 -1
- package/lib/schemas/events-default.plugin.json +1 -1
- package/lib/schemas/observable-default.plugin.json +1 -1
- package/lib/schemas/service-benchmarkify.json +229 -0
- package/lib/schemas/service-default0.json +216 -0
- package/lib/schemas/service-default1.json +242 -0
- package/lib/schemas/service-default2.json +268 -0
- package/lib/schemas/service-default3.json +65 -0
- package/lib/schemas/service-default4.json +33 -0
- package/lib/serviceBase/events.js +2 -2
- package/lib/serviceBase/events.js.map +1 -1
- package/lib/serviceBase/observable.js +1 -1
- package/lib/serviceBase/observable.js.map +1 -1
- package/lib/serviceBase/plugins.d.ts +8 -1
- package/lib/serviceBase/plugins.js +113 -13
- package/lib/serviceBase/plugins.js.map +1 -1
- package/lib/serviceBase/services.js +2 -2
- package/lib/serviceBase/services.js.map +1 -1
- package/package.json +1 -1
- package/lib/tests.js.map +0 -1
package/README.md
CHANGED
|
@@ -86,34 +86,6 @@ Boot flow (high level):
|
|
|
86
86
|
|
|
87
87
|
Timekeeping metrics are recorded for each step and logged as timers. A heartbeat counter runs hourly.
|
|
88
88
|
|
|
89
|
-
### ServiceBase APIs (for BSB contributors only)
|
|
90
|
-
- Construction (modern):
|
|
91
|
-
```ts
|
|
92
|
-
import { ServiceBase, BSBPreset } from "@bettercorp/service-base";
|
|
93
|
-
|
|
94
|
-
// Simple defaults (local dev only)
|
|
95
|
-
const app = ServiceBase.development();
|
|
96
|
-
|
|
97
|
-
// Preset with overrides (local dev only)
|
|
98
|
-
const prod = ServiceBase.fromPreset(BSBPreset.PRODUCTION, { cwd: "/app" });
|
|
99
|
-
|
|
100
|
-
// Fully custom options (local dev only)
|
|
101
|
-
const custom = ServiceBase.create({ cwd: process.cwd(), plugins: ["logging-default", "events-default"] });
|
|
102
|
-
```
|
|
103
|
-
- Lifecycle:
|
|
104
|
-
```ts
|
|
105
|
-
await app.init();
|
|
106
|
-
await app.run();
|
|
107
|
-
// app.dispose(code, reason) is called automatically on signals/errors
|
|
108
|
-
```
|
|
109
|
-
- Add a service plugin programmatically (local dev only, before services init):
|
|
110
|
-
```ts
|
|
111
|
-
import { BSBService } from "@bettercorp/service-base";
|
|
112
|
-
|
|
113
|
-
class MyService extends BSBService<{ greeting: string }> { /* ... */ }
|
|
114
|
-
await app.addService("service-my", MyService as any, { greeting: "hi" });
|
|
115
|
-
```
|
|
116
|
-
|
|
117
89
|
### Subsystems
|
|
118
90
|
- `SBConfig` (configuration)
|
|
119
91
|
- Defaults to `config-default` plugin; can be replaced via environment variables
|
|
@@ -161,7 +133,7 @@ Built‑in plugin types include: `config-*`, `logging-*`, `metrics-*`, `events-*
|
|
|
161
133
|
- `npm test`: Mocha + NYC coverage in TS mode
|
|
162
134
|
- `npm run testDev`: Run tests without coverage (faster for development)
|
|
163
135
|
- `npm run generate-docs`: Generate TypeDoc JSON to `docs.json`
|
|
164
|
-
-
|
|
136
|
+
- API Reference: Hosted at `https://types.bsbcode.dev/nodejs/`
|
|
165
137
|
- `npm run export-schemas`: Export event schemas to `lib/schemas/{plugin-name}.json`
|
|
166
138
|
- `npm run generate-plugin-json`: Generate plugin metadata in `lib/schemas/`
|
|
167
139
|
|
|
@@ -179,7 +151,7 @@ Example run (with mounted plugins directory):
|
|
|
179
151
|
docker run --rm \
|
|
180
152
|
-e BSB_PLUGINS="@bettercorp/your-plugin" \
|
|
181
153
|
-v $(pwd)/plugins:/mnt/plugins \
|
|
182
|
-
|
|
154
|
+
betterweb/service-base:9
|
|
183
155
|
```
|
|
184
156
|
|
|
185
157
|
Recommended plugin directory layout (when using `BSB_PLUGIN_DIR`):
|
|
@@ -209,8 +181,8 @@ Notes
|
|
|
209
181
|
- `BSB_PLUGINS`: Comma‑separated list of npm packages to install at container start (entrypoint.js)
|
|
210
182
|
- `BSB_PLUGIN_UPDATE`: `yes|y|true` to run `npm update` at container start
|
|
211
183
|
- Config plugin override (advanced):
|
|
212
|
-
- `
|
|
213
|
-
- `
|
|
184
|
+
- `BSB_CONFIG_PLUGIN`: Name of config plugin (must start with `config-`)
|
|
185
|
+
- `BSB_CONFIG_PLUGIN_PACKAGE`: npm package name hosting the config plugin
|
|
214
186
|
|
|
215
187
|
### Documentation
|
|
216
188
|
|
|
@@ -221,7 +193,7 @@ Notes
|
|
|
221
193
|
#### API Documentation
|
|
222
194
|
- API docs are generated with TypeDoc (`typedoc.json`).
|
|
223
195
|
- `npm run generate-docs` → emits `docs.json`
|
|
224
|
-
-
|
|
196
|
+
- API docs are served at `https://types.bsbcode.dev/nodejs/`
|
|
225
197
|
|
|
226
198
|
### Testing
|
|
227
199
|
- Tests: Mocha + ts-node with NYC coverage
|
|
@@ -238,11 +210,6 @@ Quick reference:
|
|
|
238
210
|
- Use cross-language type helpers (`uuid`, `int32`, `datetime`, etc.) for better code generation
|
|
239
211
|
- Plugin metadata auto-generates `PLUGIN_CLIENT` and schema files during build
|
|
240
212
|
|
|
241
|
-
Legacy templates are available under `templates/` but use outdated v8 patterns:
|
|
242
|
-
- `templates/plugin.ts`, `templates/pluginClient.ts` (service plugin + client)
|
|
243
|
-
- `templates/events.ts` (events plugin)
|
|
244
|
-
- `templates/logger.ts` (logging plugin)
|
|
245
|
-
|
|
246
213
|
At minimum, export a `Plugin` class in `lib/plugins/<type>-<name>/index.js` (or `src/plugins/.../index.ts` in dev). For configurable plugins, export a `Config` created with `createConfigSchema()`. Publish your plugin as an npm package or ship its prebuilt folder structure under `BSB_PLUGIN_DIR`.
|
|
247
214
|
|
|
248
215
|
### Quick Start (Container)
|
|
@@ -251,7 +218,7 @@ At minimum, export a `Plugin` class in `lib/plugins/<type>-<name>/index.js` (or
|
|
|
251
218
|
docker run --rm \
|
|
252
219
|
-v $(pwd)/plugins:/mnt/plugins:ro \
|
|
253
220
|
-e BSB_PLUGIN_DIR=/mnt/plugins \
|
|
254
|
-
|
|
221
|
+
betterweb/service-base:9
|
|
255
222
|
```
|
|
256
223
|
|
|
257
224
|
Local development (for contributors only):
|
|
@@ -259,5 +226,3 @@ Local development (for contributors only):
|
|
|
259
226
|
npm install
|
|
260
227
|
npm run dev
|
|
261
228
|
```
|
|
262
|
-
|
|
263
|
-
|
|
@@ -36,9 +36,10 @@ export interface DeploymentProfile {
|
|
|
36
36
|
/**
|
|
37
37
|
* @name NPM Package version
|
|
38
38
|
* @description The NPM package version that holds the plugin
|
|
39
|
-
* @example 1.
|
|
40
|
-
* @example 1.
|
|
39
|
+
* @example 1.2
|
|
40
|
+
* @example 1.2.3
|
|
41
41
|
*/
|
|
42
|
+
version?: string;
|
|
42
43
|
/**
|
|
43
44
|
* @name Plugin name
|
|
44
45
|
* @description The name of the plugin
|
|
@@ -0,0 +1,312 @@
|
|
|
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 { Observable } from "../../index";
|
|
28
|
+
import { BSBService, BSBServiceConstructor } from "../../base";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
export declare const Config: import("../../index").BSBPluginConfigClass<z.ZodNull>;
|
|
31
|
+
export declare const EventSchemas: {
|
|
32
|
+
readonly emitEvents: {
|
|
33
|
+
readonly 'benchmark.started': {
|
|
34
|
+
input: {
|
|
35
|
+
_bsb: "object";
|
|
36
|
+
properties: {
|
|
37
|
+
readonly name: import("../../index").BSBStringType;
|
|
38
|
+
readonly timestamp: import("../../index").BSBStringType;
|
|
39
|
+
};
|
|
40
|
+
required: string[];
|
|
41
|
+
description?: string;
|
|
42
|
+
optional?: boolean;
|
|
43
|
+
nullable?: boolean;
|
|
44
|
+
};
|
|
45
|
+
description?: string;
|
|
46
|
+
readonly __brand: "fire-and-forget";
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
readonly onEvents: {
|
|
50
|
+
readonly 'benchmark.trigger': {
|
|
51
|
+
input: {
|
|
52
|
+
_bsb: "object";
|
|
53
|
+
properties: {
|
|
54
|
+
readonly testName: import("../../index").BSBStringType & {
|
|
55
|
+
optional: true;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
required: string[];
|
|
59
|
+
description?: string;
|
|
60
|
+
optional?: boolean;
|
|
61
|
+
nullable?: boolean;
|
|
62
|
+
};
|
|
63
|
+
description?: string;
|
|
64
|
+
readonly __brand: "fire-and-forget";
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
readonly emitReturnableEvents: {
|
|
68
|
+
readonly 'performance.test': {
|
|
69
|
+
input: {
|
|
70
|
+
_bsb: "object";
|
|
71
|
+
properties: {
|
|
72
|
+
readonly iterations: import("../../index").BSBNumberType;
|
|
73
|
+
readonly warmup: import("../../index").BSBBooleanType;
|
|
74
|
+
};
|
|
75
|
+
required: string[];
|
|
76
|
+
description?: string;
|
|
77
|
+
optional?: boolean;
|
|
78
|
+
nullable?: boolean;
|
|
79
|
+
};
|
|
80
|
+
output: {
|
|
81
|
+
_bsb: "object";
|
|
82
|
+
properties: {
|
|
83
|
+
readonly duration: import("../../index").BSBNumberType;
|
|
84
|
+
readonly opsPerSecond: import("../../index").BSBNumberType;
|
|
85
|
+
};
|
|
86
|
+
required: string[];
|
|
87
|
+
description?: string;
|
|
88
|
+
optional?: boolean;
|
|
89
|
+
nullable?: boolean;
|
|
90
|
+
};
|
|
91
|
+
description?: string;
|
|
92
|
+
defaultTimeout?: number;
|
|
93
|
+
readonly __brand: "returnable";
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
readonly onReturnableEvents: {
|
|
97
|
+
readonly add: {
|
|
98
|
+
input: {
|
|
99
|
+
_bsb: "object";
|
|
100
|
+
properties: {
|
|
101
|
+
readonly a: import("../../index").BSBNumberType;
|
|
102
|
+
readonly b: import("../../index").BSBNumberType;
|
|
103
|
+
};
|
|
104
|
+
required: string[];
|
|
105
|
+
description?: string;
|
|
106
|
+
optional?: boolean;
|
|
107
|
+
nullable?: boolean;
|
|
108
|
+
};
|
|
109
|
+
output: import("../../index").BSBNumberType;
|
|
110
|
+
description?: string;
|
|
111
|
+
defaultTimeout?: number;
|
|
112
|
+
readonly __brand: "returnable";
|
|
113
|
+
};
|
|
114
|
+
readonly void: {
|
|
115
|
+
input: {
|
|
116
|
+
_bsb: "object";
|
|
117
|
+
properties: {};
|
|
118
|
+
required: string[];
|
|
119
|
+
description?: string;
|
|
120
|
+
optional?: boolean;
|
|
121
|
+
nullable?: boolean;
|
|
122
|
+
};
|
|
123
|
+
output: import("../../index").BSBType;
|
|
124
|
+
description?: string;
|
|
125
|
+
defaultTimeout?: number;
|
|
126
|
+
readonly __brand: "returnable";
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
readonly emitBroadcast: {
|
|
130
|
+
readonly 'benchmark.results': {
|
|
131
|
+
input: {
|
|
132
|
+
_bsb: "object";
|
|
133
|
+
properties: {
|
|
134
|
+
readonly testName: import("../../index").BSBStringType;
|
|
135
|
+
readonly results: import("../../index").BSBArrayType;
|
|
136
|
+
readonly timestamp: import("../../index").BSBStringType;
|
|
137
|
+
};
|
|
138
|
+
required: string[];
|
|
139
|
+
description?: string;
|
|
140
|
+
optional?: boolean;
|
|
141
|
+
nullable?: boolean;
|
|
142
|
+
};
|
|
143
|
+
description?: string;
|
|
144
|
+
readonly __brand: "broadcast";
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
readonly onBroadcast: {
|
|
148
|
+
readonly 'system.load': {
|
|
149
|
+
input: {
|
|
150
|
+
_bsb: "object";
|
|
151
|
+
properties: {
|
|
152
|
+
readonly cpuUsage: import("../../index").BSBNumberType;
|
|
153
|
+
readonly memoryUsage: import("../../index").BSBNumberType;
|
|
154
|
+
readonly timestamp: import("../../index").BSBStringType;
|
|
155
|
+
};
|
|
156
|
+
required: string[];
|
|
157
|
+
description?: string;
|
|
158
|
+
optional?: boolean;
|
|
159
|
+
nullable?: boolean;
|
|
160
|
+
};
|
|
161
|
+
description?: string;
|
|
162
|
+
readonly __brand: "broadcast";
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
export declare class Plugin extends BSBService<InstanceType<typeof Config>, typeof EventSchemas> {
|
|
167
|
+
static Config: import("../../index").BSBPluginConfigClass<z.ZodNull>;
|
|
168
|
+
static EventSchemas: {
|
|
169
|
+
readonly emitEvents: {
|
|
170
|
+
readonly 'benchmark.started': {
|
|
171
|
+
input: {
|
|
172
|
+
_bsb: "object";
|
|
173
|
+
properties: {
|
|
174
|
+
readonly name: import("../../index").BSBStringType;
|
|
175
|
+
readonly timestamp: import("../../index").BSBStringType;
|
|
176
|
+
};
|
|
177
|
+
required: string[];
|
|
178
|
+
description?: string;
|
|
179
|
+
optional?: boolean;
|
|
180
|
+
nullable?: boolean;
|
|
181
|
+
};
|
|
182
|
+
description?: string;
|
|
183
|
+
readonly __brand: "fire-and-forget";
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
readonly onEvents: {
|
|
187
|
+
readonly 'benchmark.trigger': {
|
|
188
|
+
input: {
|
|
189
|
+
_bsb: "object";
|
|
190
|
+
properties: {
|
|
191
|
+
readonly testName: import("../../index").BSBStringType & {
|
|
192
|
+
optional: true;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
required: string[];
|
|
196
|
+
description?: string;
|
|
197
|
+
optional?: boolean;
|
|
198
|
+
nullable?: boolean;
|
|
199
|
+
};
|
|
200
|
+
description?: string;
|
|
201
|
+
readonly __brand: "fire-and-forget";
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
readonly emitReturnableEvents: {
|
|
205
|
+
readonly 'performance.test': {
|
|
206
|
+
input: {
|
|
207
|
+
_bsb: "object";
|
|
208
|
+
properties: {
|
|
209
|
+
readonly iterations: import("../../index").BSBNumberType;
|
|
210
|
+
readonly warmup: import("../../index").BSBBooleanType;
|
|
211
|
+
};
|
|
212
|
+
required: string[];
|
|
213
|
+
description?: string;
|
|
214
|
+
optional?: boolean;
|
|
215
|
+
nullable?: boolean;
|
|
216
|
+
};
|
|
217
|
+
output: {
|
|
218
|
+
_bsb: "object";
|
|
219
|
+
properties: {
|
|
220
|
+
readonly duration: import("../../index").BSBNumberType;
|
|
221
|
+
readonly opsPerSecond: import("../../index").BSBNumberType;
|
|
222
|
+
};
|
|
223
|
+
required: string[];
|
|
224
|
+
description?: string;
|
|
225
|
+
optional?: boolean;
|
|
226
|
+
nullable?: boolean;
|
|
227
|
+
};
|
|
228
|
+
description?: string;
|
|
229
|
+
defaultTimeout?: number;
|
|
230
|
+
readonly __brand: "returnable";
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
readonly onReturnableEvents: {
|
|
234
|
+
readonly add: {
|
|
235
|
+
input: {
|
|
236
|
+
_bsb: "object";
|
|
237
|
+
properties: {
|
|
238
|
+
readonly a: import("../../index").BSBNumberType;
|
|
239
|
+
readonly b: import("../../index").BSBNumberType;
|
|
240
|
+
};
|
|
241
|
+
required: string[];
|
|
242
|
+
description?: string;
|
|
243
|
+
optional?: boolean;
|
|
244
|
+
nullable?: boolean;
|
|
245
|
+
};
|
|
246
|
+
output: import("../../index").BSBNumberType;
|
|
247
|
+
description?: string;
|
|
248
|
+
defaultTimeout?: number;
|
|
249
|
+
readonly __brand: "returnable";
|
|
250
|
+
};
|
|
251
|
+
readonly void: {
|
|
252
|
+
input: {
|
|
253
|
+
_bsb: "object";
|
|
254
|
+
properties: {};
|
|
255
|
+
required: string[];
|
|
256
|
+
description?: string;
|
|
257
|
+
optional?: boolean;
|
|
258
|
+
nullable?: boolean;
|
|
259
|
+
};
|
|
260
|
+
output: import("../../index").BSBType;
|
|
261
|
+
description?: string;
|
|
262
|
+
defaultTimeout?: number;
|
|
263
|
+
readonly __brand: "returnable";
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
readonly emitBroadcast: {
|
|
267
|
+
readonly 'benchmark.results': {
|
|
268
|
+
input: {
|
|
269
|
+
_bsb: "object";
|
|
270
|
+
properties: {
|
|
271
|
+
readonly testName: import("../../index").BSBStringType;
|
|
272
|
+
readonly results: import("../../index").BSBArrayType;
|
|
273
|
+
readonly timestamp: import("../../index").BSBStringType;
|
|
274
|
+
};
|
|
275
|
+
required: string[];
|
|
276
|
+
description?: string;
|
|
277
|
+
optional?: boolean;
|
|
278
|
+
nullable?: boolean;
|
|
279
|
+
};
|
|
280
|
+
description?: string;
|
|
281
|
+
readonly __brand: "broadcast";
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
readonly onBroadcast: {
|
|
285
|
+
readonly 'system.load': {
|
|
286
|
+
input: {
|
|
287
|
+
_bsb: "object";
|
|
288
|
+
properties: {
|
|
289
|
+
readonly cpuUsage: import("../../index").BSBNumberType;
|
|
290
|
+
readonly memoryUsage: import("../../index").BSBNumberType;
|
|
291
|
+
readonly timestamp: import("../../index").BSBStringType;
|
|
292
|
+
};
|
|
293
|
+
required: string[];
|
|
294
|
+
description?: string;
|
|
295
|
+
optional?: boolean;
|
|
296
|
+
nullable?: boolean;
|
|
297
|
+
};
|
|
298
|
+
description?: string;
|
|
299
|
+
readonly __brand: "broadcast";
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
initBeforePlugins?: string[] | undefined;
|
|
304
|
+
runBeforePlugins?: string[] | undefined;
|
|
305
|
+
runAfterPlugins?: string[] | undefined;
|
|
306
|
+
initAfterPlugins?: string[] | undefined;
|
|
307
|
+
private self;
|
|
308
|
+
dispose?(): void;
|
|
309
|
+
init(obs: Observable): Promise<void>;
|
|
310
|
+
constructor(config: BSBServiceConstructor<InstanceType<typeof Config>, typeof EventSchemas>);
|
|
311
|
+
run(obs: Observable): Promise<void>;
|
|
312
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
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.Plugin = exports.EventSchemas = exports.Config = void 0;
|
|
30
|
+
const index_1 = require("../../index");
|
|
31
|
+
const base_1 = require("../../base");
|
|
32
|
+
const schema_events_1 = require("../../interfaces/schema-events");
|
|
33
|
+
const zod_1 = require("zod");
|
|
34
|
+
const Benchmarkify = require("benchmarkify");
|
|
35
|
+
exports.Config = (0, base_1.createConfigSchema)({
|
|
36
|
+
name: 'service-benchmarkify',
|
|
37
|
+
description: 'Benchmarking service for performance testing',
|
|
38
|
+
version: '1.0.0',
|
|
39
|
+
image: '../docs/public/assets/images/bsb-logo.png',
|
|
40
|
+
tags: ['benchmark', 'performance', 'test'],
|
|
41
|
+
}, zod_1.z.null());
|
|
42
|
+
exports.EventSchemas = (0, schema_events_1.createEventSchemas)({
|
|
43
|
+
// Events this service emits (fire-and-forget, first listener receives)
|
|
44
|
+
emitEvents: {
|
|
45
|
+
'benchmark.started': (0, schema_events_1.createFireAndForgetEvent)(base_1.bsb.object({
|
|
46
|
+
name: base_1.bsb.string({ description: 'Benchmark name' }),
|
|
47
|
+
timestamp: base_1.bsb.datetime('Start timestamp')
|
|
48
|
+
}, 'Benchmark start parameters'), 'Benchmark test started')
|
|
49
|
+
},
|
|
50
|
+
// Events this service listens to (fire-and-forget)
|
|
51
|
+
onEvents: {
|
|
52
|
+
'benchmark.trigger': (0, schema_events_1.createFireAndForgetEvent)(base_1.bsb.object({
|
|
53
|
+
testName: (0, base_1.optional)(base_1.bsb.string({ description: 'Name of test to run' }))
|
|
54
|
+
}, 'Benchmark trigger parameters'), 'Trigger benchmark execution')
|
|
55
|
+
},
|
|
56
|
+
// Returnable events this service emits (requests from this service)
|
|
57
|
+
emitReturnableEvents: {
|
|
58
|
+
'performance.test': (0, schema_events_1.createReturnableEvent)(base_1.bsb.object({
|
|
59
|
+
iterations: base_1.bsb.number({ description: 'Number of iterations to run' }),
|
|
60
|
+
warmup: base_1.bsb.boolean('Whether to run warmup iterations')
|
|
61
|
+
}, 'Performance test parameters'), base_1.bsb.object({
|
|
62
|
+
duration: base_1.bsb.number({ description: 'Test duration in milliseconds' }),
|
|
63
|
+
opsPerSecond: base_1.bsb.number({ description: 'Operations per second' })
|
|
64
|
+
}, 'Performance test results'), 'Request performance test execution')
|
|
65
|
+
},
|
|
66
|
+
// Returnable events this service listens to (requests to this service)
|
|
67
|
+
onReturnableEvents: {
|
|
68
|
+
add: (0, schema_events_1.createReturnableEvent)(base_1.bsb.object({
|
|
69
|
+
a: base_1.bsb.number({ description: 'First number' }),
|
|
70
|
+
b: base_1.bsb.number({ description: 'Second number' })
|
|
71
|
+
}, 'Add input parameters'), base_1.bsb.number({ description: 'Sum of numbers' }), 'Add two numbers'),
|
|
72
|
+
void: (0, schema_events_1.createReturnableEvent)(base_1.bsb.object({}, 'Empty parameters'), base_1.bsb.void(), 'Void event for benchmarking')
|
|
73
|
+
},
|
|
74
|
+
// Broadcast events this service emits (all listeners receive)
|
|
75
|
+
emitBroadcast: {
|
|
76
|
+
'benchmark.results': (0, schema_events_1.createBroadcastEvent)(base_1.bsb.object({
|
|
77
|
+
testName: base_1.bsb.string({ description: 'Test name' }),
|
|
78
|
+
results: base_1.bsb.array(base_1.bsb.object({
|
|
79
|
+
operation: base_1.bsb.string({ description: 'Operation name' }),
|
|
80
|
+
opsPerSecond: base_1.bsb.number({ description: 'Operations per second' }),
|
|
81
|
+
duration: base_1.bsb.number({ description: 'Duration in milliseconds' })
|
|
82
|
+
}, 'Benchmark result entry'), { description: 'Array of benchmark results' }),
|
|
83
|
+
timestamp: base_1.bsb.datetime('Results timestamp')
|
|
84
|
+
}, 'Benchmark results parameters'), 'Broadcast benchmark results to all interested parties')
|
|
85
|
+
},
|
|
86
|
+
// Broadcast events this service listens to
|
|
87
|
+
onBroadcast: {
|
|
88
|
+
'system.load': (0, schema_events_1.createBroadcastEvent)(base_1.bsb.object({
|
|
89
|
+
cpuUsage: base_1.bsb.number({ description: 'CPU usage percentage' }),
|
|
90
|
+
memoryUsage: base_1.bsb.number({ description: 'Memory usage percentage' }),
|
|
91
|
+
timestamp: base_1.bsb.datetime('Load measurement timestamp')
|
|
92
|
+
}, 'System load parameters'), 'Listen for system load updates')
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
class Plugin extends base_1.BSBService {
|
|
96
|
+
static Config = exports.Config;
|
|
97
|
+
static EventSchemas = exports.EventSchemas;
|
|
98
|
+
// PLUGIN_CLIENT auto-generated from Config.metadata
|
|
99
|
+
initBeforePlugins;
|
|
100
|
+
runBeforePlugins;
|
|
101
|
+
runAfterPlugins;
|
|
102
|
+
initAfterPlugins;
|
|
103
|
+
self;
|
|
104
|
+
async init(obs) {
|
|
105
|
+
await this.events.onReturnableEvent('add', obs, async (obs, input) => {
|
|
106
|
+
return input.a + input.b;
|
|
107
|
+
});
|
|
108
|
+
await this.events.onReturnableEvent('void', obs, async (obs, input) => {
|
|
109
|
+
return;
|
|
110
|
+
});
|
|
111
|
+
await this.events.onEvent('benchmark.trigger', obs, async (obs, input) => {
|
|
112
|
+
obs.log.info("Benchmark triggered: {testName}", { testName: input.testName || 'default' });
|
|
113
|
+
return;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
;
|
|
117
|
+
constructor(config) {
|
|
118
|
+
super(config);
|
|
119
|
+
this.self = new index_1.ServiceClient(Plugin, this);
|
|
120
|
+
}
|
|
121
|
+
async run(obs) {
|
|
122
|
+
obs.log.info("Running service-benchmarkify");
|
|
123
|
+
let benchmark = new Benchmarkify("BSB benchmark").printHeader();
|
|
124
|
+
const bench = benchmark.createSuite("Call local actions");
|
|
125
|
+
const self = this;
|
|
126
|
+
bench.add("BSB:emitEventAndReturn:add", async (done) => {
|
|
127
|
+
await self.self.events.emitEventAndReturn('add', obs, { a: 5, b: 3 }, 1);
|
|
128
|
+
done();
|
|
129
|
+
});
|
|
130
|
+
bench.add("BSB:emitEventAndReturn:void", async (done) => {
|
|
131
|
+
await self.self.events.emitEventAndReturn('void', obs, {}, 1);
|
|
132
|
+
done();
|
|
133
|
+
});
|
|
134
|
+
await benchmark.run();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.Plugin = Plugin;
|
|
138
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/service-benchmarkify/index.ts"],"names":[],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