@twin.org/telemetry-service 0.0.2-next.3 → 0.0.3-next.1
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/dist/es/index.js +7 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/ITelemetryServiceConstructorOptions.js +4 -0
- package/dist/es/models/ITelemetryServiceConstructorOptions.js.map +1 -0
- package/dist/es/restEntryPoints.js +10 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/{esm/index.mjs → es/telemetryRoutes.js} +13 -124
- package/dist/es/telemetryRoutes.js.map +1 -0
- package/dist/es/telemetryService.js +109 -0
- package/dist/es/telemetryService.js.map +1 -0
- package/dist/types/index.d.ts +4 -4
- package/dist/types/telemetryService.d.ts +6 -1
- package/docs/changelog.md +27 -0
- package/docs/open-api/spec.json +32 -444
- package/docs/reference/classes/TelemetryService.md +18 -0
- package/package.json +6 -8
- package/dist/cjs/index.cjs +0 -582
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./telemetryRoutes.js";
|
|
4
|
+
export * from "./telemetryService.js";
|
|
5
|
+
export * from "./restEntryPoints.js";
|
|
6
|
+
export * from "./models/ITelemetryServiceConstructorOptions.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iDAAiD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./telemetryRoutes.js\";\nexport * from \"./telemetryService.js\";\nexport * from \"./restEntryPoints.js\";\nexport * from \"./models/ITelemetryServiceConstructorOptions.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITelemetryServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/ITelemetryServiceConstructorOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The options for the telemetry service constructor.\n */\nexport interface ITelemetryServiceConstructorOptions {\n\t/**\n\t * The type of the telemetry connector to use.\n\t * @default telemetry\n\t */\n\ttelemetryConnectorType?: string;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { generateRestRoutesTelemetry, tagsTelemetry } from "./telemetryRoutes.js";
|
|
2
|
+
export const restEntryPoints = [
|
|
3
|
+
{
|
|
4
|
+
name: "telemetry",
|
|
5
|
+
defaultBaseRoute: "telemetry",
|
|
6
|
+
tags: tagsTelemetry,
|
|
7
|
+
generateRoutes: generateRestRoutesTelemetry
|
|
8
|
+
}
|
|
9
|
+
];
|
|
10
|
+
//# sourceMappingURL=restEntryPoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restEntryPoints.js","sourceRoot":"","sources":["../../src/restEntryPoints.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAElF,MAAM,CAAC,MAAM,eAAe,GAA2B;IACtD;QACC,IAAI,EAAE,WAAW;QACjB,gBAAgB,EAAE,WAAW;QAC7B,IAAI,EAAE,aAAa;QACnB,cAAc,EAAE,2BAA2B;KAC3C;CACD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteEntryPoint } from \"@twin.org/api-models\";\nimport { generateRestRoutesTelemetry, tagsTelemetry } from \"./telemetryRoutes.js\";\n\nexport const restEntryPoints: IRestRouteEntryPoint[] = [\n\t{\n\t\tname: \"telemetry\",\n\t\tdefaultBaseRoute: \"telemetry\",\n\t\ttags: tagsTelemetry,\n\t\tgenerateRoutes: generateRestRoutesTelemetry\n\t}\n];\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MetricType
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { Coerce, ComponentFactory, Guards } from "@twin.org/core";
|
|
2
|
+
import { MetricType } from "@twin.org/telemetry-models";
|
|
3
|
+
import { HeaderTypes, HttpStatusCode } from "@twin.org/web";
|
|
5
4
|
/**
|
|
6
5
|
* The source used when communicating about these routes.
|
|
7
6
|
*/
|
|
@@ -9,7 +8,7 @@ const ROUTES_SOURCE = "telemetryRoutes";
|
|
|
9
8
|
/**
|
|
10
9
|
* The tag to associate with the routes.
|
|
11
10
|
*/
|
|
12
|
-
const tagsTelemetry = [
|
|
11
|
+
export const tagsTelemetry = [
|
|
13
12
|
{
|
|
14
13
|
name: "Telemetry",
|
|
15
14
|
description: "Endpoints which are modelled to access a telemetry contract."
|
|
@@ -21,7 +20,7 @@ const tagsTelemetry = [
|
|
|
21
20
|
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
22
21
|
* @returns The generated routes.
|
|
23
22
|
*/
|
|
24
|
-
function generateRestRoutesTelemetry(baseRouteName, componentName) {
|
|
23
|
+
export function generateRestRoutesTelemetry(baseRouteName, componentName) {
|
|
25
24
|
const createMetricRoute = {
|
|
26
25
|
operationId: "telemetryCreateMetric",
|
|
27
26
|
summary: "Create a telemetry metric",
|
|
@@ -337,7 +336,7 @@ function generateRestRoutesTelemetry(baseRouteName, componentName) {
|
|
|
337
336
|
* @param request The request.
|
|
338
337
|
* @returns The response object with additional http response properties.
|
|
339
338
|
*/
|
|
340
|
-
async function telemetryCreateMetric(httpRequestContext, componentName, request) {
|
|
339
|
+
export async function telemetryCreateMetric(httpRequestContext, componentName, request) {
|
|
341
340
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
342
341
|
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
343
342
|
const component = ComponentFactory.get(componentName);
|
|
@@ -362,7 +361,7 @@ async function telemetryCreateMetric(httpRequestContext, componentName, request)
|
|
|
362
361
|
* @param request The request.
|
|
363
362
|
* @returns The response object with additional http response properties.
|
|
364
363
|
*/
|
|
365
|
-
async function telemetryGetMetric(httpRequestContext, componentName, request) {
|
|
364
|
+
export async function telemetryGetMetric(httpRequestContext, componentName, request) {
|
|
366
365
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
367
366
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
368
367
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
@@ -377,7 +376,7 @@ async function telemetryGetMetric(httpRequestContext, componentName, request) {
|
|
|
377
376
|
* @param request The request.
|
|
378
377
|
* @returns The response object with additional http response properties.
|
|
379
378
|
*/
|
|
380
|
-
async function telemetryUpdateMetric(httpRequestContext, componentName, request) {
|
|
379
|
+
export async function telemetryUpdateMetric(httpRequestContext, componentName, request) {
|
|
381
380
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
382
381
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
383
382
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
@@ -398,7 +397,7 @@ async function telemetryUpdateMetric(httpRequestContext, componentName, request)
|
|
|
398
397
|
* @param request The request.
|
|
399
398
|
* @returns The response object with additional http response properties.
|
|
400
399
|
*/
|
|
401
|
-
async function telemetryAddMetricValue(httpRequestContext, componentName, request) {
|
|
400
|
+
export async function telemetryAddMetricValue(httpRequestContext, componentName, request) {
|
|
402
401
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
403
402
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
404
403
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
@@ -414,7 +413,7 @@ async function telemetryAddMetricValue(httpRequestContext, componentName, reques
|
|
|
414
413
|
* @param request The request.
|
|
415
414
|
* @returns The response object with additional http response properties.
|
|
416
415
|
*/
|
|
417
|
-
async function telemetryRemoveMetric(httpRequestContext, componentName, request) {
|
|
416
|
+
export async function telemetryRemoveMetric(httpRequestContext, componentName, request) {
|
|
418
417
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
419
418
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
420
419
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
@@ -431,7 +430,7 @@ async function telemetryRemoveMetric(httpRequestContext, componentName, request)
|
|
|
431
430
|
* @param request The request.
|
|
432
431
|
* @returns The response object with additional http response properties.
|
|
433
432
|
*/
|
|
434
|
-
async function telemetryMetricList(httpRequestContext, componentName, request) {
|
|
433
|
+
export async function telemetryMetricList(httpRequestContext, componentName, request) {
|
|
435
434
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
436
435
|
Guards.object(ROUTES_SOURCE, "request.query", request.query);
|
|
437
436
|
const component = ComponentFactory.get(componentName);
|
|
@@ -447,7 +446,7 @@ async function telemetryMetricList(httpRequestContext, componentName, request) {
|
|
|
447
446
|
* @param request The request.
|
|
448
447
|
* @returns The response object with additional http response properties.
|
|
449
448
|
*/
|
|
450
|
-
async function telemetryMetricValueList(httpRequestContext, componentName, request) {
|
|
449
|
+
export async function telemetryMetricValueList(httpRequestContext, componentName, request) {
|
|
451
450
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
452
451
|
Guards.object(ROUTES_SOURCE, "request.query", request.query);
|
|
453
452
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
@@ -457,114 +456,4 @@ async function telemetryMetricValueList(httpRequestContext, componentName, reque
|
|
|
457
456
|
body: itemsAndCursor
|
|
458
457
|
};
|
|
459
458
|
}
|
|
460
|
-
|
|
461
|
-
// Copyright 2024 IOTA Stiftung.
|
|
462
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
463
|
-
/**
|
|
464
|
-
* Service for performing telemetry operations to a connector.
|
|
465
|
-
*/
|
|
466
|
-
class TelemetryService {
|
|
467
|
-
/**
|
|
468
|
-
* Runtime name for the class.
|
|
469
|
-
*/
|
|
470
|
-
static CLASS_NAME = "TelemetryService";
|
|
471
|
-
/**
|
|
472
|
-
* Telemetry connector used by the service.
|
|
473
|
-
* @internal
|
|
474
|
-
*/
|
|
475
|
-
_telemetryConnector;
|
|
476
|
-
/**
|
|
477
|
-
* Create a new instance of TelemetryService.
|
|
478
|
-
* @param options The options for the connector.
|
|
479
|
-
*/
|
|
480
|
-
constructor(options) {
|
|
481
|
-
this._telemetryConnector = TelemetryConnectorFactory.get(options?.telemetryConnectorType ?? "telemetry");
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Create a new metric.
|
|
485
|
-
* @param metric The metric details.
|
|
486
|
-
* @returns Nothing.
|
|
487
|
-
*/
|
|
488
|
-
async createMetric(metric) {
|
|
489
|
-
Guards.object(TelemetryService.CLASS_NAME, "metric", metric);
|
|
490
|
-
await this._telemetryConnector.createMetric(metric);
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Get the metric details and it's most recent value.
|
|
494
|
-
* @param id The metric id.
|
|
495
|
-
* @returns The metric details and it's most recent value.
|
|
496
|
-
*/
|
|
497
|
-
async getMetric(id) {
|
|
498
|
-
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
499
|
-
return this._telemetryConnector.getMetric(id);
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Update metric.
|
|
503
|
-
* @param metric The metric details.
|
|
504
|
-
* @returns Nothing.
|
|
505
|
-
*/
|
|
506
|
-
async updateMetric(metric) {
|
|
507
|
-
Guards.object(TelemetryService.CLASS_NAME, "metric", metric);
|
|
508
|
-
Guards.stringValue(TelemetryService.CLASS_NAME, "metric.id", metric.id);
|
|
509
|
-
return this._telemetryConnector.updateMetric(metric);
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Add a metric value.
|
|
513
|
-
* @param id The id of the metric.
|
|
514
|
-
* @param value The value for the add operation.
|
|
515
|
-
* @param customData The custom data for the add operation.
|
|
516
|
-
* @returns The created metric value id.
|
|
517
|
-
*/
|
|
518
|
-
async addMetricValue(id, value, customData) {
|
|
519
|
-
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
520
|
-
Guards.defined(TelemetryService.CLASS_NAME, "value", value);
|
|
521
|
-
return this._telemetryConnector.addMetricValue(id, value, customData);
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Remove metric.
|
|
525
|
-
* @param id The id of the metric.
|
|
526
|
-
* @returns Nothing.
|
|
527
|
-
*/
|
|
528
|
-
async removeMetric(id) {
|
|
529
|
-
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
530
|
-
return this._telemetryConnector.removeMetric(id);
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Query the metrics.
|
|
534
|
-
* @param type The type of the metric.
|
|
535
|
-
* @param cursor The cursor to request the next chunk of entities.
|
|
536
|
-
* @param limit Limit the number of entities to return.
|
|
537
|
-
* @returns All the entities for the storage matching the conditions,
|
|
538
|
-
* and a cursor which can be used to request more entities.
|
|
539
|
-
* @throws NotImplementedError if the implementation does not support retrieval.
|
|
540
|
-
*/
|
|
541
|
-
async query(type, cursor, limit) {
|
|
542
|
-
return this._telemetryConnector.query(type, cursor, limit);
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Query the metric values.
|
|
546
|
-
* @param id The id of the metric.
|
|
547
|
-
* @param timeStart The inclusive time as the start of the metric entries.
|
|
548
|
-
* @param timeEnd The inclusive time as the end of the metric entries.
|
|
549
|
-
* @param cursor The cursor to request the next chunk of entities.
|
|
550
|
-
* @param limit Limit the number of entities to return.
|
|
551
|
-
* @returns All the entities for the storage matching the conditions,
|
|
552
|
-
* and a cursor which can be used to request more entities.
|
|
553
|
-
* @throws NotImplementedError if the implementation does not support retrieval.
|
|
554
|
-
*/
|
|
555
|
-
async queryValues(id, timeStart, timeEnd, cursor, limit) {
|
|
556
|
-
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
557
|
-
return this._telemetryConnector.queryValues(id, timeStart, timeEnd, cursor, limit);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
const restEntryPoints = [
|
|
562
|
-
{
|
|
563
|
-
name: "telemetry",
|
|
564
|
-
defaultBaseRoute: "telemetry",
|
|
565
|
-
tags: tagsTelemetry,
|
|
566
|
-
generateRoutes: generateRestRoutesTelemetry
|
|
567
|
-
}
|
|
568
|
-
];
|
|
569
|
-
|
|
570
|
-
export { TelemetryService, generateRestRoutesTelemetry, restEntryPoints, tagsTelemetry, telemetryAddMetricValue, telemetryCreateMetric, telemetryGetMetric, telemetryMetricList, telemetryMetricValueList, telemetryRemoveMetric, telemetryUpdateMetric };
|
|
459
|
+
//# sourceMappingURL=telemetryRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryRoutes.js","sourceRoot":"","sources":["../../src/telemetryRoutes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EACN,UAAU,EAYV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW;IACpC;QACC,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,8DAA8D;KAC3E;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAC1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AAG,CAAsB,aAAa,CAAC,CAAC;IAE3E,MAAM,cAAc,GAAG,MAAM,SAAS,CAAC,KAAK,CAC3C,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAe,EACjD,OAAO,EAAE,KAAK,EAAE,MAAM,EACtB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CACpC,CAAC;IAEF,OAAO;QACN,IAAI,EAAE,cAAc;KACpB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC7C,kBAAuC,EACvC,aAAqB,EACrB,OAAoC;IAEpC,MAAM,CAAC,MAAM,CAA8B,aAAa,aAAmB,OAAO,CAAC,CAAC;IACpF,MAAM,CAAC,MAAM,CACZ,aAAa,mBAEb,OAAO,CAAC,KAAK,CACb,CAAC;IACF,MAAM,CAAC,WAAW,CAAC,aAAa,2BAAiC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAExF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAsB,aAAa,CAAC,CAAC;IAE3E,MAAM,cAAc,GAAG,MAAM,SAAS,CAAC,WAAW,CACjD,OAAO,EAAE,UAAU,CAAC,EAAE,EACtB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,EACxC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,EACtC,OAAO,EAAE,KAAK,EAAE,MAAM,EACtB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CACpC,CAAC;IAEF,OAAO;QACN,IAAI,EAAE,cAAc;KACpB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tICreatedResponse,\n\tIHttpRequestContext,\n\tINoContentResponse,\n\tIRestRoute,\n\tITag\n} from \"@twin.org/api-models\";\nimport { Coerce, ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tMetricType,\n\ttype ITelemetryAddMetricValueRequest,\n\ttype ITelemetryComponent,\n\ttype ITelemetryCreateMetricRequest,\n\ttype ITelemetryGetMetricRequest,\n\ttype ITelemetryGetMetricResponse,\n\ttype ITelemetryListRequest,\n\ttype ITelemetryListResponse,\n\ttype ITelemetryRemoveMetricRequest,\n\ttype ITelemetryUpdateMetricRequest,\n\ttype ITelemetryValuesListRequest,\n\ttype ITelemetryValuesListResponse\n} from \"@twin.org/telemetry-models\";\nimport { HeaderTypes, HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"telemetryRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsTelemetry: ITag[] = [\n\t{\n\t\tname: \"Telemetry\",\n\t\tdescription: \"Endpoints which are modelled to access a telemetry contract.\"\n\t}\n];\n\n/**\n * The REST routes for telemetry.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesTelemetry(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createMetricRoute: IRestRoute<ITelemetryCreateMetricRequest, ICreatedResponse> = {\n\t\toperationId: \"telemetryCreateMetric\",\n\t\tsummary: \"Create a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/metric`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryCreateMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryCreateMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryCreateMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\tdescription: \"This is my counter\",\n\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryCreateMetricResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"my-counter\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getMetricRoute: IRestRoute<ITelemetryGetMetricRequest, ITelemetryGetMetricResponse> = {\n\t\toperationId: \"telemetryGetMetric\",\n\t\tsummary: \"Get a telemetry metric and it's most recent value\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryGetMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryGetMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryGetMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryGetMetricResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryGetMetricResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tmetric: {\n\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\tdescription: \"This is my counter\",\n\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\tts: 1715252922273,\n\t\t\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst updateMetricRoute: IRestRoute<ITelemetryUpdateMetricRequest, INoContentResponse> = {\n\t\toperationId: \"telemetryUpdateMetric\",\n\t\tsummary: \"Update a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryUpdateMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryUpdateMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryUpdateMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tlabel: \"My New Label\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst addMetricValueRoute: IRestRoute<ITelemetryAddMetricValueRequest, ICreatedResponse> = {\n\t\toperationId: \"telemetryAddMetricValue\",\n\t\tsummary: \"Add a telemetry metric value\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/metric/:id/value`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryAddMetricValue(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryAddMetricValueRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryAddMetricValueRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryAddMetricValueIncRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tvalue: \"inc\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryAddMetricValueResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"aabbccdd11223445566\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeMetricRoute: IRestRoute<ITelemetryRemoveMetricRequest, INoContentResponse> = {\n\t\toperationId: \"telemetryRemoveMetric\",\n\t\tsummary: \"Remove a telemetry metric and it's values.\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryRemoveMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryRemoveMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryRemoveMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listMetricsRoute: IRestRoute<ITelemetryListRequest, ITelemetryListResponse> = {\n\t\toperationId: \"telemetryListEntries\",\n\t\tsummary: \"Get a list of the telemetry metrics\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryMetricList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryListRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryListRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\ttype: MetricType.Counter\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryListResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryListResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tentities: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"my-counter-2\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"My Counter 2\",\n\t\t\t\t\t\t\t\t\t\ttype: MetricType.IncDecCounter,\n\t\t\t\t\t\t\t\t\t\tunit: \"M\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tcursor: \"1\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listMetricsValuesRoute: IRestRoute<\n\t\tITelemetryValuesListRequest,\n\t\tITelemetryValuesListResponse\n\t> = {\n\t\toperationId: \"telemetryValuesListEntries\",\n\t\tsummary: \"Get a list of the values for a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric/:id/value`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryMetricValueList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryValuesListRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryValuesListRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryValuesListResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryValuesListResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tmetric: {\n\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tentities: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\t\tts: 1715252922273,\n\t\t\t\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\t\tts: 1715252922274,\n\t\t\t\t\t\t\t\t\t\tvalue: 11\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tcursor: \"1\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [\n\t\tcreateMetricRoute,\n\t\tgetMetricRoute,\n\t\tupdateMetricRoute,\n\t\taddMetricValueRoute,\n\t\tremoveMetricRoute,\n\t\tlistMetricsRoute,\n\t\tlistMetricsValuesRoute\n\t];\n}\n\n/**\n * Create a new telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryCreateMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryCreateMetricRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<ITelemetryCreateMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryCreateMetricRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.createMetric({\n\t\tid: request.body.id,\n\t\tlabel: request.body.label,\n\t\tdescription: request.body.description,\n\t\ttype: request.body.type,\n\t\tunit: request.body.unit\n\t});\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: request.body.id\n\t\t}\n\t};\n}\n\n/**\n * Gets a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryGetMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryGetMetricRequest\n): Promise<ITelemetryGetMetricResponse> {\n\tGuards.object<ITelemetryGetMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryGetMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tconst result = await component.getMetric(request.pathParams.id);\n\treturn { body: result };\n}\n\n/**\n * Updates a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryUpdateMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryUpdateMetricRequest\n): Promise<INoContentResponse> {\n\tGuards.object<ITelemetryUpdateMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryUpdateMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object<ITelemetryUpdateMetricRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.updateMetric({\n\t\tid: request.pathParams.id,\n\t\tlabel: request.body.label,\n\t\tdescription: request.body.description,\n\t\tunit: request.body.unit\n\t});\n\n\treturn { statusCode: HttpStatusCode.noContent };\n}\n\n/**\n * Add a telemetry metric value.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryAddMetricValue(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryAddMetricValueRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<ITelemetryAddMetricValueRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryAddMetricValueRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object<ITelemetryAddMetricValueRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tconst id = await component.addMetricValue(\n\t\trequest.pathParams.id,\n\t\trequest.body.value,\n\t\trequest.body.customData\n\t);\n\n\treturn { statusCode: HttpStatusCode.created, headers: { [HeaderTypes.Location]: id } };\n}\n\n/**\n * Removes a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryRemoveMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryRemoveMetricRequest\n): Promise<INoContentResponse> {\n\tGuards.object<ITelemetryRemoveMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryRemoveMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.removeMetric(request.pathParams.id);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get a list of the telemetry metrics.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryMetricList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryListRequest\n): Promise<ITelemetryListResponse> {\n\tGuards.object<ITelemetryListRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryListRequest[\"query\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.query),\n\t\trequest.query\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\n\tconst itemsAndCursor = await component.query(\n\t\tCoerce.number(request?.query?.type) as MetricType,\n\t\trequest?.query?.cursor,\n\t\tCoerce.number(request?.query?.limit)\n\t);\n\n\treturn {\n\t\tbody: itemsAndCursor\n\t};\n}\n\n/**\n * Get a list of the telemetry metric values.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryMetricValueList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryValuesListRequest\n): Promise<ITelemetryValuesListResponse> {\n\tGuards.object<ITelemetryValuesListRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryValuesListRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.query),\n\t\trequest.query\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\n\tconst itemsAndCursor = await component.queryValues(\n\t\trequest?.pathParams.id,\n\t\tCoerce.number(request?.query?.timeStart),\n\t\tCoerce.number(request?.query?.timeEnd),\n\t\trequest?.query?.cursor,\n\t\tCoerce.number(request?.query?.limit)\n\t);\n\n\treturn {\n\t\tbody: itemsAndCursor\n\t};\n}\n"]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Guards } from "@twin.org/core";
|
|
4
|
+
import { TelemetryConnectorFactory } from "@twin.org/telemetry-models";
|
|
5
|
+
/**
|
|
6
|
+
* Service for performing telemetry operations to a connector.
|
|
7
|
+
*/
|
|
8
|
+
export class TelemetryService {
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static CLASS_NAME = "TelemetryService";
|
|
13
|
+
/**
|
|
14
|
+
* Telemetry connector used by the service.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
_telemetryConnector;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of TelemetryService.
|
|
20
|
+
* @param options The options for the connector.
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this._telemetryConnector = TelemetryConnectorFactory.get(options?.telemetryConnectorType ?? "telemetry");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns the class name of the component.
|
|
27
|
+
* @returns The class name of the component.
|
|
28
|
+
*/
|
|
29
|
+
className() {
|
|
30
|
+
return TelemetryService.CLASS_NAME;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a new metric.
|
|
34
|
+
* @param metric The metric details.
|
|
35
|
+
* @returns Nothing.
|
|
36
|
+
*/
|
|
37
|
+
async createMetric(metric) {
|
|
38
|
+
Guards.object(TelemetryService.CLASS_NAME, "metric", metric);
|
|
39
|
+
await this._telemetryConnector.createMetric(metric);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the metric details and it's most recent value.
|
|
43
|
+
* @param id The metric id.
|
|
44
|
+
* @returns The metric details and it's most recent value.
|
|
45
|
+
*/
|
|
46
|
+
async getMetric(id) {
|
|
47
|
+
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
48
|
+
return this._telemetryConnector.getMetric(id);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Update metric.
|
|
52
|
+
* @param metric The metric details.
|
|
53
|
+
* @returns Nothing.
|
|
54
|
+
*/
|
|
55
|
+
async updateMetric(metric) {
|
|
56
|
+
Guards.object(TelemetryService.CLASS_NAME, "metric", metric);
|
|
57
|
+
Guards.stringValue(TelemetryService.CLASS_NAME, "metric.id", metric.id);
|
|
58
|
+
return this._telemetryConnector.updateMetric(metric);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Add a metric value.
|
|
62
|
+
* @param id The id of the metric.
|
|
63
|
+
* @param value The value for the add operation.
|
|
64
|
+
* @param customData The custom data for the add operation.
|
|
65
|
+
* @returns The created metric value id.
|
|
66
|
+
*/
|
|
67
|
+
async addMetricValue(id, value, customData) {
|
|
68
|
+
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
69
|
+
Guards.defined(TelemetryService.CLASS_NAME, "value", value);
|
|
70
|
+
return this._telemetryConnector.addMetricValue(id, value, customData);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Remove metric.
|
|
74
|
+
* @param id The id of the metric.
|
|
75
|
+
* @returns Nothing.
|
|
76
|
+
*/
|
|
77
|
+
async removeMetric(id) {
|
|
78
|
+
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
79
|
+
return this._telemetryConnector.removeMetric(id);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Query the metrics.
|
|
83
|
+
* @param type The type of the metric.
|
|
84
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
85
|
+
* @param limit Limit the number of entities to return.
|
|
86
|
+
* @returns All the entities for the storage matching the conditions,
|
|
87
|
+
* and a cursor which can be used to request more entities.
|
|
88
|
+
* @throws NotImplementedError if the implementation does not support retrieval.
|
|
89
|
+
*/
|
|
90
|
+
async query(type, cursor, limit) {
|
|
91
|
+
return this._telemetryConnector.query(type, cursor, limit);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Query the metric values.
|
|
95
|
+
* @param id The id of the metric.
|
|
96
|
+
* @param timeStart The inclusive time as the start of the metric entries.
|
|
97
|
+
* @param timeEnd The inclusive time as the end of the metric entries.
|
|
98
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
99
|
+
* @param limit Limit the number of entities to return.
|
|
100
|
+
* @returns All the entities for the storage matching the conditions,
|
|
101
|
+
* and a cursor which can be used to request more entities.
|
|
102
|
+
* @throws NotImplementedError if the implementation does not support retrieval.
|
|
103
|
+
*/
|
|
104
|
+
async queryValues(id, timeStart, timeEnd, cursor, limit) {
|
|
105
|
+
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
106
|
+
return this._telemetryConnector.queryValues(id, timeStart, timeEnd, cursor, limit);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=telemetryService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryService.js","sourceRoot":"","sources":["../../src/telemetryService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,C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B,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAChE,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,EAAU;QACnC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,KAAK,CACjB,IAAiB,EACjB,MAAe,EACf,KAAc;QAYd,OAAO,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK,CAAC,WAAW,CACvB,EAAU,EACV,SAAkB,EAClB,OAAgB,EAChB,MAAe,EACf,KAAc;QAed,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACpF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tTelemetryConnectorFactory,\n\ttype ITelemetryComponent,\n\ttype ITelemetryConnector,\n\ttype ITelemetryMetric,\n\ttype ITelemetryMetricValue,\n\ttype MetricType\n} from \"@twin.org/telemetry-models\";\nimport type { ITelemetryServiceConstructorOptions } from \"./models/ITelemetryServiceConstructorOptions.js\";\n\n/**\n * Service for performing telemetry operations to a connector.\n */\nexport class TelemetryService implements ITelemetryComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TelemetryService>();\n\n\t/**\n\t * Telemetry connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _telemetryConnector: ITelemetryConnector;\n\n\t/**\n\t * Create a new instance of TelemetryService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: ITelemetryServiceConstructorOptions) {\n\t\tthis._telemetryConnector = TelemetryConnectorFactory.get(\n\t\t\toptions?.telemetryConnectorType ?? \"telemetry\"\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 TelemetryService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new metric.\n\t * @param metric The metric details.\n\t * @returns Nothing.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(TelemetryService.CLASS_NAME, nameof(metric), metric);\n\n\t\tawait this._telemetryConnector.createMetric(metric);\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(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.getMetric(id);\n\t}\n\n\t/**\n\t * Update metric.\n\t * @param metric The metric details.\n\t * @returns Nothing.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(TelemetryService.CLASS_NAME, nameof(metric), metric);\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(metric.id), metric.id);\n\t\treturn this._telemetryConnector.updateMetric(metric);\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: \"inc\" | \"dec\" | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\tGuards.defined(TelemetryService.CLASS_NAME, nameof(value), value);\n\t\treturn this._telemetryConnector.addMetricValue(id, value, customData);\n\t}\n\n\t/**\n\t * Remove metric.\n\t * @param id The id of the metric.\n\t * @returns Nothing.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.removeMetric(id);\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\treturn this._telemetryConnector.query(type, cursor, limit);\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\t\t/**\n\t\t * The values for the metric.\n\t\t */\n\t\tentities: ITelemetryMetricValue[];\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\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.queryValues(id, timeStart, timeEnd, cursor, limit);\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./telemetryRoutes";
|
|
2
|
-
export * from "./telemetryService";
|
|
3
|
-
export * from "./restEntryPoints";
|
|
4
|
-
export * from "./models/ITelemetryServiceConstructorOptions";
|
|
1
|
+
export * from "./telemetryRoutes.js";
|
|
2
|
+
export * from "./telemetryService.js";
|
|
3
|
+
export * from "./restEntryPoints.js";
|
|
4
|
+
export * from "./models/ITelemetryServiceConstructorOptions.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ITelemetryComponent, type ITelemetryMetric, type ITelemetryMetricValue, type MetricType } from "@twin.org/telemetry-models";
|
|
2
|
-
import type { ITelemetryServiceConstructorOptions } from "./models/ITelemetryServiceConstructorOptions";
|
|
2
|
+
import type { ITelemetryServiceConstructorOptions } from "./models/ITelemetryServiceConstructorOptions.js";
|
|
3
3
|
/**
|
|
4
4
|
* Service for performing telemetry operations to a connector.
|
|
5
5
|
*/
|
|
@@ -13,6 +13,11 @@ export declare class TelemetryService implements ITelemetryComponent {
|
|
|
13
13
|
* @param options The options for the connector.
|
|
14
14
|
*/
|
|
15
15
|
constructor(options?: ITelemetryServiceConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the class name of the component.
|
|
18
|
+
* @returns The class name of the component.
|
|
19
|
+
*/
|
|
20
|
+
className(): string;
|
|
16
21
|
/**
|
|
17
22
|
* Create a new metric.
|
|
18
23
|
* @param metric The metric details.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @twin.org/telemetry-service - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.1](https://github.com/twinfoundation/telemetry/compare/telemetry-service-v0.0.3-next.0...telemetry-service-v0.0.3-next.1) (2025-11-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add context id features ([#19](https://github.com/twinfoundation/telemetry/issues/19)) ([5942442](https://github.com/twinfoundation/telemetry/commit/5942442991fa7ad7afa9d8b7c4583326a8c4c9ae))
|
|
9
|
+
* add validate-locales ([24ed804](https://github.com/twinfoundation/telemetry/commit/24ed804f7ebc47036f323722bc18452729860c92))
|
|
10
|
+
* eslint migration to flat config ([69ac91a](https://github.com/twinfoundation/telemetry/commit/69ac91a89d0b5bc63374a0bd314f770b557dabb4))
|
|
11
|
+
* remove unused namespace ([54939fa](https://github.com/twinfoundation/telemetry/commit/54939faac3790dc1b51aa96a54005a03c99f98da))
|
|
12
|
+
* remove unused namespace ([02dcabb](https://github.com/twinfoundation/telemetry/commit/02dcabbe00f5b03d5e4b2c12e655efac50409acf))
|
|
13
|
+
* update dependencies ([0e55c48](https://github.com/twinfoundation/telemetry/commit/0e55c48de4139c6fe66b823101ca17973e60847c))
|
|
14
|
+
* update framework core ([4b10bcd](https://github.com/twinfoundation/telemetry/commit/4b10bcd4d3101151671bdcf9aef7c54f5937fc2a))
|
|
15
|
+
* use shared store mechanism ([#7](https://github.com/twinfoundation/telemetry/issues/7)) ([806fe2c](https://github.com/twinfoundation/telemetry/commit/806fe2c2b7653d6b949c27ebf57bd13c3e040242))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* query params force coercion ([ec7999e](https://github.com/twinfoundation/telemetry/commit/ec7999eadb66c65585efa19f3ce4cabb50eed761))
|
|
21
|
+
* Update metric endpoint paths by removing trailing slashes and query type as string ([#3](https://github.com/twinfoundation/telemetry/issues/3)) ([b386ca5](https://github.com/twinfoundation/telemetry/commit/b386ca55404aa933ad8917f82a7f0e588593fcc8))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Dependencies
|
|
25
|
+
|
|
26
|
+
* The following workspace dependencies were updated
|
|
27
|
+
* dependencies
|
|
28
|
+
* @twin.org/telemetry-models bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
29
|
+
|
|
3
30
|
## [0.0.2-next.3](https://github.com/twinfoundation/telemetry/compare/telemetry-service-v0.0.2-next.2...telemetry-service-v0.0.2-next.3) (2025-10-09)
|
|
4
31
|
|
|
5
32
|
|