@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.
Files changed (182) hide show
  1. package/LICENSE +665 -0
  2. package/LICENSE.commercial +32 -0
  3. package/README.md +263 -0
  4. package/bsb-plugin.json +62 -0
  5. package/lib/base/BSBConfig.d.ts +130 -0
  6. package/lib/base/BSBConfig.js +95 -0
  7. package/lib/base/BSBConfig.js.map +1 -0
  8. package/lib/base/BSBEvents.d.ts +207 -0
  9. package/lib/base/BSBEvents.js +101 -0
  10. package/lib/base/BSBEvents.js.map +1 -0
  11. package/lib/base/BSBObservable.d.ts +178 -0
  12. package/lib/base/BSBObservable.js +91 -0
  13. package/lib/base/BSBObservable.js.map +1 -0
  14. package/lib/base/BSBService.d.ts +277 -0
  15. package/lib/base/BSBService.js +366 -0
  16. package/lib/base/BSBService.js.map +1 -0
  17. package/lib/base/BSBServiceClient.d.ts +135 -0
  18. package/lib/base/BSBServiceClient.js +130 -0
  19. package/lib/base/BSBServiceClient.js.map +1 -0
  20. package/lib/base/EventValidator.d.ts +137 -0
  21. package/lib/base/EventValidator.js +210 -0
  22. package/lib/base/EventValidator.js.map +1 -0
  23. package/lib/base/ObservableBackend.d.ts +281 -0
  24. package/lib/base/ObservableBackend.js +515 -0
  25. package/lib/base/ObservableBackend.js.map +1 -0
  26. package/lib/base/PluginConfig.d.ts +196 -0
  27. package/lib/base/PluginConfig.js +96 -0
  28. package/lib/base/PluginConfig.js.map +1 -0
  29. package/lib/base/PluginEvents.d.ts +140 -0
  30. package/lib/base/PluginEvents.js +268 -0
  31. package/lib/base/PluginEvents.js.map +1 -0
  32. package/lib/base/PluginObservable.d.ts +196 -0
  33. package/lib/base/PluginObservable.js +250 -0
  34. package/lib/base/PluginObservable.js.map +1 -0
  35. package/lib/base/ResourceContext.d.ts +70 -0
  36. package/lib/base/ResourceContext.js +54 -0
  37. package/lib/base/ResourceContext.js.map +1 -0
  38. package/lib/base/base.d.ts +264 -0
  39. package/lib/base/base.js +182 -0
  40. package/lib/base/base.js.map +1 -0
  41. package/lib/base/errorMessages.d.ts +56 -0
  42. package/lib/base/errorMessages.js +70 -0
  43. package/lib/base/errorMessages.js.map +1 -0
  44. package/lib/base/factory.d.ts +58 -0
  45. package/lib/base/factory.js +167 -0
  46. package/lib/base/factory.js.map +1 -0
  47. package/lib/base/functions.d.ts +117 -0
  48. package/lib/base/functions.js +152 -0
  49. package/lib/base/functions.js.map +1 -0
  50. package/lib/base/index.d.ts +44 -0
  51. package/lib/base/index.js +64 -0
  52. package/lib/base/index.js.map +1 -0
  53. package/lib/base/logFormatter.d.ts +50 -0
  54. package/lib/base/logFormatter.js +105 -0
  55. package/lib/base/logFormatter.js.map +1 -0
  56. package/lib/base/tools.d.ts +316 -0
  57. package/lib/base/tools.js +666 -0
  58. package/lib/base/tools.js.map +1 -0
  59. package/lib/cli.d.ts +28 -0
  60. package/lib/cli.js +254 -0
  61. package/lib/cli.js.map +1 -0
  62. package/lib/dev.d.ts +27 -0
  63. package/lib/dev.js +200 -0
  64. package/lib/dev.js.map +1 -0
  65. package/lib/index.d.ts +32 -0
  66. package/lib/index.js +49 -0
  67. package/lib/index.js.map +1 -0
  68. package/lib/interfaces/events.d.ts +67 -0
  69. package/lib/interfaces/events.js +44 -0
  70. package/lib/interfaces/events.js.map +1 -0
  71. package/lib/interfaces/index.d.ts +38 -0
  72. package/lib/interfaces/index.js +59 -0
  73. package/lib/interfaces/index.js.map +1 -0
  74. package/lib/interfaces/logging.d.ts +106 -0
  75. package/lib/interfaces/logging.js +39 -0
  76. package/lib/interfaces/logging.js.map +1 -0
  77. package/lib/interfaces/metrics.d.ts +365 -0
  78. package/lib/interfaces/metrics.js +46 -0
  79. package/lib/interfaces/metrics.js.map +1 -0
  80. package/lib/interfaces/observable-types.d.ts +63 -0
  81. package/lib/interfaces/observable-types.js +49 -0
  82. package/lib/interfaces/observable-types.js.map +1 -0
  83. package/lib/interfaces/observable.d.ts +297 -0
  84. package/lib/interfaces/observable.js +29 -0
  85. package/lib/interfaces/observable.js.map +1 -0
  86. package/lib/interfaces/options.d.ts +164 -0
  87. package/lib/interfaces/options.js +56 -0
  88. package/lib/interfaces/options.js.map +1 -0
  89. package/lib/interfaces/plugins.d.ts +143 -0
  90. package/lib/interfaces/plugins.js +45 -0
  91. package/lib/interfaces/plugins.js.map +1 -0
  92. package/lib/interfaces/result.d.ts +129 -0
  93. package/lib/interfaces/result.js +162 -0
  94. package/lib/interfaces/result.js.map +1 -0
  95. package/lib/interfaces/schema-events.d.ts +378 -0
  96. package/lib/interfaces/schema-events.js +247 -0
  97. package/lib/interfaces/schema-events.js.map +1 -0
  98. package/lib/interfaces/schema-types.d.ts +407 -0
  99. package/lib/interfaces/schema-types.js +581 -0
  100. package/lib/interfaces/schema-types.js.map +1 -0
  101. package/lib/interfaces/service.d.ts +48 -0
  102. package/lib/interfaces/service.js +29 -0
  103. package/lib/interfaces/service.js.map +1 -0
  104. package/lib/interfaces/tools.d.ts +65 -0
  105. package/lib/interfaces/tools.js +50 -0
  106. package/lib/interfaces/tools.js.map +1 -0
  107. package/lib/plugins/config-default/index.d.ts +59 -0
  108. package/lib/plugins/config-default/index.js +197 -0
  109. package/lib/plugins/config-default/index.js.map +1 -0
  110. package/lib/plugins/config-default/interfaces.d.ts +92 -0
  111. package/lib/plugins/config-default/interfaces.js +36 -0
  112. package/lib/plugins/config-default/interfaces.js.map +1 -0
  113. package/lib/plugins/events-default/events/broadcast.d.ts +36 -0
  114. package/lib/plugins/events-default/events/broadcast.js +85 -0
  115. package/lib/plugins/events-default/events/broadcast.js.map +1 -0
  116. package/lib/plugins/events-default/events/emit.d.ts +38 -0
  117. package/lib/plugins/events-default/events/emit.js +104 -0
  118. package/lib/plugins/events-default/events/emit.js.map +1 -0
  119. package/lib/plugins/events-default/events/emitAndReturn.d.ts +36 -0
  120. package/lib/plugins/events-default/events/emitAndReturn.js +100 -0
  121. package/lib/plugins/events-default/events/emitAndReturn.js.map +1 -0
  122. package/lib/plugins/events-default/events/emitStreamAndReceiveStream.d.ts +38 -0
  123. package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js +134 -0
  124. package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js.map +1 -0
  125. package/lib/plugins/events-default/events/index.d.ts +30 -0
  126. package/lib/plugins/events-default/events/index.js +38 -0
  127. package/lib/plugins/events-default/events/index.js.map +1 -0
  128. package/lib/plugins/events-default/index.d.ts +57 -0
  129. package/lib/plugins/events-default/index.js +86 -0
  130. package/lib/plugins/events-default/index.js.map +1 -0
  131. package/lib/plugins/observable-default/index.d.ts +43 -0
  132. package/lib/plugins/observable-default/index.js +151 -0
  133. package/lib/plugins/observable-default/index.js.map +1 -0
  134. package/lib/schemas/config-default.json +34 -0
  135. package/lib/schemas/config-default.plugin.json +36 -0
  136. package/lib/schemas/events-default.json +18 -0
  137. package/lib/schemas/events-default.plugin.json +17 -0
  138. package/lib/schemas/observable-default.json +33 -0
  139. package/lib/schemas/observable-default.plugin.json +24 -0
  140. package/lib/scripts/bsb-client-cli.d.ts +21 -0
  141. package/lib/scripts/bsb-client-cli.js +701 -0
  142. package/lib/scripts/bsb-client-cli.js.map +1 -0
  143. package/lib/scripts/bsb-plugin-cli.d.ts +15 -0
  144. package/lib/scripts/bsb-plugin-cli.js +547 -0
  145. package/lib/scripts/bsb-plugin-cli.js.map +1 -0
  146. package/lib/scripts/export-schemas.d.ts +17 -0
  147. package/lib/scripts/export-schemas.js +205 -0
  148. package/lib/scripts/export-schemas.js.map +1 -0
  149. package/lib/scripts/extract-schemas-from-source.d.ts +23 -0
  150. package/lib/scripts/extract-schemas-from-source.js +604 -0
  151. package/lib/scripts/extract-schemas-from-source.js.map +1 -0
  152. package/lib/scripts/generate-client-types.d.ts +22 -0
  153. package/lib/scripts/generate-client-types.js +537 -0
  154. package/lib/scripts/generate-client-types.js.map +1 -0
  155. package/lib/scripts/generate-plugin-json.d.ts +17 -0
  156. package/lib/scripts/generate-plugin-json.js +219 -0
  157. package/lib/scripts/generate-plugin-json.js.map +1 -0
  158. package/lib/serviceBase/config.d.ts +83 -0
  159. package/lib/serviceBase/config.js +236 -0
  160. package/lib/serviceBase/config.js.map +1 -0
  161. package/lib/serviceBase/events.d.ts +91 -0
  162. package/lib/serviceBase/events.js +519 -0
  163. package/lib/serviceBase/events.js.map +1 -0
  164. package/lib/serviceBase/index.d.ts +33 -0
  165. package/lib/serviceBase/index.js +50 -0
  166. package/lib/serviceBase/index.js.map +1 -0
  167. package/lib/serviceBase/observable.d.ts +249 -0
  168. package/lib/serviceBase/observable.js +551 -0
  169. package/lib/serviceBase/observable.js.map +1 -0
  170. package/lib/serviceBase/plugins.d.ts +48 -0
  171. package/lib/serviceBase/plugins.js +184 -0
  172. package/lib/serviceBase/plugins.js.map +1 -0
  173. package/lib/serviceBase/serviceBase.d.ts +228 -0
  174. package/lib/serviceBase/serviceBase.js +420 -0
  175. package/lib/serviceBase/serviceBase.js.map +1 -0
  176. package/lib/serviceBase/services.d.ts +63 -0
  177. package/lib/serviceBase/services.js +346 -0
  178. package/lib/serviceBase/services.js.map +1 -0
  179. package/lib/tests.d.ts +27 -0
  180. package/lib/tests.js +44 -0
  181. package/lib/tests.js.map +1 -0
  182. package/package.json +91 -0
@@ -0,0 +1,365 @@
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 { BSBError } from "../base";
28
+ import { IPluginLogging } from "./logging";
29
+ /**
30
+ * @group Observable
31
+ * @category Plugin Development Tools
32
+ * @see {@link https://bsbcode.dev/languages/nodejs/types/interfaces/IPluginObservable.html | API: IPluginObservable}
33
+ * @internal
34
+ *
35
+ * Unified interface combining logging and metrics capabilities.
36
+ * This is the internal interface implemented by ObservableBackend.
37
+ */
38
+ export interface IPluginObservable extends IPluginLogging, IPluginMetrics {
39
+ }
40
+ /**
41
+ * @group Metrics
42
+ * @category Plugin Development Tools
43
+ * @see {@link https://bsbcode.dev/languages/nodejs/types/interfaces/IPluginMetrics.html | API: IPluginMetrics}
44
+ */
45
+ export interface IPluginMetrics {
46
+ /**
47
+ * Creates a counter metric.
48
+ * A Counter is a metric that represents a monotonically increasing value.
49
+ * It is used to measure the cumulative count of an event that increases
50
+ * over time and resets to zero only when the process restarts.
51
+ *
52
+ * @remarks
53
+ * Use Cases:
54
+ *
55
+ * Event Counting: Counting the number of requests received, errors encountered, or messages processed.
56
+ * Work Done: Measuring the total number of bytes read or written, tasks completed, or jobs processed.
57
+ * Characteristics:
58
+ *
59
+ * Monotonic: Counters can only increase or reset. They cannot decrease.
60
+ * Sum: The focus is on the total accumulated value over time.
61
+ * Example: A Counter can be used to count the number of HTTP requests received by a server.
62
+ *
63
+ * @param name - The name of the counter metric
64
+ * @param description - A description of the counter metric
65
+ * @param help - More information about the counter metric
66
+ * @param labels - Optional labels to associate with the counter metric
67
+ * @returns A Counter object that can be used to update the counter metric
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * let counter = this.metrics.createCounter("my-counter", "A counter metric");
72
+ * counter.inc(); // Increment the counter by 1
73
+ * counter.inc(1); // Increment the counter by 1
74
+ * counter.inc(10); // Increment the counter by 10
75
+ * ```
76
+ * @see {@link https://bsbcode.dev/languages/nodejs/types/interfaces/IPluginMetrics.html#createCounter | API: IPluginMetrics#createCounter}
77
+ */
78
+ createCounter<LABELS extends string | undefined>(name: string, description: string, help: string, labels?: LABELS[]): Counter<LABELS>;
79
+ /**
80
+ * Creates a gauge metric.
81
+ * A Gauge is a metric that represents a value that can go up and down.
82
+ * It measures the current value of a particular data point at a specific moment in time.
83
+ *
84
+ * @remarks
85
+ * Use Cases:
86
+ *
87
+ * Resource Levels: Monitoring CPU usage, memory consumption, or disk space.
88
+ * Temperature or Pressure: Tracking real-time sensor readings.
89
+ * Current State: Measuring the current number of active users or open connections.
90
+ * Characteristics:
91
+ *
92
+ * Variable: Gauges can increase and decrease over time.
93
+ * Instantaneous: Captures a snapshot of a value at a particular time.
94
+ * Example: A Gauge can be used to measure the current temperature of a system or the current memory usage of an application.
95
+ *
96
+ * @param name - The name of the gauge metric
97
+ * @param description - A description of the gauge metric
98
+ * @param help - More information about the gauge metric
99
+ * @param labels - Optional labels to associate with the gauge metric
100
+ * @returns A Gauge object that can be used to update the gauge metric
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * let gauge = this.metrics.createGauge("my-gauge", "A gauge metric");
105
+ * gauge.set(10); // Set the gauge to 10
106
+ * gauge.set(20); // Set the gauge to 20
107
+ * gauge.set(30); // Set the gauge to 30
108
+ * gauge.increment(); // Increment the gauge by 1
109
+ * gauge.increment(10); // Increment the gauge by 10
110
+ * gauge.decrement(); // Decrement the gauge by 1
111
+ * gauge.decrement(10); // Decrement the gauge by 10
112
+ * ```
113
+ * @see {@link https://bsbcode.dev/languages/nodejs/types/interfaces/IPluginMetrics.html#createGauge | API: IPluginMetrics#createGauge}
114
+ */
115
+ createGauge<LABELS extends string | undefined>(name: string, description: string, help: string, labels?: LABELS[]): Gauge<LABELS>;
116
+ /**
117
+ * Creates a histogram metric.
118
+ * A Histogram is a metric that collects data samples and counts them in predefined buckets.
119
+ * It provides statistical distribution of values over time, capturing not just the
120
+ * total sum but also the distribution of values.
121
+ *
122
+ * @remarks
123
+ * Use Cases:
124
+ *
125
+ * Event Distribution: Measuring the distribution of events received by a system, such as the number of requests per second or the distribution of response times.
126
+ * Work Done: Measuring the distribution of bytes read or written, tasks completed, or jobs processed.
127
+ * Characteristics:
128
+ *
129
+ * Monotonic: Histograms can only increase or reset. They cannot decrease.
130
+ * Sum: The focus is on the total accumulated value over time.
131
+ * Example: A Histogram can be used to measure the distribution of response times for a web server.
132
+ *
133
+ * @param name - The name of the histogram metric
134
+ * @param description - A description of the histogram metric
135
+ * @param help - More information about the histogram metric
136
+ * @param boundaries - Optional boundaries for the histogram metric
137
+ * @param labels - Optional labels to associate with the histogram metric
138
+ * @returns A Histogram object that can be used to update the histogram metric
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * let histogram = this.metrics.createHistogram("my-histogram", "A histogram metric");
143
+ * histogram.record(10); // Record the value 10 in the histogram
144
+ * histogram.record(20); // Record the value 20 in the histogram
145
+ * histogram.record(30); // Record the value 30 in the histogram
146
+ * ```
147
+ * @see {@link https://bsbcode.dev/languages/nodejs/types/interfaces/IPluginMetrics.html#createHistogram | API: IPluginMetrics#createHistogram}
148
+ */
149
+ createHistogram<LABELS extends string | undefined>(name: string, description: string, help: string, boundaries?: number[], labels?: LABELS[]): Histogram<LABELS>;
150
+ /**
151
+ * Creates a trace metric.
152
+ * A Trace is a metric that represents a sequence of events or operations that form a request or transaction.
153
+ * It provides a way to track and monitor the flow of operations across your application.
154
+ *
155
+ * @remarks
156
+ * Use Cases:
157
+ * - Request Tracing: Following a request as it moves through different services or components
158
+ * - Performance Monitoring: Tracking the timing and dependencies of operations
159
+ * - Error Tracking: Identifying where in a sequence of operations an error occurred
160
+ * - Distributed Tracing: Monitoring operations across multiple services
161
+ *
162
+ * Characteristics:
163
+ * - Unique Identification: Each trace has a unique ID
164
+ * - Attributes: Can include key-value pairs for additional context
165
+ * - Error Handling: Built-in support for error recording
166
+ * - Lifecycle Management: Clear start and end points
167
+ *
168
+ * @param name - The name of the trace, used to identify the operation or request being traced
169
+ * @param attributes - Optional key-value pairs providing additional context about the trace
170
+ * @returns A Trace object that can be used to record spans, errors, and manage the trace lifecycle
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * // Create a simple trace
175
+ * const trace = this.metrics.createTrace("user-registration");
176
+ *
177
+ * // OR Create a trace with attributes
178
+ * const trace = this.metrics.createTrace("payment-processing", {
179
+ * "customer-id": "12345",
180
+ * "payment-method": "credit-card"
181
+ * });
182
+ *
183
+ * // Using the trace
184
+ * try {
185
+ * // Perform operations
186
+ * const span = this.metrics.createSpan(trace, "get-customer-balance");
187
+ * // Do some external work
188
+ * span.end({balance: 100});
189
+ * trace.end({transactionId: "12345"});
190
+ * } catch (error) {
191
+ * trace.error(error);
192
+ * }
193
+ * trace.end();
194
+ * ```
195
+ * @see {@link https://bsbcode.dev/languages/nodejs/types/interfaces/IPluginMetrics.html#createTrace | API: IPluginMetrics#createTrace}
196
+ */
197
+ createTrace(name: string, attributes?: Record<string, string | number | boolean>): Trace;
198
+ /**
199
+ * Creates a new span from an existing trace (automatic parent span).
200
+ * @param trace - The trace to associate with the span
201
+ * @param name - The name of the span
202
+ * @param attributes - Optional attributes to associate with the span
203
+ * @returns A Span object that can be used to update the span metric
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * let span = this.metrics.createSpan(trace, "span-1", {"key": "value"});
208
+ * span.end();
209
+ * ```
210
+ * @see {@link https://bsbcode.dev/languages/nodejs/types/interfaces/IPluginMetrics.html#createSpan | API: IPluginMetrics#createSpan}
211
+ */
212
+ createSpan(trace: DTrace, name: string, attributes?: Record<string, string | number | boolean>): Trace;
213
+ /***
214
+ * Create Timer
215
+ * A Timer is a metric that measures the time taken to execute a block of code.
216
+ * It provides a simple way to measure the time taken to execute a block of code.
217
+ *
218
+ * @remarks
219
+ * Use Cases:
220
+ *
221
+ * Event Timing: Measuring the time taken to execute a block of code.
222
+ * Work Done: Measuring the time taken to execute a block of code.
223
+ * Characteristics:
224
+ *
225
+ * Monotonic: Timers can only increase or reset. They cannot decrease.
226
+ * Sum: The focus is on the total accumulated value over time.
227
+ * Example: A Timer can be used to measure the time taken to execute a block of code.
228
+ *
229
+ * @returns A Timer object that can be used to update the timer metric
230
+ *
231
+ * @example
232
+ * ```ts
233
+ * let timer = this.metrics.createTimer(); // Start the timer
234
+ * // Do some work
235
+ * let elapsedTime = timer.stop(); // Stop the timer and get the elapsed time in nanoseconds
236
+ * ```
237
+ * @see {@link https://bsbcode.dev/languages/nodejs/types/interfaces/IPluginMetrics.html#createTimer | API: IPluginMetrics#createTimer}
238
+ */
239
+ createTimer(): Timer;
240
+ }
241
+ export interface Timer {
242
+ /**
243
+ * Stops the timer
244
+ * @return The elapsed time in milliseconds
245
+ */
246
+ stop(): number;
247
+ }
248
+ export interface Trace {
249
+ /**
250
+ * This trace ID.
251
+ */
252
+ id: Readonly<string>;
253
+ /**
254
+ * This trace.
255
+ */
256
+ trace: Readonly<DTrace>;
257
+ /**
258
+ * Starts a new span with the specified name.
259
+ *
260
+ * @param name - The name of the span
261
+ * @param attributes - Optional attributes to associate with the span
262
+ */
263
+ /**
264
+ * Starts a new span linked to a parent span.
265
+ *
266
+ * @param parentSpanId - Optional parent span ID
267
+ * @param name - The name of the span
268
+ * @param attributes - Optional attributes to associate with the span
269
+ */
270
+ /**
271
+ * Records an error in the current span.
272
+ *
273
+ * @param error - The error to record
274
+ * @param attributes - Optional attributes to associate with the span
275
+ */
276
+ error(error: BSBError<any> | Error, attributes?: Record<string, string | number | boolean>): void;
277
+ /**
278
+ * Ends the current trace or span.
279
+ * If the trace was created, then it will end both. However if it references an existing trace, then it will only end the span.
280
+ *
281
+ * @param attributes - Optional attributes to associate with the trace
282
+ */
283
+ end(attributes?: Record<string, string | number | boolean>): void;
284
+ }
285
+ export declare const createFakeDTrace: (trace: string, span: string) => DTrace;
286
+ /**
287
+ * @hidden
288
+ */
289
+ export interface DTrace {
290
+ /**
291
+ * This trace ID.
292
+ */
293
+ t: Readonly<string>;
294
+ /**
295
+ * This span ID.
296
+ */
297
+ s: Readonly<string>;
298
+ }
299
+ export interface Span {
300
+ /**
301
+ * This span ID.
302
+ */
303
+ id: Readonly<string>;
304
+ /**
305
+ * This trace ID.
306
+ */
307
+ /**
308
+ * This dTrace reference.
309
+ */
310
+ trace: Readonly<DTrace>;
311
+ /**
312
+ * Ends the current span.
313
+ *
314
+ * @param attributes - Optional attributes to associate with the span
315
+ */
316
+ end(attributes?: Record<string, string | number | boolean>): void;
317
+ /**
318
+ * Records an error in the current span.
319
+ *
320
+ * @param error - The error to record
321
+ * @param attributes - Optional labels to associate with the span
322
+ */
323
+ error(error: BSBError<any> | Error, attributes?: Record<string, string | number | boolean>): void;
324
+ }
325
+ export interface Counter<LABELS extends string | undefined = undefined> {
326
+ /**
327
+ * Adds a value to the counter metric.
328
+ *
329
+ * @param value - The value to add to the counter metric
330
+ * @param labels - Optional labels to associate with the counter metric
331
+ */
332
+ increment(value?: number, labels?: LABELS extends string ? Partial<Record<LABELS, string>> : never): void;
333
+ }
334
+ export interface Gauge<LABELS extends string | undefined = undefined> {
335
+ /**
336
+ * Sets the value of the gauge metric.
337
+ *
338
+ * @param value - The value to set the gauge metric
339
+ * @param labels - Optional labels to associate with the gauge metric
340
+ */
341
+ set(value: number, labels?: LABELS extends string ? Partial<Record<LABELS, string>> : never): void;
342
+ /**
343
+ * Increments the value of the gauge metric by a specified amount.
344
+ *
345
+ * @param value - The amount to increment the gauge metric by
346
+ * @param labels - Optional labels to associate with the gauge metric
347
+ */
348
+ increment(value?: number, labels?: LABELS extends string ? Partial<Record<LABELS, string>> : never): void;
349
+ /**
350
+ * Decrements the value of the gauge metric by a specified amount.
351
+ *
352
+ * @param value - The amount to decrement the gauge metric by
353
+ * @param labels - Optional labels to associate with the gauge metric
354
+ */
355
+ decrement(value?: number, labels?: LABELS extends string ? Partial<Record<LABELS, string>> : never): void;
356
+ }
357
+ export interface Histogram<LABELS extends string | undefined = undefined> {
358
+ /**
359
+ * Records a value in the histogram metric.
360
+ *
361
+ * @param value - The value to record in the histogram metric
362
+ * @param labels - Optional labels to associate with the histogram metric
363
+ */
364
+ record(value: number, labels?: LABELS extends string ? Partial<Record<LABELS, string>> : never): void;
365
+ }
@@ -0,0 +1,46 @@
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.createFakeDTrace = void 0;
30
+ /**
31
+ * @hidden
32
+ */
33
+ const traceCache = new Map();
34
+ const createFakeDTrace = (trace, span) => {
35
+ const cacheKey = `${trace}:${span}`;
36
+ let cached = traceCache.get(cacheKey);
37
+ if (!cached) {
38
+ cached = { t: `INTERNAL:${trace}`, s: span };
39
+ if (traceCache.size < 1000) { // Prevent memory leaks
40
+ traceCache.set(cacheKey, cached);
41
+ }
42
+ }
43
+ return cached;
44
+ };
45
+ exports.createFakeDTrace = createFakeDTrace;
46
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/interfaces/metrics.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAsRH;;GAEG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;AACtC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,IAAY,EAAU,EAAE;IACtE,MAAM,QAAQ,GAAG,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC;IACpC,IAAI,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,EAAE,CAAC,EAAE,YAAY,KAAK,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC;QAC7C,IAAI,UAAU,CAAC,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,uBAAuB;YACnD,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAVW,QAAA,gBAAgB,oBAU3B"}
@@ -0,0 +1,63 @@
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 { PluginDefinition, FilterDetailed } from "./plugins";
28
+ /**
29
+ * Observable event types - unified logging, metrics, and tracing events
30
+ * @hidden
31
+ */
32
+ export declare const ObservableEventTypesBase: {
33
+ readonly debug: "debug";
34
+ readonly info: "info";
35
+ readonly warn: "warn";
36
+ readonly error: "error";
37
+ readonly counter: "counter";
38
+ readonly gauge: "gauge";
39
+ readonly histogram: "histogram";
40
+ readonly spanStart: "spanStart";
41
+ readonly spanEnd: "spanEnd";
42
+ readonly spanError: "spanError";
43
+ };
44
+ /**
45
+ * @hidden
46
+ */
47
+ export type ObservableEventTypes = (typeof ObservableEventTypesBase)[keyof typeof ObservableEventTypesBase];
48
+ /**
49
+ * @hidden
50
+ */
51
+ export type ObservableFilterDetailed = FilterDetailed<ObservableEventTypes>;
52
+ /**
53
+ * Observable filter - controls which events go to which plugin instances
54
+ * @hidden
55
+ */
56
+ export type ObservableFilter = ObservableFilterDetailed | Record<ObservableEventTypes, boolean> | Record<ObservableEventTypes, Array<string>> | Array<ObservableEventTypes>;
57
+ /**
58
+ * Observable plugin configuration
59
+ * @hidden
60
+ */
61
+ export interface ObservableConfig extends PluginDefinition {
62
+ filter?: ObservableFilter;
63
+ }
@@ -0,0 +1,49 @@
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.ObservableEventTypesBase = void 0;
30
+ /**
31
+ * Observable event types - unified logging, metrics, and tracing events
32
+ * @hidden
33
+ */
34
+ exports.ObservableEventTypesBase = {
35
+ // Logging events
36
+ debug: "debug",
37
+ info: "info",
38
+ warn: "warn",
39
+ error: "error",
40
+ // Metrics events
41
+ counter: "counter",
42
+ gauge: "gauge",
43
+ histogram: "histogram",
44
+ // Tracing events
45
+ spanStart: "spanStart",
46
+ spanEnd: "spanEnd",
47
+ spanError: "spanError",
48
+ };
49
+ //# sourceMappingURL=observable-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable-types.js","sourceRoot":"","sources":["../../src/interfaces/observable-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAIH;;;GAGG;AACU,QAAA,wBAAwB,GAAG;IACtC,iBAAiB;IACjB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,iBAAiB;IACjB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,iBAAiB;IACjB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;CACd,CAAC"}