All files metadata.ts

100% Statements 49/49
100% Branches 4/4
100% Functions 10/10
100% Lines 45/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115                              1x                   21x   21x 21x 21x 21x 21x     1x 8x     1x 58x   1x         1x           54x 54x 54x 54x   54x 54x           1x         1x         1x 1x   1x         1x           72x 72x 72x   1x         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x    
'use strict';
 
import { HttpMethod } from './server-types';
 
export type PreprocessorFunction = (req: Express.Request) => Express.Request;
 
export interface SeviceProperty {
    type: ParamType;
    name: string;
    propertyType: any;
}
 
/**
 * Metadata for REST service classes
 */
export class ServiceClass {
 
    public targetClass: any;
    public path: string;
    public roles: Array<string>;
    public processors: Array<PreprocessorFunction>;
    public methods: Map<string, ServiceMethod>;
    public languages: Array<string>;
    public accepts: Array<string>;
    public properties: Map<string, SeviceProperty>;
    public isAbstract: boolean = false;
    constructor(targetClass: any) {
        this.targetClass = targetClass;
        this.methods = new Map<string, ServiceMethod>();
        this.properties = new Map<string, SeviceProperty>();
        this.languages = new Array<string>();
        this.accepts = new Array<string>();
    }
 
    public addProperty(key: string, paramType: ParamType, paramName: string, propertyType: any) {
        this.properties.set(key, { type: paramType, name: paramName, propertyType: propertyType });
    }
 
    public hasProperties(): boolean {
        return (this.properties && this.properties.size > 0);
    }
}
 
/**
 * Metadata for REST service methods
 */
export class ServiceMethod {
    public name: string;
    public path: string;
    public roles: Array<string>;
    public resolvedPath: string;
    public httpMethod: HttpMethod;
    public parameters: Array<MethodParam> = new Array<MethodParam>();
    public mustParseCookies: boolean = false;
    public files: Array<FileParam> = new Array<FileParam>();
    public mustParseBody: boolean = false;
    public bodyParserOptions: any;
    public mustParseForms: boolean = false;
    public acceptMultiTypedParam: boolean = false;
    public languages: Array<string>;
    public accepts: Array<string>;
    public resolvedLanguages: Array<string>;
    public resolvedAccepts: Array<string>;
    public processors: Array<PreprocessorFunction>;
}
 
/**
 * 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,
    query,
    header,
    cookie,
    form,
    body,
    param,
    file,
    files,
    context,
    context_request,
    context_response,
    context_next,
    context_accept,
    context_accept_language
}