@bsb/base 9.0.4 → 9.1.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/lib/base/BSBConfig.d.ts +3 -3
- package/lib/base/BSBConfig.js +9 -14
- package/lib/base/BSBConfig.js.map +1 -1
- package/lib/base/BSBEvents.d.ts +3 -3
- package/lib/base/BSBEvents.js +12 -17
- package/lib/base/BSBEvents.js.map +1 -1
- package/lib/base/BSBObservable.d.ts +4 -4
- package/lib/base/BSBObservable.js +17 -22
- package/lib/base/BSBObservable.js.map +1 -1
- package/lib/base/BSBService.d.ts +7 -8
- package/lib/base/BSBService.js +17 -22
- package/lib/base/BSBService.js.map +1 -1
- package/lib/base/BSBServiceClient.d.ts +4 -4
- package/lib/base/BSBServiceClient.js +12 -18
- package/lib/base/BSBServiceClient.js.map +1 -1
- package/lib/base/EventValidator.d.ts +16 -17
- package/lib/base/EventValidator.js +13 -34
- package/lib/base/EventValidator.js.map +1 -1
- package/lib/base/ObservableBackend.d.ts +2 -2
- package/lib/base/ObservableBackend.js +21 -26
- package/lib/base/ObservableBackend.js.map +1 -1
- package/lib/base/PluginConfig.d.ts +9 -7
- package/lib/base/PluginConfig.js +4 -11
- package/lib/base/PluginConfig.js.map +1 -1
- package/lib/base/PluginEvents.d.ts +4 -4
- package/lib/base/PluginEvents.js +4 -9
- package/lib/base/PluginEvents.js.map +1 -1
- package/lib/base/PluginObservable.d.ts +13 -14
- package/lib/base/PluginObservable.js +4 -8
- package/lib/base/PluginObservable.js.map +1 -1
- package/lib/base/ResourceContext.d.ts +1 -1
- package/lib/base/ResourceContext.js +1 -5
- package/lib/base/ResourceContext.js.map +1 -1
- package/lib/base/base.d.ts +3 -3
- package/lib/base/base.js +10 -18
- package/lib/base/base.js.map +1 -1
- package/lib/base/errorMessages.d.ts +1 -1
- package/lib/base/errorMessages.js +6 -11
- package/lib/base/errorMessages.js.map +1 -1
- package/lib/base/factory.d.ts +1 -1
- package/lib/base/factory.js +19 -22
- package/lib/base/factory.js.map +1 -1
- package/lib/base/functions.d.ts +19 -14
- package/lib/base/functions.js +19 -26
- package/lib/base/functions.js.map +1 -1
- package/lib/base/index.d.ts +18 -18
- package/lib/base/index.js +18 -37
- package/lib/base/index.js.map +1 -1
- package/lib/base/logFormatter.d.ts +1 -1
- package/lib/base/logFormatter.js +10 -14
- package/lib/base/logFormatter.js.map +1 -1
- package/lib/base/module-runtime.d.ts +3 -0
- package/lib/base/module-runtime.js +15 -0
- package/lib/base/module-runtime.js.map +1 -0
- package/lib/base/tools.d.ts +1 -1
- package/lib/base/tools.js +9 -13
- package/lib/base/tools.js.map +1 -1
- package/lib/cli.js +13 -12
- package/lib/cli.js.map +1 -1
- package/lib/dev.js +22 -11
- package/lib/dev.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -19
- package/lib/index.js.map +1 -1
- package/lib/interfaces/events.d.ts +2 -2
- package/lib/interfaces/events.js +1 -4
- package/lib/interfaces/events.js.map +1 -1
- package/lib/interfaces/index.d.ts +13 -12
- package/lib/interfaces/index.js +12 -32
- package/lib/interfaces/index.js.map +1 -1
- package/lib/interfaces/logging.d.ts +3 -3
- package/lib/interfaces/logging.js +1 -4
- package/lib/interfaces/logging.js.map +1 -1
- package/lib/interfaces/metrics.d.ts +2 -2
- package/lib/interfaces/metrics.js +1 -5
- package/lib/interfaces/metrics.js.map +1 -1
- package/lib/interfaces/observable-types.d.ts +1 -1
- package/lib/interfaces/observable-types.js +1 -4
- package/lib/interfaces/observable-types.js.map +1 -1
- package/lib/interfaces/observable.d.ts +8 -9
- package/lib/interfaces/observable.js +1 -2
- package/lib/interfaces/observable.js.map +1 -1
- package/lib/interfaces/options.d.ts +15 -6
- package/lib/interfaces/options.js +2 -5
- package/lib/interfaces/options.js.map +1 -1
- package/lib/interfaces/plugins.d.ts +2 -2
- package/lib/interfaces/plugins.js +1 -4
- package/lib/interfaces/plugins.js.map +1 -1
- package/lib/interfaces/result.js +8 -18
- package/lib/interfaces/result.js.map +1 -1
- package/lib/interfaces/schema-events.d.ts +5 -20
- package/lib/interfaces/schema-events.js +7 -14
- package/lib/interfaces/schema-events.js.map +1 -1
- package/lib/interfaces/schema-types.d.ts +32 -352
- package/lib/interfaces/schema-types.js +77 -512
- package/lib/interfaces/schema-types.js.map +1 -1
- package/lib/interfaces/service.d.ts +1 -1
- package/lib/interfaces/service.js +1 -2
- package/lib/interfaces/service.js.map +1 -1
- package/lib/interfaces/tools.js +8 -13
- package/lib/interfaces/tools.js.map +1 -1
- package/lib/plugins/config-default/index.d.ts +16 -14
- package/lib/plugins/config-default/index.js +66 -50
- package/lib/plugins/config-default/index.js.map +1 -1
- package/lib/plugins/config-default/interfaces.d.ts +1 -1
- package/lib/plugins/config-default/interfaces.js +1 -2
- package/lib/plugins/config-default/interfaces.js.map +1 -1
- package/lib/plugins/events-default/events/broadcast.d.ts +1 -1
- package/lib/plugins/events-default/events/broadcast.js +2 -6
- package/lib/plugins/events-default/events/broadcast.js.map +1 -1
- package/lib/plugins/events-default/events/emit.d.ts +1 -1
- package/lib/plugins/events-default/events/emit.js +4 -8
- package/lib/plugins/events-default/events/emit.js.map +1 -1
- package/lib/plugins/events-default/events/emitAndReturn.d.ts +1 -1
- package/lib/plugins/events-default/events/emitAndReturn.js +4 -8
- package/lib/plugins/events-default/events/emitAndReturn.js.map +1 -1
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.d.ts +1 -1
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js +8 -12
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js.map +1 -1
- package/lib/plugins/events-default/events/index.d.ts +4 -4
- package/lib/plugins/events-default/events/index.js +4 -11
- package/lib/plugins/events-default/events/index.js.map +1 -1
- package/lib/plugins/events-default/index.d.ts +5 -5
- package/lib/plugins/events-default/index.js +10 -15
- package/lib/plugins/events-default/index.js.map +1 -1
- package/lib/plugins/observable-default/index.d.ts +5 -5
- package/lib/plugins/observable-default/index.js +8 -13
- package/lib/plugins/observable-default/index.js.map +1 -1
- package/lib/plugins/service-benchmarkify/index.d.ts +196 -0
- package/lib/plugins/service-benchmarkify/index.js +133 -0
- package/lib/plugins/service-benchmarkify/index.js.map +1 -0
- package/lib/plugins/service-default0/index.d.ts +189 -0
- package/lib/plugins/service-default0/index.js +113 -0
- package/lib/plugins/service-default0/index.js.map +1 -0
- package/lib/{tests/sb/plugins/events/emitStreamAndReceiveStream.d.ts → plugins/service-default1/client.d.ts} +16 -4
- package/lib/plugins/service-default1/client.js +66 -0
- package/lib/plugins/service-default1/client.js.map +1 -0
- package/lib/plugins/service-default1/index.d.ts +202 -0
- package/lib/plugins/service-default1/index.js +174 -0
- package/lib/plugins/service-default1/index.js.map +1 -0
- package/lib/plugins/service-default2/index.d.ts +217 -0
- package/lib/plugins/service-default2/index.js +132 -0
- package/lib/plugins/service-default2/index.js.map +1 -0
- package/lib/plugins/service-default3/index.d.ts +91 -0
- package/lib/plugins/service-default3/index.js +83 -0
- package/lib/plugins/service-default3/index.js.map +1 -0
- package/lib/plugins/service-default4/index.d.ts +67 -0
- package/lib/{tests.js → plugins/service-default4/index.js} +31 -17
- package/lib/plugins/service-default4/index.js.map +1 -0
- package/lib/schemas/config-default.json +24 -16
- package/lib/schemas/config-default.plugin.json +24 -16
- package/lib/schemas/events-default.json +1 -1
- package/lib/schemas/events-default.plugin.json +1 -1
- package/lib/schemas/observable-default.json +15 -5
- package/lib/schemas/observable-default.plugin.json +15 -5
- package/lib/schemas/service-benchmarkify.json +314 -0
- package/lib/schemas/service-default0.json +279 -0
- package/lib/schemas/service-default1.json +327 -0
- package/lib/schemas/service-default2.json +355 -0
- package/lib/schemas/service-default3.json +107 -0
- package/lib/schemas/service-default4.json +63 -0
- package/lib/scripts/bsb-client-cli.js +9 -9
- package/lib/scripts/bsb-client-cli.js.map +1 -1
- package/lib/scripts/bsb-plugin-cli.js +93 -64
- package/lib/scripts/bsb-plugin-cli.js.map +1 -1
- package/lib/scripts/export-schemas.js +15 -12
- package/lib/scripts/export-schemas.js.map +1 -1
- package/lib/scripts/extract-schemas-from-source.js +73 -56
- package/lib/scripts/extract-schemas-from-source.js.map +1 -1
- package/lib/scripts/generate-client-types.d.ts +1 -16
- package/lib/scripts/generate-client-types.js +120 -313
- package/lib/scripts/generate-client-types.js.map +1 -1
- package/lib/scripts/generate-plugin-json.js +9 -10
- package/lib/scripts/generate-plugin-json.js.map +1 -1
- package/lib/serviceBase/config.d.ts +4 -4
- package/lib/serviceBase/config.js +33 -35
- package/lib/serviceBase/config.js.map +1 -1
- package/lib/serviceBase/events.d.ts +6 -6
- package/lib/serviceBase/events.js +42 -44
- package/lib/serviceBase/events.js.map +1 -1
- package/lib/serviceBase/index.d.ts +7 -7
- package/lib/serviceBase/index.js +7 -23
- package/lib/serviceBase/index.js.map +1 -1
- package/lib/serviceBase/observable.d.ts +5 -5
- package/lib/serviceBase/observable.js +21 -25
- package/lib/serviceBase/observable.js.map +1 -1
- package/lib/serviceBase/plugins.d.ts +3 -3
- package/lib/serviceBase/plugins.js +48 -54
- package/lib/serviceBase/plugins.js.map +1 -1
- package/lib/serviceBase/serviceBase.d.ts +3 -3
- package/lib/serviceBase/serviceBase.js +40 -44
- package/lib/serviceBase/serviceBase.js.map +1 -1
- package/lib/serviceBase/services.d.ts +6 -6
- package/lib/serviceBase/services.js +21 -22
- package/lib/serviceBase/services.js.map +1 -1
- package/package.json +18 -11
- package/lib/tests/mocks.d.ts +0 -37
- package/lib/tests/mocks.js +0 -164
- package/lib/tests/mocks.js.map +0 -1
- package/lib/tests/sb/plugins/events/broadcast.d.ts +0 -30
- package/lib/tests/sb/plugins/events/broadcast.js +0 -357
- package/lib/tests/sb/plugins/events/broadcast.js.map +0 -1
- package/lib/tests/sb/plugins/events/emit.d.ts +0 -30
- package/lib/tests/sb/plugins/events/emit.js +0 -353
- package/lib/tests/sb/plugins/events/emit.js.map +0 -1
- package/lib/tests/sb/plugins/events/emitAndReturn.d.ts +0 -30
- package/lib/tests/sb/plugins/events/emitAndReturn.js +0 -382
- package/lib/tests/sb/plugins/events/emitAndReturn.js.map +0 -1
- package/lib/tests/sb/plugins/events/emitStreamAndReceiveStream.js +0 -298
- package/lib/tests/sb/plugins/events/emitStreamAndReceiveStream.js.map +0 -1
- package/lib/tests/sb/plugins/events/index.d.ts +0 -28
- package/lib/tests/sb/plugins/events/index.js +0 -69
- package/lib/tests/sb/plugins/events/index.js.map +0 -1
- package/lib/tests/trace.d.ts +0 -41
- package/lib/tests/trace.js +0 -85
- package/lib/tests/trace.js.map +0 -1
- package/lib/tests.d.ts +0 -27
- package/lib/tests.js.map +0 -1
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* You should have received a copy of the GNU Affero General Public License
|
|
20
20
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
21
21
|
*/
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
22
|
+
import { IPluginLogging, DTrace, BSBType } from "../interfaces/index.js";
|
|
23
|
+
import type { ParseResult } from '@anyvali/js';
|
|
24
24
|
export interface ValidationResult<T = any> {
|
|
25
25
|
success: boolean;
|
|
26
26
|
data?: T;
|
|
@@ -35,7 +35,7 @@ export interface EventValidationConfig {
|
|
|
35
35
|
performanceThreshold?: number;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Utility class for validating event data using
|
|
38
|
+
* Utility class for validating event data using AnyVali schemas.
|
|
39
39
|
* Provides performance monitoring and configurable validation behavior.
|
|
40
40
|
* @group Validation
|
|
41
41
|
* @category Tools
|
|
@@ -61,31 +61,24 @@ export declare class EventValidator {
|
|
|
61
61
|
* Validate input data for an event.
|
|
62
62
|
* @param eventName - Name of the event being validated
|
|
63
63
|
* @param data - Data to validate
|
|
64
|
-
* @param schema -
|
|
64
|
+
* @param schema - AnyVali schema to validate against
|
|
65
65
|
* @param trace - Trace for logging context
|
|
66
66
|
* @param eventConfig - Override configuration for this validation
|
|
67
67
|
* @returns Validation result with parsed data or error
|
|
68
68
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/EventValidator.html#validateInput | API: EventValidator#validateInput}
|
|
69
69
|
*/
|
|
70
|
-
validateInput<T = unknown>(eventName: string, data: unknown, schema: BSBType
|
|
70
|
+
validateInput<T = unknown>(eventName: string, data: unknown, schema: BSBType, trace: DTrace, eventConfig?: Partial<EventValidationConfig>): ValidationResult<T>;
|
|
71
71
|
/**
|
|
72
72
|
* Validate output/return data for an event.
|
|
73
73
|
* @param eventName - Name of the event being validated
|
|
74
74
|
* @param data - Data to validate
|
|
75
|
-
* @param schema -
|
|
75
|
+
* @param schema - AnyVali schema to validate against
|
|
76
76
|
* @param trace - Trace for logging context
|
|
77
77
|
* @param eventConfig - Override configuration for this validation
|
|
78
78
|
* @returns Validation result with parsed data or error
|
|
79
79
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/EventValidator.html#validateOutput | API: EventValidator#validateOutput}
|
|
80
80
|
*/
|
|
81
|
-
validateOutput<T = unknown>(eventName: string, data: unknown, schema: BSBType
|
|
82
|
-
/**
|
|
83
|
-
* Check if a schema is a BSBType or a Zod schema.
|
|
84
|
-
* @param schema - Schema to check
|
|
85
|
-
* @returns True if schema is a BSBType
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
private isBSBType;
|
|
81
|
+
validateOutput<T = unknown>(eventName: string, data: unknown, schema: BSBType, trace: DTrace, eventConfig?: Partial<EventValidationConfig>): ValidationResult<T>;
|
|
89
82
|
/**
|
|
90
83
|
* Validate event data using schemas from a validation schema map.
|
|
91
84
|
* @param eventName - Name of the event to validate
|
|
@@ -116,18 +109,24 @@ export declare class EventValidator {
|
|
|
116
109
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ValidationError.html | API: ValidationError}
|
|
117
110
|
*/
|
|
118
111
|
export declare class ValidationError extends Error {
|
|
119
|
-
readonly
|
|
112
|
+
readonly issues: ParseResult<unknown> extends {
|
|
113
|
+
success: false;
|
|
114
|
+
issues: infer TIssues;
|
|
115
|
+
} ? TIssues : unknown;
|
|
120
116
|
readonly eventName: string;
|
|
121
117
|
readonly direction: 'input' | 'output';
|
|
122
118
|
/**
|
|
123
119
|
* Create a new validation error.
|
|
124
120
|
* @param message - Error message
|
|
125
|
-
* @param
|
|
121
|
+
* @param issues - The underlying AnyVali validation issues
|
|
126
122
|
* @param eventName - Name of the event that failed validation
|
|
127
123
|
* @param direction - Whether the failure was on 'input' or 'output'
|
|
128
124
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ValidationError.html#constructor | API: ValidationError#constructor}
|
|
129
125
|
*/
|
|
130
|
-
constructor(message: string,
|
|
126
|
+
constructor(message: string, issues: ParseResult<unknown> extends {
|
|
127
|
+
success: false;
|
|
128
|
+
issues: infer TIssues;
|
|
129
|
+
} ? TIssues : unknown, eventName: string, direction: 'input' | 'output');
|
|
131
130
|
/**
|
|
132
131
|
* Get a formatted string representation of the validation errors.
|
|
133
132
|
* @returns Formatted error details
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
3
|
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
@@ -20,9 +19,6 @@
|
|
|
20
19
|
* You should have received a copy of the GNU Affero General Public License
|
|
21
20
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
22
21
|
*/
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.ValidationError = exports.EventValidator = void 0;
|
|
25
|
-
const interfaces_1 = require("../interfaces");
|
|
26
22
|
const DEFAULT_VALIDATION_CONFIG = {
|
|
27
23
|
enabled: true,
|
|
28
24
|
logValidationErrors: true,
|
|
@@ -32,13 +28,13 @@ const DEFAULT_VALIDATION_CONFIG = {
|
|
|
32
28
|
performanceThreshold: 100
|
|
33
29
|
};
|
|
34
30
|
/**
|
|
35
|
-
* Utility class for validating event data using
|
|
31
|
+
* Utility class for validating event data using AnyVali schemas.
|
|
36
32
|
* Provides performance monitoring and configurable validation behavior.
|
|
37
33
|
* @group Validation
|
|
38
34
|
* @category Tools
|
|
39
35
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/EventValidator.html | API: EventValidator}
|
|
40
36
|
*/
|
|
41
|
-
class EventValidator {
|
|
37
|
+
export class EventValidator {
|
|
42
38
|
config;
|
|
43
39
|
logger;
|
|
44
40
|
/**
|
|
@@ -63,40 +59,27 @@ class EventValidator {
|
|
|
63
59
|
* Validate input data for an event.
|
|
64
60
|
* @param eventName - Name of the event being validated
|
|
65
61
|
* @param data - Data to validate
|
|
66
|
-
* @param schema -
|
|
62
|
+
* @param schema - AnyVali schema to validate against
|
|
67
63
|
* @param trace - Trace for logging context
|
|
68
64
|
* @param eventConfig - Override configuration for this validation
|
|
69
65
|
* @returns Validation result with parsed data or error
|
|
70
66
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/EventValidator.html#validateInput | API: EventValidator#validateInput}
|
|
71
67
|
*/
|
|
72
68
|
validateInput(eventName, data, schema, trace, eventConfig) {
|
|
73
|
-
|
|
74
|
-
const zodSchema = this.isBSBType(schema) ? (0, interfaces_1.bsbToZod)(schema) : schema;
|
|
75
|
-
return this.performValidation(eventName, data, zodSchema, trace, 'input', eventConfig);
|
|
69
|
+
return this.performValidation(eventName, data, schema, trace, 'input', eventConfig);
|
|
76
70
|
}
|
|
77
71
|
/**
|
|
78
72
|
* Validate output/return data for an event.
|
|
79
73
|
* @param eventName - Name of the event being validated
|
|
80
74
|
* @param data - Data to validate
|
|
81
|
-
* @param schema -
|
|
75
|
+
* @param schema - AnyVali schema to validate against
|
|
82
76
|
* @param trace - Trace for logging context
|
|
83
77
|
* @param eventConfig - Override configuration for this validation
|
|
84
78
|
* @returns Validation result with parsed data or error
|
|
85
79
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/EventValidator.html#validateOutput | API: EventValidator#validateOutput}
|
|
86
80
|
*/
|
|
87
81
|
validateOutput(eventName, data, schema, trace, eventConfig) {
|
|
88
|
-
|
|
89
|
-
const zodSchema = this.isBSBType(schema) ? (0, interfaces_1.bsbToZod)(schema) : schema;
|
|
90
|
-
return this.performValidation(eventName, data, zodSchema, trace, 'output', eventConfig);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Check if a schema is a BSBType or a Zod schema.
|
|
94
|
-
* @param schema - Schema to check
|
|
95
|
-
* @returns True if schema is a BSBType
|
|
96
|
-
* @private
|
|
97
|
-
*/
|
|
98
|
-
isBSBType(schema) {
|
|
99
|
-
return schema && typeof schema === 'object' && '_bsb' in schema;
|
|
82
|
+
return this.performValidation(eventName, data, schema, trace, 'output', eventConfig);
|
|
100
83
|
}
|
|
101
84
|
/**
|
|
102
85
|
* Validate event data using schemas from a validation schema map.
|
|
@@ -151,13 +134,11 @@ class EventValidator {
|
|
|
151
134
|
};
|
|
152
135
|
}
|
|
153
136
|
catch (error) {
|
|
154
|
-
const zodError = error;
|
|
155
137
|
if (config.logValidationErrors && this.logger) {
|
|
156
|
-
const errorMsg = `Event validation failed for '${eventName}' ${direction}: ${
|
|
138
|
+
const errorMsg = `Event validation failed for '${eventName}' ${direction}: ${error instanceof Error ? error.message : String(error)}`;
|
|
157
139
|
this.logger.error(trace, errorMsg);
|
|
158
140
|
}
|
|
159
141
|
if (config.throwOnValidationFailure) {
|
|
160
|
-
// Throw the original Zod error
|
|
161
142
|
throw error;
|
|
162
143
|
}
|
|
163
144
|
return {
|
|
@@ -167,28 +148,27 @@ class EventValidator {
|
|
|
167
148
|
}
|
|
168
149
|
}
|
|
169
150
|
}
|
|
170
|
-
exports.EventValidator = EventValidator;
|
|
171
151
|
/**
|
|
172
152
|
* Custom error class for validation failures.
|
|
173
153
|
* @group Validation
|
|
174
154
|
* @category Errors
|
|
175
155
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ValidationError.html | API: ValidationError}
|
|
176
156
|
*/
|
|
177
|
-
class ValidationError extends Error {
|
|
178
|
-
|
|
157
|
+
export class ValidationError extends Error {
|
|
158
|
+
issues;
|
|
179
159
|
eventName;
|
|
180
160
|
direction;
|
|
181
161
|
/**
|
|
182
162
|
* Create a new validation error.
|
|
183
163
|
* @param message - Error message
|
|
184
|
-
* @param
|
|
164
|
+
* @param issues - The underlying AnyVali validation issues
|
|
185
165
|
* @param eventName - Name of the event that failed validation
|
|
186
166
|
* @param direction - Whether the failure was on 'input' or 'output'
|
|
187
167
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ValidationError.html#constructor | API: ValidationError#constructor}
|
|
188
168
|
*/
|
|
189
|
-
constructor(message,
|
|
169
|
+
constructor(message, issues, eventName, direction) {
|
|
190
170
|
super(message);
|
|
191
|
-
this.
|
|
171
|
+
this.issues = issues;
|
|
192
172
|
this.eventName = eventName;
|
|
193
173
|
this.direction = direction;
|
|
194
174
|
this.name = 'ValidationError';
|
|
@@ -203,8 +183,7 @@ class ValidationError extends Error {
|
|
|
203
183
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/ValidationError.html#getFormattedErrors | API: ValidationError#getFormattedErrors}
|
|
204
184
|
*/
|
|
205
185
|
getFormattedErrors() {
|
|
206
|
-
return this.
|
|
186
|
+
return this.issues.map((err) => `${err.path.join('.')}: ${err.message}`).join('; ');
|
|
207
187
|
}
|
|
208
188
|
}
|
|
209
|
-
exports.ValidationError = ValidationError;
|
|
210
189
|
//# sourceMappingURL=EventValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventValidator.js","sourceRoot":"","sources":["../../src/base/EventValidator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EventValidator.js","sourceRoot":"","sources":["../../src/base/EventValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAoBH,MAAM,yBAAyB,GAA0B;IACvD,OAAO,EAAE,IAAI;IACb,mBAAmB,EAAE,IAAI;IACzB,wBAAwB,EAAE,IAAI;IAC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AC;IACH,CAAC;IAED;;;;OAIG;IACI,kBAAkB;QACvB,OAAQ,IAAI,CAAC,MAAgB,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,EAAE,CAC7C,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,OAAO,EAAE,CACxC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;CACF"}
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
25
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
26
|
*/
|
|
27
|
-
import { Counter, DEBUG_MODE, DTrace, Gauge, Histogram, SmartLogMeta, Timer, Trace } from "../interfaces";
|
|
28
|
-
import { BSBError } from "./errorMessages";
|
|
27
|
+
import { Counter, DEBUG_MODE, DTrace, Gauge, Histogram, SmartLogMeta, Timer, Trace } from "../interfaces/index.js";
|
|
28
|
+
import { BSBError } from "./errorMessages.js";
|
|
29
29
|
/**
|
|
30
30
|
* Observable bus interface - unified for both logging and metrics
|
|
31
31
|
* @hidden
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
3
|
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
@@ -25,19 +24,18 @@
|
|
|
25
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
26
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const base_1 = require("./base");
|
|
27
|
+
import { v7 as uuidv7 } from "uuid";
|
|
28
|
+
import { randomFillSync } from "node:crypto";
|
|
29
|
+
import { Tools } from './tools.js';
|
|
30
|
+
import { createFakeDTrace } from "../interfaces/index.js";
|
|
31
|
+
import { BSBError } from "./errorMessages.js";
|
|
32
|
+
import { MS_PER_NS, NS_PER_SEC } from "./base.js";
|
|
35
33
|
/**
|
|
36
34
|
* Generate OpenTelemetry-compliant trace ID (32 hex chars lowercase)
|
|
37
35
|
* @returns 32-character hexadecimal trace ID
|
|
38
36
|
*/
|
|
39
37
|
function generateTraceId() {
|
|
40
|
-
return (
|
|
38
|
+
return uuidv7().replace(/-/g, '').toLowerCase();
|
|
41
39
|
}
|
|
42
40
|
/**
|
|
43
41
|
* Generate OpenTelemetry-compliant span ID (16 hex chars lowercase)
|
|
@@ -51,9 +49,7 @@ function generateSpanId() {
|
|
|
51
49
|
crypto.getRandomValues(bytes);
|
|
52
50
|
}
|
|
53
51
|
else {
|
|
54
|
-
|
|
55
|
-
const nodeCrypto = require('crypto');
|
|
56
|
-
nodeCrypto.randomFillSync(bytes);
|
|
52
|
+
randomFillSync(bytes);
|
|
57
53
|
}
|
|
58
54
|
return Array.from(bytes)
|
|
59
55
|
.map(b => b.toString(16).padStart(2, '0'))
|
|
@@ -81,7 +77,7 @@ function normalizeAttributes(attributes) {
|
|
|
81
77
|
* @hidden
|
|
82
78
|
*/
|
|
83
79
|
function internalTrace(span) {
|
|
84
|
-
return
|
|
80
|
+
return createFakeDTrace("base/ObservableBackend", span);
|
|
85
81
|
}
|
|
86
82
|
/**
|
|
87
83
|
* Represents a single span in a distributed trace
|
|
@@ -230,7 +226,7 @@ class ObservableBackendTrace {
|
|
|
230
226
|
* );
|
|
231
227
|
* ```
|
|
232
228
|
*/
|
|
233
|
-
class ObservableBackend {
|
|
229
|
+
export class ObservableBackend {
|
|
234
230
|
bus;
|
|
235
231
|
pluginName;
|
|
236
232
|
appId;
|
|
@@ -305,16 +301,16 @@ class ObservableBackend {
|
|
|
305
301
|
this.bus.warn(this.pluginName, trace, message, ...meta);
|
|
306
302
|
}
|
|
307
303
|
error(traceOrError, message, ...meta) {
|
|
308
|
-
if (traceOrError instanceof
|
|
304
|
+
if (traceOrError instanceof BSBError) {
|
|
309
305
|
if (traceOrError.raw !== null) {
|
|
310
306
|
this.bus.error(this.pluginName, traceOrError.raw.trace, traceOrError.raw.message, traceOrError.raw.meta);
|
|
311
307
|
return;
|
|
312
308
|
}
|
|
313
|
-
this.error(
|
|
309
|
+
this.error(createFakeDTrace('base/ObservableBackend', 'error'), traceOrError.message + ' - error ');
|
|
314
310
|
return;
|
|
315
311
|
}
|
|
316
|
-
if (!
|
|
317
|
-
this.error(
|
|
312
|
+
if (!Tools.isObject(traceOrError) || !Tools.isString(traceOrError.t) || !Tools.isString(traceOrError.s)) {
|
|
313
|
+
this.error(createFakeDTrace('base/ObservableBackend', 'errorType'), JSON.stringify(traceOrError));
|
|
318
314
|
return;
|
|
319
315
|
}
|
|
320
316
|
this.bus.error(this.pluginName, traceOrError, message, ...meta);
|
|
@@ -345,7 +341,7 @@ class ObservableBackend {
|
|
|
345
341
|
*/
|
|
346
342
|
createCounter(name, description, help, labels) {
|
|
347
343
|
if (!this.bus.isReady) {
|
|
348
|
-
throw new
|
|
344
|
+
throw new BSBError(internalTrace("createCounter"), "Metrics not ready!");
|
|
349
345
|
}
|
|
350
346
|
this.bus.createCounter(Date.now(), this.pluginName, name, description, help, labels);
|
|
351
347
|
return {
|
|
@@ -380,7 +376,7 @@ class ObservableBackend {
|
|
|
380
376
|
*/
|
|
381
377
|
createGauge(name, description, help, labels) {
|
|
382
378
|
if (!this.bus.isReady) {
|
|
383
|
-
throw new
|
|
379
|
+
throw new BSBError(internalTrace("createGauge"), "Metrics not ready!");
|
|
384
380
|
}
|
|
385
381
|
this.bus.createGauge(Date.now(), this.pluginName, name, description, help, labels);
|
|
386
382
|
return {
|
|
@@ -424,7 +420,7 @@ class ObservableBackend {
|
|
|
424
420
|
*/
|
|
425
421
|
createHistogram(name, description, help, boundaries, labels) {
|
|
426
422
|
if (!this.bus.isReady) {
|
|
427
|
-
throw new
|
|
423
|
+
throw new BSBError(internalTrace("createHistogram"), "Metrics not ready!");
|
|
428
424
|
}
|
|
429
425
|
this.bus.createHistogram(Date.now(), this.pluginName, name, description, help, boundaries, labels);
|
|
430
426
|
return {
|
|
@@ -454,7 +450,7 @@ class ObservableBackend {
|
|
|
454
450
|
*/
|
|
455
451
|
createTrace(name, attributes) {
|
|
456
452
|
if (!this.bus.isReady) {
|
|
457
|
-
throw new
|
|
453
|
+
throw new BSBError(internalTrace("createTrace"), "Metrics not ready!");
|
|
458
454
|
}
|
|
459
455
|
return new ObservableBackendTrace(this.bus, this.appId, this.pluginName, null, { name, attributes });
|
|
460
456
|
}
|
|
@@ -479,7 +475,7 @@ class ObservableBackend {
|
|
|
479
475
|
*/
|
|
480
476
|
createSpan(trace, name, attributes) {
|
|
481
477
|
if (!this.bus.isReady) {
|
|
482
|
-
throw new
|
|
478
|
+
throw new BSBError(internalTrace("createSpan"), "Metrics not ready!");
|
|
483
479
|
}
|
|
484
480
|
return new ObservableBackendTrace(this.bus, this.appId, this.pluginName, trace, { name, attributes });
|
|
485
481
|
}
|
|
@@ -500,16 +496,15 @@ class ObservableBackend {
|
|
|
500
496
|
*/
|
|
501
497
|
createTimer() {
|
|
502
498
|
if (!this.bus.isReady) {
|
|
503
|
-
throw new
|
|
499
|
+
throw new BSBError(internalTrace("createTimer"), "Metrics not ready!");
|
|
504
500
|
}
|
|
505
501
|
const start = process.hrtime();
|
|
506
502
|
return {
|
|
507
503
|
stop: () => {
|
|
508
504
|
const diff = process.hrtime(start);
|
|
509
|
-
return (diff[0] *
|
|
505
|
+
return (diff[0] * NS_PER_SEC + diff[1]) * MS_PER_NS;
|
|
510
506
|
}
|
|
511
507
|
};
|
|
512
508
|
}
|
|
513
509
|
}
|
|
514
|
-
exports.ObservableBackend = ObservableBackend;
|
|
515
510
|
//# sourceMappingURL=ObservableBackend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableBackend.js","sourceRoot":"","sources":["../../src/base/ObservableBackend.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"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AAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACtB,MAAM,IAAI,QAAQ,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,oBAAoB,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/B,OAAO;YACL,IAAI,EAAE,GAAG,EAAE;gBACT,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;YACtD,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
25
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
26
|
*/
|
|
27
|
-
import {
|
|
27
|
+
import type { BaseSchema, Infer } from '@anyvali/js';
|
|
28
28
|
/**
|
|
29
29
|
* The definition of the config with zod validation
|
|
30
30
|
* @example
|
|
@@ -32,7 +32,7 @@ import { z } from "zod";
|
|
|
32
32
|
* a: z.string(),
|
|
33
33
|
* });
|
|
34
34
|
*/
|
|
35
|
-
export type BSBPluginConfigType =
|
|
35
|
+
export type BSBPluginConfigType = BaseSchema<any, any> | undefined;
|
|
36
36
|
export type BSBPluginConfigDefinition = BSBPluginConfig<BSBPluginConfigType>;
|
|
37
37
|
export type BSBPluginConfigClass<TSchema extends BSBPluginConfigType = BSBPluginConfigType> = {
|
|
38
38
|
new (cwd: string, packageCwd: string, pluginCwd: string, pluginName: string): BSBPluginConfig<TSchema>;
|
|
@@ -59,7 +59,7 @@ export type BSBPluginConfigClass<TSchema extends BSBPluginConfigType = BSBPlugin
|
|
|
59
59
|
* }
|
|
60
60
|
* return existingConfig;
|
|
61
61
|
*/
|
|
62
|
-
export type BSBConfigMigration<T extends BSBPluginConfigType> = (versionFrom: string | null, versionTo: string, existingConfig?:
|
|
62
|
+
export type BSBConfigMigration<T extends BSBPluginConfigType> = (versionFrom: string | null, versionTo: string, existingConfig?: Infer<Exclude<T, undefined>>) => Promise<Infer<Exclude<T, undefined>>>;
|
|
63
63
|
/**
|
|
64
64
|
* Plugin metadata information for enhanced discoverability and documentation.
|
|
65
65
|
* Used for auto-generating PLUGIN_CLIENT and bsb-plugin.json.
|
|
@@ -72,10 +72,10 @@ export interface BSBPluginMetadata {
|
|
|
72
72
|
name: string;
|
|
73
73
|
/** Short description of what the plugin does */
|
|
74
74
|
description: string;
|
|
75
|
-
/** Semantic version (e.g., "1.0.0") */
|
|
76
|
-
version?: string;
|
|
77
75
|
/** Author name or organization */
|
|
78
76
|
author?: string;
|
|
77
|
+
/** Plugin version */
|
|
78
|
+
version?: string;
|
|
79
79
|
/** License type (e.g., "MIT", "AGPL-3.0") */
|
|
80
80
|
license?: string;
|
|
81
81
|
/** Documentation URL */
|
|
@@ -88,6 +88,8 @@ export interface BSBPluginMetadata {
|
|
|
88
88
|
documentation?: string[];
|
|
89
89
|
/** Relative path to plugin image file (PNG recommended) */
|
|
90
90
|
image?: string;
|
|
91
|
+
/** Logical plugin category */
|
|
92
|
+
category?: 'service' | 'observable' | 'events' | 'config' | 'other';
|
|
91
93
|
/** This plugin must initialize before these plugins */
|
|
92
94
|
initBeforePlugins?: string[];
|
|
93
95
|
/** This plugin must initialize after these plugins */
|
|
@@ -97,7 +99,7 @@ export interface BSBPluginMetadata {
|
|
|
97
99
|
/** This plugin must run after these plugins */
|
|
98
100
|
runAfterPlugins?: string[];
|
|
99
101
|
}
|
|
100
|
-
export type BSBConfigDefintionReference<T extends BSBPluginConfigType, AS = undefined> = [T] extends [undefined] ? AS :
|
|
102
|
+
export type BSBConfigDefintionReference<T extends BSBPluginConfigType, AS = undefined> = [T] extends [undefined] ? AS : Infer<Exclude<T, undefined>>;
|
|
101
103
|
export type BSBReferenceConfigType = BSBPluginConfigType | null;
|
|
102
104
|
export type BSBReferencePluginConfigType = BSBPluginConfig<BSBPluginConfigType> | null;
|
|
103
105
|
export type BSBReferenceConfigDefinition<ReferencedConfig extends BSBReferenceConfigType> = ReferencedConfig extends null ? null : ReferencedConfig;
|
|
@@ -183,7 +185,7 @@ export declare class BSBPluginConfigRef extends BSBPluginConfig<any> {
|
|
|
183
185
|
*
|
|
184
186
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/createConfigSchema.html | API: createConfigSchema}
|
|
185
187
|
*/
|
|
186
|
-
export declare function createConfigSchema<const TSchema extends
|
|
188
|
+
export declare function createConfigSchema<const TSchema extends BaseSchema<any, any>>(metadata: BSBPluginMetadata, schema: TSchema): BSBPluginConfigClass<TSchema>;
|
|
187
189
|
export declare function createConfigSchema(metadata: BSBPluginMetadata): BSBPluginConfigClass<undefined>;
|
|
188
190
|
/**
|
|
189
191
|
* Extract category from plugin name based on directory prefix.
|
package/lib/base/PluginConfig.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
3
|
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
@@ -25,10 +24,6 @@
|
|
|
25
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
26
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
26
|
*/
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.BSBPluginConfigRef = exports.BSBPluginConfig = void 0;
|
|
30
|
-
exports.createConfigSchema = createConfigSchema;
|
|
31
|
-
exports.getCategoryFromPluginName = getCategoryFromPluginName;
|
|
32
27
|
/**
|
|
33
28
|
* Base class for plugin configuration.
|
|
34
29
|
*
|
|
@@ -40,7 +35,7 @@ exports.getCategoryFromPluginName = getCategoryFromPluginName;
|
|
|
40
35
|
*
|
|
41
36
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/BSBPluginConfig.html | API: BSBPluginConfig}
|
|
42
37
|
*/
|
|
43
|
-
class BSBPluginConfig {
|
|
38
|
+
export class BSBPluginConfig {
|
|
44
39
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
40
|
constructor(cwd, packageCwd, pluginCwd, pluginName) {
|
|
46
41
|
}
|
|
@@ -56,16 +51,14 @@ class BSBPluginConfig {
|
|
|
56
51
|
*/
|
|
57
52
|
metadata;
|
|
58
53
|
}
|
|
59
|
-
exports.BSBPluginConfig = BSBPluginConfig;
|
|
60
54
|
/**
|
|
61
55
|
* @hidden
|
|
62
56
|
* DO NOT REFERENCE/USE THIS CLASS - IT IS AN INTERNALLY REFERENCED CLASS
|
|
63
57
|
*/
|
|
64
|
-
class BSBPluginConfigRef extends BSBPluginConfig {
|
|
58
|
+
export class BSBPluginConfigRef extends BSBPluginConfig {
|
|
65
59
|
validationSchema = {};
|
|
66
60
|
}
|
|
67
|
-
|
|
68
|
-
function createConfigSchema(metadata, schema) {
|
|
61
|
+
export function createConfigSchema(metadata, schema) {
|
|
69
62
|
const ConfigClass = class extends BSBPluginConfig {
|
|
70
63
|
validationSchema = schema;
|
|
71
64
|
static metadata = metadata;
|
|
@@ -82,7 +75,7 @@ function createConfigSchema(metadata, schema) {
|
|
|
82
75
|
* - events-rabbitmq -> events
|
|
83
76
|
* - config-default -> config
|
|
84
77
|
*/
|
|
85
|
-
function getCategoryFromPluginName(pluginName) {
|
|
78
|
+
export function getCategoryFromPluginName(pluginName) {
|
|
86
79
|
if (pluginName.startsWith('service-'))
|
|
87
80
|
return 'service';
|
|
88
81
|
if (pluginName.startsWith('observable-'))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginConfig.js","sourceRoot":"","sources":["../../src/base/PluginConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PluginConfig.js","sourceRoot":"","sources":["../../src/base/PluginConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AA8GH;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,eAAe;IAGnC,6DAA6D;IAC7D,YAAY,GAAW,EAAE,UAAkB,EAAE,SAAiB,EAAE,UAAkB;IAClF,CAAC;IAID;;;OAGG;IACH,MAAM,CAAU,QAAQ,CAAoB;IAE5C;;;;OAIG;IACI,QAAQ,CAAqB;CACrC;AAED;;;GAGG;AACH,MAAM,OAAO,kBACT,SAAQ,eAAoB;IACvB,gBAAgB,GAAG,EAAE,CAAC;CAC9B;AA2DD,MAAM,UAAU,kBAAkB,CAChC,QAA2B,EAC3B,MAAgB;IAEhB,MAAM,WAAW,GAAG,KAAM,SAAQ,eAAwB;QACxD,gBAAgB,GAAG,MAAiB,CAAC;QACrC,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC;QAEpC,8DAA8D;QACrD,QAAQ,GAAG,QAAQ,CAAC;KAC9B,CAAC;IACF,OAAO,WAA4C,CAAC;AACtD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC1D,IAAI,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,SAAS,CAAC;IACxD,IAAI,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAAO,YAAY,CAAC;IAC9D,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,QAAQ,CAAC;IACtD,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,QAAQ,CAAC;IACtD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
26
|
*/
|
|
27
27
|
import { Readable } from "node:stream";
|
|
28
|
-
import { DEBUG_MODE, DTrace, BSBEventSchemas, EventInputType, EventOutputType, Observable, IPluginObservable } from "../interfaces";
|
|
29
|
-
import { SBEvents } from "../serviceBase";
|
|
30
|
-
import { BSBService } from "./BSBService";
|
|
31
|
-
import { BSBServiceClient } from "./BSBServiceClient";
|
|
28
|
+
import { DEBUG_MODE, DTrace, BSBEventSchemas, EventInputType, EventOutputType, Observable, IPluginObservable } from "../interfaces/index.js";
|
|
29
|
+
import { SBEvents } from "../serviceBase/index.js";
|
|
30
|
+
import { BSBService } from "./BSBService.js";
|
|
31
|
+
import { BSBServiceClient } from "./BSBServiceClient.js";
|
|
32
32
|
/**
|
|
33
33
|
* Plugin event schema definition.
|
|
34
34
|
* Define event schemas once and get both TypeScript types and runtime validation.
|
package/lib/base/PluginEvents.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
3
|
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
@@ -25,16 +24,14 @@
|
|
|
25
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
26
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
|
-
exports.BSBPluginEventsRef = exports.PluginEvents = void 0;
|
|
30
|
-
const EventValidator_1 = require("./EventValidator");
|
|
27
|
+
import { EventValidator } from "./EventValidator.js";
|
|
31
28
|
/**
|
|
32
29
|
* Schema-first plugin events handler with automatic validation and object parameters.
|
|
33
30
|
* @group Events
|
|
34
31
|
* @category Plugin Development Tools
|
|
35
32
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html | API: PluginEvents}
|
|
36
33
|
*/
|
|
37
|
-
class PluginEvents {
|
|
34
|
+
export class PluginEvents {
|
|
38
35
|
events;
|
|
39
36
|
service;
|
|
40
37
|
cachedPluginName;
|
|
@@ -45,7 +42,7 @@ class PluginEvents {
|
|
|
45
42
|
this.service = context;
|
|
46
43
|
this.cachedPluginName = context.pluginName;
|
|
47
44
|
this.eventSchemas = eventSchemas;
|
|
48
|
-
this.validator = new
|
|
45
|
+
this.validator = new EventValidator({}, observableBackend);
|
|
49
46
|
}
|
|
50
47
|
/**
|
|
51
48
|
* Helper to extract DTrace from Observable | DTrace
|
|
@@ -251,12 +248,11 @@ class PluginEvents {
|
|
|
251
248
|
return this.events.sendStream(trace, this.cachedPluginName, eventName, streamId, stream);
|
|
252
249
|
}
|
|
253
250
|
}
|
|
254
|
-
exports.PluginEvents = PluginEvents;
|
|
255
251
|
/**
|
|
256
252
|
* @hidden
|
|
257
253
|
* DO NOT REFERENCE/USE THIS CLASS - IT IS AN INTERNALLY REFERENCED CLASS
|
|
258
254
|
*/
|
|
259
|
-
class BSBPluginEventsRef {
|
|
255
|
+
export class BSBPluginEventsRef {
|
|
260
256
|
emitEvents = {};
|
|
261
257
|
onEvents = {};
|
|
262
258
|
emitReturnableEvents = {};
|
|
@@ -264,5 +260,4 @@ class BSBPluginEventsRef {
|
|
|
264
260
|
emitBroadcast = {};
|
|
265
261
|
onBroadcast = {};
|
|
266
262
|
}
|
|
267
|
-
exports.BSBPluginEventsRef = BSBPluginEventsRef;
|
|
268
263
|
//# sourceMappingURL=PluginEvents.js.map
|