@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
package/lib/base/base.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
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.MS_PER_NS = exports.NS_PER_SEC = exports.BaseWithObservableAndConfig = exports.BaseWithObservable = exports.BaseWithConfig = exports.Base = exports.MainBase = void 0;
|
|
30
|
+
const ObservableBackend_1 = require("./ObservableBackend");
|
|
31
|
+
/**
|
|
32
|
+
* @hidden
|
|
33
|
+
*/
|
|
34
|
+
class MainBase {
|
|
35
|
+
/**
|
|
36
|
+
* The unique app id of the app that is running
|
|
37
|
+
* @readonly
|
|
38
|
+
* @type {string}
|
|
39
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/MainBase.html#appId | API: MainBase.appId}
|
|
40
|
+
*/
|
|
41
|
+
appId = "tbd";
|
|
42
|
+
/**
|
|
43
|
+
* The mode the app is running in
|
|
44
|
+
* @readonly
|
|
45
|
+
* @type {DEBUG_MODE}
|
|
46
|
+
* @example production (production mode - no debug)
|
|
47
|
+
* @example production-debug (production mode - debug)
|
|
48
|
+
* @example development (development mode - debug)
|
|
49
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/MainBase.html#mode | API: MainBase.mode}
|
|
50
|
+
*/
|
|
51
|
+
mode = "development";
|
|
52
|
+
/**
|
|
53
|
+
* The current working directory of the app
|
|
54
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/MainBase.html#cwd | API: MainBase.cwd}
|
|
55
|
+
*/
|
|
56
|
+
cwd;
|
|
57
|
+
/**
|
|
58
|
+
* The current working directory of the plugin
|
|
59
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/MainBase.html#packageCwd | API: MainBase.packageCwd}
|
|
60
|
+
*/
|
|
61
|
+
packageCwd;
|
|
62
|
+
/**
|
|
63
|
+
* The current working directory of the service
|
|
64
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/MainBase.html#pluginCwd | API: MainBase.pluginCwd}
|
|
65
|
+
*/
|
|
66
|
+
pluginCwd;
|
|
67
|
+
/**
|
|
68
|
+
* The deployment region for resource context
|
|
69
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/MainBase.html#region | API: MainBase.region}
|
|
70
|
+
*/
|
|
71
|
+
region;
|
|
72
|
+
constructor(config) {
|
|
73
|
+
this.appId = config.appId;
|
|
74
|
+
this.mode = config.mode;
|
|
75
|
+
if (config.pluginName !== "") {
|
|
76
|
+
this.pluginName = config.pluginName;
|
|
77
|
+
}
|
|
78
|
+
this.cwd = config.cwd;
|
|
79
|
+
this.packageCwd = config.packageCwd;
|
|
80
|
+
this.pluginCwd = config.pluginCwd;
|
|
81
|
+
this.region = config.region;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.MainBase = MainBase;
|
|
85
|
+
/**
|
|
86
|
+
* @hidden
|
|
87
|
+
*/
|
|
88
|
+
class Base extends MainBase {
|
|
89
|
+
/**
|
|
90
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Base.html | API: Base}
|
|
91
|
+
*/
|
|
92
|
+
constructor(config) {
|
|
93
|
+
super(config);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.Base = Base;
|
|
97
|
+
/**
|
|
98
|
+
* @hidden
|
|
99
|
+
* used by logging plugins (does not need events or logging since logging logs its own logs)
|
|
100
|
+
*/
|
|
101
|
+
class BaseWithConfig extends Base {
|
|
102
|
+
/**
|
|
103
|
+
* The config of the plugin
|
|
104
|
+
* @type {PluginConfig}
|
|
105
|
+
* @readonly
|
|
106
|
+
*/
|
|
107
|
+
config;
|
|
108
|
+
constructor(config) {
|
|
109
|
+
super(config);
|
|
110
|
+
this.config = config.config;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.BaseWithConfig = BaseWithConfig;
|
|
114
|
+
/**
|
|
115
|
+
* @hidden
|
|
116
|
+
* Base class with internal observable support for Observable creation.
|
|
117
|
+
*
|
|
118
|
+
* **v9 Architecture:**
|
|
119
|
+
* - Logging and metrics accessed via Observable: `obs.log.info("message")`, `obs.metrics.counter(...)`
|
|
120
|
+
* - Use `this.createObservable()` to create new root traces
|
|
121
|
+
* - Pass Observable through all methods for trace context
|
|
122
|
+
*
|
|
123
|
+
* @see {@link Observable} for the unified observable interface
|
|
124
|
+
* @see {@link BSBService.createObservable} for creating Observables
|
|
125
|
+
*/
|
|
126
|
+
class BaseWithObservable extends Base {
|
|
127
|
+
/**
|
|
128
|
+
* @hidden
|
|
129
|
+
* Internal ObservableBackend instance for creating Observables.
|
|
130
|
+
* NOT accessible to plugin code - use Observable instead.
|
|
131
|
+
*/
|
|
132
|
+
_observable;
|
|
133
|
+
constructor(config) {
|
|
134
|
+
super(config);
|
|
135
|
+
this._observable = new ObservableBackend_1.ObservableBackend(config.mode, config.appId, config.pluginName, config.sbObservable);
|
|
136
|
+
// Observable backend initialized
|
|
137
|
+
// Accessible via this.__internalObservable for creating Observables
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @hidden
|
|
141
|
+
* Get internal observable backend for Observable creation.
|
|
142
|
+
* NOT for direct plugin use.
|
|
143
|
+
*/
|
|
144
|
+
get __internalObservable() {
|
|
145
|
+
return this._observable;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.BaseWithObservable = BaseWithObservable;
|
|
149
|
+
/**
|
|
150
|
+
* @hidden
|
|
151
|
+
* Base class with config and internal observable support.
|
|
152
|
+
* Use Observable for all logging and metrics operations.
|
|
153
|
+
*/
|
|
154
|
+
class BaseWithObservableAndConfig extends BaseWithConfig {
|
|
155
|
+
/**
|
|
156
|
+
* @hidden
|
|
157
|
+
* Internal ObservableBackend instance for creating Observables.
|
|
158
|
+
*/
|
|
159
|
+
_observable;
|
|
160
|
+
constructor(config) {
|
|
161
|
+
super(config);
|
|
162
|
+
this._observable = new ObservableBackend_1.ObservableBackend(config.mode, config.appId, config.pluginName, config.sbObservable);
|
|
163
|
+
// Observable backend initialized
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @hidden
|
|
167
|
+
* Get internal observable backend for Observable creation.
|
|
168
|
+
*/
|
|
169
|
+
get __internalObservable() {
|
|
170
|
+
return this._observable;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.BaseWithObservableAndConfig = BaseWithObservableAndConfig;
|
|
174
|
+
/**
|
|
175
|
+
* @hidden
|
|
176
|
+
*/
|
|
177
|
+
exports.NS_PER_SEC = 1e9;
|
|
178
|
+
/**
|
|
179
|
+
* @hidden
|
|
180
|
+
*/
|
|
181
|
+
exports.MS_PER_NS = 1e-6;
|
|
182
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/base/base.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAKH,2DAAwD;AAuBxD;;GAEG;AACH,MAAsB,QAAQ;IAC5B;;;;;OAKG;IACa,KAAK,GAAW,KAAK,CAAC;IAEtC;;;;;;;;OAQG;IACa,IAAI,GAAe,aAAa,CAAC;IACjD;;;OAGG;IACa,GAAG,CAAS;IAC5B;;;OAGG;IACa,UAAU,CAAS;IACnC;;;OAGG;IACa,SAAS,CAAS;IAQlC;;;OAGG;IACa,MAAM,CAAU;IAEhC,YAAY,MAAsB;QAChC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,MAAM,CAAC,UAAU,KAAK,EAAE,EAAE,CAAC;YAC7B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM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AC,WAAW,CAAC;IAC1B,CAAC;CACF;AA7BD,kEA6BC;AAED;;GAEG;AACU,QAAA,UAAU,GAAG,GAAG,CAAC;AAC9B;;GAEG;AACU,QAAA,SAAS,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { DTrace, LogMeta, ParamsFromString } from "../interfaces";
|
|
28
|
+
/**
|
|
29
|
+
* @hidden
|
|
30
|
+
*/
|
|
31
|
+
export type ErrorLogMetaDefinition<T extends string> = {
|
|
32
|
+
trace: DTrace;
|
|
33
|
+
message: T;
|
|
34
|
+
meta: LogMeta<T>;
|
|
35
|
+
};
|
|
36
|
+
export type ErrorLogMeta<T extends string> = ParamsFromString<T> extends never ? [undefined?] : [meta: LogMeta<T>];
|
|
37
|
+
/**
|
|
38
|
+
* BSBError is a custom error class that allows for better error handling and logging
|
|
39
|
+
*
|
|
40
|
+
* @group Errors
|
|
41
|
+
* @category Tools
|
|
42
|
+
* @param message - The message to log
|
|
43
|
+
* @param meta - Additional information to log with the message
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/BSBError.html | API: BSBError}
|
|
47
|
+
*/
|
|
48
|
+
export declare class BSBError<T extends string> extends Error {
|
|
49
|
+
constructor(trace: DTrace, message: T, ...meta: ErrorLogMeta<T>);
|
|
50
|
+
raw: ErrorLogMetaDefinition<string> | null;
|
|
51
|
+
toString(): string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @hidden
|
|
55
|
+
*/
|
|
56
|
+
export declare function BSB_ERROR_METHOD_NOT_IMPLEMENTED(className: string, method: string): BSBError<"Method not implemented: {class}.{method}">;
|
|
@@ -0,0 +1,70 @@
|
|
|
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.BSBError = void 0;
|
|
30
|
+
exports.BSB_ERROR_METHOD_NOT_IMPLEMENTED = BSB_ERROR_METHOD_NOT_IMPLEMENTED;
|
|
31
|
+
const interfaces_1 = require("../interfaces");
|
|
32
|
+
const logFormatter_1 = require("./logFormatter");
|
|
33
|
+
/**
|
|
34
|
+
* BSBError is a custom error class that allows for better error handling and logging
|
|
35
|
+
*
|
|
36
|
+
* @group Errors
|
|
37
|
+
* @category Tools
|
|
38
|
+
* @param message - The message to log
|
|
39
|
+
* @param meta - Additional information to log with the message
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/BSBError.html | API: BSBError}
|
|
43
|
+
*/
|
|
44
|
+
class BSBError extends Error {
|
|
45
|
+
constructor(trace, message, ...meta) {
|
|
46
|
+
const formatter = new logFormatter_1.LogFormatter();
|
|
47
|
+
super(formatter.formatLog(trace, message, ...meta));
|
|
48
|
+
this.name = "BSBError-" + message;
|
|
49
|
+
this.raw = {
|
|
50
|
+
trace,
|
|
51
|
+
message,
|
|
52
|
+
meta: meta,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
raw = null;
|
|
56
|
+
toString() {
|
|
57
|
+
return this.message;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.BSBError = BSBError;
|
|
61
|
+
/**
|
|
62
|
+
* @hidden
|
|
63
|
+
*/
|
|
64
|
+
function BSB_ERROR_METHOD_NOT_IMPLEMENTED(className, method) {
|
|
65
|
+
return new BSBError((0, interfaces_1.createFakeDTrace)('base/errorMessages', 'BSB_ERROR_METHOD_NOT_IMPLEMENTED'), "Method not implemented: {class}.{method}", {
|
|
66
|
+
class: className,
|
|
67
|
+
method: method,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=errorMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMessages.js","sourceRoot":"","sources":["../../src/base/errorMessages.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAuDH,4EAYC;AAjED,8CAAoF;AACpF,iDAA8C;AAc9C;;;;;;;GAOG;AACH;;GAEG;AACH,MAAa,QACX,SAAQ,KAAK;IACb,YACE,KAAa,EACb,OAAU,EACV,GAAG,IAAqB;QAExB,MAAM,SAAS,GAAG,IAAI,2BAAY,EAAE,CAAC;QACrC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,WAAW,GAAG,OAAO,CAAC;QAClC,IAAI,CAAC,GAAG,GAAG;YACT,KAAK;YACL,OAAO;YACP,IAAI,EAAE,IAAI;SACX,CAAC;IACJ,CAAC;IAEM,GAAG,GAA0C,IAAI,CAAC;IAElD,QAAQ;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAtBD,4BAsBC;AAED;;GAEG;AACH,SAAgB,gCAAgC,CAC9C,SAAiB,EACjB,MAAc;IAEd,OAAO,IAAI,QAAQ,CACjB,IAAA,6BAAgB,EAAC,oBAAoB,EAAE,kCAAkC,CAAC,EAC1E,0CAA0C,EAC1C;QACE,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,MAAM;KACf,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { BSBOptions, ResolvedBSBOptions, SimpleBSBOptions, BSBPreset } from "../interfaces";
|
|
28
|
+
/**
|
|
29
|
+
* Resolves BSB options with defaults
|
|
30
|
+
*
|
|
31
|
+
* @param options - User provided options
|
|
32
|
+
* @returns Resolved options with all defaults applied
|
|
33
|
+
*
|
|
34
|
+
* @group Main
|
|
35
|
+
* @category Factory
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveBSBOptions(options?: BSBOptions): ResolvedBSBOptions;
|
|
38
|
+
/**
|
|
39
|
+
* Creates BSBOptions from simple configuration
|
|
40
|
+
*
|
|
41
|
+
* @param simple - Simple configuration options
|
|
42
|
+
* @returns BSBOptions for ServiceBase
|
|
43
|
+
*
|
|
44
|
+
* @group Main
|
|
45
|
+
* @category Factory
|
|
46
|
+
*/
|
|
47
|
+
export declare function fromSimpleOptions(simple?: SimpleBSBOptions): BSBOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Creates BSBOptions from preset configuration
|
|
50
|
+
*
|
|
51
|
+
* @param preset - Preset type
|
|
52
|
+
* @param overrides - Additional options to override preset defaults
|
|
53
|
+
* @returns BSBOptions for ServiceBase
|
|
54
|
+
*
|
|
55
|
+
* @group Main
|
|
56
|
+
* @category Factory
|
|
57
|
+
*/
|
|
58
|
+
export declare function fromPreset(preset: BSBPreset, overrides?: Partial<BSBOptions>): BSBOptions;
|
|
@@ -0,0 +1,167 @@
|
|
|
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.resolveBSBOptions = resolveBSBOptions;
|
|
30
|
+
exports.fromSimpleOptions = fromSimpleOptions;
|
|
31
|
+
exports.fromPreset = fromPreset;
|
|
32
|
+
const uuid_1 = require("uuid");
|
|
33
|
+
const node_os_1 = require("node:os");
|
|
34
|
+
const interfaces_1 = require("../interfaces");
|
|
35
|
+
const config_1 = require("../serviceBase/config");
|
|
36
|
+
const plugins_1 = require("../serviceBase/plugins");
|
|
37
|
+
const observable_1 = require("../serviceBase/observable");
|
|
38
|
+
const events_1 = require("../serviceBase/events");
|
|
39
|
+
const services_1 = require("../serviceBase/services");
|
|
40
|
+
/**
|
|
41
|
+
* Resolves BSB options with defaults
|
|
42
|
+
*
|
|
43
|
+
* @param options - User provided options
|
|
44
|
+
* @returns Resolved options with all defaults applied
|
|
45
|
+
*
|
|
46
|
+
* @group Main
|
|
47
|
+
* @category Factory
|
|
48
|
+
*/
|
|
49
|
+
function resolveBSBOptions(options = {}) {
|
|
50
|
+
const { debug = true, live = false, cwd = process.cwd(), appId, region, config = config_1.SBConfig, plugins = plugins_1.SBPlugins, observable = observable_1.SBObservable, events = events_1.SBEvents, services = services_1.SBServices } = options;
|
|
51
|
+
// Determine debug mode
|
|
52
|
+
let mode;
|
|
53
|
+
if (live === false) {
|
|
54
|
+
mode = "development";
|
|
55
|
+
}
|
|
56
|
+
else if (debug === true) {
|
|
57
|
+
mode = "production-debug";
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
mode = "production";
|
|
61
|
+
}
|
|
62
|
+
// Generate app ID if not provided
|
|
63
|
+
let resolvedAppId;
|
|
64
|
+
if (appId) {
|
|
65
|
+
resolvedAppId = appId;
|
|
66
|
+
}
|
|
67
|
+
else if (typeof process.env.BSB_APP_ID === "string" && process.env.BSB_APP_ID.length > 2) {
|
|
68
|
+
resolvedAppId = process.env.BSB_APP_ID;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
resolvedAppId = `${(0, node_os_1.hostname)()}-${(0, uuid_1.v7)()}`;
|
|
72
|
+
}
|
|
73
|
+
// Resolve region from option → env → undefined
|
|
74
|
+
let resolvedRegion;
|
|
75
|
+
if (region) {
|
|
76
|
+
resolvedRegion = region;
|
|
77
|
+
}
|
|
78
|
+
else if (typeof process.env.BSB_REGION === "string" && process.env.BSB_REGION.length > 0) {
|
|
79
|
+
resolvedRegion = process.env.BSB_REGION;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
resolvedRegion = undefined;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
debug,
|
|
86
|
+
live,
|
|
87
|
+
cwd,
|
|
88
|
+
appId: resolvedAppId,
|
|
89
|
+
region: resolvedRegion,
|
|
90
|
+
mode,
|
|
91
|
+
config,
|
|
92
|
+
plugins,
|
|
93
|
+
observable,
|
|
94
|
+
events,
|
|
95
|
+
services
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates BSBOptions from simple configuration
|
|
100
|
+
*
|
|
101
|
+
* @param simple - Simple configuration options
|
|
102
|
+
* @returns BSBOptions for ServiceBase
|
|
103
|
+
*
|
|
104
|
+
* @group Main
|
|
105
|
+
* @category Factory
|
|
106
|
+
*/
|
|
107
|
+
function fromSimpleOptions(simple = {}) {
|
|
108
|
+
const { cwd = process.cwd(), debug = process.env.NODE_ENV !== "production" } = simple;
|
|
109
|
+
// TODO: Handle config file loading and plugin list processing
|
|
110
|
+
// This would need integration with the config system
|
|
111
|
+
return {
|
|
112
|
+
debug,
|
|
113
|
+
cwd,
|
|
114
|
+
live: process.env.NODE_ENV === "production"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Creates BSBOptions from preset configuration
|
|
119
|
+
*
|
|
120
|
+
* @param preset - Preset type
|
|
121
|
+
* @param overrides - Additional options to override preset defaults
|
|
122
|
+
* @returns BSBOptions for ServiceBase
|
|
123
|
+
*
|
|
124
|
+
* @group Main
|
|
125
|
+
* @category Factory
|
|
126
|
+
*/
|
|
127
|
+
function fromPreset(preset, overrides = {}) {
|
|
128
|
+
let baseOptions;
|
|
129
|
+
switch (preset) {
|
|
130
|
+
case interfaces_1.BSBPreset.MINIMAL:
|
|
131
|
+
baseOptions = {
|
|
132
|
+
debug: false,
|
|
133
|
+
live: true,
|
|
134
|
+
cwd: process.cwd()
|
|
135
|
+
};
|
|
136
|
+
break;
|
|
137
|
+
case interfaces_1.BSBPreset.DEVELOPMENT:
|
|
138
|
+
baseOptions = {
|
|
139
|
+
debug: true,
|
|
140
|
+
live: false,
|
|
141
|
+
cwd: process.cwd()
|
|
142
|
+
};
|
|
143
|
+
break;
|
|
144
|
+
case interfaces_1.BSBPreset.PRODUCTION:
|
|
145
|
+
baseOptions = {
|
|
146
|
+
debug: false,
|
|
147
|
+
live: true,
|
|
148
|
+
cwd: process.cwd()
|
|
149
|
+
};
|
|
150
|
+
break;
|
|
151
|
+
case interfaces_1.BSBPreset.TESTING:
|
|
152
|
+
baseOptions = {
|
|
153
|
+
debug: true,
|
|
154
|
+
live: false,
|
|
155
|
+
cwd: process.cwd()
|
|
156
|
+
// TODO: Add mock implementations for testing
|
|
157
|
+
};
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
throw new Error(`Unknown preset: ${preset}`);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
...baseOptions,
|
|
164
|
+
...overrides
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/base/factory.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;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AE,IAAI;gBACX,IAAI,EAAE,KAAK;gBACX,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;aACnB,CAAC;YACF,MAAM;QAER,KAAK,sBAAS,CAAC,UAAU;YACvB,WAAW,GAAG;gBACZ,KAAK,EAAE,KAAK;gBACZ,IAAI,EAAE,IAAI;gBACV,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;aACnB,CAAC;YACF,MAAM;QAER,KAAK,sBAAS,CAAC,OAAO;YACpB,WAAW,GAAG;gBACZ,KAAK,EAAE,IAAI;gBACX,IAAI,EAAE,KAAK;gBACX,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;gBAClB,6CAA6C;aAC9C,CAAC;YACF,MAAM;QAER;YACE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,OAAO;QACL,GAAG,WAAW;QACd,GAAG,SAAS;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
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 { DTrace } from '../interfaces/metrics';
|
|
28
|
+
import { z } from "zod";
|
|
29
|
+
type SmartFunctionCallFunc = {
|
|
30
|
+
[Symbol.toStringTag]?: string;
|
|
31
|
+
(...args: any[]): any;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* initializes a function call and calls it with context but shows as the function type (async/sync)
|
|
35
|
+
* @group Functions
|
|
36
|
+
* @category Tools
|
|
37
|
+
* @param context - the context to call the function with
|
|
38
|
+
* @param input - the function to call
|
|
39
|
+
* @param params - the parameters to pass to the function
|
|
40
|
+
* @returns Async/Sync called function return type or immediately if the input is not a function
|
|
41
|
+
* @throws BSBError context is not an object
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const myFunc = async (a: string, b: number) => {
|
|
46
|
+
* console.log("called with " + a + " and " + b);
|
|
47
|
+
* };
|
|
48
|
+
* console.log("done with " + (await SmartFunctionCallThroughAsync(this, myFunc, "a", 5)));
|
|
49
|
+
* ```
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const myFunc = (a: string, b: number) => {
|
|
53
|
+
* console.log("called with " + a + " and " + b);
|
|
54
|
+
* };
|
|
55
|
+
* console.log("done with " + SmartFunctionCallThroughAsync(this, myFunc, "a", 5));
|
|
56
|
+
* ```
|
|
57
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/SmartFunctionCallThroughAsync.html | API: SmartFunctionCallThroughAsync}
|
|
58
|
+
*/
|
|
59
|
+
export declare function SmartFunctionCallThroughAsync<T extends SmartFunctionCallFunc>(trace: DTrace, context: any, input: T | undefined, ...params: Parameters<T>): Promise<ReturnType<T> | void> | ReturnType<T> | void;
|
|
60
|
+
/**
|
|
61
|
+
* Initializes a function call and calls it with context but shows as the function type (async)
|
|
62
|
+
* @group Functions
|
|
63
|
+
* @category Tools
|
|
64
|
+
* @param trace - the trace to use
|
|
65
|
+
* @param context - the context to call the function with
|
|
66
|
+
* @param input - the function to call
|
|
67
|
+
* @param params - the parameters to pass to the function
|
|
68
|
+
* @returns Async called function return type or immediately if the input is not a function
|
|
69
|
+
* @throws BSBError context is not an object
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const myFunc = async (a: string, b: number) => {
|
|
74
|
+
* console.log("called with " + a + " and " + b);
|
|
75
|
+
* };
|
|
76
|
+
* console.log("done with " + await SmartFunctionCallAsync(this, myFunc, "a", 5));
|
|
77
|
+
* ```
|
|
78
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/SmartFunctionCallAsync.html | API: SmartFunctionCallAsync}
|
|
79
|
+
*/
|
|
80
|
+
export declare function SmartFunctionCallAsync<T extends SmartFunctionCallFunc>(context: any, input: T | undefined, ...params: Parameters<T>): Promise<ReturnType<T> | void>;
|
|
81
|
+
/**
|
|
82
|
+
* initializes a function call and calls it with context but shows as the function type (sync)
|
|
83
|
+
* @group Functions
|
|
84
|
+
* @category Tools
|
|
85
|
+
* @param context
|
|
86
|
+
* @param input
|
|
87
|
+
* @param params
|
|
88
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/SmartFunctionCallSync.html | API: SmartFunctionCallSync}
|
|
89
|
+
*/
|
|
90
|
+
export declare function SmartFunctionCallSync<T extends SmartFunctionCallFunc>(context: any, input: T | undefined, ...params: Parameters<T>): ReturnType<T> | void;
|
|
91
|
+
/**
|
|
92
|
+
* Validated environment properties for the BSB runtime.
|
|
93
|
+
*
|
|
94
|
+
* Use {@link getEnvProps} to read and validate the current process env.
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/modules.html#ENV_PROPS | API: ENV_PROPS}
|
|
97
|
+
*/
|
|
98
|
+
export declare const ENV_PROPS: z.ZodObject<{
|
|
99
|
+
BSB_PROFILE: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
100
|
+
BSB_CONFIG_FILE: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
101
|
+
APP_DIR: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
102
|
+
BSB_LOGGER_PLUGIN: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
103
|
+
BSB_LOGGER_PLUGIN_PACKAGE: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
/**
|
|
106
|
+
* Parse and validate the current environment against {@link ENV_PROPS}.
|
|
107
|
+
*
|
|
108
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/getEnvProps.html | API: getEnvProps}
|
|
109
|
+
*/
|
|
110
|
+
export declare function getEnvProps(): {
|
|
111
|
+
BSB_PROFILE: string;
|
|
112
|
+
BSB_CONFIG_FILE: string;
|
|
113
|
+
APP_DIR: string;
|
|
114
|
+
BSB_LOGGER_PLUGIN: string;
|
|
115
|
+
BSB_LOGGER_PLUGIN_PACKAGE: string;
|
|
116
|
+
};
|
|
117
|
+
export {};
|