import * as Domain from "../../domain"; import { Task } from "../../utils"; /** * Define the structure of a Connection * * Connections are used to capture Protocol specific behaviours and metadata */ export interface Connection { /** * unique identifer for the connection */ uri: string; /** * current condition of the connection */ state: Connection.State; /** * handle delivering a Message to the connected entity */ send: (protocol: Connection.Protocol, ctx: Task.Context) => Promise; /** * called when a Message is received from this connection */ receive?: (protocol: Connection.Protocol, ctx: Task.Context) => Promise; /** * handle any desired teardown */ close?: () => Promise; } export declare namespace Connection { type Protocol = Domain.Message | Domain.ApiRequest | any; enum State { UNKNOWN = 0, NEW = 1, REQUESTED = 2, DENIED = 3, GRANTED = 4, CLOSED = 5, BROKEN = 6 } }