@3sixty/telemetry-models 0.0.0-stage → 0.20.0-next.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 +201 -0
- package/README.md +24 -2
- package/dist/es/connectors/multiTelemetryConnector.js +184 -0
- package/dist/es/connectors/multiTelemetryConnector.js.map +1 -0
- package/dist/es/connectors/silentTelemetryConnector.js +57 -0
- package/dist/es/connectors/silentTelemetryConnector.js.map +1 -0
- package/dist/es/factories/metricsProducerFactory.js +13 -0
- package/dist/es/factories/metricsProducerFactory.js.map +1 -0
- package/dist/es/factories/telemetryConnectorFactory.js +9 -0
- package/dist/es/factories/telemetryConnectorFactory.js.map +1 -0
- package/dist/es/helpers/metricHelper.js +139 -0
- package/dist/es/helpers/metricHelper.js.map +1 -0
- package/dist/es/index.js +30 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IMetricsCollectorComponent.js +2 -0
- package/dist/es/models/IMetricsCollectorComponent.js.map +1 -0
- package/dist/es/models/IMetricsProducer.js +2 -0
- package/dist/es/models/IMetricsProducer.js.map +1 -0
- package/dist/es/models/IMultiTelemetryConnectorConstructorOptions.js +4 -0
- package/dist/es/models/IMultiTelemetryConnectorConstructorOptions.js.map +1 -0
- package/dist/es/models/ITelemetryComponent.js +2 -0
- package/dist/es/models/ITelemetryComponent.js.map +1 -0
- package/dist/es/models/ITelemetryConnector.js +2 -0
- package/dist/es/models/ITelemetryConnector.js.map +1 -0
- package/dist/es/models/ITelemetryMetric.js +2 -0
- package/dist/es/models/ITelemetryMetric.js.map +1 -0
- package/dist/es/models/ITelemetryMetricValue.js +4 -0
- package/dist/es/models/ITelemetryMetricValue.js.map +1 -0
- package/dist/es/models/ITelemetryMetricValueEntry.js +2 -0
- package/dist/es/models/ITelemetryMetricValueEntry.js.map +1 -0
- package/dist/es/models/api/ITelemetryAddMetricValueRequest.js +2 -0
- package/dist/es/models/api/ITelemetryAddMetricValueRequest.js.map +1 -0
- package/dist/es/models/api/ITelemetryCreateMetricRequest.js +2 -0
- package/dist/es/models/api/ITelemetryCreateMetricRequest.js.map +1 -0
- package/dist/es/models/api/ITelemetryGetMetricRequest.js +4 -0
- package/dist/es/models/api/ITelemetryGetMetricRequest.js.map +1 -0
- package/dist/es/models/api/ITelemetryGetMetricResponse.js +2 -0
- package/dist/es/models/api/ITelemetryGetMetricResponse.js.map +1 -0
- package/dist/es/models/api/ITelemetryGetMetricValueRequest.js +4 -0
- package/dist/es/models/api/ITelemetryGetMetricValueRequest.js.map +1 -0
- package/dist/es/models/api/ITelemetryGetMetricValueResponse.js +2 -0
- package/dist/es/models/api/ITelemetryGetMetricValueResponse.js.map +1 -0
- package/dist/es/models/api/ITelemetryListRequest.js +4 -0
- package/dist/es/models/api/ITelemetryListRequest.js.map +1 -0
- package/dist/es/models/api/ITelemetryListResponse.js +2 -0
- package/dist/es/models/api/ITelemetryListResponse.js.map +1 -0
- package/dist/es/models/api/ITelemetryRemoveMetricRequest.js +4 -0
- package/dist/es/models/api/ITelemetryRemoveMetricRequest.js.map +1 -0
- package/dist/es/models/api/ITelemetryUpdateMetricRequest.js +4 -0
- package/dist/es/models/api/ITelemetryUpdateMetricRequest.js.map +1 -0
- package/dist/es/models/api/ITelemetryValuesListRequest.js +4 -0
- package/dist/es/models/api/ITelemetryValuesListRequest.js.map +1 -0
- package/dist/es/models/api/ITelemetryValuesListResponse.js +2 -0
- package/dist/es/models/api/ITelemetryValuesListResponse.js.map +1 -0
- package/dist/es/models/metricCounterOperation.js +17 -0
- package/dist/es/models/metricCounterOperation.js.map +1 -0
- package/dist/es/models/metricType.js +21 -0
- package/dist/es/models/metricType.js.map +1 -0
- package/dist/types/connectors/multiTelemetryConnector.d.ts +124 -0
- package/dist/types/connectors/silentTelemetryConnector.d.ts +56 -0
- package/dist/types/factories/metricsProducerFactory.d.ts +10 -0
- package/dist/types/factories/telemetryConnectorFactory.d.ts +6 -0
- package/dist/types/helpers/metricHelper.d.ts +67 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/models/IMetricsCollectorComponent.d.ts +6 -0
- package/dist/types/models/IMetricsProducer.d.ts +27 -0
- package/dist/types/models/IMultiTelemetryConnectorConstructorOptions.d.ts +9 -0
- package/dist/types/models/ITelemetryComponent.d.ts +109 -0
- package/dist/types/models/ITelemetryConnector.d.ts +109 -0
- package/dist/types/models/ITelemetryMetric.d.ts +31 -0
- package/dist/types/models/ITelemetryMetricValue.d.ts +23 -0
- package/dist/types/models/ITelemetryMetricValueEntry.d.ts +20 -0
- package/dist/types/models/api/ITelemetryAddMetricValueRequest.d.ts +30 -0
- package/dist/types/models/api/ITelemetryCreateMetricRequest.d.ts +11 -0
- package/dist/types/models/api/ITelemetryGetMetricRequest.d.ts +14 -0
- package/dist/types/models/api/ITelemetryGetMetricResponse.d.ts +20 -0
- package/dist/types/models/api/ITelemetryGetMetricValueRequest.d.ts +18 -0
- package/dist/types/models/api/ITelemetryGetMetricValueResponse.d.ts +10 -0
- package/dist/types/models/api/ITelemetryListRequest.d.ts +22 -0
- package/dist/types/models/api/ITelemetryListResponse.d.ts +19 -0
- package/dist/types/models/api/ITelemetryRemoveMetricRequest.d.ts +14 -0
- package/dist/types/models/api/ITelemetryUpdateMetricRequest.d.ts +31 -0
- package/dist/types/models/api/ITelemetryValuesListRequest.d.ts +35 -0
- package/dist/types/models/api/ITelemetryValuesListResponse.d.ts +24 -0
- package/dist/types/models/metricCounterOperation.d.ts +17 -0
- package/dist/types/models/metricType.d.ts +21 -0
- package/docs/changelog.md +0 -0
- package/docs/examples.md +142 -0
- package/docs/reference/classes/MetricHelper.md +226 -0
- package/docs/reference/classes/MultiTelemetryConnector.md +357 -0
- package/docs/reference/classes/SilentTelemetryConnector.md +191 -0
- package/docs/reference/index.md +42 -0
- package/docs/reference/interfaces/IMetricsCollectorComponent.md +7 -0
- package/docs/reference/interfaces/IMetricsProducer.md +45 -0
- package/docs/reference/interfaces/IMultiTelemetryConnectorConstructorOptions.md +11 -0
- package/docs/reference/interfaces/ITelemetryAddMetricValueRequest.md +41 -0
- package/docs/reference/interfaces/ITelemetryComponent.md +271 -0
- package/docs/reference/interfaces/ITelemetryConnector.md +271 -0
- package/docs/reference/interfaces/ITelemetryCreateMetricRequest.md +12 -0
- package/docs/reference/interfaces/ITelemetryGetMetricRequest.md +17 -0
- package/docs/reference/interfaces/ITelemetryGetMetricResponse.md +23 -0
- package/docs/reference/interfaces/ITelemetryGetMetricValueRequest.md +23 -0
- package/docs/reference/interfaces/ITelemetryGetMetricValueResponse.md +11 -0
- package/docs/reference/interfaces/ITelemetryListRequest.md +29 -0
- package/docs/reference/interfaces/ITelemetryListResponse.md +23 -0
- package/docs/reference/interfaces/ITelemetryMetric.md +52 -0
- package/docs/reference/interfaces/ITelemetryMetricValue.md +39 -0
- package/docs/reference/interfaces/ITelemetryMetricValueEntry.md +31 -0
- package/docs/reference/interfaces/ITelemetryRemoveMetricRequest.md +17 -0
- package/docs/reference/interfaces/ITelemetryUpdateMetricRequest.md +43 -0
- package/docs/reference/interfaces/ITelemetryValuesListRequest.md +49 -0
- package/docs/reference/interfaces/ITelemetryValuesListResponse.md +29 -0
- package/docs/reference/type-aliases/MetricCounterOperation.md +5 -0
- package/docs/reference/type-aliases/MetricType.md +5 -0
- package/docs/reference/variables/MetricCounterOperation.md +19 -0
- package/docs/reference/variables/MetricType.md +25 -0
- package/docs/reference/variables/MetricsProducerFactory.md +9 -0
- package/docs/reference/variables/TelemetryConnectorFactory.md +5 -0
- package/locales/en.json +7 -0
- package/package.json +51 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 IOTA Stiftung.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 3Sixty Telemetry Models
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared telemetry models for connectors and services.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install @3sixty/telemetry-models
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
|
|
14
|
+
|
|
15
|
+
## Reference
|
|
16
|
+
|
|
17
|
+
Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
|
|
18
|
+
|
|
19
|
+
## Changelog
|
|
20
|
+
|
|
21
|
+
The changes between each version can be found in [docs/changelog.md](docs/changelog.md)
|
|
22
|
+
|
|
23
|
+
## Origin
|
|
24
|
+
|
|
25
|
+
This package is derived from the original [iotaledger/twin-telemetry](https://github.com/iotaledger/twin-telemetry/tree/next/packages/telemetry-models) repository.
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Guards, Is, NotImplementedError, NotSupportedError } from "@3sixty/core";
|
|
4
|
+
import { TelemetryConnectorFactory } from "../factories/telemetryConnectorFactory.js";
|
|
5
|
+
import { MetricType } from "../models/metricType.js";
|
|
6
|
+
/**
|
|
7
|
+
* Class for performing telemetry operations on multiple connectors.
|
|
8
|
+
*/
|
|
9
|
+
export class MultiTelemetryConnector {
|
|
10
|
+
/**
|
|
11
|
+
* The namespace for the class.
|
|
12
|
+
*/
|
|
13
|
+
static NAMESPACE = "multi";
|
|
14
|
+
/**
|
|
15
|
+
* Runtime name for the class.
|
|
16
|
+
*/
|
|
17
|
+
static CLASS_NAME = "MultiTelemetryConnector";
|
|
18
|
+
/**
|
|
19
|
+
* The connectors to send the telemetry entries to.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
_telemetryConnectors;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new instance of MultiTelemetryConnector.
|
|
25
|
+
* @param options The options for the connector.
|
|
26
|
+
*/
|
|
27
|
+
constructor(options) {
|
|
28
|
+
Guards.object(MultiTelemetryConnector.CLASS_NAME, "options", options);
|
|
29
|
+
Guards.arrayValue(MultiTelemetryConnector.CLASS_NAME, "options.telemetryConnectorTypes", options.telemetryConnectorTypes);
|
|
30
|
+
this._telemetryConnectors = options.telemetryConnectorTypes.map(t => TelemetryConnectorFactory.get(t));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns the class name of the component.
|
|
34
|
+
* @returns The class name of the component.
|
|
35
|
+
*/
|
|
36
|
+
className() {
|
|
37
|
+
return MultiTelemetryConnector.CLASS_NAME;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create one or more metrics.
|
|
41
|
+
* @param metric The metric details, or the details of several metrics.
|
|
42
|
+
* @returns A promise that resolves when the metrics have been created on all connectors.
|
|
43
|
+
*/
|
|
44
|
+
async createMetric(metric) {
|
|
45
|
+
const metrics = Is.array(metric) ? metric : [metric];
|
|
46
|
+
for (const entry of metrics) {
|
|
47
|
+
Guards.object(MultiTelemetryConnector.CLASS_NAME, "entry", entry);
|
|
48
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "entry.id", entry.id);
|
|
49
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "entry.label", entry.label);
|
|
50
|
+
Guards.arrayOneOf(MultiTelemetryConnector.CLASS_NAME, "entry.type", entry.type, Object.values(MetricType));
|
|
51
|
+
}
|
|
52
|
+
await Promise.allSettled(this._telemetryConnectors.map(async (telemetryConnector) => telemetryConnector.createMetric(metric)));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the metric details and it's most recent value.
|
|
56
|
+
* @param id The metric id.
|
|
57
|
+
* @returns The metric details and it's most recent value.
|
|
58
|
+
*/
|
|
59
|
+
async getMetric(id) {
|
|
60
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "id", id);
|
|
61
|
+
for (const telemetryConnector of this._telemetryConnectors) {
|
|
62
|
+
const getMetricResult = telemetryConnector.getMetric?.(id);
|
|
63
|
+
if (!Is.empty(getMetricResult)) {
|
|
64
|
+
return getMetricResult;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new NotSupportedError(MultiTelemetryConnector.CLASS_NAME, "notSupported", {
|
|
68
|
+
methodName: "getMetric"
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get a specific metric value by its id.
|
|
73
|
+
* @param id The id of the metric.
|
|
74
|
+
* @param valueId The id of the metric value.
|
|
75
|
+
* @returns The metric value.
|
|
76
|
+
*/
|
|
77
|
+
async getMetricValue(id, valueId) {
|
|
78
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "id", id);
|
|
79
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "valueId", valueId);
|
|
80
|
+
for (const telemetryConnector of this._telemetryConnectors) {
|
|
81
|
+
const getMetricValueResult = telemetryConnector.getMetricValue?.(id, valueId);
|
|
82
|
+
if (!Is.empty(getMetricValueResult)) {
|
|
83
|
+
return getMetricValueResult;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw new NotSupportedError(MultiTelemetryConnector.CLASS_NAME, "notSupported", {
|
|
87
|
+
methodName: "getMetricValue"
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Update metric.
|
|
92
|
+
* @param metric The metric details.
|
|
93
|
+
* @returns A promise that resolves when the metric has been updated on all connectors.
|
|
94
|
+
*/
|
|
95
|
+
async updateMetric(metric) {
|
|
96
|
+
Guards.object(MultiTelemetryConnector.CLASS_NAME, "metric", metric);
|
|
97
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "metric.id", metric.id);
|
|
98
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "metric.label", metric.label);
|
|
99
|
+
await Promise.allSettled(this._telemetryConnectors.map(async (telemetryConnector) => telemetryConnector.updateMetric(metric)));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Add a metric value.
|
|
103
|
+
* @param id The id of the metric.
|
|
104
|
+
* @param value The value for the add operation.
|
|
105
|
+
* @param customData The custom data for the add operation.
|
|
106
|
+
* @returns The created metric value id.
|
|
107
|
+
*/
|
|
108
|
+
async addMetricValue(id, value, customData) {
|
|
109
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "id", id);
|
|
110
|
+
const results = await Promise.allSettled(this._telemetryConnectors.map(async (telemetryConnector) => telemetryConnector.addMetricValue(id, value, customData)));
|
|
111
|
+
if (results[0].status === "fulfilled") {
|
|
112
|
+
return results[0].value;
|
|
113
|
+
}
|
|
114
|
+
throw new NotSupportedError(MultiTelemetryConnector.CLASS_NAME, "notSupported", {
|
|
115
|
+
methodName: "addMetricValue"
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Add multiple metric values.
|
|
120
|
+
* @param values The metric values to add.
|
|
121
|
+
* @returns The created metric value ids, in the order the values were supplied.
|
|
122
|
+
*/
|
|
123
|
+
async addMetricValues(values) {
|
|
124
|
+
Guards.array(MultiTelemetryConnector.CLASS_NAME, "values", values);
|
|
125
|
+
const results = await Promise.allSettled(this._telemetryConnectors.map(async (telemetryConnector) => telemetryConnector.addMetricValues(values)));
|
|
126
|
+
if (results[0]?.status === "fulfilled") {
|
|
127
|
+
return results[0].value;
|
|
128
|
+
}
|
|
129
|
+
throw new NotSupportedError(MultiTelemetryConnector.CLASS_NAME, "notSupported", {
|
|
130
|
+
methodName: "addMetricValues"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Remove metric.
|
|
135
|
+
* @param id The id of the metric.
|
|
136
|
+
* @returns A promise that resolves when the metric has been removed from all connectors.
|
|
137
|
+
*/
|
|
138
|
+
async removeMetric(id) {
|
|
139
|
+
Guards.stringValue(MultiTelemetryConnector.CLASS_NAME, "id", id);
|
|
140
|
+
await Promise.allSettled(this._telemetryConnectors.map(async (telemetryConnector) => telemetryConnector.removeMetric(id)));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Query the metrics.
|
|
144
|
+
* @param type The type of the metric.
|
|
145
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
146
|
+
* @param limit Limit the number of entities to return.
|
|
147
|
+
* @returns All the entities for the storage matching the conditions,
|
|
148
|
+
* and a cursor which can be used to request more entities.
|
|
149
|
+
* @throws NotImplementedError if the implementation does not support retrieval.
|
|
150
|
+
*/
|
|
151
|
+
async query(type, cursor, limit) {
|
|
152
|
+
// See if we can find a connector that supports querying.
|
|
153
|
+
for (const telemetryConnector of this._telemetryConnectors) {
|
|
154
|
+
const queryBound = telemetryConnector.query?.bind(telemetryConnector);
|
|
155
|
+
if (Is.function(queryBound)) {
|
|
156
|
+
return queryBound(type, cursor, limit);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
throw new NotImplementedError(MultiTelemetryConnector.CLASS_NAME, "query");
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Query the metric values.
|
|
163
|
+
* @param id The id of the metric.
|
|
164
|
+
* @param timeStart The inclusive time as the start of the metric entries.
|
|
165
|
+
* @param timeEnd The inclusive time as the end of the metric entries.
|
|
166
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
167
|
+
* @param limit Limit the number of entities to return.
|
|
168
|
+
* @returns All the entities for the storage matching the conditions,
|
|
169
|
+
* and a cursor which can be used to request more entities.
|
|
170
|
+
* @throws NotImplementedError if the implementation does not support retrieval.
|
|
171
|
+
*/
|
|
172
|
+
async queryValues(id, timeStart, timeEnd, cursor, limit) {
|
|
173
|
+
// See if we can find a connector that supports querying.
|
|
174
|
+
// If it throws anything other than not implemented, we should throw it.
|
|
175
|
+
for (const telemetryConnector of this._telemetryConnectors) {
|
|
176
|
+
const queryValuesBound = telemetryConnector.queryValues?.bind(telemetryConnector);
|
|
177
|
+
if (Is.function(queryValuesBound)) {
|
|
178
|
+
return queryValuesBound(id, timeStart, timeEnd, cursor, limit);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
throw new NotImplementedError(MultiTelemetryConnector.CLASS_NAME, "queryValues");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=multiTelemetryConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiTelemetryConnector.js","sourceRoot":"","sources":["../../../src/connectors/multiTelemetryConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAOtF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACnC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,OAAO,CAAC;IAEnD;;OAEG;IACI,MAAM,CAAU,UAAU,6BAA6C;IAE9E;;;OAGG;IACc,oBAAoB,CAAwB;IAE7D;;;OAGG;IACH,YAAY,OAAmD;QAC9D,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAC5E,MAAM,CAAC,UAAU,CAChB,uBAAuB,CAAC,UAAU,qCAElC,OAAO,CAAC,uBAAuB,CAC/B,CAAC;QACF,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACnE,yBAAyB,CAAC,GAAG,CAAC,CAAC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,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YAChE,CAAC;QACF,CAAC;QAED,MAAM,IAAI,mBAAmB,CAAC,uBAAuB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAClF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Guards, Is, NotImplementedError, NotSupportedError } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { TelemetryConnectorFactory } from \"../factories/telemetryConnectorFactory.js\";\nimport type { IMultiTelemetryConnectorConstructorOptions } from \"../models/IMultiTelemetryConnectorConstructorOptions.js\";\nimport type { ITelemetryConnector } from \"../models/ITelemetryConnector.js\";\nimport type { ITelemetryMetric } from \"../models/ITelemetryMetric.js\";\nimport type { ITelemetryMetricValue } from \"../models/ITelemetryMetricValue.js\";\nimport type { ITelemetryMetricValueEntry } from \"../models/ITelemetryMetricValueEntry.js\";\nimport type { MetricCounterOperation } from \"../models/metricCounterOperation.js\";\nimport { MetricType } from \"../models/metricType.js\";\n\n/**\n * Class for performing telemetry operations on multiple connectors.\n */\nexport class MultiTelemetryConnector implements ITelemetryConnector {\n\t/**\n\t * The namespace for the class.\n\t */\n\tpublic static readonly NAMESPACE: string = \"multi\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MultiTelemetryConnector>();\n\n\t/**\n\t * The connectors to send the telemetry entries to.\n\t * @internal\n\t */\n\tprivate readonly _telemetryConnectors: ITelemetryConnector[];\n\n\t/**\n\t * Create a new instance of MultiTelemetryConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IMultiTelemetryConnectorConstructorOptions) {\n\t\tGuards.object(MultiTelemetryConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.arrayValue(\n\t\t\tMultiTelemetryConnector.CLASS_NAME,\n\t\t\tnameof(options.telemetryConnectorTypes),\n\t\t\toptions.telemetryConnectorTypes\n\t\t);\n\t\tthis._telemetryConnectors = options.telemetryConnectorTypes.map(t =>\n\t\t\tTelemetryConnectorFactory.get(t)\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn MultiTelemetryConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create one or more metrics.\n\t * @param metric The metric details, or the details of several metrics.\n\t * @returns A promise that resolves when the metrics have been created on all connectors.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric | ITelemetryMetric[]): Promise<void> {\n\t\tconst metrics = Is.array<ITelemetryMetric>(metric) ? metric : [metric];\n\n\t\tfor (const entry of metrics) {\n\t\t\tGuards.object<ITelemetryMetric>(MultiTelemetryConnector.CLASS_NAME, nameof(entry), entry);\n\t\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(entry.id), entry.id);\n\t\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(entry.label), entry.label);\n\t\t\tGuards.arrayOneOf(\n\t\t\t\tMultiTelemetryConnector.CLASS_NAME,\n\t\t\t\tnameof(entry.type),\n\t\t\t\tentry.type,\n\t\t\t\tObject.values(MetricType)\n\t\t\t);\n\t\t}\n\n\t\tawait Promise.allSettled(\n\t\t\tthis._telemetryConnectors.map(async telemetryConnector =>\n\t\t\t\ttelemetryConnector.createMetric(metric)\n\t\t\t)\n\t\t);\n\t}\n\n\t/**\n\t * Get the metric details and it's most recent value.\n\t * @param id The metric id.\n\t * @returns The metric details and it's most recent value.\n\t */\n\tpublic async getMetric(id: string): Promise<{\n\t\tmetric: ITelemetryMetric;\n\t\tvalue?: ITelemetryMetricValue;\n\t}> {\n\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(id), id);\n\n\t\tfor (const telemetryConnector of this._telemetryConnectors) {\n\t\t\tconst getMetricResult = telemetryConnector.getMetric?.(id);\n\t\t\tif (!Is.empty(getMetricResult)) {\n\t\t\t\treturn getMetricResult;\n\t\t\t}\n\t\t}\n\t\tthrow new NotSupportedError(MultiTelemetryConnector.CLASS_NAME, \"notSupported\", {\n\t\t\tmethodName: \"getMetric\"\n\t\t});\n\t}\n\n\t/**\n\t * Get a specific metric value by its id.\n\t * @param id The id of the metric.\n\t * @param valueId The id of the metric value.\n\t * @returns The metric value.\n\t */\n\tpublic async getMetricValue(id: string, valueId: string): Promise<ITelemetryMetricValue> {\n\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(valueId), valueId);\n\n\t\tfor (const telemetryConnector of this._telemetryConnectors) {\n\t\t\tconst getMetricValueResult = telemetryConnector.getMetricValue?.(id, valueId);\n\t\t\tif (!Is.empty(getMetricValueResult)) {\n\t\t\t\treturn getMetricValueResult;\n\t\t\t}\n\t\t}\n\t\tthrow new NotSupportedError(MultiTelemetryConnector.CLASS_NAME, \"notSupported\", {\n\t\t\tmethodName: \"getMetricValue\"\n\t\t});\n\t}\n\n\t/**\n\t * Update metric.\n\t * @param metric The metric details.\n\t * @returns A promise that resolves when the metric has been updated on all connectors.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(MultiTelemetryConnector.CLASS_NAME, nameof(metric), metric);\n\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(metric.id), metric.id);\n\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(metric.label), metric.label);\n\n\t\tawait Promise.allSettled(\n\t\t\tthis._telemetryConnectors.map(async telemetryConnector =>\n\t\t\t\ttelemetryConnector.updateMetric(metric)\n\t\t\t)\n\t\t);\n\t}\n\n\t/**\n\t * Add a metric value.\n\t * @param id The id of the metric.\n\t * @param value The value for the add operation.\n\t * @param customData The custom data for the add operation.\n\t * @returns The created metric value id.\n\t */\n\tpublic async addMetricValue(\n\t\tid: string,\n\t\tvalue: MetricCounterOperation | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst results = await Promise.allSettled(\n\t\t\tthis._telemetryConnectors.map(async telemetryConnector =>\n\t\t\t\ttelemetryConnector.addMetricValue(id, value, customData)\n\t\t\t)\n\t\t);\n\n\t\tif (results[0].status === \"fulfilled\") {\n\t\t\treturn results[0].value;\n\t\t}\n\t\tthrow new NotSupportedError(MultiTelemetryConnector.CLASS_NAME, \"notSupported\", {\n\t\t\tmethodName: \"addMetricValue\"\n\t\t});\n\t}\n\n\t/**\n\t * Add multiple metric values.\n\t * @param values The metric values to add.\n\t * @returns The created metric value ids, in the order the values were supplied.\n\t */\n\tpublic async addMetricValues(values: ITelemetryMetricValueEntry[]): Promise<string[]> {\n\t\tGuards.array<ITelemetryMetricValueEntry>(\n\t\t\tMultiTelemetryConnector.CLASS_NAME,\n\t\t\tnameof(values),\n\t\t\tvalues\n\t\t);\n\n\t\tconst results = await Promise.allSettled(\n\t\t\tthis._telemetryConnectors.map(async telemetryConnector =>\n\t\t\t\ttelemetryConnector.addMetricValues(values)\n\t\t\t)\n\t\t);\n\n\t\tif (results[0]?.status === \"fulfilled\") {\n\t\t\treturn results[0].value;\n\t\t}\n\t\tthrow new NotSupportedError(MultiTelemetryConnector.CLASS_NAME, \"notSupported\", {\n\t\t\tmethodName: \"addMetricValues\"\n\t\t});\n\t}\n\n\t/**\n\t * Remove metric.\n\t * @param id The id of the metric.\n\t * @returns A promise that resolves when the metric has been removed from all connectors.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {\n\t\tGuards.stringValue(MultiTelemetryConnector.CLASS_NAME, nameof(id), id);\n\n\t\tawait Promise.allSettled(\n\t\t\tthis._telemetryConnectors.map(async telemetryConnector => telemetryConnector.removeMetric(id))\n\t\t);\n\t}\n\n\t/**\n\t * Query the metrics.\n\t * @param type The type of the metric.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async query(\n\t\ttype?: MetricType,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metrics.\n\t\t */\n\t\tentities: ITelemetryMetric[];\n\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\t// See if we can find a connector that supports querying.\n\t\tfor (const telemetryConnector of this._telemetryConnectors) {\n\t\t\tconst queryBound = telemetryConnector.query?.bind(telemetryConnector);\n\t\t\tif (Is.function(queryBound)) {\n\t\t\t\treturn queryBound(type, cursor, limit);\n\t\t\t}\n\t\t}\n\n\t\tthrow new NotImplementedError(MultiTelemetryConnector.CLASS_NAME, \"query\");\n\t}\n\n\t/**\n\t * Query the metric values.\n\t * @param id The id of the metric.\n\t * @param timeStart The inclusive time as the start of the metric entries.\n\t * @param timeEnd The inclusive time as the end of the metric entries.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async queryValues(\n\t\tid: string,\n\t\ttimeStart?: number,\n\t\ttimeEnd?: number,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metric details.\n\t\t */\n\t\tmetric: ITelemetryMetric;\n\n\t\t/**\n\t\t * The values for the metric.\n\t\t */\n\t\tentities: ITelemetryMetricValue[];\n\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\t// See if we can find a connector that supports querying.\n\t\t// If it throws anything other than not implemented, we should throw it.\n\t\tfor (const telemetryConnector of this._telemetryConnectors) {\n\t\t\tconst queryValuesBound = telemetryConnector.queryValues?.bind(telemetryConnector);\n\t\t\tif (Is.function(queryValuesBound)) {\n\t\t\t\treturn queryValuesBound(id, timeStart, timeEnd, cursor, limit);\n\t\t\t}\n\t\t}\n\n\t\tthrow new NotImplementedError(MultiTelemetryConnector.CLASS_NAME, \"queryValues\");\n\t}\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class for performing telemetry operations to nowhere.
|
|
3
|
+
*/
|
|
4
|
+
export class SilentTelemetryConnector {
|
|
5
|
+
/**
|
|
6
|
+
* The namespace for the class.
|
|
7
|
+
*/
|
|
8
|
+
static NAMESPACE = "silent";
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static CLASS_NAME = "SilentTelemetryConnector";
|
|
13
|
+
/**
|
|
14
|
+
* Returns the class name of the component.
|
|
15
|
+
* @returns The class name of the component.
|
|
16
|
+
*/
|
|
17
|
+
className() {
|
|
18
|
+
return SilentTelemetryConnector.CLASS_NAME;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create one or more metrics.
|
|
22
|
+
* @param metric The metric details, or the details of several metrics.
|
|
23
|
+
* @returns A promise that resolves when the metric has been created.
|
|
24
|
+
*/
|
|
25
|
+
async createMetric(metric) { }
|
|
26
|
+
/**
|
|
27
|
+
* Update metric.
|
|
28
|
+
* @param metric The metric details.
|
|
29
|
+
* @returns A promise that resolves when the metric has been updated.
|
|
30
|
+
*/
|
|
31
|
+
async updateMetric(metric) { }
|
|
32
|
+
/**
|
|
33
|
+
* Update metric value.
|
|
34
|
+
* @param id The id of the metric.
|
|
35
|
+
* @param value The value for the update operation.
|
|
36
|
+
* @param customData The custom data for the update operation.
|
|
37
|
+
* @returns The created metric value id.
|
|
38
|
+
*/
|
|
39
|
+
async addMetricValue(id, value, customData) {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Add multiple metric values.
|
|
44
|
+
* @param values The metric values to add.
|
|
45
|
+
* @returns The created metric value ids.
|
|
46
|
+
*/
|
|
47
|
+
async addMetricValues(values) {
|
|
48
|
+
return values.map(() => "");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Remove metric.
|
|
52
|
+
* @param id The id of the metric.
|
|
53
|
+
* @returns A promise that resolves when the metric and all its values have been removed.
|
|
54
|
+
*/
|
|
55
|
+
async removeMetric(id) { }
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=silentTelemetryConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"silentTelemetryConnector.js","sourceRoot":"","sources":["../../../src/connectors/silentTelemetryConnector.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,QAAQ,CAAC;IAEpD;;OAEG;IACI,MAAM,CAAU,UAAU,8BAA8C;IAE/E;;;OAGG;IACI,SAAS;QACf,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAA6C,IAAkB,CAAC;IAE1F;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAAsC,IAAkB,CAAC;IAEnF;;;;;;OAMG;IACI,KAAK,CAAC,cAAc,CAC1B,EAAU,EACV,KAAsC,EACtC,UAAuC;QAEvC,OAAO,EAAE,CAAC;IACX,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,eAAe,CAAC,MAAoC;QAChE,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,EAAU,IAAkB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@3sixty/nameof\";\nimport type { ITelemetryConnector } from \"../models/ITelemetryConnector.js\";\nimport type { ITelemetryMetric } from \"../models/ITelemetryMetric.js\";\nimport type { ITelemetryMetricValueEntry } from \"../models/ITelemetryMetricValueEntry.js\";\nimport type { MetricCounterOperation } from \"../models/metricCounterOperation.js\";\n\n/**\n * Class for performing telemetry operations to nowhere.\n */\nexport class SilentTelemetryConnector implements ITelemetryConnector {\n\t/**\n\t * The namespace for the class.\n\t */\n\tpublic static readonly NAMESPACE: string = \"silent\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<SilentTelemetryConnector>();\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn SilentTelemetryConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create one or more metrics.\n\t * @param metric The metric details, or the details of several metrics.\n\t * @returns A promise that resolves when the metric has been created.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric | ITelemetryMetric[]): Promise<void> {}\n\n\t/**\n\t * Update metric.\n\t * @param metric The metric details.\n\t * @returns A promise that resolves when the metric has been updated.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {}\n\n\t/**\n\t * Update metric value.\n\t * @param id The id of the metric.\n\t * @param value The value for the update operation.\n\t * @param customData The custom data for the update operation.\n\t * @returns The created metric value id.\n\t */\n\tpublic async addMetricValue(\n\t\tid: string,\n\t\tvalue: MetricCounterOperation | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Add multiple metric values.\n\t * @param values The metric values to add.\n\t * @returns The created metric value ids.\n\t */\n\tpublic async addMetricValues(values: ITelemetryMetricValueEntry[]): Promise<string[]> {\n\t\treturn values.map(() => \"\");\n\t}\n\n\t/**\n\t * Remove metric.\n\t * @param id The id of the metric.\n\t * @returns A promise that resolves when the metric and all its values have been removed.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {}\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Factory } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for `IMetricsProducer` implementations.
|
|
6
|
+
*
|
|
7
|
+
* The engine registers producers with `MetricsProducerFactory` during
|
|
8
|
+
* initialisation. Third-party apps can also register their own producers
|
|
9
|
+
* before `engine.start()` is called.
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
12
|
+
export const MetricsProducerFactory = Factory.createFactory("metrics-producer");
|
|
13
|
+
//# sourceMappingURL=metricsProducerFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metricsProducerFactory.js","sourceRoot":"","sources":["../../../src/factories/metricsProducerFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;;;;;GAMG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC,aAAa,CAAmB,kBAAkB,CAAC,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@3sixty/core\";\nimport type { IMetricsProducer } from \"../models/IMetricsProducer.js\";\n\n/**\n * Factory for `IMetricsProducer` implementations.\n *\n * The engine registers producers with `MetricsProducerFactory` during\n * initialisation. Third-party apps can also register their own producers\n * before `engine.start()` is called.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const MetricsProducerFactory = Factory.createFactory<IMetricsProducer>(\"metrics-producer\");\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Factory } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating telemetry connectors.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
export const TelemetryConnectorFactory = Factory.createFactory("telemetry");
|
|
9
|
+
//# sourceMappingURL=telemetryConnectorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryConnectorFactory.js","sourceRoot":"","sources":["../../../src/factories/telemetryConnectorFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAC,aAAa,CAAsB,WAAW,CAAC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@3sixty/core\";\nimport type { ITelemetryConnector } from \"../models/ITelemetryConnector.js\";\n\n/**\n * Factory for creating telemetry connectors.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const TelemetryConnectorFactory = Factory.createFactory<ITelemetryConnector>(\"telemetry\");\n"]}
|