@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,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB Plugin Metadata Generation Script
|
|
4
|
+
*
|
|
5
|
+
* Discovers publishable core plugins and generates plugin metadata JSON files.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* npm run generate-plugin-json
|
|
9
|
+
*
|
|
10
|
+
* Output:
|
|
11
|
+
* - lib/schemas/{plugin-name}.plugin.json
|
|
12
|
+
* - bsb-plugin.json (registry-facing root manifest)
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.generatePluginMetadata = main;
|
|
16
|
+
const fs = require("fs");
|
|
17
|
+
const path = require("path");
|
|
18
|
+
const PluginConfig_1 = require("../base/PluginConfig");
|
|
19
|
+
const CORE_PLUGIN_OVERRIDES = {
|
|
20
|
+
'config-default': {
|
|
21
|
+
name: 'config-default',
|
|
22
|
+
description: 'Default configuration plugin for BSB profile and plugin resolution.',
|
|
23
|
+
tags: ['core', 'config', 'default'],
|
|
24
|
+
documentation: ['./docs/core-plugins/config-default.md'],
|
|
25
|
+
},
|
|
26
|
+
'events-default': {
|
|
27
|
+
name: 'events-default',
|
|
28
|
+
description: 'In-process events plugin with emit, returnable, and broadcast support.',
|
|
29
|
+
tags: ['core', 'events', 'default'],
|
|
30
|
+
documentation: ['./docs/core-plugins/events-default.md'],
|
|
31
|
+
},
|
|
32
|
+
'observable-default': {
|
|
33
|
+
name: 'observable-default',
|
|
34
|
+
description: 'Default console-based observable plugin for logs and diagnostics.',
|
|
35
|
+
tags: ['core', 'observable', 'default'],
|
|
36
|
+
documentation: ['./docs/core-plugins/observable-default.md'],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Discover all plugin modules in the lib directory.
|
|
41
|
+
* Looks for plugin entry points in lib/plugins/{plugin-name}/index.js
|
|
42
|
+
*/
|
|
43
|
+
function discoverPlugins(libDir) {
|
|
44
|
+
const pluginPaths = [];
|
|
45
|
+
const pluginsDir = path.join(libDir, 'plugins');
|
|
46
|
+
if (!fs.existsSync(pluginsDir)) {
|
|
47
|
+
return pluginPaths;
|
|
48
|
+
}
|
|
49
|
+
const pluginDirs = fs.readdirSync(pluginsDir, { withFileTypes: true })
|
|
50
|
+
.filter(dirent => dirent.isDirectory())
|
|
51
|
+
.map(dirent => dirent.name);
|
|
52
|
+
for (const dir of pluginDirs) {
|
|
53
|
+
const indexPath = path.join(pluginsDir, dir, 'index.js');
|
|
54
|
+
if (fs.existsSync(indexPath)) {
|
|
55
|
+
pluginPaths.push(indexPath);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return pluginPaths;
|
|
59
|
+
}
|
|
60
|
+
function shouldPublishPlugin(pluginId) {
|
|
61
|
+
if (pluginId.startsWith('service-')) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return Object.prototype.hasOwnProperty.call(CORE_PLUGIN_OVERRIDES, pluginId);
|
|
65
|
+
}
|
|
66
|
+
function buildRootManifestEntries(pluginMetaFiles, packageJson) {
|
|
67
|
+
return pluginMetaFiles.map((meta) => {
|
|
68
|
+
const id = meta.id;
|
|
69
|
+
const entry = {
|
|
70
|
+
id,
|
|
71
|
+
name: meta.name,
|
|
72
|
+
basePath: './',
|
|
73
|
+
description: meta.description || '',
|
|
74
|
+
tags: meta.tags || [],
|
|
75
|
+
documentation: meta.documentation || [],
|
|
76
|
+
pluginPath: `src/plugins/${id}/`,
|
|
77
|
+
};
|
|
78
|
+
if (meta.image) {
|
|
79
|
+
entry.image = meta.image;
|
|
80
|
+
}
|
|
81
|
+
const repoUrl = meta.repository || packageJson.repository?.url || packageJson.repository || '';
|
|
82
|
+
if (repoUrl) {
|
|
83
|
+
entry.links = { github: typeof repoUrl === 'string' ? repoUrl : '' };
|
|
84
|
+
}
|
|
85
|
+
return entry;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Main generation function.
|
|
90
|
+
*/
|
|
91
|
+
async function main() {
|
|
92
|
+
const projectRoot = path.resolve(__dirname, '..', '..');
|
|
93
|
+
const libDir = path.join(projectRoot, 'lib');
|
|
94
|
+
const schemasDir = path.join(libDir, 'schemas');
|
|
95
|
+
// Ensure lib directory exists (must run after build)
|
|
96
|
+
if (!fs.existsSync(libDir)) {
|
|
97
|
+
// eslint-disable-next-line no-console
|
|
98
|
+
console.error('Error: lib directory not found. Run npm run build first.');
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
// Create schemas output directory
|
|
102
|
+
if (!fs.existsSync(schemasDir)) {
|
|
103
|
+
fs.mkdirSync(schemasDir, { recursive: true });
|
|
104
|
+
}
|
|
105
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
106
|
+
let packageJson = {};
|
|
107
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
108
|
+
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
109
|
+
}
|
|
110
|
+
// Discover all plugins
|
|
111
|
+
const pluginPaths = discoverPlugins(libDir);
|
|
112
|
+
if (pluginPaths.length === 0) {
|
|
113
|
+
// eslint-disable-next-line no-console
|
|
114
|
+
console.log('No plugins found to generate metadata from.');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// eslint-disable-next-line no-console
|
|
118
|
+
console.log(`Found ${pluginPaths.length} plugin(s) to generate metadata from...`);
|
|
119
|
+
let generatedCount = 0;
|
|
120
|
+
let errorCount = 0;
|
|
121
|
+
const generatedPluginMetadata = [];
|
|
122
|
+
// Process each plugin
|
|
123
|
+
for (const pluginPath of pluginPaths) {
|
|
124
|
+
try {
|
|
125
|
+
const pluginName = path.basename(path.dirname(pluginPath));
|
|
126
|
+
if (!shouldPublishPlugin(pluginName)) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
// Import the plugin module
|
|
130
|
+
const pluginModule = await Promise.resolve(`${pluginPath}`).then(s => require(s));
|
|
131
|
+
// Look for Plugin export
|
|
132
|
+
if (!pluginModule.Plugin) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const Plugin = pluginModule.Plugin;
|
|
136
|
+
const metadata = (Plugin.Config && Plugin.Config.metadata)
|
|
137
|
+
? Plugin.Config.metadata
|
|
138
|
+
: CORE_PLUGIN_OVERRIDES[pluginName];
|
|
139
|
+
if (!metadata) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// Read version from package.json if available
|
|
143
|
+
const version = packageJson.version || metadata.version || '1.0.0';
|
|
144
|
+
// Create plugin metadata object - only include fields with actual values
|
|
145
|
+
const pluginMetadata = {
|
|
146
|
+
id: pluginName,
|
|
147
|
+
name: metadata.name,
|
|
148
|
+
version,
|
|
149
|
+
description: metadata.description || '',
|
|
150
|
+
category: (0, PluginConfig_1.getCategoryFromPluginName)(pluginName),
|
|
151
|
+
tags: metadata.tags || [],
|
|
152
|
+
documentation: Array.isArray(metadata.documentation) ? metadata.documentation : [],
|
|
153
|
+
dependencies: [],
|
|
154
|
+
};
|
|
155
|
+
// Only include optional fields if they have real values
|
|
156
|
+
if (metadata.author)
|
|
157
|
+
pluginMetadata.author = metadata.author;
|
|
158
|
+
if (metadata.license)
|
|
159
|
+
pluginMetadata.license = metadata.license;
|
|
160
|
+
if (metadata.homepage)
|
|
161
|
+
pluginMetadata.homepage = metadata.homepage;
|
|
162
|
+
if (metadata.repository)
|
|
163
|
+
pluginMetadata.repository = metadata.repository;
|
|
164
|
+
if (metadata.image)
|
|
165
|
+
pluginMetadata.image = metadata.image;
|
|
166
|
+
// Read auto-detected dependencies and config schema from schema JSON
|
|
167
|
+
const schemaJsonPath = path.join(schemasDir, `${pluginName}.json`);
|
|
168
|
+
if (fs.existsSync(schemaJsonPath)) {
|
|
169
|
+
try {
|
|
170
|
+
const schema = JSON.parse(fs.readFileSync(schemaJsonPath, 'utf-8'));
|
|
171
|
+
if (Array.isArray(schema.dependencies) && schema.dependencies.length > 0) {
|
|
172
|
+
pluginMetadata.dependencies = schema.dependencies;
|
|
173
|
+
}
|
|
174
|
+
if (schema.configSchema && typeof schema.configSchema === 'object') {
|
|
175
|
+
pluginMetadata.configSchema = schema.configSchema;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// Non-fatal, skip malformed schema
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Write to file
|
|
183
|
+
const outputPath = path.join(schemasDir, `${pluginName}.plugin.json`);
|
|
184
|
+
fs.writeFileSync(outputPath, JSON.stringify(pluginMetadata, null, 2), 'utf-8');
|
|
185
|
+
generatedPluginMetadata.push(pluginMetadata);
|
|
186
|
+
// eslint-disable-next-line no-console
|
|
187
|
+
console.log(` Generated metadata for ${metadata.name} (v${version})`);
|
|
188
|
+
generatedCount++;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
errorCount++;
|
|
192
|
+
// eslint-disable-next-line no-console
|
|
193
|
+
console.error(` Error generating metadata for ${path.basename(path.dirname(pluginPath))}: ${error instanceof Error ? error.message : String(error)}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Generate root bsb-plugin.json manifest for registry publish workflow
|
|
197
|
+
if (generatedPluginMetadata.length > 0) {
|
|
198
|
+
const rootPluginJson = {
|
|
199
|
+
nodejs: buildRootManifestEntries(generatedPluginMetadata, packageJson),
|
|
200
|
+
};
|
|
201
|
+
fs.writeFileSync(path.join(projectRoot, 'bsb-plugin.json'), JSON.stringify(rootPluginJson, null, 2), 'utf-8');
|
|
202
|
+
}
|
|
203
|
+
// eslint-disable-next-line no-console
|
|
204
|
+
console.log(`\nMetadata generation complete: ${generatedCount} generated, ${errorCount} errors`);
|
|
205
|
+
// eslint-disable-next-line no-console
|
|
206
|
+
console.log(`Metadata files written to: ${schemasDir}`);
|
|
207
|
+
if (errorCount > 0) {
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Run if called directly
|
|
212
|
+
if (require.main === module) {
|
|
213
|
+
main().catch(error => {
|
|
214
|
+
// eslint-disable-next-line no-console
|
|
215
|
+
console.error('Fatal error during metadata generation:', error);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=generate-plugin-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-plugin-json.js","sourceRoot":"","sources":["../../src/scripts/generate-plugin-json.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AA2Pc,sCAAsB;AAzPvC,yBAAyB;AACzB,6BAA6B;AAC7B,uDAAiE;AAcjE,MAAM,qBAAqB,GAA+B;IACxD,gBAAgB,EAAE;QAChB,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,qEAAqE;QAClF,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC;QACnC,aAAa,EAAE,CAAC,uCAAuC,CAAC;KACzD;IACD,gBAAgB,EAAE;QAChB,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,wEAAwE;QACrF,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC;QACnC,aAAa,EAAE,CAAC,uCAAuC,CAAC;KACzD;IACD,oBAAoB,EAAE;QACpB,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,mEAAmE;QAChF,IAAI,EAA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AAK,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { BSBConfig } from "../base";
|
|
28
|
+
import { DEBUG_MODE, DTrace, EventsConfig, LoadedPlugin, ObservableConfig, PluginDefinition, PluginType, Observable } from "../interfaces";
|
|
29
|
+
import { SBObservable } from "./observable";
|
|
30
|
+
import { SBPlugins } from "./plugins";
|
|
31
|
+
/**
|
|
32
|
+
* BSB Config Controller
|
|
33
|
+
*
|
|
34
|
+
* This class is responsible for managing the configuration in the BSB framework.
|
|
35
|
+
* If you have a specific way of managing configuration, you can extend this class and then use your own class when creating the ServiceBase instance.
|
|
36
|
+
*
|
|
37
|
+
* @group Config
|
|
38
|
+
* @category Core
|
|
39
|
+
*/
|
|
40
|
+
export declare class SBConfig {
|
|
41
|
+
private static readonly DEFAULT_CONFIG_ENV_KEYS;
|
|
42
|
+
/**
|
|
43
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBConfig.html | API: SBConfig}
|
|
44
|
+
*/
|
|
45
|
+
private mode;
|
|
46
|
+
private appId;
|
|
47
|
+
private cwd;
|
|
48
|
+
private sbPlugins;
|
|
49
|
+
private sbObservable;
|
|
50
|
+
private observableBackend;
|
|
51
|
+
private configPlugin;
|
|
52
|
+
private createObservable;
|
|
53
|
+
constructor(appId: string, mode: DEBUG_MODE, cwd: string, sbObservable: SBObservable, sbPlugins: SBPlugins, createObservable: (trace: DTrace, pluginName: string, attributes?: Record<string, string | number | boolean>) => Observable);
|
|
54
|
+
private getConfigPluginEnvSubset;
|
|
55
|
+
private resolveConfigPluginConfig;
|
|
56
|
+
private isFlatJsonSchemaProperty;
|
|
57
|
+
private validateConfigPluginSchemaShape;
|
|
58
|
+
getPluginConfig(trace: DTrace, pluginType: PluginType, name: string): Promise<object | null>;
|
|
59
|
+
getServicePlugins(trace: DTrace): Promise<Record<string, PluginDefinition>>;
|
|
60
|
+
getEventsPlugins(trace: DTrace): Promise<Record<string, EventsConfig>>;
|
|
61
|
+
getObservablePlugins(trace: DTrace): Promise<Record<string, ObservableConfig>>;
|
|
62
|
+
getServicePluginDefinition(trace: DTrace, pluginName: string): Promise<{
|
|
63
|
+
name: string;
|
|
64
|
+
enabled: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Dispose config subsystem
|
|
68
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBConfig.html#dispose | API: SBConfig.dispose}
|
|
69
|
+
*/
|
|
70
|
+
dispose(): void;
|
|
71
|
+
private configPackage;
|
|
72
|
+
private configPluginName;
|
|
73
|
+
/**
|
|
74
|
+
* Set the active config plugin implementation
|
|
75
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBConfig.html#setConfigPlugin | API: SBConfig.setConfigPlugin}
|
|
76
|
+
*/
|
|
77
|
+
setConfigPlugin(reference: LoadedPlugin<"config">): Promise<BSBConfig<any>>;
|
|
78
|
+
/**
|
|
79
|
+
* Initialize config plugin (default or loaded)
|
|
80
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBConfig.html#init | API: SBConfig.init}
|
|
81
|
+
*/
|
|
82
|
+
init(): Promise<void>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
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.SBConfig = void 0;
|
|
30
|
+
const base_1 = require("../base");
|
|
31
|
+
const interfaces_1 = require("../interfaces");
|
|
32
|
+
const index_1 = require("../plugins/config-default/index");
|
|
33
|
+
const zod_1 = require("zod");
|
|
34
|
+
/**
|
|
35
|
+
* @hidden
|
|
36
|
+
*/
|
|
37
|
+
function internalTrace(span) {
|
|
38
|
+
return (0, interfaces_1.createFakeDTrace)("serviceBase/SBConfig", span);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* BSB Config Controller
|
|
42
|
+
*
|
|
43
|
+
* This class is responsible for managing the configuration in the BSB framework.
|
|
44
|
+
* If you have a specific way of managing configuration, you can extend this class and then use your own class when creating the ServiceBase instance.
|
|
45
|
+
*
|
|
46
|
+
* @group Config
|
|
47
|
+
* @category Core
|
|
48
|
+
*/
|
|
49
|
+
class SBConfig {
|
|
50
|
+
static DEFAULT_CONFIG_ENV_KEYS = ["BSB_PROFILE", "BSB_CONFIG_FILE"];
|
|
51
|
+
/**
|
|
52
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBConfig.html | API: SBConfig}
|
|
53
|
+
*/
|
|
54
|
+
mode = "development";
|
|
55
|
+
appId;
|
|
56
|
+
cwd;
|
|
57
|
+
sbPlugins;
|
|
58
|
+
sbObservable;
|
|
59
|
+
observableBackend;
|
|
60
|
+
configPlugin;
|
|
61
|
+
createObservable;
|
|
62
|
+
constructor(appId, mode, cwd, sbObservable, sbPlugins, createObservable) {
|
|
63
|
+
this.appId = appId;
|
|
64
|
+
this.mode = mode;
|
|
65
|
+
this.cwd = cwd;
|
|
66
|
+
this.sbObservable = sbObservable;
|
|
67
|
+
this.sbPlugins = sbPlugins;
|
|
68
|
+
this.createObservable = createObservable;
|
|
69
|
+
const defaultConfigSchema = new index_1.Config(cwd, cwd, cwd, "config-default").validationSchema;
|
|
70
|
+
const defaultConfig = this.resolveConfigPluginConfig(defaultConfigSchema, SBConfig.DEFAULT_CONFIG_ENV_KEYS);
|
|
71
|
+
this.observableBackend = new base_1.ObservableBackend(mode, appId, "sb-config", sbObservable);
|
|
72
|
+
this.configPlugin = new index_1.Plugin({
|
|
73
|
+
appId,
|
|
74
|
+
mode,
|
|
75
|
+
pluginName: "sb-config",
|
|
76
|
+
cwd,
|
|
77
|
+
packageCwd: cwd,
|
|
78
|
+
pluginCwd: cwd,
|
|
79
|
+
config: defaultConfig,
|
|
80
|
+
sbObservable,
|
|
81
|
+
pluginVersion: "0.0.0",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
getConfigPluginEnvSubset(validationSchema, fallbackKeys = []) {
|
|
85
|
+
const scopedEnv = {};
|
|
86
|
+
const allowedKeys = new Set(fallbackKeys);
|
|
87
|
+
if (!base_1.Tools.isNullOrUndefined(validationSchema)) {
|
|
88
|
+
const jsonSchema = zod_1.z.toJSONSchema(validationSchema);
|
|
89
|
+
if (jsonSchema.type === "object" && base_1.Tools.isObject(jsonSchema.properties)) {
|
|
90
|
+
Object.keys(jsonSchema.properties).forEach((key) => allowedKeys.add(key));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const key of allowedKeys) {
|
|
94
|
+
const value = process.env[key];
|
|
95
|
+
if (typeof value === "string") {
|
|
96
|
+
scopedEnv[key] = value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return scopedEnv;
|
|
100
|
+
}
|
|
101
|
+
resolveConfigPluginConfig(validationSchema, fallbackKeys = []) {
|
|
102
|
+
if (base_1.Tools.isNullOrUndefined(validationSchema)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const scopedEnv = this.getConfigPluginEnvSubset(validationSchema, fallbackKeys);
|
|
106
|
+
return validationSchema.parse(scopedEnv);
|
|
107
|
+
}
|
|
108
|
+
isFlatJsonSchemaProperty(schema) {
|
|
109
|
+
if (!schema || typeof schema !== "object")
|
|
110
|
+
return false;
|
|
111
|
+
const t = schema.type;
|
|
112
|
+
if (t === "object" || t === "array")
|
|
113
|
+
return false;
|
|
114
|
+
if (Array.isArray(t) && (t.includes("object") || t.includes("array")))
|
|
115
|
+
return false;
|
|
116
|
+
if (Array.isArray(schema.oneOf) && schema.oneOf.some((x) => !this.isFlatJsonSchemaProperty(x)))
|
|
117
|
+
return false;
|
|
118
|
+
if (Array.isArray(schema.anyOf) && schema.anyOf.some((x) => !this.isFlatJsonSchemaProperty(x)))
|
|
119
|
+
return false;
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
validateConfigPluginSchemaShape(trace, validationSchema) {
|
|
123
|
+
const obs = this.createObservable(trace, "config");
|
|
124
|
+
const jsonSchema = zod_1.z.toJSONSchema(validationSchema);
|
|
125
|
+
if (jsonSchema?.type !== "object") {
|
|
126
|
+
throw new base_1.BSBError(obs.trace, "Config plugin schema must be an object or omitted");
|
|
127
|
+
}
|
|
128
|
+
const properties = jsonSchema?.properties || {};
|
|
129
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
130
|
+
if (!this.isFlatJsonSchemaProperty(propSchema)) {
|
|
131
|
+
throw new base_1.BSBError(obs.trace, "Config plugin schema property {key} must be flat (no object/array)", { key });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async getPluginConfig(trace, pluginType, name) {
|
|
136
|
+
const obs = this.createObservable(trace, "config");
|
|
137
|
+
return await this.configPlugin.getPluginConfig(obs, pluginType, name);
|
|
138
|
+
}
|
|
139
|
+
async getServicePlugins(trace) {
|
|
140
|
+
const obs = this.createObservable(trace, "config");
|
|
141
|
+
return await this.configPlugin.getServicePlugins(obs);
|
|
142
|
+
}
|
|
143
|
+
async getEventsPlugins(trace) {
|
|
144
|
+
const obs = this.createObservable(trace, "config");
|
|
145
|
+
return await this.configPlugin.getEventsPlugins(obs);
|
|
146
|
+
}
|
|
147
|
+
async getObservablePlugins(trace) {
|
|
148
|
+
const obs = this.createObservable(trace, "config");
|
|
149
|
+
return await this.configPlugin.getObservablePlugins(obs);
|
|
150
|
+
}
|
|
151
|
+
async getServicePluginDefinition(trace, pluginName) {
|
|
152
|
+
const obs = this.createObservable(trace, "config");
|
|
153
|
+
return await this.configPlugin.getServicePluginDefinition(obs, pluginName);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Dispose config subsystem
|
|
157
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBConfig.html#dispose | API: SBConfig.dispose}
|
|
158
|
+
*/
|
|
159
|
+
dispose() {
|
|
160
|
+
(0, base_1.SmartFunctionCallSync)(this.configPlugin, this.configPlugin.dispose);
|
|
161
|
+
}
|
|
162
|
+
configPackage;
|
|
163
|
+
configPluginName = "config-default";
|
|
164
|
+
/**
|
|
165
|
+
* Set the active config plugin implementation
|
|
166
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBConfig.html#setConfigPlugin | API: SBConfig.setConfigPlugin}
|
|
167
|
+
*/
|
|
168
|
+
async setConfigPlugin(reference) {
|
|
169
|
+
const tTrace = internalTrace(`setConfigPlugin`);
|
|
170
|
+
if (reference.serviceConfig && !base_1.Tools.isNullOrUndefined(reference.serviceConfig.validationSchema)) {
|
|
171
|
+
this.validateConfigPluginSchemaShape(tTrace, reference.serviceConfig.validationSchema);
|
|
172
|
+
}
|
|
173
|
+
const pluginConfig = this.resolveConfigPluginConfig(reference.serviceConfig?.validationSchema);
|
|
174
|
+
this.configPlugin = new reference.plugin({
|
|
175
|
+
appId: this.appId,
|
|
176
|
+
mode: this.mode,
|
|
177
|
+
pluginName: reference.name,
|
|
178
|
+
cwd: this.cwd,
|
|
179
|
+
packageCwd: reference.packageCwd,
|
|
180
|
+
pluginCwd: reference.pluginCwd,
|
|
181
|
+
config: pluginConfig,
|
|
182
|
+
sbObservable: this.sbObservable,
|
|
183
|
+
pluginVersion: reference.version,
|
|
184
|
+
});
|
|
185
|
+
this.observableBackend.info(tTrace, "Adding {pluginName} as config", {
|
|
186
|
+
pluginName: reference.name,
|
|
187
|
+
});
|
|
188
|
+
this.observableBackend.debug(tTrace, `Init: {name}`, {
|
|
189
|
+
name: this.configPluginName,
|
|
190
|
+
});
|
|
191
|
+
const obs = this.createObservable(tTrace, "config");
|
|
192
|
+
await (0, base_1.SmartFunctionCallAsync)(this.configPlugin, this.configPlugin.init, obs);
|
|
193
|
+
this.observableBackend.info(tTrace, `Init: {name}: OK`, {
|
|
194
|
+
name: this.configPluginName,
|
|
195
|
+
});
|
|
196
|
+
return this.configPlugin;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Initialize config plugin (default or loaded)
|
|
200
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBConfig.html#init | API: SBConfig.init}
|
|
201
|
+
*/
|
|
202
|
+
async init() {
|
|
203
|
+
const tTrace = internalTrace(`init`);
|
|
204
|
+
if (base_1.Tools.isString(process.env.BSB_CONFIG_PLUGIN) &&
|
|
205
|
+
process.env.BSB_CONFIG_PLUGIN.startsWith("config-")) {
|
|
206
|
+
this.configPluginName = process.env.BSB_CONFIG_PLUGIN;
|
|
207
|
+
if (base_1.Tools.isString(process.env.BSB_CONFIG_PLUGIN_PACKAGE)) {
|
|
208
|
+
this.configPackage = process.env.BSB_CONFIG_PLUGIN_PACKAGE;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
this.observableBackend.debug(tTrace, "Add config {name} from ({package})", {
|
|
212
|
+
package: this.configPackage ?? "this project",
|
|
213
|
+
name: this.configPluginName,
|
|
214
|
+
});
|
|
215
|
+
if (this.configPluginName === "config-default") {
|
|
216
|
+
const obs = this.createObservable(tTrace, "config");
|
|
217
|
+
await (0, base_1.SmartFunctionCallAsync)(this.configPlugin, this.configPlugin.init, obs);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.observableBackend.debug(tTrace, `Import config plugin: {name} from ({package})`, {
|
|
221
|
+
package: this.configPackage ?? "this project",
|
|
222
|
+
name: this.configPluginName,
|
|
223
|
+
});
|
|
224
|
+
const newPlugin = await this.sbPlugins.loadPlugin(this.observableBackend, this.configPackage ?? null, this.configPluginName, this.configPluginName);
|
|
225
|
+
if (newPlugin === null || !newPlugin.success) {
|
|
226
|
+
this.observableBackend.error(tTrace, "Failed to import config plugin: {name} from ({package})", {
|
|
227
|
+
package: this.configPackage ?? "this project",
|
|
228
|
+
name: this.configPluginName,
|
|
229
|
+
});
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
await this.setConfigPlugin(newPlugin.data);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.SBConfig = SBConfig;
|
|
236
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/serviceBase/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,kCAOiB;AACjB,8CAWuB;AACvB,2DAA6G;AAG7G,6BAAwB;AAExB;;GAEG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAA,6BAAgB,EAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAa,QAAQ;IACX,MAAM,CAAU,uBAAuB,GAAG,CAAC,aAAa,EAAE,iBAAiB,CAAU,CAAC;IAC9F;;OAEG;IACK,IAAI,GAAe,aAAa,CAAC;IACjC,KAAK,CAAS;IACd,GAAG,CAAS;IACZ,SAAS,CAAY;IACrB,YAAY,CAAe;IAC3B,iBAAiB,CAAoB;IACrC,YAAY,CAAY;IACxB,gBAAgB,CAA4G;IAEpI,YACE,KAAa,EACb,IAAgB,EAChB,GAAW,EACX,YAA0B,EAC1B,SAAoB,EACpB,gBAA2H;QAE3H,IAAI,CAAC,KAAK,GAAG,KAA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AI,CAAC,SAAS,CAAC,UAAU,CAC/C,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,aAAa,IAAI,IAAI,EAC1B,IAAI,CAAC,gBAAgB,EACrB,IAAI,CAAC,gBAAgB,CACtB,CAAC;QACF,IAAI,SAAS,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;YAC7C,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,EACjC,yDAAyD,EACzD;gBACE,OAAO,EAAE,IAAI,CAAC,aAAa,IAAI,cAAc;gBAC7C,IAAI,EAAE,IAAI,CAAC,gBAAgB;aAC5B,CACF,CAAC;YACF,OAAO;QACT,CAAC;QAED,MAAM,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;;AAzPH,4BA0PC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 { BSBService, BSBServiceClient } from "../base";
|
|
29
|
+
import { DEBUG_MODE, DTrace, EventsFilter, IPluginDefinition, LoadedPlugin, Observable } from "../interfaces";
|
|
30
|
+
import { SBConfig } from "./config";
|
|
31
|
+
import { SBObservable } from "./observable";
|
|
32
|
+
import { SBPlugins } from "./plugins";
|
|
33
|
+
/**
|
|
34
|
+
* BSB Events Controller
|
|
35
|
+
*
|
|
36
|
+
* This class is responsible for managing the events in the BSB framework.
|
|
37
|
+
* If you have a specific way of managing events, you can extend this class and then use your own class when creating the ServiceBase instance.
|
|
38
|
+
*
|
|
39
|
+
* @group Events
|
|
40
|
+
* @category Core
|
|
41
|
+
*/
|
|
42
|
+
export declare class SBEvents {
|
|
43
|
+
/**
|
|
44
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/SBEvents.html | API: SBEvents}
|
|
45
|
+
*/
|
|
46
|
+
private events;
|
|
47
|
+
private readonly mode;
|
|
48
|
+
private readonly appId;
|
|
49
|
+
private readonly cwd;
|
|
50
|
+
private sbPlugins;
|
|
51
|
+
private readonly observableBackend;
|
|
52
|
+
private metricCounters;
|
|
53
|
+
private metricGauges;
|
|
54
|
+
private createObservable;
|
|
55
|
+
constructor(appId: string, mode: DEBUG_MODE, cwd: string, sbPlugins: SBPlugins, sbObservable: SBObservable, createObservable: (trace: DTrace, pluginName: string, attributes?: Record<string, string | number | boolean>) => Observable);
|
|
56
|
+
dispose(): void;
|
|
57
|
+
private getPluginsMatchingTriggerEvent;
|
|
58
|
+
private getPluginForEvent;
|
|
59
|
+
init(sbConfig: SBConfig, sbObservable: SBObservable): Promise<void>;
|
|
60
|
+
run(): Promise<void>;
|
|
61
|
+
addPlugin(sbObservable: SBObservable, plugin: IPluginDefinition, reference: LoadedPlugin<"events">, config: any, filter?: EventsFilter): Promise<import("../base").BSBEventsRef>;
|
|
62
|
+
private addEvents;
|
|
63
|
+
private handleOnBroadcast;
|
|
64
|
+
onBroadcast(context: BSBService<any, any> | BSBServiceClient<any>, trace: DTrace, pluginName: string, event: string, listener: {
|
|
65
|
+
(trace: DTrace, ...args: Array<any>): Promise<void> | void;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
emitBroadcast(trace: DTrace, pluginName: string, event: string, ...args: Array<any>): Promise<void>;
|
|
68
|
+
private handleOnEvent;
|
|
69
|
+
onEvent(trace: DTrace, context: BSBService | BSBServiceClient<any>, pluginName: string, event: string, listener: {
|
|
70
|
+
(trace: DTrace, ...args: Array<any>): Promise<void> | void;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
onEventSpecific(trace: DTrace, serverId: string, context: BSBService | BSBServiceClient<any>, pluginName: string, event: string, listener: {
|
|
73
|
+
(trace: DTrace, ...args: Array<any>): Promise<void> | void;
|
|
74
|
+
}): Promise<void>;
|
|
75
|
+
emitEvent(trace: DTrace, pluginName: string, event: string, ...args: Array<any>): Promise<void>;
|
|
76
|
+
emitEventSpecific(trace: DTrace, serverId: string, pluginName: string, event: string, ...args: Array<any>): Promise<void>;
|
|
77
|
+
private handleOnReturnableEvent;
|
|
78
|
+
onReturnableEvent(trace: DTrace, context: BSBService | BSBServiceClient<any>, pluginName: string, event: string, listener: {
|
|
79
|
+
(trace: DTrace, ...args: Array<any>): Promise<any> | any;
|
|
80
|
+
}): Promise<void>;
|
|
81
|
+
onReturnableEventSpecific(trace: DTrace, serverId: string, context: BSBService | BSBServiceClient<any>, pluginName: string, event: string, listener: {
|
|
82
|
+
(trace: DTrace, ...args: Array<any>): Promise<any> | any;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
emitEventAndReturn(trace: DTrace, pluginName: string, event: string, timeoutSeconds: number, ...args: Array<any>): Promise<any>;
|
|
85
|
+
emitEventAndReturnSpecific(trace: DTrace, serverId: string, pluginName: string, event: string, timeoutSeconds: number, ...args: Array<any>): Promise<any>;
|
|
86
|
+
private handleOnReceiveStream;
|
|
87
|
+
receiveStream(trace: DTrace, context: BSBService | BSBServiceClient<any>, pluginName: string, event: string, listener: {
|
|
88
|
+
(error: Error | null, stream: Readable): Promise<void>;
|
|
89
|
+
}, timeoutSeconds?: number): Promise<string>;
|
|
90
|
+
sendStream(trace: DTrace, pluginName: string, event: string, streamId: string, stream: Readable): Promise<void>;
|
|
91
|
+
}
|