'use strict'; import { HttpMethod, ParserType, ServiceProcessor } from './server-types'; export interface ServiceProperty { type: ParamType; name: string; propertyType: any; } /** * Metadata for REST service classes */ export class ServiceClass { [key: string]: any; public targetClass: any; public path: string; public authenticator: Record>; public preProcessors: Array; public postProcessors: Array; public methods: Map; public bodyParserOptions: any; public bodyParserType: ParserType; public languages: Array; public accepts: Array; public properties: Map; public isAbstract: boolean = false; public ignoreNextMiddlewares: boolean = false; constructor(targetClass: any) { this.targetClass = targetClass; this.methods = new Map(); this.properties = new Map(); } public addProperty(key: string, property: ServiceProperty) { this.properties.set(key, property); } public hasProperties(): boolean { return (this.properties && this.properties.size > 0); } } /** * Metadata for REST service methods */ export class ServiceMethod { [key: string]: any; public name: string; public path: string; public authenticator: Record>; public resolvedPath: string; public httpMethod: HttpMethod; public parameters: Array = new Array(); public mustParseCookies: boolean = false; public files: Array = new Array(); public mustParseBody: boolean = false; public bodyParserOptions: any; public bodyParserType: ParserType; public mustParseForms: boolean = false; public acceptMultiTypedParam: boolean = false; public languages: Array; public accepts: Array; public resolvedLanguages: Array; public resolvedAccepts: Array; public preProcessors: Array; public postProcessors: Array; public ignoreNextMiddlewares: boolean = false; } /** * Metadata for File parameters on REST methods */ export class FileParam { public name: string; public singleFile: boolean; constructor(name: string, singleFile: boolean) { this.name = name; this.singleFile = singleFile; } } /** * Metadata for REST service method parameters */ export class MethodParam { public name: string; public type: Function; public paramType: ParamType; constructor(name: string, type: Function, paramType: ParamType) { this.name = name; this.type = type; this.paramType = paramType; } } /** * Enumeration of accepted parameter types */ export enum ParamType { path = 'path', query = 'query', header = 'header', cookie = 'cookie', form = 'form', body = 'body', param = 'param', file = 'file', files = 'files', context = 'context', context_request = 'context_request', context_response = 'context_response', context_next = 'context_next', context_accept = 'context_accept', context_accept_language = 'context_accept_language' }