@bsb/tests 0.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.
Files changed (58) hide show
  1. package/README.md +7 -0
  2. package/bin/bsb-tests.cjs +376 -0
  3. package/docs/index.md +101 -0
  4. package/lib/index.d.ts +7 -0
  5. package/lib/index.js +24 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/mocks.d.ts +39 -0
  8. package/lib/mocks.js +191 -0
  9. package/lib/mocks.js.map +1 -0
  10. package/lib/plugins/config-default/index.d.ts +27 -0
  11. package/lib/plugins/config-default/index.js +172 -0
  12. package/lib/plugins/config-default/index.js.map +1 -0
  13. package/lib/plugins/events-default/index.d.ts +27 -0
  14. package/lib/plugins/events-default/index.js +143 -0
  15. package/lib/plugins/events-default/index.js.map +1 -0
  16. package/lib/plugins/logging-default/index.d.ts +27 -0
  17. package/lib/plugins/logging-default/index.js +390 -0
  18. package/lib/plugins/logging-default/index.js.map +1 -0
  19. package/lib/plugins/observable-default/index.d.ts +27 -0
  20. package/lib/plugins/observable-default/index.js +166 -0
  21. package/lib/plugins/observable-default/index.js.map +1 -0
  22. package/lib/runner/plugin-custom.d.ts +1 -0
  23. package/lib/runner/plugin-custom.js +119 -0
  24. package/lib/runner/plugin-custom.js.map +1 -0
  25. package/lib/runner/plugin-events.d.ts +1 -0
  26. package/lib/runner/plugin-events.js +37 -0
  27. package/lib/runner/plugin-events.js.map +1 -0
  28. package/lib/runner/plugin-observable.d.ts +1 -0
  29. package/lib/runner/plugin-observable.js +22 -0
  30. package/lib/runner/plugin-observable.js.map +1 -0
  31. package/lib/runner/setup.d.ts +1 -0
  32. package/lib/runner/setup.js +19 -0
  33. package/lib/runner/setup.js.map +1 -0
  34. package/lib/sb/plugins/events/broadcast.d.ts +30 -0
  35. package/lib/sb/plugins/events/broadcast.js +390 -0
  36. package/lib/sb/plugins/events/broadcast.js.map +1 -0
  37. package/lib/sb/plugins/events/emit.d.ts +30 -0
  38. package/lib/sb/plugins/events/emit.js +386 -0
  39. package/lib/sb/plugins/events/emit.js.map +1 -0
  40. package/lib/sb/plugins/events/emitAndReturn.d.ts +30 -0
  41. package/lib/sb/plugins/events/emitAndReturn.js +415 -0
  42. package/lib/sb/plugins/events/emitAndReturn.js.map +1 -0
  43. package/lib/sb/plugins/events/emitStreamAndReceiveStream.d.ts +30 -0
  44. package/lib/sb/plugins/events/emitStreamAndReceiveStream.js +331 -0
  45. package/lib/sb/plugins/events/emitStreamAndReceiveStream.js.map +1 -0
  46. package/lib/sb/plugins/events/index.d.ts +28 -0
  47. package/lib/sb/plugins/events/index.js +69 -0
  48. package/lib/sb/plugins/events/index.js.map +1 -0
  49. package/lib/sb/plugins/events/plugin.d.ts +0 -0
  50. package/lib/sb/plugins/events/plugin.js +2 -0
  51. package/lib/sb/plugins/events/plugin.js.map +1 -0
  52. package/lib/sb/plugins/observable/index.d.ts +28 -0
  53. package/lib/sb/plugins/observable/index.js +141 -0
  54. package/lib/sb/plugins/observable/index.js.map +1 -0
  55. package/lib/trace.d.ts +40 -0
  56. package/lib/trace.js +85 -0
  57. package/lib/trace.js.map +1 -0
  58. package/package.json +51 -0
package/lib/mocks.js ADDED
@@ -0,0 +1,191 @@
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.generateNullLogging = exports.getEventsConstructorConfig = exports.getConfigConstructorConfig = exports.getLoggingConstructorConfig = exports.getObservableConstructorConfig = exports.newMetrics = exports.newSBObservable = exports.MockSBPlugins = exports.MockSBEvents = exports.MockSBConfig = exports.MockSBObservable = void 0;
30
+ const base_1 = require("@bsb/base");
31
+ const events_1 = require("events");
32
+ const MockSBObservable = () => {
33
+ const observableBus = new events_1.EventEmitter();
34
+ observableBus.on('error', (...args) => { }); // Prevent unhandled error events
35
+ return {
36
+ observableBus,
37
+ isReady: true,
38
+ // Logging methods - emit to bus
39
+ debug: (plugin, trace, message, meta) => {
40
+ observableBus.emit('debug', plugin, trace, message, meta);
41
+ },
42
+ info: (plugin, trace, message, meta) => {
43
+ observableBus.emit('info', plugin, trace, message, meta);
44
+ },
45
+ warn: (plugin, trace, message, meta) => {
46
+ observableBus.emit('warn', plugin, trace, message, meta);
47
+ },
48
+ error: (plugin, trace, message, meta) => {
49
+ observableBus.emit('error', plugin, trace, message, meta);
50
+ },
51
+ // Metrics methods - emit to bus
52
+ createCounter: (timestamp, pluginName, name, description, help, labels) => {
53
+ observableBus.emit('createCounter', timestamp, pluginName, name, description, help, labels);
54
+ },
55
+ incrementCounter: (timestamp, pluginName, name, value, labels) => {
56
+ observableBus.emit('incrementCounter', timestamp, pluginName, name, value, labels);
57
+ },
58
+ createGauge: (timestamp, pluginName, name, description, help, labels) => {
59
+ observableBus.emit('createGauge', timestamp, pluginName, name, description, help, labels);
60
+ },
61
+ setGauge: (timestamp, pluginName, name, value, labels) => {
62
+ observableBus.emit('setGauge', timestamp, pluginName, name, value, labels);
63
+ },
64
+ createHistogram: (timestamp, pluginName, name, description, help, boundaries, labels) => {
65
+ observableBus.emit('createHistogram', timestamp, pluginName, name, description, help, boundaries, labels);
66
+ },
67
+ observeHistogram: (timestamp, pluginName, name, value, labels) => {
68
+ observableBus.emit('observeHistogram', timestamp, pluginName, name, value, labels);
69
+ },
70
+ // Span methods - emit to bus
71
+ startSpan: (timestamp, appId, pluginName, traceId, parentSpanId, spanId, name, attributes) => {
72
+ observableBus.emit('spanStart', { t: traceId, s: spanId }, pluginName, name, attributes);
73
+ },
74
+ endSpan: (timestamp, appId, pluginName, traceId, spanId, attributes) => {
75
+ observableBus.emit('spanEnd', { t: traceId, s: spanId }, pluginName, attributes);
76
+ },
77
+ errorSpan: (timestamp, appId, pluginName, traceId, spanId, error, attributes) => {
78
+ observableBus.emit('spanError', { t: traceId, s: spanId }, pluginName, error, attributes);
79
+ },
80
+ // Lifecycle methods
81
+ setupObservablePlugins: async () => { },
82
+ init: async () => { },
83
+ run: async () => { },
84
+ dispose: async () => { },
85
+ };
86
+ };
87
+ exports.MockSBObservable = MockSBObservable;
88
+ const MockSBConfig = () => {
89
+ const SB = {
90
+ getObservablePlugins: async (obs) => ({}),
91
+ getEventsPlugins: async (obs) => ({}),
92
+ getServicePlugins: async (obs) => ({}),
93
+ getPluginConfig: async (obs, pluginType, name) => null,
94
+ getServicePluginDefinition: async (obs, pluginName) => ({ name: pluginName, enabled: true }),
95
+ dispose: () => { },
96
+ setConfigPlugin: async () => {
97
+ return SB;
98
+ },
99
+ init: async () => { },
100
+ };
101
+ return SB;
102
+ };
103
+ exports.MockSBConfig = MockSBConfig;
104
+ const MockSBEvents = () => {
105
+ return {
106
+ eventsBus: new events_1.EventEmitter(),
107
+ dispose: () => { },
108
+ init: async () => { },
109
+ run: async () => { },
110
+ };
111
+ };
112
+ exports.MockSBEvents = MockSBEvents;
113
+ const MockSBPlugins = () => {
114
+ return {
115
+ getPlugins: async () => ({}),
116
+ dispose: () => { },
117
+ init: async () => { },
118
+ run: async () => { },
119
+ };
120
+ };
121
+ exports.MockSBPlugins = MockSBPlugins;
122
+ const newSBObservable = async () => {
123
+ const observable = (0, exports.MockSBObservable)();
124
+ return observable;
125
+ };
126
+ exports.newSBObservable = newSBObservable;
127
+ const newMetrics = async () => {
128
+ const observable = await (0, exports.newSBObservable)();
129
+ return new base_1.ObservableBackend("development", "test-app", "test-plugin", observable);
130
+ };
131
+ exports.newMetrics = newMetrics;
132
+ const getObservableConstructorConfig = (mode = "development") => {
133
+ return {
134
+ appId: "test-app",
135
+ packageCwd: process.cwd(),
136
+ pluginCwd: process.cwd(),
137
+ cwd: process.cwd(),
138
+ mode: mode,
139
+ pluginName: "test-plugin",
140
+ pluginVersion: "0.0.0",
141
+ config: undefined,
142
+ };
143
+ };
144
+ exports.getObservableConstructorConfig = getObservableConstructorConfig;
145
+ const getLoggingConstructorConfig = (mode = "development") => {
146
+ return {
147
+ appId: "test-app",
148
+ packageCwd: process.cwd(),
149
+ pluginCwd: process.cwd(),
150
+ cwd: process.cwd(),
151
+ mode: mode,
152
+ pluginName: "logging-default",
153
+ pluginVersion: "0.0.0",
154
+ config: undefined,
155
+ };
156
+ };
157
+ exports.getLoggingConstructorConfig = getLoggingConstructorConfig;
158
+ const getConfigConstructorConfig = (config) => {
159
+ return {
160
+ appId: "test-app",
161
+ packageCwd: process.cwd(),
162
+ pluginCwd: process.cwd(),
163
+ cwd: process.cwd(),
164
+ mode: "development",
165
+ pluginName: "config-default",
166
+ pluginVersion: "0.0.0",
167
+ sbObservable: (0, exports.MockSBObservable)(),
168
+ config: config,
169
+ };
170
+ };
171
+ exports.getConfigConstructorConfig = getConfigConstructorConfig;
172
+ const getEventsConstructorConfig = async (config) => {
173
+ return {
174
+ appId: "test-app",
175
+ packageCwd: process.cwd(),
176
+ pluginCwd: process.cwd(),
177
+ cwd: process.cwd(),
178
+ mode: "development",
179
+ pluginName: "test-plugin",
180
+ pluginVersion: "0.0.0",
181
+ sbObservable: (0, exports.MockSBObservable)(),
182
+ config: config,
183
+ };
184
+ };
185
+ exports.getEventsConstructorConfig = getEventsConstructorConfig;
186
+ const generateNullLogging = () => {
187
+ const sbObservable = (0, exports.MockSBObservable)();
188
+ return new base_1.ObservableBackend("development", "test-app", "test-plugin", sbObservable);
189
+ };
190
+ exports.generateNullLogging = generateNullLogging;
191
+ //# sourceMappingURL=mocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mocks.js","sourceRoot":"","sources":["../src/mocks.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,oCAAuK;AACvK,mCAAsC;AAM/B,MAAM,gBAAgB,GAAG,GAAiB,EAAE;IACjD,MAAM,aAAa,GAAG,IAAI,qBAAY,EAAE,CAAC;IACzC,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,iCAAiC;IAEpF,OAAO;QACL,aAAa;QACb,OAAO,EAAE,IAAI;QAEb,gCAAgC;QAChC,KAAK,EAAE,CAAC,MAAc,EAAE,KAAa,EAAE,OAAe,EAAE,IAAkB,EAAE,EAAE;YAC5E,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,EAAE,CAAC,MAAc,EAAE,KAAa,EAAE,OAAe,EAAE,IAAkB,EAAE,EAAE;YAC3E,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,EAAE,CAAC,MAAc,EAAE,KAAa,EAAE,OAAe,EAAE,IAAkB,EAAE,EAAE;YAC3E,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;QACD,KAAK,EAAE,CA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;AAHW,QAAA,mBAAmB,uBAG9B"}
@@ -0,0 +1,27 @@
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 {};
@@ -0,0 +1,172 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || (function () {
45
+ var ownKeys = function(o) {
46
+ ownKeys = Object.getOwnPropertyNames || function (o) {
47
+ var ar = [];
48
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
49
+ return ar;
50
+ };
51
+ return ownKeys(o);
52
+ };
53
+ return function (mod) {
54
+ if (mod && mod.__esModule) return mod;
55
+ var result = {};
56
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
57
+ __setModuleDefault(result, mod);
58
+ return result;
59
+ };
60
+ })();
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ const assert = __importStar(require("assert"));
66
+ const path_1 = __importDefault(require("path"));
67
+ const base_1 = require("@bsb/base");
68
+ const trace_1 = require("../../trace");
69
+ const mocks_1 = require("../../mocks");
70
+ const pluginModule = process.env.BSB_TEST_PLUGIN_MODULE;
71
+ if (!pluginModule) {
72
+ throw new Error("BSB_TEST_PLUGIN_MODULE is required for config-default tests");
73
+ }
74
+ const resolvedModule = path_1.default.resolve(pluginModule);
75
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
76
+ const mod = require(resolvedModule);
77
+ const Plugin = mod.Plugin || mod.default || mod;
78
+ const fixturePath = path_1.default.join(__dirname, "..", "..", "..", "fixtures", "sec-config.yaml");
79
+ describe("plugins/config-default", () => {
80
+ const obs = (0, trace_1.createTestObservable)();
81
+ it("should throw if config file is missing", () => {
82
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
83
+ BSB_PROFILE: "default",
84
+ BSB_CONFIG_FILE: "missing-config.yaml",
85
+ }));
86
+ assert.throws(() => plugin.init(obs));
87
+ });
88
+ it("should throw for unknown profile", () => {
89
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
90
+ BSB_PROFILE: "missing",
91
+ BSB_CONFIG_FILE: fixturePath,
92
+ }));
93
+ assert.throws(() => plugin.init(obs));
94
+ });
95
+ it("should load config and expose enabled plugins", async () => {
96
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
97
+ BSB_PROFILE: "default",
98
+ BSB_CONFIG_FILE: fixturePath,
99
+ }));
100
+ plugin.init(obs);
101
+ const observables = await plugin.getObservablePlugins();
102
+ assert.ok(observables["obs-enabled"]);
103
+ assert.ok(!observables["obs-disabled"]);
104
+ const events = await plugin.getEventsPlugins();
105
+ assert.ok(events["ev-enabled"]);
106
+ assert.ok(!events["ev-disabled"]);
107
+ const services = await plugin.getServicePlugins();
108
+ assert.ok(services["svc-enabled"]);
109
+ assert.ok(!services["svc-disabled"]);
110
+ });
111
+ it("should return plugin configs for correct types", async () => {
112
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
113
+ BSB_PROFILE: "default",
114
+ BSB_CONFIG_FILE: fixturePath,
115
+ }));
116
+ plugin.init(obs);
117
+ const evConfig = await plugin.getPluginConfig(obs, base_1.PluginTypes.events, "ev-enabled");
118
+ assert.deepEqual(evConfig, { foo: "bar" });
119
+ const obsConfig = await plugin.getPluginConfig(obs, base_1.PluginTypes.observable, "obs-enabled");
120
+ assert.deepEqual(obsConfig, { level: "info" });
121
+ const svcConfig = await plugin.getPluginConfig(obs, base_1.PluginTypes.service, "svc-enabled");
122
+ assert.deepEqual(svcConfig, { hello: "world" });
123
+ const cfgConfig = await plugin.getPluginConfig(obs, base_1.PluginTypes.config, "config-default");
124
+ assert.strictEqual(cfgConfig, null);
125
+ });
126
+ it("should resolve service plugin definition", async () => {
127
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
128
+ BSB_PROFILE: "default",
129
+ BSB_CONFIG_FILE: fixturePath,
130
+ }));
131
+ plugin.init(obs);
132
+ const def = await plugin.getServicePluginDefinition(obs, "service-default0");
133
+ assert.strictEqual(def.name, "svc-enabled");
134
+ assert.strictEqual(def.enabled, true);
135
+ });
136
+ it("should resolve disabled service plugin definition", async () => {
137
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
138
+ BSB_PROFILE: "default",
139
+ BSB_CONFIG_FILE: fixturePath,
140
+ }));
141
+ plugin.init(obs);
142
+ const def = await plugin.getServicePluginDefinition(obs, "service-only-disabled");
143
+ assert.strictEqual(def.name, "svc-only-disabled");
144
+ assert.strictEqual(def.enabled, false);
145
+ });
146
+ it("should throw when service plugin missing", async () => {
147
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
148
+ BSB_PROFILE: "default",
149
+ BSB_CONFIG_FILE: fixturePath,
150
+ }));
151
+ plugin.init(obs);
152
+ await assert.rejects(plugin.getServicePluginDefinition(obs, "missing-plugin"));
153
+ });
154
+ it("should list plugins", async () => {
155
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
156
+ BSB_PROFILE: "default",
157
+ BSB_CONFIG_FILE: fixturePath,
158
+ }));
159
+ plugin.init(obs);
160
+ const plugins = await plugin.getPlugins();
161
+ assert.ok(plugins.find((p) => p.name === "svc-enabled"));
162
+ });
163
+ it("dispose should clear config", () => {
164
+ const plugin = new Plugin((0, mocks_1.getConfigConstructorConfig)({
165
+ BSB_PROFILE: "default",
166
+ BSB_CONFIG_FILE: fixturePath,
167
+ }));
168
+ plugin.init(obs);
169
+ plugin.dispose();
170
+ });
171
+ });
172
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/config-default/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAiC;AACjC,gDAAwB;AACxB,oCAAwC;AACxC,uCAAmD;AACnD,uCAAyD;AAEzD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;AAExD,IAAI,CAAC,YAAY,EAAE,CAAC;IAClB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAClD,8DAA8D;AAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AACpC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC;AAEhD,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC;AAE1F,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,GAAG,GAAG,IAAA,4BAAoB,GAAE,CAAC;IAEnC,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAA,kCAA0B,EAAC;YACn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AAC,CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACnC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAA,kCAA0B,EAAC;YACnD,WAAW,EAAE,SAAS;YACtB,eAAe,EAAE,WAAW;SAC7B,CAAC,CAAC,CAAC;QACJ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEjB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1C,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAA,kCAA0B,EAAC;YACnD,WAAW,EAAE,SAAS;YACtB,eAAe,EAAE,WAAW;SAC7B,CAAC,CAAC,CAAC;QACJ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,MAAM,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,27 @@
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 {};
@@ -0,0 +1,143 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || (function () {
45
+ var ownKeys = function(o) {
46
+ ownKeys = Object.getOwnPropertyNames || function (o) {
47
+ var ar = [];
48
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
49
+ return ar;
50
+ };
51
+ return ownKeys(o);
52
+ };
53
+ return function (mod) {
54
+ if (mod && mod.__esModule) return mod;
55
+ var result = {};
56
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
57
+ __setModuleDefault(result, mod);
58
+ return result;
59
+ };
60
+ })();
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ const assert = __importStar(require("assert"));
66
+ const path_1 = __importDefault(require("path"));
67
+ const crypto_1 = require("crypto");
68
+ const index_1 = require("../../sb/plugins/events/index");
69
+ const trace_1 = require("../../trace");
70
+ const mocks_1 = require("../../mocks");
71
+ const pluginModule = process.env.BSB_TEST_PLUGIN_MODULE;
72
+ if (!pluginModule) {
73
+ throw new Error("BSB_TEST_PLUGIN_MODULE is required for events-default tests");
74
+ }
75
+ const resolvedModule = path_1.default.resolve(pluginModule);
76
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
77
+ const mod = require(resolvedModule);
78
+ const Plugin = mod.Plugin || mod.default || mod;
79
+ const pluginRoot = path_1.default.dirname(resolvedModule);
80
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
81
+ const emitDirect = require(path_1.default.join(pluginRoot, "events", "emit")).emit;
82
+ describe("plugins/events-default", () => {
83
+ describe("Events Emit", async () => {
84
+ const dummyObs = (0, trace_1.createTestObservable)();
85
+ it("_lastReceivedMessageIds should be empty on init", async () => {
86
+ const emit = new emitDirect((0, mocks_1.generateNullLogging)(), await (0, mocks_1.newMetrics)());
87
+ assert.equal(emit._lastReceivedMessageIds.length, 0);
88
+ });
89
+ it("_lastReceivedMessageIds should contain latest emit ID", async () => {
90
+ const emit = new emitDirect((0, mocks_1.generateNullLogging)(), await (0, mocks_1.newMetrics)());
91
+ await emit.onEvent(dummyObs, "b", "c", async () => { });
92
+ await emit.emitEvent(dummyObs, "b", "c", []);
93
+ assert.equal(emit._lastReceivedMessageIds.length, 1);
94
+ });
95
+ it("_lastReceivedMessageIds should call only once", async () => {
96
+ const emit = new emitDirect((0, mocks_1.generateNullLogging)(), await (0, mocks_1.newMetrics)());
97
+ const testID = (0, crypto_1.randomUUID)();
98
+ let called = 0;
99
+ await emit.onEvent(dummyObs, "b", "c", async () => {
100
+ called++;
101
+ });
102
+ emit.emit(`b-c`, dummyObs, {
103
+ msgID: testID,
104
+ data: [],
105
+ });
106
+ assert.equal(called, 1);
107
+ });
108
+ it("_lastReceivedMessageIds should call only once, per id", async () => {
109
+ const emit = new emitDirect((0, mocks_1.generateNullLogging)(), await (0, mocks_1.newMetrics)());
110
+ const testID1 = (0, crypto_1.randomUUID)();
111
+ const testID2 = (0, crypto_1.randomUUID)();
112
+ let called = 0;
113
+ await emit.onEvent(dummyObs, "b", "c", async () => {
114
+ called++;
115
+ });
116
+ emit.emit(`b-c`, dummyObs, {
117
+ msgID: testID1,
118
+ data: [],
119
+ });
120
+ emit.emit(`b-c`, dummyObs, {
121
+ msgID: testID2,
122
+ data: [],
123
+ });
124
+ assert.equal(called, 2);
125
+ });
126
+ it("_lastReceivedMessageIds should cycle ids > 50", async () => {
127
+ const emit = new emitDirect((0, mocks_1.generateNullLogging)(), await (0, mocks_1.newMetrics)());
128
+ const testIDs = "."
129
+ .repeat(100)
130
+ .split("")
131
+ .map(() => (0, crypto_1.randomUUID)());
132
+ await emit.onEvent(dummyObs, "b", "c", async () => { });
133
+ for (const emitID of testIDs)
134
+ emit.emit(`b-c`, dummyObs, {
135
+ msgID: emitID,
136
+ data: [],
137
+ });
138
+ assert.equal(emit._lastReceivedMessageIds.length, 51);
139
+ });
140
+ });
141
+ (0, index_1.RunEventsPluginTests)(Plugin);
142
+ });
143
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/events-default/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAiC;AACjC,gDAAwB;AACxB,mCAAoC;AACpC,yDAAqE;AACrE,uCAAmD;AACnD,uCAA8D;AAE9D,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;AAExD,IAAI,CAAC,YAAY,EAAE,CAAC;IAClB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAClD,8DAA8D;AAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AACpC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC;AAEhD,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AAChD,8DAA8D;AAC9D,MAAM,UAAU,GAAG,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAEzE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,QAAQ,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QACjC,MAAM,QAAQ,GAAG,IAAA,4BAAoB,GAAE,CAAC;QAExC,EAAE,CAAC,iDAAiD,E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,EAAE,GAAE,CAAC,CAAC,CAAC;YACvD,KAAK,MAAM,MAAM,IAAI,OAAO;gBAC1B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE;oBACzB,KAAK,EAAE,MAAM;oBACb,IAAI,EAAE,EAAE;iBACT,CAAC,CAAC;YACL,MAAM,CAAC,KAAK,CAAE,IAAY,CAAC,uBAAuB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,4BAAoB,EAAC,MAAM,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,27 @@
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 {};