@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,152 @@
|
|
|
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.ENV_PROPS = void 0;
|
|
30
|
+
exports.SmartFunctionCallThroughAsync = SmartFunctionCallThroughAsync;
|
|
31
|
+
exports.SmartFunctionCallAsync = SmartFunctionCallAsync;
|
|
32
|
+
exports.SmartFunctionCallSync = SmartFunctionCallSync;
|
|
33
|
+
exports.getEnvProps = getEnvProps;
|
|
34
|
+
const metrics_1 = require("../interfaces/metrics");
|
|
35
|
+
const errorMessages_1 = require("./errorMessages");
|
|
36
|
+
const zod_1 = require("zod");
|
|
37
|
+
/**
|
|
38
|
+
* @hidden
|
|
39
|
+
*/
|
|
40
|
+
function internalTrace(span) {
|
|
41
|
+
return (0, metrics_1.createFakeDTrace)("base/functions", span);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* initializes a function call and calls it with context but shows as the function type (async/sync)
|
|
45
|
+
* @group Functions
|
|
46
|
+
* @category Tools
|
|
47
|
+
* @param context - the context to call the function with
|
|
48
|
+
* @param input - the function to call
|
|
49
|
+
* @param params - the parameters to pass to the function
|
|
50
|
+
* @returns Async/Sync called function return type or immediately if the input is not a function
|
|
51
|
+
* @throws BSBError context is not an object
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const myFunc = async (a: string, b: number) => {
|
|
56
|
+
* console.log("called with " + a + " and " + b);
|
|
57
|
+
* };
|
|
58
|
+
* console.log("done with " + (await SmartFunctionCallThroughAsync(this, myFunc, "a", 5)));
|
|
59
|
+
* ```
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const myFunc = (a: string, b: number) => {
|
|
63
|
+
* console.log("called with " + a + " and " + b);
|
|
64
|
+
* };
|
|
65
|
+
* console.log("done with " + SmartFunctionCallThroughAsync(this, myFunc, "a", 5));
|
|
66
|
+
* ```
|
|
67
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/SmartFunctionCallThroughAsync.html | API: SmartFunctionCallThroughAsync}
|
|
68
|
+
*/
|
|
69
|
+
function SmartFunctionCallThroughAsync(trace, context, input, ...params) {
|
|
70
|
+
if (typeof input !== "function")
|
|
71
|
+
return;
|
|
72
|
+
if (typeof context !== "object") {
|
|
73
|
+
throw new errorMessages_1.BSBError(trace, "SmartFunctionCallThroughAsync: context is not an object");
|
|
74
|
+
}
|
|
75
|
+
return input.call(context, ...params);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Initializes a function call and calls it with context but shows as the function type (async)
|
|
79
|
+
* @group Functions
|
|
80
|
+
* @category Tools
|
|
81
|
+
* @param trace - the trace to use
|
|
82
|
+
* @param context - the context to call the function with
|
|
83
|
+
* @param input - the function to call
|
|
84
|
+
* @param params - the parameters to pass to the function
|
|
85
|
+
* @returns Async called function return type or immediately if the input is not a function
|
|
86
|
+
* @throws BSBError context is not an object
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const myFunc = async (a: string, b: number) => {
|
|
91
|
+
* console.log("called with " + a + " and " + b);
|
|
92
|
+
* };
|
|
93
|
+
* console.log("done with " + await SmartFunctionCallAsync(this, myFunc, "a", 5));
|
|
94
|
+
* ```
|
|
95
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/SmartFunctionCallAsync.html | API: SmartFunctionCallAsync}
|
|
96
|
+
*/
|
|
97
|
+
async function SmartFunctionCallAsync(context, input, ...params) {
|
|
98
|
+
if (typeof input !== "function")
|
|
99
|
+
return;
|
|
100
|
+
if (typeof context !== "object") {
|
|
101
|
+
throw new errorMessages_1.BSBError(internalTrace("SmartFunctionCallAsync"), "SmartFunctionCallAsync: context is not an object");
|
|
102
|
+
}
|
|
103
|
+
if (input[Symbol.toStringTag] === "AsyncFunction") {
|
|
104
|
+
return await input.call(context, ...params);
|
|
105
|
+
}
|
|
106
|
+
return input.call(context, ...params);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* initializes a function call and calls it with context but shows as the function type (sync)
|
|
110
|
+
* @group Functions
|
|
111
|
+
* @category Tools
|
|
112
|
+
* @param context
|
|
113
|
+
* @param input
|
|
114
|
+
* @param params
|
|
115
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/SmartFunctionCallSync.html | API: SmartFunctionCallSync}
|
|
116
|
+
*/
|
|
117
|
+
function SmartFunctionCallSync(context, input, ...params) {
|
|
118
|
+
if (typeof input !== "function")
|
|
119
|
+
return;
|
|
120
|
+
if (typeof context !== "object") {
|
|
121
|
+
throw new errorMessages_1.BSBError(internalTrace("SmartFunctionCallSync"), "SmartFunctionCallSync: context is not an object");
|
|
122
|
+
}
|
|
123
|
+
return input.call(context, ...params);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Validated environment properties for the BSB runtime.
|
|
127
|
+
*
|
|
128
|
+
* Use {@link getEnvProps} to read and validate the current process env.
|
|
129
|
+
*
|
|
130
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/modules.html#ENV_PROPS | API: ENV_PROPS}
|
|
131
|
+
*/
|
|
132
|
+
exports.ENV_PROPS = zod_1.z.object({
|
|
133
|
+
/** Active configuration profile (e.g. "default", "prod") */
|
|
134
|
+
BSB_PROFILE: zod_1.z.string().optional().default("default"),
|
|
135
|
+
/** Path to the root config file when not using plugin-based sources */
|
|
136
|
+
BSB_CONFIG_FILE: zod_1.z.string().optional().default("config.yaml"),
|
|
137
|
+
/** Application working directory */
|
|
138
|
+
APP_DIR: zod_1.z.string().optional().default(process.cwd()),
|
|
139
|
+
/** Logger plugin name to load */
|
|
140
|
+
BSB_LOGGER_PLUGIN: zod_1.z.string().optional().default("config-default"),
|
|
141
|
+
/** Logger plugin package (if different from name) */
|
|
142
|
+
BSB_LOGGER_PLUGIN_PACKAGE: zod_1.z.string().optional().default("config-default"),
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Parse and validate the current environment against {@link ENV_PROPS}.
|
|
146
|
+
*
|
|
147
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/getEnvProps.html | API: getEnvProps}
|
|
148
|
+
*/
|
|
149
|
+
function getEnvProps() {
|
|
150
|
+
return exports.ENV_PROPS.parse(process.env);
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/base/functions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AA6CH,sEAaC;AAsBD,wDAeC;AAWD,sDAYC;AA2BD,kCAEC;AAjJD,mDAAiE;AACjE,mDAA2C;AAC3C,6BAAwB;AAExB;;GAEG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAA,0BAAgB,EAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,6BAA6B,CAC3C,KAAa,EACb,OAAY,EACZ,KAAoB,EACpB,GAAG,MAAqB;IAExB,IAAI,OAAO,KAAK,KAAK,UAAU;QAAE,OAAO;IACxC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,wBAAQ,CAAC,KAAK,EACtB,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACI,KAAK,UAAU,sBAAsB,CAC1C,OAAY,EACZ,KAAoB,EACpB,GAAG,MAAqB;IAExB,IAAI,OAAO,KAAK,KAAK,UAAU;QAAE,OAAO;IACxC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,wBAAQ,CAAC,aAAa,CAAC,wBAAwB,CAAC,EACxD,kDAAkD,CACnD,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,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;;;;GAIG;AACH,SAAgB,WAAW;IACzB,OAAO,iBAAS,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
export * from "./base";
|
|
28
|
+
export * from "./PluginConfig";
|
|
29
|
+
export * from "./tools";
|
|
30
|
+
export * from "./errorMessages";
|
|
31
|
+
export * from "./functions";
|
|
32
|
+
export * from "./logFormatter";
|
|
33
|
+
export * from "./PluginEvents";
|
|
34
|
+
export * from "./ObservableBackend";
|
|
35
|
+
export * from "./BSBService";
|
|
36
|
+
export * from "./BSBEvents";
|
|
37
|
+
export * from "./BSBConfig";
|
|
38
|
+
export * from "./BSBObservable";
|
|
39
|
+
export * from "./BSBServiceClient";
|
|
40
|
+
export * from "./factory";
|
|
41
|
+
export * from "./EventValidator";
|
|
42
|
+
export * from "./ResourceContext";
|
|
43
|
+
export * from "./PluginObservable";
|
|
44
|
+
export { bsb, optional } from "../interfaces/schema-types";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
40
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.optional = exports.bsb = void 0;
|
|
44
|
+
__exportStar(require("./base"), exports);
|
|
45
|
+
__exportStar(require("./PluginConfig"), exports);
|
|
46
|
+
__exportStar(require("./tools"), exports);
|
|
47
|
+
__exportStar(require("./errorMessages"), exports);
|
|
48
|
+
__exportStar(require("./functions"), exports);
|
|
49
|
+
__exportStar(require("./logFormatter"), exports);
|
|
50
|
+
__exportStar(require("./PluginEvents"), exports);
|
|
51
|
+
__exportStar(require("./ObservableBackend"), exports);
|
|
52
|
+
__exportStar(require("./BSBService"), exports);
|
|
53
|
+
__exportStar(require("./BSBEvents"), exports);
|
|
54
|
+
__exportStar(require("./BSBConfig"), exports);
|
|
55
|
+
__exportStar(require("./BSBObservable"), exports);
|
|
56
|
+
__exportStar(require("./BSBServiceClient"), exports);
|
|
57
|
+
__exportStar(require("./factory"), exports);
|
|
58
|
+
__exportStar(require("./EventValidator"), exports);
|
|
59
|
+
__exportStar(require("./ResourceContext"), exports);
|
|
60
|
+
__exportStar(require("./PluginObservable"), exports);
|
|
61
|
+
var schema_types_1 = require("../interfaces/schema-types");
|
|
62
|
+
Object.defineProperty(exports, "bsb", { enumerable: true, get: function () { return schema_types_1.bsb; } });
|
|
63
|
+
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return schema_types_1.optional; } });
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;;;;;;;;;;;;;;;AAEH,yCAAuB;AACvB,iDAA+B;AAC/B,0CAAwB;AACxB,kDAAgC;AAChC,8CAA4B;AAC5B,iDAA+B;AAC/B,iDAA+B;AAC/B,sDAAoC;AACpC,+CAA6B;AAC7B,8CAA4B;AAC5B,8CAA4B;AAC5B,kDAAgC;AAChC,qDAAmC;AACnC,4CAA0B;AAC1B,mDAAiC;AACjC,oDAAkC;AAClC,qDAAmC;AACnC,2DAA2D;AAAlD,mGAAA,GAAG,OAAA;AAAE,wGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 } from "../interfaces";
|
|
28
|
+
/**
|
|
29
|
+
* Log Formatter
|
|
30
|
+
* This class is used to format the log data to a string
|
|
31
|
+
* @group Logging
|
|
32
|
+
* @category Tools
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const logFormatter = new LogFormatter();
|
|
36
|
+
* const formattedLog = logFormatter.formatLog("This {a} a log {b}", {
|
|
37
|
+
* a: "is",
|
|
38
|
+
* b: "message",
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/LogFormatter.html | API: LogFormatter}
|
|
44
|
+
*/
|
|
45
|
+
export declare class LogFormatter {
|
|
46
|
+
private isUnsafeLogData;
|
|
47
|
+
private getSafeData;
|
|
48
|
+
formatData(meta: any, key: string): string;
|
|
49
|
+
formatLog<T extends string>(trace: DTrace, message: T, meta?: LogMeta<T>): string;
|
|
50
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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.LogFormatter = void 0;
|
|
30
|
+
const tools_1 = require("./tools");
|
|
31
|
+
/**
|
|
32
|
+
* Log Formatter
|
|
33
|
+
* This class is used to format the log data to a string
|
|
34
|
+
* @group Logging
|
|
35
|
+
* @category Tools
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const logFormatter = new LogFormatter();
|
|
39
|
+
* const formattedLog = logFormatter.formatLog("This {a} a log {b}", {
|
|
40
|
+
* a: "is",
|
|
41
|
+
* b: "message",
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/LogFormatter.html | API: LogFormatter}
|
|
47
|
+
*/
|
|
48
|
+
class LogFormatter {
|
|
49
|
+
isUnsafeLogData(value) {
|
|
50
|
+
return tools_1.Tools.isObject(value) && !tools_1.Tools.isNullOrUndefined(value.safeValue);
|
|
51
|
+
}
|
|
52
|
+
getSafeData(data, key) {
|
|
53
|
+
if (tools_1.Tools.isNullOrUndefined(data)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const dataFromKeyVP = data[key];
|
|
57
|
+
if (this.isUnsafeLogData(dataFromKeyVP)) {
|
|
58
|
+
return dataFromKeyVP.safeValue;
|
|
59
|
+
}
|
|
60
|
+
return dataFromKeyVP;
|
|
61
|
+
}
|
|
62
|
+
formatData(meta, key) {
|
|
63
|
+
const referencedVar = this.getSafeData(meta, key);
|
|
64
|
+
if (tools_1.Tools.isNullOrUndefined(referencedVar)) {
|
|
65
|
+
return "*null/undefined*";
|
|
66
|
+
}
|
|
67
|
+
if (tools_1.Tools.isDate(referencedVar)) {
|
|
68
|
+
return referencedVar.toISOString();
|
|
69
|
+
}
|
|
70
|
+
if (tools_1.Tools.isString(referencedVar)) {
|
|
71
|
+
return referencedVar;
|
|
72
|
+
}
|
|
73
|
+
if (tools_1.Tools.isArray(referencedVar)) {
|
|
74
|
+
return referencedVar
|
|
75
|
+
.map((x) => tools_1.Tools.isSimpleType(x)
|
|
76
|
+
? tools_1.Tools.isString(x)
|
|
77
|
+
? x
|
|
78
|
+
: x.toString()
|
|
79
|
+
: JSON.stringify(x))
|
|
80
|
+
.join(",");
|
|
81
|
+
}
|
|
82
|
+
/*if (
|
|
83
|
+
Tools.isObject(referencedVar) &&
|
|
84
|
+
Tools.isFunction(referencedVar.toString)
|
|
85
|
+
)
|
|
86
|
+
return referencedVar.toString();*/
|
|
87
|
+
return JSON.stringify(referencedVar);
|
|
88
|
+
}
|
|
89
|
+
formatLog(trace, message, meta) {
|
|
90
|
+
let nMeta = {
|
|
91
|
+
__t: (!trace.t || trace.t === '') ? 'TRACE ID ERROR' : trace.t,
|
|
92
|
+
__s: (!trace.s || trace.s === '') ? 'SPAN ID ERROR' : trace.s,
|
|
93
|
+
...(meta ?? {}),
|
|
94
|
+
};
|
|
95
|
+
const dataToParse = `[{__t}:{__s}] ${message}`.split("{");
|
|
96
|
+
let outString = dataToParse[0];
|
|
97
|
+
for (let i = 1; i < dataToParse.length; i++) {
|
|
98
|
+
const removedVar = dataToParse[i].split("}");
|
|
99
|
+
outString += this.formatData(nMeta, removedVar[0]) + removedVar[1];
|
|
100
|
+
}
|
|
101
|
+
return outString;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.LogFormatter = LogFormatter;
|
|
105
|
+
//# sourceMappingURL=logFormatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logFormatter.js","sourceRoot":"","sources":["../../src/base/logFormatter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAGH,mCAAgC;AAEhC;;;;;;;;;;;;;GAaG;AACH;;GAEG;AACH,MAAa,YAAY;IACf,eAAe,CAAC,KAAU;QAChC,OAAO,aAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,aAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC5E,CAAC;IAEO,WAAW,CAAmB,IAAgB,EAAE,GAAW;QACjE,IAAI,aAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,aAAa,GACjB,IACD,CACC,GAAG,CACJ,CAAC;QACF,IAAI,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,CAAC;YACxC,OAAO,aAAa,CAAC,SAAS,CAAC;QACjC,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IAEM,UAAU,CAAC,IAAS,EAAE,GAAW;QACtC,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAClD,IAAI,aAAK,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC;YAC3C,OAAO,kBAAkB,CAAC;QAC5B,CAAC;QACD,IAAI,aAAK,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YAChC,OAAO,aAAa,CAAC,WAAW,EAAE,CAAC;QACrC,CAAC;QACD,IAAI,aAAK,CAAC,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