Skip to content

Commit

Permalink
Renamed to MetricEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaakko Heusala committed Jan 22, 2024
1 parent 3c6c623 commit ffd1b9e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions metrics/MetricCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Entity } from "../entities/types/Entity";
import { ReadonlyJsonObject } from "../Json";
import { MetricDTO } from "./MetricDTO";
import { PrometheusMetricEntity } from "./PrometheusMetricEntity";
import { MetricEntity } from "./MetricEntity";
import { MetricCollectionDTO } from "./MetricCollectionDTO";

/**
Expand Down Expand Up @@ -35,7 +35,7 @@ export interface MetricCollection extends Entity<MetricCollectionDTO> {
/**
* Get a payload.
*/
getPayload () : readonly PrometheusMetricEntity[];
getPayload () : readonly MetricEntity[];

/**
* Get a payload as DTO.
Expand All @@ -47,7 +47,7 @@ export interface MetricCollection extends Entity<MetricCollectionDTO> {
*
* @param payload
*/
setPayload (payload : readonly ( MetricDTO | PrometheusMetricEntity )[]) : this;
setPayload (payload : readonly ( MetricDTO | MetricEntity )[]) : this;

/**
* Set a payload.
Expand All @@ -56,6 +56,6 @@ export interface MetricCollection extends Entity<MetricCollectionDTO> {
*
* @param payload
*/
payload (payload : readonly (MetricDTO | PrometheusMetricEntity)[]) : this;
payload (payload : readonly (MetricDTO | MetricEntity)[]) : this;

}
4 changes: 2 additions & 2 deletions metrics/MetricCollectionEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import { EntityFactoryImpl } from "../entities/types/EntityFactoryImpl";
import { VariableType } from "../entities/types/VariableType";
import { PrometheusMetricEntity } from "./PrometheusMetricEntity";
import { MetricEntity } from "./MetricEntity";
import { MetricCollection } from "./MetricCollection";
import { MetricCollectionDTO } from "./MetricCollectionDTO";

export const MetricCollectionEntityFactory = (
EntityFactoryImpl.create<MetricCollectionDTO, MetricCollection>('MetricCollection')
.add( EntityFactoryImpl.createArrayProperty("payload").setTypes(PrometheusMetricEntity) )
.add( EntityFactoryImpl.createArrayProperty("payload").setTypes(MetricEntity) )
);

export const isMetricCollectionDTO = MetricCollectionEntityFactory.createTestFunctionOfDTO();
Expand Down
58 changes: 29 additions & 29 deletions metrics/PrometheusMetricEntity.ts → metrics/MetricEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,69 @@ import { Metric } from "./Metric";
import { MetricDTO } from "./MetricDTO";
import { MetricType } from "./types/MetricType";

export const PrometheusMetricEntityFactory = (
EntityFactoryImpl.create<MetricDTO, Metric>('PrometheusMetric')
export const MetricEntityFactory = (
EntityFactoryImpl.create<MetricDTO, Metric>('Metric')
.add( EntityFactoryImpl.createProperty("name").setTypes(VariableType.STRING, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("help").setTypes(VariableType.STRING, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("type").setTypes(MetricType, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("labels").setTypes(VariableType.JSON, VariableType.UNDEFINED) )
.add( EntityFactoryImpl.createProperty("value").setTypes(VariableType.STRING, VariableType.UNDEFINED) )
);

export const isPrometheusMetricDTO = PrometheusMetricEntityFactory.createTestFunctionOfDTO();
export const isMetricDTO = MetricEntityFactory.createTestFunctionOfDTO();

export const isPrometheusMetric = PrometheusMetricEntityFactory.createTestFunctionOfInterface();
export const isMetric = MetricEntityFactory.createTestFunctionOfInterface();

export const explainPrometheusMetricDTO = PrometheusMetricEntityFactory.createExplainFunctionOfDTO();
export const explainMetricDTO = MetricEntityFactory.createExplainFunctionOfDTO();

export const isPrometheusMetricDTOOrUndefined = PrometheusMetricEntityFactory.createTestFunctionOfDTOorOneOf(VariableType.UNDEFINED);
export const isMetricDTOOrUndefined = MetricEntityFactory.createTestFunctionOfDTOorOneOf(VariableType.UNDEFINED);

export const explainPrometheusMetricDTOOrUndefined = PrometheusMetricEntityFactory.createExplainFunctionOfDTOorOneOf(VariableType.UNDEFINED);
export const explainMetricDTOOrUndefined = MetricEntityFactory.createExplainFunctionOfDTOorOneOf(VariableType.UNDEFINED);

export const BasePrometheusMetricEntity = PrometheusMetricEntityFactory.createEntityType();
export const BaseMetricEntity = MetricEntityFactory.createEntityType();

/**
* PrometheusMetric entity.
* Metric entity.
*/
export class PrometheusMetricEntity
extends BasePrometheusMetricEntity
export class MetricEntity
extends BaseMetricEntity
implements Metric
{

/**
* Creates a PrometheusMetric entity.
* Creates a metric entity.
*
* @param value The optional DTO of PrometheusMetric
* @param value The optional DTO of Metric
*/
public static create (
value ?: MetricDTO,
) : PrometheusMetricEntity {
return new PrometheusMetricEntity(value);
) : MetricEntity {
return new MetricEntity(value);
}

/**
* Creates a PrometheusMetric entity from DTO.
* Creates a Metric entity from DTO.
*
* @param dto The optional DTO of PrometheusMetric
* @param dto The optional DTO of Metric
*/
public static createFromDTO (
dto : MetricDTO,
) : PrometheusMetricEntity {
return new PrometheusMetricEntity(dto);
) : MetricEntity {
return new MetricEntity(dto);
}

/**
* Merges multiple values as one entity.
*/
public static merge (
...values: readonly (MetricDTO | Metric | PrometheusMetricEntity)[]
) : PrometheusMetricEntity {
return PrometheusMetricEntity.createFromDTO(
...values: readonly (MetricDTO | Metric | MetricEntity)[]
) : MetricEntity {
return MetricEntity.createFromDTO(
reduce(
values,
(
prev: MetricDTO,
item: MetricDTO | Metric | PrometheusMetricEntity,
item: MetricDTO | Metric | MetricEntity,
) : MetricDTO => {
const dto : MetricDTO = this.toDTO(item);
return {
Expand All @@ -91,19 +91,19 @@ export class PrometheusMetricEntity
* Normalizes the value as a DTO.
*/
public static toDTO (
value: MetricDTO | Metric | PrometheusMetricEntity,
value: MetricDTO | Metric | MetricEntity,
) : MetricDTO {
if (isPrometheusMetricEntity(value)) {
if (isMetricEntity(value)) {
return value.getDTO();
} else if (isPrometheusMetric(value)) {
} else if (isMetric(value)) {
return value.getDTO();
} else {
return value;
}
}

/**
* Construct an entity of PrometheusMetricEntity.
* Construct an entity of MetricEntity.
*/
public constructor (
dto ?: MetricDTO | undefined,
Expand Down Expand Up @@ -151,6 +151,6 @@ export class PrometheusMetricEntity

}

export function isPrometheusMetricEntity (value: unknown): value is PrometheusMetricEntity {
return value instanceof PrometheusMetricEntity;
export function isMetricEntity ( value: unknown): value is MetricEntity {
return value instanceof MetricEntity;
}

0 comments on commit ffd1b9e

Please sign in to comment.