import * as http from 'http' ; import * as net from 'net' ; import { createEvent , EventsUnion , Event } from '@marblejs/core' ; export enum ServerEventType { CONNECT = 'connect' , CONNECTION = 'connection' , CLIENT_ERROR = 'clientError' , CLOSE = 'close' , CHECK_CONTINUE = 'checkContinue' , CHECK_EXPECTATION = 'checkExpectation' , ERROR = 'error' , REQUEST = 'request' , UPGRADE = 'upgrade' , LISTENING = 'listening' } export const ServerEvent = { connect : createEvent ( ServerEventType . CONNECT , ( request , socket , head ) => ( { request , socket , head } ) ) , connection : createEvent ( ServerEventType . CONNECTION , ( socket ) => ( { socket } ) ) , clientError : createEvent ( ServerEventType . CLIENT_ERROR , ( error , socket ) => ( { error , socket } ) ) , close : createEvent ( ServerEventType . CLOSE ) , checkContinue : createEvent ( ServerEventType . CHECK_CONTINUE , ( request , response ) => ( { request , response } ) ) , checkExpectation : createEvent ( ServerEventType . CHECK_EXPECTATION , ( request , response ) => ( { request , response } ) ) , error : createEvent ( ServerEventType . ERROR , ( error ) => ( { error } ) ) , request : createEvent ( ServerEventType . REQUEST , ( request , response ) => ( { request , response } ) ) , upgrade : createEvent ( ServerEventType . UPGRADE , ( request , socket , head ) => ( { request , socket , head } ) ) , listening : createEvent ( ServerEventType . LISTENING , ( port , host ) => ( { port , host } ) ) , } ; export type AllServerEvents = EventsUnion < typeof ServerEvent > ; export function isConnectEvent ( event ) { return event . type === ServerEventType . CONNECT ; } export function isConnectionEvent ( event ) { return event . type === ServerEventType . CONNECTION ; } export function isClientErrorEvent ( event ) { return event . type === ServerEventType . CLIENT_ERROR ; } export function isCloseEvent ( event ) { return event . type === ServerEventType . CLOSE ; } export function isCheckContinueEvent ( event ) { return event . type === ServerEventType . CHECK_CONTINUE ; } export function isCheckExpectationEvent ( event ) { return event . type === ServerEventType . CHECK_EXPECTATION ; } export function isListeningEvent ( event ) { return event . type === ServerEventType . LISTENING ; } export function isUpgradeEvent ( event ) { return event . type === ServerEventType . UPGRADE ; } export function isErrorEvent ( event ) { return event . type === ServerEventType . ERROR ; } export function isRequestEvent ( event ) { return event . type === ServerEventType . REQUEST ; }