@twin.org/telemetry-service 0.0.2-next.3 → 0.0.3-next.2

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.
@@ -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,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=ITelemetryServiceConstructorOptions.js.map
@@ -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 { Guards, ComponentFactory, Coerce } from '@twin.org/core';
2
- import { MetricType, TelemetryConnectorFactory } from '@twin.org/telemetry-models';
3
- import { HttpStatusCode, HeaderTypes } from '@twin.org/web';
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",
@@ -230,7 +229,7 @@ function generateRestRoutesTelemetry(baseRouteName, componentName) {
230
229
  id: "telemetryListRequestExample",
231
230
  request: {
232
231
  query: {
233
- type: MetricType.Counter
232
+ type: MetricType.Counter.toString()
234
233
  }
235
234
  }
236
235
  }
@@ -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,CAC1C,aAAqB,EACrB,aAAqB;IAErB,MAAM,iBAAiB,GAAgE;QACtF,WAAW,EAAE,uBAAuB;QACpC,OAAO,EAAE,2BAA2B;QACpC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI;QAC1B,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,SAAS;QAC/B,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,EAAE,CAC9C,qBAAqB,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC;QAClE,WAAW,EAAE;YACZ,IAAI,iCAAyC;YAC7C,QAAQ,EAAE;gBACT;oBACC,EAAE,EAAE,qCAAqC;oBACzC,OAAO,EAAE;wBACR,IAAI,EAAE;4BACL,EAAE,EAAE,YAAY;4BAChB,KAAK,EAAE,YAAY;4BACnB,WAAW,EAAE,oBAAoB;4BACjC,IAAI,EAAE,UAAU,CAAC,OAAO;4BACxB,IAAI,EAAE,IAAI;yBACV;qBACD;iBACD;aACD;SACD;QACD,YAAY,EAAE;YACb;g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,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.toString()\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,CAAC;AAExC,OAAO,EACN,yBAAyB,EAMzB,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;OAEG;IACI,MAAM,CAAU,UAAU,sBAAsC;IAEvE;;;OAGG;IACc,mBAAmB,CAAsB;IAE1D;;;OAGG;IACH,YAAY,OAA6C;QACxD,IAAI,CA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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"]}
@@ -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,46 @@
1
1
  # @twin.org/telemetry-service - Changelog
2
2
 
3
+ ## [0.0.3-next.2](https://github.com/twinfoundation/telemetry/compare/telemetry-service-v0.0.3-next.1...telemetry-service-v0.0.3-next.2) (2026-03-02)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * api data types ([2edc5ac](https://github.com/twinfoundation/telemetry/commit/2edc5ac665b996a1b29173cac3b389fa3ceafa34))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/telemetry-models bumped from 0.0.3-next.1 to 0.0.3-next.2
16
+
17
+ ## [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)
18
+
19
+
20
+ ### Features
21
+
22
+ * add context id features ([#19](https://github.com/twinfoundation/telemetry/issues/19)) ([5942442](https://github.com/twinfoundation/telemetry/commit/5942442991fa7ad7afa9d8b7c4583326a8c4c9ae))
23
+ * add validate-locales ([24ed804](https://github.com/twinfoundation/telemetry/commit/24ed804f7ebc47036f323722bc18452729860c92))
24
+ * eslint migration to flat config ([69ac91a](https://github.com/twinfoundation/telemetry/commit/69ac91a89d0b5bc63374a0bd314f770b557dabb4))
25
+ * remove unused namespace ([54939fa](https://github.com/twinfoundation/telemetry/commit/54939faac3790dc1b51aa96a54005a03c99f98da))
26
+ * remove unused namespace ([02dcabb](https://github.com/twinfoundation/telemetry/commit/02dcabbe00f5b03d5e4b2c12e655efac50409acf))
27
+ * update dependencies ([0e55c48](https://github.com/twinfoundation/telemetry/commit/0e55c48de4139c6fe66b823101ca17973e60847c))
28
+ * update framework core ([4b10bcd](https://github.com/twinfoundation/telemetry/commit/4b10bcd4d3101151671bdcf9aef7c54f5937fc2a))
29
+ * use shared store mechanism ([#7](https://github.com/twinfoundation/telemetry/issues/7)) ([806fe2c](https://github.com/twinfoundation/telemetry/commit/806fe2c2b7653d6b949c27ebf57bd13c3e040242))
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * query params force coercion ([ec7999e](https://github.com/twinfoundation/telemetry/commit/ec7999eadb66c65585efa19f3ce4cabb50eed761))
35
+ * 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))
36
+
37
+
38
+ ### Dependencies
39
+
40
+ * The following workspace dependencies were updated
41
+ * dependencies
42
+ * @twin.org/telemetry-models bumped from 0.0.3-next.0 to 0.0.3-next.1
43
+
3
44
  ## [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
45
 
5
46
 
@@ -139,8 +139,9 @@
139
139
  "in": "query",
140
140
  "required": false,
141
141
  "schema": {
142
- "$ref": "#/components/schemas/MetricType"
143
- }
142
+ "type": "string"
143
+ },
144
+ "example": "0"
144
145
  },
145
146
  {
146
147
  "name": "cursor",
@@ -707,10 +708,7 @@
707
708
  "in": "query",
708
709
  "required": false,
709
710
  "schema": {
710
- "type": [
711
- "number",
712
- "string"
713
- ]
711
+ "type": "string"
714
712
  }
715
713
  },
716
714
  {
@@ -719,10 +717,7 @@
719
717
  "in": "query",
720
718
  "required": false,
721
719
  "schema": {
722
- "type": [
723
- "number",
724
- "string"
725
- ]
720
+ "type": "string"
726
721
  }
727
722
  },
728
723
  {
@@ -880,7 +875,6 @@
880
875
  "name",
881
876
  "message"
882
877
  ],
883
- "additionalProperties": false,
884
878
  "description": "Model to describe serialized error."
885
879
  },
886
880
  "MetricType": {
@@ -931,7 +925,6 @@
931
925
  "required": [
932
926
  "value"
933
927
  ],
934
- "additionalProperties": false,
935
928
  "description": "The data to be used in the update."
936
929
  },
937
930
  "TelemetryGetMetricResponse": {
@@ -948,7 +941,6 @@
948
941
  "metric",
949
942
  "value"
950
943
  ],
951
- "additionalProperties": false,
952
944
  "description": "The body parameters."
953
945
  },
954
946
  "TelemetryListResponse": {
@@ -956,13 +948,10 @@
956
948
  "properties": {
957
949
  "entities": {
958
950
  "type": "array",
959
- "items": false,
960
- "description": "The metrics.",
961
- "prefixItems": [
962
- {
963
- "$ref": "#/components/schemas/TelemetryMetric"
964
- }
965
- ]
951
+ "items": {
952
+ "$ref": "#/components/schemas/TelemetryMetric"
953
+ },
954
+ "description": "The metrics."
966
955
  },
967
956
  "cursor": {
968
957
  "type": "string",
@@ -972,7 +961,6 @@
972
961
  "required": [
973
962
  "entities"
974
963
  ],
975
- "additionalProperties": false,
976
964
  "description": "The response payload."
977
965
  },
978
966
  "TelemetryMetric": {
@@ -1003,7 +991,6 @@
1003
991
  "label",
1004
992
  "type"
1005
993
  ],
1006
- "additionalProperties": false,
1007
994
  "description": "Interface describing a telemetry metric."
1008
995
  },
1009
996
  "TelemetryMetricValue": {
@@ -1032,7 +1019,6 @@
1032
1019
  "ts",
1033
1020
  "value"
1034
1021
  ],
1035
- "additionalProperties": false,
1036
1022
  "description": "Interface describing a telemetry metric value."
1037
1023
  },
1038
1024
  "TelemetryUpdateMetricRequest": {
@@ -1054,7 +1040,6 @@
1054
1040
  "required": [
1055
1041
  "label"
1056
1042
  ],
1057
- "additionalProperties": false,
1058
1043
  "description": "The data to be used in the update."
1059
1044
  },
1060
1045
  "TelemetryValuesListResponse": {
@@ -1065,13 +1050,10 @@
1065
1050
  },
1066
1051
  "entities": {
1067
1052
  "type": "array",
1068
- "items": false,
1069
- "description": "The metric values.",
1070
- "prefixItems": [
1071
- {
1072
- "$ref": "#/components/schemas/TelemetryMetricValue"
1073
- }
1074
- ]
1053
+ "items": {
1054
+ "$ref": "#/components/schemas/TelemetryMetricValue"
1055
+ },
1056
+ "description": "The metric values."
1075
1057
  },
1076
1058
  "cursor": {
1077
1059
  "type": "string",
@@ -1082,7 +1064,6 @@
1082
1064
  "metric",
1083
1065
  "entities"
1084
1066
  ],
1085
- "additionalProperties": false,
1086
1067
  "description": "The response payload."
1087
1068
  }
1088
1069
  },
@@ -36,6 +36,24 @@ Runtime name for the class.
36
36
 
37
37
  ## Methods
38
38
 
39
+ ### className()
40
+
41
+ > **className**(): `string`
42
+
43
+ Returns the class name of the component.
44
+
45
+ #### Returns
46
+
47
+ `string`
48
+
49
+ The class name of the component.
50
+
51
+ #### Implementation of
52
+
53
+ `ITelemetryComponent.className`
54
+
55
+ ***
56
+
39
57
  ### createMetric()
40
58
 
41
59
  > **createMetric**(`metric`): `Promise`\<`void`\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/telemetry-service",
3
- "version": "0.0.2-next.3",
3
+ "version": "0.0.3-next.2",
4
4
  "description": "Telemetry contract implementation and REST endpoint definitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,23 +18,21 @@
18
18
  "@twin.org/core": "next",
19
19
  "@twin.org/entity": "next",
20
20
  "@twin.org/nameof": "next",
21
- "@twin.org/telemetry-models": "0.0.2-next.3",
21
+ "@twin.org/telemetry-models": "0.0.3-next.2",
22
22
  "@twin.org/web": "next"
23
23
  },
24
- "main": "./dist/cjs/index.cjs",
25
- "module": "./dist/esm/index.mjs",
24
+ "main": "./dist/es/index.js",
26
25
  "types": "./dist/types/index.d.ts",
27
26
  "exports": {
28
27
  ".": {
29
28
  "types": "./dist/types/index.d.ts",
30
- "require": "./dist/cjs/index.cjs",
31
- "import": "./dist/esm/index.mjs"
29
+ "import": "./dist/es/index.js",
30
+ "default": "./dist/es/index.js"
32
31
  },
33
32
  "./locales/*.json": "./locales/*.json"
34
33
  },
35
34
  "files": [
36
- "dist/cjs",
37
- "dist/esm",
35
+ "dist/es",
38
36
  "dist/types",
39
37
  "locales",
40
38
  "docs"
@@ -1,582 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@twin.org/core');
4
- var telemetryModels = require('@twin.org/telemetry-models');
5
- var web = require('@twin.org/web');
6
-
7
- /**
8
- * The source used when communicating about these routes.
9
- */
10
- const ROUTES_SOURCE = "telemetryRoutes";
11
- /**
12
- * The tag to associate with the routes.
13
- */
14
- const tagsTelemetry = [
15
- {
16
- name: "Telemetry",
17
- description: "Endpoints which are modelled to access a telemetry contract."
18
- }
19
- ];
20
- /**
21
- * The REST routes for telemetry.
22
- * @param baseRouteName Prefix to prepend to the paths.
23
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
24
- * @returns The generated routes.
25
- */
26
- function generateRestRoutesTelemetry(baseRouteName, componentName) {
27
- const createMetricRoute = {
28
- operationId: "telemetryCreateMetric",
29
- summary: "Create a telemetry metric",
30
- tag: tagsTelemetry[0].name,
31
- method: "POST",
32
- path: `${baseRouteName}/metric`,
33
- handler: async (httpRequestContext, request) => telemetryCreateMetric(httpRequestContext, componentName, request),
34
- requestType: {
35
- type: "ITelemetryCreateMetricRequest",
36
- examples: [
37
- {
38
- id: "telemetryCreateMetricRequestExample",
39
- request: {
40
- body: {
41
- id: "my-counter",
42
- label: "My Counter",
43
- description: "This is my counter",
44
- type: telemetryModels.MetricType.Counter,
45
- unit: "KG"
46
- }
47
- }
48
- }
49
- ]
50
- },
51
- responseType: [
52
- {
53
- type: "ICreatedResponse",
54
- examples: [
55
- {
56
- id: "telemetryCreateMetricResponseExample",
57
- response: {
58
- statusCode: web.HttpStatusCode.created,
59
- headers: {
60
- [web.HeaderTypes.Location]: "my-counter"
61
- }
62
- }
63
- }
64
- ]
65
- }
66
- ]
67
- };
68
- const getMetricRoute = {
69
- operationId: "telemetryGetMetric",
70
- summary: "Get a telemetry metric and it's most recent value",
71
- tag: tagsTelemetry[0].name,
72
- method: "GET",
73
- path: `${baseRouteName}/metric/:id`,
74
- handler: async (httpRequestContext, request) => telemetryGetMetric(httpRequestContext, componentName, request),
75
- requestType: {
76
- type: "ITelemetryGetMetricRequest",
77
- examples: [
78
- {
79
- id: "telemetryGetMetricRequestExample",
80
- request: {
81
- pathParams: {
82
- id: "my-counter"
83
- }
84
- }
85
- }
86
- ]
87
- },
88
- responseType: [
89
- {
90
- type: "ITelemetryGetMetricResponse",
91
- examples: [
92
- {
93
- id: "telemetryGetMetricResponseExample",
94
- response: {
95
- body: {
96
- metric: {
97
- id: "my-counter",
98
- label: "My Counter",
99
- description: "This is my counter",
100
- type: telemetryModels.MetricType.Counter,
101
- unit: "KG"
102
- },
103
- value: {
104
- id: "aabbccdd11223445566",
105
- ts: 1715252922273,
106
- value: 10
107
- }
108
- }
109
- }
110
- }
111
- ]
112
- }
113
- ]
114
- };
115
- const updateMetricRoute = {
116
- operationId: "telemetryUpdateMetric",
117
- summary: "Update a telemetry metric",
118
- tag: tagsTelemetry[0].name,
119
- method: "PUT",
120
- path: `${baseRouteName}/metric/:id`,
121
- handler: async (httpRequestContext, request) => telemetryUpdateMetric(httpRequestContext, componentName, request),
122
- requestType: {
123
- type: "ITelemetryUpdateMetricRequest",
124
- examples: [
125
- {
126
- id: "telemetryUpdateMetricRequestExample",
127
- request: {
128
- pathParams: {
129
- id: "my-counter"
130
- },
131
- body: {
132
- label: "My New Label"
133
- }
134
- }
135
- }
136
- ]
137
- },
138
- responseType: [
139
- {
140
- type: "INoContentResponse"
141
- }
142
- ]
143
- };
144
- const addMetricValueRoute = {
145
- operationId: "telemetryAddMetricValue",
146
- summary: "Add a telemetry metric value",
147
- tag: tagsTelemetry[0].name,
148
- method: "POST",
149
- path: `${baseRouteName}/metric/:id/value`,
150
- handler: async (httpRequestContext, request) => telemetryAddMetricValue(httpRequestContext, componentName, request),
151
- requestType: {
152
- type: "ITelemetryAddMetricValueRequest",
153
- examples: [
154
- {
155
- id: "telemetryAddMetricValueRequestExample",
156
- request: {
157
- pathParams: {
158
- id: "my-counter"
159
- },
160
- body: {
161
- value: 10
162
- }
163
- }
164
- },
165
- {
166
- id: "telemetryAddMetricValueIncRequestExample",
167
- request: {
168
- pathParams: {
169
- id: "my-counter"
170
- },
171
- body: {
172
- value: "inc"
173
- }
174
- }
175
- }
176
- ]
177
- },
178
- responseType: [
179
- {
180
- type: "ICreatedResponse",
181
- examples: [
182
- {
183
- id: "telemetryAddMetricValueResponseExample",
184
- response: {
185
- statusCode: web.HttpStatusCode.created,
186
- headers: {
187
- [web.HeaderTypes.Location]: "aabbccdd11223445566"
188
- }
189
- }
190
- }
191
- ]
192
- }
193
- ]
194
- };
195
- const removeMetricRoute = {
196
- operationId: "telemetryRemoveMetric",
197
- summary: "Remove a telemetry metric and it's values.",
198
- tag: tagsTelemetry[0].name,
199
- method: "DELETE",
200
- path: `${baseRouteName}/metric/:id`,
201
- handler: async (httpRequestContext, request) => telemetryRemoveMetric(httpRequestContext, componentName, request),
202
- requestType: {
203
- type: "ITelemetryRemoveMetricRequest",
204
- examples: [
205
- {
206
- id: "telemetryRemoveMetricRequestExample",
207
- request: {
208
- pathParams: {
209
- id: "my-counter"
210
- }
211
- }
212
- }
213
- ]
214
- },
215
- responseType: [
216
- {
217
- type: "INoContentResponse"
218
- }
219
- ]
220
- };
221
- const listMetricsRoute = {
222
- operationId: "telemetryListEntries",
223
- summary: "Get a list of the telemetry metrics",
224
- tag: tagsTelemetry[0].name,
225
- method: "GET",
226
- path: `${baseRouteName}/metric`,
227
- handler: async (httpRequestContext, request) => telemetryMetricList(httpRequestContext, componentName, request),
228
- requestType: {
229
- type: "ITelemetryListRequest",
230
- examples: [
231
- {
232
- id: "telemetryListRequestExample",
233
- request: {
234
- query: {
235
- type: telemetryModels.MetricType.Counter
236
- }
237
- }
238
- }
239
- ]
240
- },
241
- responseType: [
242
- {
243
- type: "ITelemetryListResponse",
244
- examples: [
245
- {
246
- id: "telemetryListResponseExample",
247
- response: {
248
- body: {
249
- entities: [
250
- {
251
- id: "my-counter",
252
- label: "My Counter",
253
- type: telemetryModels.MetricType.Counter,
254
- unit: "KG"
255
- },
256
- {
257
- id: "my-counter-2",
258
- label: "My Counter 2",
259
- type: telemetryModels.MetricType.IncDecCounter,
260
- unit: "M"
261
- }
262
- ],
263
- cursor: "1"
264
- }
265
- }
266
- }
267
- ]
268
- }
269
- ]
270
- };
271
- const listMetricsValuesRoute = {
272
- operationId: "telemetryValuesListEntries",
273
- summary: "Get a list of the values for a telemetry metric",
274
- tag: tagsTelemetry[0].name,
275
- method: "GET",
276
- path: `${baseRouteName}/metric/:id/value`,
277
- handler: async (httpRequestContext, request) => telemetryMetricValueList(httpRequestContext, componentName, request),
278
- requestType: {
279
- type: "ITelemetryValuesListRequest",
280
- examples: [
281
- {
282
- id: "telemetryValuesListRequestExample",
283
- request: {
284
- pathParams: {
285
- id: "my-counter"
286
- }
287
- }
288
- }
289
- ]
290
- },
291
- responseType: [
292
- {
293
- type: "ITelemetryValuesListResponse",
294
- examples: [
295
- {
296
- id: "telemetryValuesListResponseExample",
297
- response: {
298
- body: {
299
- metric: {
300
- id: "my-counter",
301
- label: "My Counter",
302
- type: telemetryModels.MetricType.Counter,
303
- unit: "KG"
304
- },
305
- entities: [
306
- {
307
- id: "aabbccdd11223445566",
308
- ts: 1715252922273,
309
- value: 10
310
- },
311
- {
312
- id: "aabbccdd11223445566",
313
- ts: 1715252922274,
314
- value: 11
315
- }
316
- ],
317
- cursor: "1"
318
- }
319
- }
320
- }
321
- ]
322
- }
323
- ]
324
- };
325
- return [
326
- createMetricRoute,
327
- getMetricRoute,
328
- updateMetricRoute,
329
- addMetricValueRoute,
330
- removeMetricRoute,
331
- listMetricsRoute,
332
- listMetricsValuesRoute
333
- ];
334
- }
335
- /**
336
- * Create a new telemetry metric.
337
- * @param httpRequestContext The request context for the API.
338
- * @param componentName The name of the component to use in the routes.
339
- * @param request The request.
340
- * @returns The response object with additional http response properties.
341
- */
342
- async function telemetryCreateMetric(httpRequestContext, componentName, request) {
343
- core.Guards.object(ROUTES_SOURCE, "request", request);
344
- core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
345
- const component = core.ComponentFactory.get(componentName);
346
- await component.createMetric({
347
- id: request.body.id,
348
- label: request.body.label,
349
- description: request.body.description,
350
- type: request.body.type,
351
- unit: request.body.unit
352
- });
353
- return {
354
- statusCode: web.HttpStatusCode.created,
355
- headers: {
356
- [web.HeaderTypes.Location]: request.body.id
357
- }
358
- };
359
- }
360
- /**
361
- * Gets a telemetry metric.
362
- * @param httpRequestContext The request context for the API.
363
- * @param componentName The name of the component to use in the routes.
364
- * @param request The request.
365
- * @returns The response object with additional http response properties.
366
- */
367
- async function telemetryGetMetric(httpRequestContext, componentName, request) {
368
- core.Guards.object(ROUTES_SOURCE, "request", request);
369
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
370
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
371
- const component = core.ComponentFactory.get(componentName);
372
- const result = await component.getMetric(request.pathParams.id);
373
- return { body: result };
374
- }
375
- /**
376
- * Updates a telemetry metric.
377
- * @param httpRequestContext The request context for the API.
378
- * @param componentName The name of the component to use in the routes.
379
- * @param request The request.
380
- * @returns The response object with additional http response properties.
381
- */
382
- async function telemetryUpdateMetric(httpRequestContext, componentName, request) {
383
- core.Guards.object(ROUTES_SOURCE, "request", request);
384
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
385
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
386
- core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
387
- const component = core.ComponentFactory.get(componentName);
388
- await component.updateMetric({
389
- id: request.pathParams.id,
390
- label: request.body.label,
391
- description: request.body.description,
392
- unit: request.body.unit
393
- });
394
- return { statusCode: web.HttpStatusCode.noContent };
395
- }
396
- /**
397
- * Add a telemetry metric value.
398
- * @param httpRequestContext The request context for the API.
399
- * @param componentName The name of the component to use in the routes.
400
- * @param request The request.
401
- * @returns The response object with additional http response properties.
402
- */
403
- async function telemetryAddMetricValue(httpRequestContext, componentName, request) {
404
- core.Guards.object(ROUTES_SOURCE, "request", request);
405
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
406
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
407
- core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
408
- const component = core.ComponentFactory.get(componentName);
409
- const id = await component.addMetricValue(request.pathParams.id, request.body.value, request.body.customData);
410
- return { statusCode: web.HttpStatusCode.created, headers: { [web.HeaderTypes.Location]: id } };
411
- }
412
- /**
413
- * Removes a telemetry metric.
414
- * @param httpRequestContext The request context for the API.
415
- * @param componentName The name of the component to use in the routes.
416
- * @param request The request.
417
- * @returns The response object with additional http response properties.
418
- */
419
- async function telemetryRemoveMetric(httpRequestContext, componentName, request) {
420
- core.Guards.object(ROUTES_SOURCE, "request", request);
421
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
422
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
423
- const component = core.ComponentFactory.get(componentName);
424
- await component.removeMetric(request.pathParams.id);
425
- return {
426
- statusCode: web.HttpStatusCode.noContent
427
- };
428
- }
429
- /**
430
- * Get a list of the telemetry metrics.
431
- * @param httpRequestContext The request context for the API.
432
- * @param componentName The name of the component to use in the routes.
433
- * @param request The request.
434
- * @returns The response object with additional http response properties.
435
- */
436
- async function telemetryMetricList(httpRequestContext, componentName, request) {
437
- core.Guards.object(ROUTES_SOURCE, "request", request);
438
- core.Guards.object(ROUTES_SOURCE, "request.query", request.query);
439
- const component = core.ComponentFactory.get(componentName);
440
- const itemsAndCursor = await component.query(core.Coerce.number(request?.query?.type), request?.query?.cursor, core.Coerce.number(request?.query?.limit));
441
- return {
442
- body: itemsAndCursor
443
- };
444
- }
445
- /**
446
- * Get a list of the telemetry metric values.
447
- * @param httpRequestContext The request context for the API.
448
- * @param componentName The name of the component to use in the routes.
449
- * @param request The request.
450
- * @returns The response object with additional http response properties.
451
- */
452
- async function telemetryMetricValueList(httpRequestContext, componentName, request) {
453
- core.Guards.object(ROUTES_SOURCE, "request", request);
454
- core.Guards.object(ROUTES_SOURCE, "request.query", request.query);
455
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
456
- const component = core.ComponentFactory.get(componentName);
457
- const itemsAndCursor = await component.queryValues(request?.pathParams.id, core.Coerce.number(request?.query?.timeStart), core.Coerce.number(request?.query?.timeEnd), request?.query?.cursor, core.Coerce.number(request?.query?.limit));
458
- return {
459
- body: itemsAndCursor
460
- };
461
- }
462
-
463
- // Copyright 2024 IOTA Stiftung.
464
- // SPDX-License-Identifier: Apache-2.0.
465
- /**
466
- * Service for performing telemetry operations to a connector.
467
- */
468
- class TelemetryService {
469
- /**
470
- * Runtime name for the class.
471
- */
472
- static CLASS_NAME = "TelemetryService";
473
- /**
474
- * Telemetry connector used by the service.
475
- * @internal
476
- */
477
- _telemetryConnector;
478
- /**
479
- * Create a new instance of TelemetryService.
480
- * @param options The options for the connector.
481
- */
482
- constructor(options) {
483
- this._telemetryConnector = telemetryModels.TelemetryConnectorFactory.get(options?.telemetryConnectorType ?? "telemetry");
484
- }
485
- /**
486
- * Create a new metric.
487
- * @param metric The metric details.
488
- * @returns Nothing.
489
- */
490
- async createMetric(metric) {
491
- core.Guards.object(TelemetryService.CLASS_NAME, "metric", metric);
492
- await this._telemetryConnector.createMetric(metric);
493
- }
494
- /**
495
- * Get the metric details and it's most recent value.
496
- * @param id The metric id.
497
- * @returns The metric details and it's most recent value.
498
- */
499
- async getMetric(id) {
500
- core.Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
501
- return this._telemetryConnector.getMetric(id);
502
- }
503
- /**
504
- * Update metric.
505
- * @param metric The metric details.
506
- * @returns Nothing.
507
- */
508
- async updateMetric(metric) {
509
- core.Guards.object(TelemetryService.CLASS_NAME, "metric", metric);
510
- core.Guards.stringValue(TelemetryService.CLASS_NAME, "metric.id", metric.id);
511
- return this._telemetryConnector.updateMetric(metric);
512
- }
513
- /**
514
- * Add a metric value.
515
- * @param id The id of the metric.
516
- * @param value The value for the add operation.
517
- * @param customData The custom data for the add operation.
518
- * @returns The created metric value id.
519
- */
520
- async addMetricValue(id, value, customData) {
521
- core.Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
522
- core.Guards.defined(TelemetryService.CLASS_NAME, "value", value);
523
- return this._telemetryConnector.addMetricValue(id, value, customData);
524
- }
525
- /**
526
- * Remove metric.
527
- * @param id The id of the metric.
528
- * @returns Nothing.
529
- */
530
- async removeMetric(id) {
531
- core.Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
532
- return this._telemetryConnector.removeMetric(id);
533
- }
534
- /**
535
- * Query the metrics.
536
- * @param type The type of the metric.
537
- * @param cursor The cursor to request the next chunk of entities.
538
- * @param limit Limit the number of entities to return.
539
- * @returns All the entities for the storage matching the conditions,
540
- * and a cursor which can be used to request more entities.
541
- * @throws NotImplementedError if the implementation does not support retrieval.
542
- */
543
- async query(type, cursor, limit) {
544
- return this._telemetryConnector.query(type, cursor, limit);
545
- }
546
- /**
547
- * Query the metric values.
548
- * @param id The id of the metric.
549
- * @param timeStart The inclusive time as the start of the metric entries.
550
- * @param timeEnd The inclusive time as the end of the metric entries.
551
- * @param cursor The cursor to request the next chunk of entities.
552
- * @param limit Limit the number of entities to return.
553
- * @returns All the entities for the storage matching the conditions,
554
- * and a cursor which can be used to request more entities.
555
- * @throws NotImplementedError if the implementation does not support retrieval.
556
- */
557
- async queryValues(id, timeStart, timeEnd, cursor, limit) {
558
- core.Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
559
- return this._telemetryConnector.queryValues(id, timeStart, timeEnd, cursor, limit);
560
- }
561
- }
562
-
563
- const restEntryPoints = [
564
- {
565
- name: "telemetry",
566
- defaultBaseRoute: "telemetry",
567
- tags: tagsTelemetry,
568
- generateRoutes: generateRestRoutesTelemetry
569
- }
570
- ];
571
-
572
- exports.TelemetryService = TelemetryService;
573
- exports.generateRestRoutesTelemetry = generateRestRoutesTelemetry;
574
- exports.restEntryPoints = restEntryPoints;
575
- exports.tagsTelemetry = tagsTelemetry;
576
- exports.telemetryAddMetricValue = telemetryAddMetricValue;
577
- exports.telemetryCreateMetric = telemetryCreateMetric;
578
- exports.telemetryGetMetric = telemetryGetMetric;
579
- exports.telemetryMetricList = telemetryMetricList;
580
- exports.telemetryMetricValueList = telemetryMetricValueList;
581
- exports.telemetryRemoveMetric = telemetryRemoveMetric;
582
- exports.telemetryUpdateMetric = telemetryUpdateMetric;