import * as path from 'path' ; import * as utils from './utils' ; import { TypeDef , ProviderDef , NamedObjectDef } from './object-model' ; export type ControlFlags = { debug ? : boolean ; perf ? : boolean ; } ; export interface Request { application ? : string ; base ? : string ; entryPoint : string ; traceId ? : string ; input ? : any ; controlFlags ? : ControlFlags ; overrideTypes ? : TypeDef [ ] ; overrideObjects ? : NamedObjectDef [ ] ; overrideProviders ? : ProviderDef [ ] ; } export class RequestHelper { private static readonly REQUEST_SCHEMA : utils . JsonSchema = new utils . JsonSchema ( path . resolve ( path . resolve ( __dirname , '../schema' ) , "request.schema.json" ) ) ; private static _transform = new utils . SetDefaultValue ( { traceId : "Unknown" , overrideObjects : [ ] , overrideProviders : [ ] , overrideTypes : [ ] , controlFlags : { debug : false , perf : false } } ) ; public static validate ( jsValue ) { return this . REQUEST_SCHEMA . validate ( jsValue ) ; } public static fromJsValue ( jsValue ) { if ( ! this . validate ( jsValue ) ) throw new Error ( `Request doesn't match request schema: ${ JSON . stringify ( this . REQUEST_SCHEMA . getErrors ( ) ) }` ) ; let request = < Request > ( jsValue ) ; this . _transform . apply ( request ) ; if ( request . controlFlags . debug == null ) { request . controlFlags . debug = false ; } if ( request . controlFlags . perf == null ) { request . controlFlags . perf = false ; } return request ; } }