@bsb/base 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +665 -0
- package/LICENSE.commercial +32 -0
- package/README.md +263 -0
- package/bsb-plugin.json +62 -0
- package/lib/base/BSBConfig.d.ts +130 -0
- package/lib/base/BSBConfig.js +95 -0
- package/lib/base/BSBConfig.js.map +1 -0
- package/lib/base/BSBEvents.d.ts +207 -0
- package/lib/base/BSBEvents.js +101 -0
- package/lib/base/BSBEvents.js.map +1 -0
- package/lib/base/BSBObservable.d.ts +178 -0
- package/lib/base/BSBObservable.js +91 -0
- package/lib/base/BSBObservable.js.map +1 -0
- package/lib/base/BSBService.d.ts +277 -0
- package/lib/base/BSBService.js +366 -0
- package/lib/base/BSBService.js.map +1 -0
- package/lib/base/BSBServiceClient.d.ts +135 -0
- package/lib/base/BSBServiceClient.js +130 -0
- package/lib/base/BSBServiceClient.js.map +1 -0
- package/lib/base/EventValidator.d.ts +137 -0
- package/lib/base/EventValidator.js +210 -0
- package/lib/base/EventValidator.js.map +1 -0
- package/lib/base/ObservableBackend.d.ts +281 -0
- package/lib/base/ObservableBackend.js +515 -0
- package/lib/base/ObservableBackend.js.map +1 -0
- package/lib/base/PluginConfig.d.ts +196 -0
- package/lib/base/PluginConfig.js +96 -0
- package/lib/base/PluginConfig.js.map +1 -0
- package/lib/base/PluginEvents.d.ts +140 -0
- package/lib/base/PluginEvents.js +268 -0
- package/lib/base/PluginEvents.js.map +1 -0
- package/lib/base/PluginObservable.d.ts +196 -0
- package/lib/base/PluginObservable.js +250 -0
- package/lib/base/PluginObservable.js.map +1 -0
- package/lib/base/ResourceContext.d.ts +70 -0
- package/lib/base/ResourceContext.js +54 -0
- package/lib/base/ResourceContext.js.map +1 -0
- package/lib/base/base.d.ts +264 -0
- package/lib/base/base.js +182 -0
- package/lib/base/base.js.map +1 -0
- package/lib/base/errorMessages.d.ts +56 -0
- package/lib/base/errorMessages.js +70 -0
- package/lib/base/errorMessages.js.map +1 -0
- package/lib/base/factory.d.ts +58 -0
- package/lib/base/factory.js +167 -0
- package/lib/base/factory.js.map +1 -0
- package/lib/base/functions.d.ts +117 -0
- package/lib/base/functions.js +152 -0
- package/lib/base/functions.js.map +1 -0
- package/lib/base/index.d.ts +44 -0
- package/lib/base/index.js +64 -0
- package/lib/base/index.js.map +1 -0
- package/lib/base/logFormatter.d.ts +50 -0
- package/lib/base/logFormatter.js +105 -0
- package/lib/base/logFormatter.js.map +1 -0
- package/lib/base/tools.d.ts +316 -0
- package/lib/base/tools.js +666 -0
- package/lib/base/tools.js.map +1 -0
- package/lib/cli.d.ts +28 -0
- package/lib/cli.js +254 -0
- package/lib/cli.js.map +1 -0
- package/lib/dev.d.ts +27 -0
- package/lib/dev.js +200 -0
- package/lib/dev.js.map +1 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.js +49 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces/events.d.ts +67 -0
- package/lib/interfaces/events.js +44 -0
- package/lib/interfaces/events.js.map +1 -0
- package/lib/interfaces/index.d.ts +38 -0
- package/lib/interfaces/index.js +59 -0
- package/lib/interfaces/index.js.map +1 -0
- package/lib/interfaces/logging.d.ts +106 -0
- package/lib/interfaces/logging.js +39 -0
- package/lib/interfaces/logging.js.map +1 -0
- package/lib/interfaces/metrics.d.ts +365 -0
- package/lib/interfaces/metrics.js +46 -0
- package/lib/interfaces/metrics.js.map +1 -0
- package/lib/interfaces/observable-types.d.ts +63 -0
- package/lib/interfaces/observable-types.js +49 -0
- package/lib/interfaces/observable-types.js.map +1 -0
- package/lib/interfaces/observable.d.ts +297 -0
- package/lib/interfaces/observable.js +29 -0
- package/lib/interfaces/observable.js.map +1 -0
- package/lib/interfaces/options.d.ts +164 -0
- package/lib/interfaces/options.js +56 -0
- package/lib/interfaces/options.js.map +1 -0
- package/lib/interfaces/plugins.d.ts +143 -0
- package/lib/interfaces/plugins.js +45 -0
- package/lib/interfaces/plugins.js.map +1 -0
- package/lib/interfaces/result.d.ts +129 -0
- package/lib/interfaces/result.js +162 -0
- package/lib/interfaces/result.js.map +1 -0
- package/lib/interfaces/schema-events.d.ts +378 -0
- package/lib/interfaces/schema-events.js +247 -0
- package/lib/interfaces/schema-events.js.map +1 -0
- package/lib/interfaces/schema-types.d.ts +407 -0
- package/lib/interfaces/schema-types.js +581 -0
- package/lib/interfaces/schema-types.js.map +1 -0
- package/lib/interfaces/service.d.ts +48 -0
- package/lib/interfaces/service.js +29 -0
- package/lib/interfaces/service.js.map +1 -0
- package/lib/interfaces/tools.d.ts +65 -0
- package/lib/interfaces/tools.js +50 -0
- package/lib/interfaces/tools.js.map +1 -0
- package/lib/plugins/config-default/index.d.ts +59 -0
- package/lib/plugins/config-default/index.js +197 -0
- package/lib/plugins/config-default/index.js.map +1 -0
- package/lib/plugins/config-default/interfaces.d.ts +92 -0
- package/lib/plugins/config-default/interfaces.js +36 -0
- package/lib/plugins/config-default/interfaces.js.map +1 -0
- package/lib/plugins/events-default/events/broadcast.d.ts +36 -0
- package/lib/plugins/events-default/events/broadcast.js +85 -0
- package/lib/plugins/events-default/events/broadcast.js.map +1 -0
- package/lib/plugins/events-default/events/emit.d.ts +38 -0
- package/lib/plugins/events-default/events/emit.js +104 -0
- package/lib/plugins/events-default/events/emit.js.map +1 -0
- package/lib/plugins/events-default/events/emitAndReturn.d.ts +36 -0
- package/lib/plugins/events-default/events/emitAndReturn.js +100 -0
- package/lib/plugins/events-default/events/emitAndReturn.js.map +1 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.d.ts +38 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js +134 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js.map +1 -0
- package/lib/plugins/events-default/events/index.d.ts +30 -0
- package/lib/plugins/events-default/events/index.js +38 -0
- package/lib/plugins/events-default/events/index.js.map +1 -0
- package/lib/plugins/events-default/index.d.ts +57 -0
- package/lib/plugins/events-default/index.js +86 -0
- package/lib/plugins/events-default/index.js.map +1 -0
- package/lib/plugins/observable-default/index.d.ts +43 -0
- package/lib/plugins/observable-default/index.js +151 -0
- package/lib/plugins/observable-default/index.js.map +1 -0
- package/lib/schemas/config-default.json +34 -0
- package/lib/schemas/config-default.plugin.json +36 -0
- package/lib/schemas/events-default.json +18 -0
- package/lib/schemas/events-default.plugin.json +17 -0
- package/lib/schemas/observable-default.json +33 -0
- package/lib/schemas/observable-default.plugin.json +24 -0
- package/lib/scripts/bsb-client-cli.d.ts +21 -0
- package/lib/scripts/bsb-client-cli.js +701 -0
- package/lib/scripts/bsb-client-cli.js.map +1 -0
- package/lib/scripts/bsb-plugin-cli.d.ts +15 -0
- package/lib/scripts/bsb-plugin-cli.js +547 -0
- package/lib/scripts/bsb-plugin-cli.js.map +1 -0
- package/lib/scripts/export-schemas.d.ts +17 -0
- package/lib/scripts/export-schemas.js +205 -0
- package/lib/scripts/export-schemas.js.map +1 -0
- package/lib/scripts/extract-schemas-from-source.d.ts +23 -0
- package/lib/scripts/extract-schemas-from-source.js +604 -0
- package/lib/scripts/extract-schemas-from-source.js.map +1 -0
- package/lib/scripts/generate-client-types.d.ts +22 -0
- package/lib/scripts/generate-client-types.js +537 -0
- package/lib/scripts/generate-client-types.js.map +1 -0
- package/lib/scripts/generate-plugin-json.d.ts +17 -0
- package/lib/scripts/generate-plugin-json.js +219 -0
- package/lib/scripts/generate-plugin-json.js.map +1 -0
- package/lib/serviceBase/config.d.ts +83 -0
- package/lib/serviceBase/config.js +236 -0
- package/lib/serviceBase/config.js.map +1 -0
- package/lib/serviceBase/events.d.ts +91 -0
- package/lib/serviceBase/events.js +519 -0
- package/lib/serviceBase/events.js.map +1 -0
- package/lib/serviceBase/index.d.ts +33 -0
- package/lib/serviceBase/index.js +50 -0
- package/lib/serviceBase/index.js.map +1 -0
- package/lib/serviceBase/observable.d.ts +249 -0
- package/lib/serviceBase/observable.js +551 -0
- package/lib/serviceBase/observable.js.map +1 -0
- package/lib/serviceBase/plugins.d.ts +48 -0
- package/lib/serviceBase/plugins.js +184 -0
- package/lib/serviceBase/plugins.js.map +1 -0
- package/lib/serviceBase/serviceBase.d.ts +228 -0
- package/lib/serviceBase/serviceBase.js +420 -0
- package/lib/serviceBase/serviceBase.js.map +1 -0
- package/lib/serviceBase/services.d.ts +63 -0
- package/lib/serviceBase/services.js +346 -0
- package/lib/serviceBase/services.js.map +1 -0
- package/lib/tests.d.ts +27 -0
- package/lib/tests.js +44 -0
- package/lib/tests.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,196 @@
|
|
|
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 { z } from "zod";
|
|
28
|
+
/**
|
|
29
|
+
* The definition of the config with zod validation
|
|
30
|
+
* @example
|
|
31
|
+
* const configDefinition = z.object({
|
|
32
|
+
* a: z.string(),
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
export type BSBPluginConfigType = z.ZodTypeAny | undefined;
|
|
36
|
+
export type BSBPluginConfigDefinition = BSBPluginConfig<BSBPluginConfigType>;
|
|
37
|
+
export type BSBPluginConfigClass<TSchema extends BSBPluginConfigType = BSBPluginConfigType> = {
|
|
38
|
+
new (cwd: string, packageCwd: string, pluginCwd: string, pluginName: string): BSBPluginConfig<TSchema>;
|
|
39
|
+
metadata: BSBPluginMetadata;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Config migration handler, allows for config migrations when the plugin version changes or a new plugin setup is done
|
|
43
|
+
* @example simple version change and basic setup
|
|
44
|
+
* const configMigration = async (versionFrom: string | null, versionTo: string, existingConfig?: z.infer<BSBConfigDefinition>) => {
|
|
45
|
+
* if (versionFrom === null) {
|
|
46
|
+
* return {
|
|
47
|
+
* a: "a",
|
|
48
|
+
* };
|
|
49
|
+
* }
|
|
50
|
+
* return {
|
|
51
|
+
* a: "b",
|
|
52
|
+
* };
|
|
53
|
+
* @example basic setup and no version change handling
|
|
54
|
+
* const configMigration = async (versionFrom: string | null, versionTo: string, existingConfig?: z.infer<BSBConfigDefinition>) => {
|
|
55
|
+
* if (versionFrom === null || existingConfig === undefined) {
|
|
56
|
+
* return {
|
|
57
|
+
* a: "a",
|
|
58
|
+
* };
|
|
59
|
+
* }
|
|
60
|
+
* return existingConfig;
|
|
61
|
+
*/
|
|
62
|
+
export type BSBConfigMigration<T extends BSBPluginConfigType> = (versionFrom: string | null, versionTo: string, existingConfig?: z.infer<Exclude<T, undefined>>) => Promise<z.infer<Exclude<T, undefined>>>;
|
|
63
|
+
/**
|
|
64
|
+
* Plugin metadata information for enhanced discoverability and documentation.
|
|
65
|
+
* Used for auto-generating PLUGIN_CLIENT and bsb-plugin.json.
|
|
66
|
+
*
|
|
67
|
+
* v9: This metadata is now the single source of truth for plugin information,
|
|
68
|
+
* used to auto-generate both PLUGIN_CLIENT (for ServiceClient) and bsb-plugin.json.
|
|
69
|
+
*/
|
|
70
|
+
export interface BSBPluginMetadata {
|
|
71
|
+
/** Plugin identifier (e.g., "service-demo-todo") */
|
|
72
|
+
name: string;
|
|
73
|
+
/** Short description of what the plugin does */
|
|
74
|
+
description: string;
|
|
75
|
+
/** Semantic version (e.g., "1.0.0") */
|
|
76
|
+
version?: string;
|
|
77
|
+
/** Author name or organization */
|
|
78
|
+
author?: string;
|
|
79
|
+
/** License type (e.g., "MIT", "AGPL-3.0") */
|
|
80
|
+
license?: string;
|
|
81
|
+
/** Documentation URL */
|
|
82
|
+
homepage?: string;
|
|
83
|
+
/** Source repository URL */
|
|
84
|
+
repository?: string;
|
|
85
|
+
/** Searchable tags for plugin discovery */
|
|
86
|
+
tags?: string[];
|
|
87
|
+
/** Relative paths to markdown documentation files (e.g., ["./docs/plugin.md"]) */
|
|
88
|
+
documentation?: string[];
|
|
89
|
+
/** Relative path to plugin image file (PNG recommended) */
|
|
90
|
+
image?: string;
|
|
91
|
+
/** This plugin must initialize before these plugins */
|
|
92
|
+
initBeforePlugins?: string[];
|
|
93
|
+
/** This plugin must initialize after these plugins */
|
|
94
|
+
initAfterPlugins?: string[];
|
|
95
|
+
/** This plugin must run before these plugins */
|
|
96
|
+
runBeforePlugins?: string[];
|
|
97
|
+
/** This plugin must run after these plugins */
|
|
98
|
+
runAfterPlugins?: string[];
|
|
99
|
+
}
|
|
100
|
+
export type BSBConfigDefintionReference<T extends BSBPluginConfigType, AS = undefined> = [T] extends [undefined] ? AS : z.infer<Exclude<T, undefined>>;
|
|
101
|
+
export type BSBReferenceConfigType = BSBPluginConfigType | null;
|
|
102
|
+
export type BSBReferencePluginConfigType = BSBPluginConfig<BSBPluginConfigType> | null;
|
|
103
|
+
export type BSBReferenceConfigDefinition<ReferencedConfig extends BSBReferenceConfigType> = ReferencedConfig extends null ? null : ReferencedConfig;
|
|
104
|
+
export type BSBReferencePluginConfigDefinition<ReferencedConfig extends BSBReferencePluginConfigType> = ReferencedConfig extends null ? null : ReferencedConfig extends BSBPluginConfig<infer TSchema> ? BSBConfigDefintionReference<TSchema, never> : null;
|
|
105
|
+
/**
|
|
106
|
+
* Base class for plugin configuration.
|
|
107
|
+
*
|
|
108
|
+
* Define your Zod validation schema in {@link validationSchema}. Prefer
|
|
109
|
+
* versioned schemas using Zod unions and transforms to normalize old
|
|
110
|
+
* configs into the latest shape at parse time.
|
|
111
|
+
*
|
|
112
|
+
* Optionally provide {@link metadata} for enhanced plugin discoverability.
|
|
113
|
+
*
|
|
114
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/BSBPluginConfig.html | API: BSBPluginConfig}
|
|
115
|
+
*/
|
|
116
|
+
export declare abstract class BSBPluginConfig<MyPluginConfig extends BSBPluginConfigType = undefined> {
|
|
117
|
+
constructor(cwd: string, packageCwd: string, pluginCwd: string, pluginName: string);
|
|
118
|
+
abstract validationSchema: MyPluginConfig;
|
|
119
|
+
/**
|
|
120
|
+
* Static plugin metadata for v9 auto-generation features.
|
|
121
|
+
* Set by createConfigSchema() helper.
|
|
122
|
+
*/
|
|
123
|
+
static readonly metadata: BSBPluginMetadata;
|
|
124
|
+
/**
|
|
125
|
+
* Optional plugin metadata for enhanced discoverability and documentation.
|
|
126
|
+
* Provides information about the plugin's purpose.
|
|
127
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/BSBPluginConfig.html#metadata | API: BSBPluginConfig#metadata}
|
|
128
|
+
*/
|
|
129
|
+
metadata?: BSBPluginMetadata;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @hidden
|
|
133
|
+
* DO NOT REFERENCE/USE THIS CLASS - IT IS AN INTERNALLY REFERENCED CLASS
|
|
134
|
+
*/
|
|
135
|
+
export declare class BSBPluginConfigRef extends BSBPluginConfig<any> {
|
|
136
|
+
validationSchema: {};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Helper function to create a typed plugin configuration class with metadata.
|
|
140
|
+
*
|
|
141
|
+
* v9 Breaking Change: This replaces the manual Config class pattern.
|
|
142
|
+
* Instead of extending BSBPluginConfig directly, use this helper to create
|
|
143
|
+
* a Config class with built-in metadata support.
|
|
144
|
+
*
|
|
145
|
+
* The metadata is used to:
|
|
146
|
+
* - Auto-generate PLUGIN_CLIENT for ServiceClient usage
|
|
147
|
+
* - Auto-generate bsb-plugin.json during build
|
|
148
|
+
* - Provide plugin discovery and marketplace information
|
|
149
|
+
*
|
|
150
|
+
* @param metadata - Plugin metadata (name, description, version, dependencies, etc.)
|
|
151
|
+
* @param schema - Zod validation schema for the plugin configuration
|
|
152
|
+
* @returns A Config class that extends BSBPluginConfig with metadata
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // v9 pattern:
|
|
157
|
+
* const TodoConfigSchema = z.object({
|
|
158
|
+
* database: z.object({
|
|
159
|
+
* host: z.string().default('localhost'),
|
|
160
|
+
* port: z.number().default(5432),
|
|
161
|
+
* }),
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* export const Config = createConfigSchema(
|
|
165
|
+
* {
|
|
166
|
+
* name: 'service-demo-todo',
|
|
167
|
+
* description: 'Demo Todo Service',
|
|
168
|
+
* version: '1.0.0',
|
|
169
|
+
* author: 'BSB Team',
|
|
170
|
+
* license: 'MIT',
|
|
171
|
+
* category: 'service',
|
|
172
|
+
* tags: ['demo', 'todo', 'example'],
|
|
173
|
+
* initAfterPlugins: ['observable-default', 'events-default'],
|
|
174
|
+
* },
|
|
175
|
+
* TodoConfigSchema
|
|
176
|
+
* );
|
|
177
|
+
*
|
|
178
|
+
* // Usage in plugin:
|
|
179
|
+
* export class Plugin extends BSBService<typeof Config, typeof EventSchemas> {
|
|
180
|
+
* static Config = Config; // Required for auto-generation
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/createConfigSchema.html | API: createConfigSchema}
|
|
185
|
+
*/
|
|
186
|
+
export declare function createConfigSchema<const TSchema extends z.ZodTypeAny>(metadata: BSBPluginMetadata, schema: TSchema): BSBPluginConfigClass<TSchema>;
|
|
187
|
+
export declare function createConfigSchema(metadata: BSBPluginMetadata): BSBPluginConfigClass<undefined>;
|
|
188
|
+
/**
|
|
189
|
+
* Extract category from plugin name based on directory prefix.
|
|
190
|
+
* Examples:
|
|
191
|
+
* - service-demo-todo -> service
|
|
192
|
+
* - observable-axiom -> observable
|
|
193
|
+
* - events-rabbitmq -> events
|
|
194
|
+
* - config-default -> config
|
|
195
|
+
*/
|
|
196
|
+
export declare function getCategoryFromPluginName(pluginName: string): 'service' | 'observable' | 'events' | 'config' | 'other';
|
|
@@ -0,0 +1,96 @@
|
|
|
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.BSBPluginConfigRef = exports.BSBPluginConfig = void 0;
|
|
30
|
+
exports.createConfigSchema = createConfigSchema;
|
|
31
|
+
exports.getCategoryFromPluginName = getCategoryFromPluginName;
|
|
32
|
+
/**
|
|
33
|
+
* Base class for plugin configuration.
|
|
34
|
+
*
|
|
35
|
+
* Define your Zod validation schema in {@link validationSchema}. Prefer
|
|
36
|
+
* versioned schemas using Zod unions and transforms to normalize old
|
|
37
|
+
* configs into the latest shape at parse time.
|
|
38
|
+
*
|
|
39
|
+
* Optionally provide {@link metadata} for enhanced plugin discoverability.
|
|
40
|
+
*
|
|
41
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/BSBPluginConfig.html | API: BSBPluginConfig}
|
|
42
|
+
*/
|
|
43
|
+
class BSBPluginConfig {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
+
constructor(cwd, packageCwd, pluginCwd, pluginName) {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Static plugin metadata for v9 auto-generation features.
|
|
49
|
+
* Set by createConfigSchema() helper.
|
|
50
|
+
*/
|
|
51
|
+
static metadata;
|
|
52
|
+
/**
|
|
53
|
+
* Optional plugin metadata for enhanced discoverability and documentation.
|
|
54
|
+
* Provides information about the plugin's purpose.
|
|
55
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/BSBPluginConfig.html#metadata | API: BSBPluginConfig#metadata}
|
|
56
|
+
*/
|
|
57
|
+
metadata;
|
|
58
|
+
}
|
|
59
|
+
exports.BSBPluginConfig = BSBPluginConfig;
|
|
60
|
+
/**
|
|
61
|
+
* @hidden
|
|
62
|
+
* DO NOT REFERENCE/USE THIS CLASS - IT IS AN INTERNALLY REFERENCED CLASS
|
|
63
|
+
*/
|
|
64
|
+
class BSBPluginConfigRef extends BSBPluginConfig {
|
|
65
|
+
validationSchema = {};
|
|
66
|
+
}
|
|
67
|
+
exports.BSBPluginConfigRef = BSBPluginConfigRef;
|
|
68
|
+
function createConfigSchema(metadata, schema) {
|
|
69
|
+
const ConfigClass = class extends BSBPluginConfig {
|
|
70
|
+
validationSchema = schema;
|
|
71
|
+
static metadata = metadata;
|
|
72
|
+
// Also expose metadata on instance for backward compatibility
|
|
73
|
+
metadata = metadata;
|
|
74
|
+
};
|
|
75
|
+
return ConfigClass;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Extract category from plugin name based on directory prefix.
|
|
79
|
+
* Examples:
|
|
80
|
+
* - service-demo-todo -> service
|
|
81
|
+
* - observable-axiom -> observable
|
|
82
|
+
* - events-rabbitmq -> events
|
|
83
|
+
* - config-default -> config
|
|
84
|
+
*/
|
|
85
|
+
function getCategoryFromPluginName(pluginName) {
|
|
86
|
+
if (pluginName.startsWith('service-'))
|
|
87
|
+
return 'service';
|
|
88
|
+
if (pluginName.startsWith('observable-'))
|
|
89
|
+
return 'observable';
|
|
90
|
+
if (pluginName.startsWith('events-'))
|
|
91
|
+
return 'events';
|
|
92
|
+
if (pluginName.startsWith('config-'))
|
|
93
|
+
return 'config';
|
|
94
|
+
return 'other';
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=PluginConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginConfig.js","sourceRoot":"","sources":["../../src/base/PluginConfig.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAgNH,gDAYC;AAUD,8DAMC;AAhID;;;;;;;;;;GAUG;AACH,MAAsB,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;AArBD,0CAqBC;AAED;;;GAGG;AACH,MAAa,kBACT,SAAQ,eAAoB;IACvB,gBAAgB,GAAG,EAAE,CAAC;CAC9B;AAHD,gDAGC;AA2DD,SAAgB,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,SAAgB,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"}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 { 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";
|
|
32
|
+
/**
|
|
33
|
+
* Plugin event schema definition.
|
|
34
|
+
* Define event schemas once and get both TypeScript types and runtime validation.
|
|
35
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/modules.html#BSBPluginEvents | API: BSBPluginEvents}
|
|
36
|
+
*/
|
|
37
|
+
export type BSBPluginEvents<T extends BSBEventSchemas = BSBEventSchemas> = T;
|
|
38
|
+
/**
|
|
39
|
+
* Schema-first plugin events handler with automatic validation and object parameters.
|
|
40
|
+
* @group Events
|
|
41
|
+
* @category Plugin Development Tools
|
|
42
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html | API: PluginEvents}
|
|
43
|
+
*/
|
|
44
|
+
export declare class PluginEvents<TEventSchemas extends BSBEventSchemas = BSBEventSchemas, TClientApi extends boolean = false> {
|
|
45
|
+
private events;
|
|
46
|
+
private service;
|
|
47
|
+
private cachedPluginName;
|
|
48
|
+
private validator;
|
|
49
|
+
private eventSchemas;
|
|
50
|
+
constructor(mode: DEBUG_MODE, events: SBEvents, context: BSBService | BSBServiceClient, eventSchemas: TEventSchemas, observableBackend?: IPluginObservable);
|
|
51
|
+
/**
|
|
52
|
+
* Helper to extract DTrace from Observable | DTrace
|
|
53
|
+
* @hidden
|
|
54
|
+
*/
|
|
55
|
+
private extractTrace;
|
|
56
|
+
/**
|
|
57
|
+
* Helper to create Observable from DTrace if needed
|
|
58
|
+
* @hidden
|
|
59
|
+
*/
|
|
60
|
+
private ensureObservable;
|
|
61
|
+
/**
|
|
62
|
+
* Listen for broadcast events emitted by other plugins with full type safety.
|
|
63
|
+
* @param eventName - Name of the event to listen for (strongly typed)
|
|
64
|
+
* @param obs - Observable context (v9 BREAKING: Observable only, no longer accepts DTrace)
|
|
65
|
+
* @param listener - Function to call when event is received (receives Observable and validated input object)
|
|
66
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html#onBroadcast | API: PluginEvents#onBroadcast}
|
|
67
|
+
*/
|
|
68
|
+
onBroadcast<TBroadcast extends NonNullable<TEventSchemas['onBroadcast']>, K extends keyof TBroadcast>(eventName: K, obs: Observable, listener: (handlerObs: Observable, input: EventInputType<TBroadcast[K]>) => Promise<void>): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Emit broadcast events to all listening plugins with full type safety.
|
|
71
|
+
* @param eventName - Name of the event to emit (strongly typed)
|
|
72
|
+
* @param obs - Observable context (v9 BREAKING: Observable only, no longer accepts DTrace)
|
|
73
|
+
* @param input - Event input object (will be validated against schema)
|
|
74
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html#emitBroadcast | API: PluginEvents#emitBroadcast}
|
|
75
|
+
*/
|
|
76
|
+
emitBroadcast<TBroadcast extends NonNullable<TEventSchemas['emitBroadcast']>, K extends keyof TBroadcast>(eventName: K, obs: Observable, input: EventInputType<TBroadcast[K]>): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Listen for fire-and-forget events from other plugins with full type safety.
|
|
79
|
+
* @param eventName - Name of the event to listen for (strongly typed)
|
|
80
|
+
* @param obs - Observable context (v9 BREAKING: Observable only, no longer accepts DTrace)
|
|
81
|
+
* @param listener - Function to call when event is received (receives Observable and validated input object)
|
|
82
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html#onEvent | API: PluginEvents#onEvent}
|
|
83
|
+
*/
|
|
84
|
+
onEvent<TEvents extends NonNullable<TEventSchemas['onEvents']>, K extends keyof TEvents>(eventName: K, obs: Observable, listener: (handlerObs: Observable, input: EventInputType<TEvents[K]>) => Promise<void>): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Emit fire-and-forget events to other plugins with full type safety.
|
|
87
|
+
* @param eventName - Name of the event to emit (strongly typed)
|
|
88
|
+
* @param obs - Observable context (v9 BREAKING: Observable only, no longer accepts DTrace)
|
|
89
|
+
* @param input - Event input object (will be validated against schema)
|
|
90
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html#emitEvent | API: PluginEvents#emitEvent}
|
|
91
|
+
*/
|
|
92
|
+
emitEvent<TEvents extends NonNullable<TEventSchemas['emitEvents']>, K extends keyof TEvents>(eventName: K, obs: Observable, input: EventInputType<TEvents[K]>): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Listen for returnable events from other plugins with full type safety.
|
|
95
|
+
* @param eventName - Name of the event to listen for (strongly typed)
|
|
96
|
+
* @param obs - Observable context (v9 BREAKING: Observable only, no longer accepts DTrace)
|
|
97
|
+
* @param listener - Function to call when event is received (receives Observable), must return a value
|
|
98
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html#onReturnableEvent | API: PluginEvents#onReturnableEvent}
|
|
99
|
+
*/
|
|
100
|
+
onReturnableEvent<TEvents extends NonNullable<TEventSchemas['onReturnableEvents']>, K extends keyof TEvents>(eventName: K, obs: Observable, listener: (handlerObs: Observable, input: EventInputType<TEvents[K]>) => Promise<EventOutputType<TEvents[K]>>): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Emit returnable events and wait for response with full type safety.
|
|
103
|
+
* @param eventName - Name of the event to emit (strongly typed)
|
|
104
|
+
* @param obs - Observable context (v9 BREAKING: Observable only, no longer accepts DTrace)
|
|
105
|
+
* @param input - Event input object (will be validated against schema)
|
|
106
|
+
* @param timeoutSeconds - Optional timeout in seconds (default: 5)
|
|
107
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html#emitEventAndReturn | API: PluginEvents#emitEventAndReturn}
|
|
108
|
+
*/
|
|
109
|
+
emitEventAndReturn<TEvents extends NonNullable<TEventSchemas['emitReturnableEvents']>, K extends keyof TEvents>(eventName: K, obs: Observable, input: EventInputType<TEvents[K]>, timeoutSeconds?: number): Promise<EventOutputType<TEvents[K]>>;
|
|
110
|
+
/**
|
|
111
|
+
* Get stream ID for receiving streamed data from another plugin.
|
|
112
|
+
* @param trace - Trace for logging context
|
|
113
|
+
* @param eventName - Name of the stream event
|
|
114
|
+
* @param listener - Function called when stream is received
|
|
115
|
+
* @param timeoutSeconds - Optional timeout in seconds
|
|
116
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html#receiveStream | API: PluginEvents#receiveStream}
|
|
117
|
+
*/
|
|
118
|
+
receiveStream(trace: DTrace, eventName: string, listener: (error: Error | null, stream: Readable) => Promise<void>, timeoutSeconds?: number): Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Send stream data to another plugin.
|
|
121
|
+
* @param trace - Trace for logging context
|
|
122
|
+
* @param eventName - Name of the stream event
|
|
123
|
+
* @param streamId - ID of the stream to send to
|
|
124
|
+
* @param stream - The readable stream to send
|
|
125
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/PluginEvents.html#sendStream | API: PluginEvents#sendStream}
|
|
126
|
+
*/
|
|
127
|
+
sendStream(trace: DTrace, eventName: string, streamId: string, stream: Readable): Promise<void>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @hidden
|
|
131
|
+
* DO NOT REFERENCE/USE THIS CLASS - IT IS AN INTERNALLY REFERENCED CLASS
|
|
132
|
+
*/
|
|
133
|
+
export declare class BSBPluginEventsRef {
|
|
134
|
+
emitEvents: {};
|
|
135
|
+
onEvents: {};
|
|
136
|
+
emitReturnableEvents: {};
|
|
137
|
+
onReturnableEvents: {};
|
|
138
|
+
emitBroadcast: {};
|
|
139
|
+
onBroadcast: {};
|
|
140
|
+
}
|