UNPKG

@interopio/gateway

Version:

[![npm version](https://img.shields.io/npm/v/@interopio/gateway.svg)](https://www.npmjs.com/package/@interopio/gateway)

79 lines (70 loc) 2.19 kB
export declare namespace Metrics { export type Identity = { user?: string, system?: string, service?: string, [key: string]: string | unknown } export type State = number export type Timestamp = number export type Description = string export type Status = { state: State, timestamp: Timestamp, description: Description, updated: Timestamp, expires: Timestamp, /** * @deprecated */ 'updated-at': Timestamp, /** * @deprecated */ 'expires-at': Timestamp } export type Name = string export type Type = 'string' | 'number' | 'timestamp' | 'object' export type Composite = Record<Name, { type: Type, description?: Description, context: Context, composite?: Composite }> export type Definition = ( { name: Name, type: 'string' } | { name: Name, type: 'number' } | { name: Name, type: 'timestamp' } | { name: Name, type: 'object', composite: Composite }) & { description?: Description, context?: Context } export type StringValue = { value: string } export type NumberValue = { value: number } export type TimestampValue = { value: Timestamp } export interface ObjectValue<T> { value: { [key: string]: T } } export type Value = StringValue | NumberValue | TimestampValue | ObjectValue<Value> export type Context = Record<string, string> export type DataPoint = { value: Value, timestamp: Timestamp, context?: Context } export type Update = { identity: Identity, status?: Status, // present only for status updates metadata?: unknown metrics?: Record<string, { definition: Definition, datapoints: DataPoint[] }> } export type Publisher = { function: (metric: Update) => Promise<void> startup?: (context?: Record<string, unknown>) => Promise<unknown> cleanup?: (c?: unknown) => Promise<void> } }