All files metadata.ts

100% Statements 48/48
100% Branches 4/4
100% Functions 10/10
100% Lines 44/44
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                          1x   15x 15x 15x 15x 15x                   1x 3x     1x 40x   1x         1x         39x 39x 39x 39x   39x 39x         1x         1x   1x 1x         1x         1x   51x 51x 51x           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 interface SeviceProperty {
    type: ParamType;
    name: string;
    propertyType: any;
}
 
/**
 * Metadata for REST service classes
 */
export class ServiceClass {
    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>();
    }
 
    targetClass: any;
    path: string;
    methods: Map<string, ServiceMethod>;
    languages: Array<string>;
    accepts: Array<string>;
    properties: Map<string, SeviceProperty>;
 
    addProperty(key: string, paramType: ParamType, paramName: string, propertyType: any) {
        this.properties.set(key, { type: paramType, name: paramName, propertyType: propertyType });
    }
 
    hasProperties(): boolean {
        return (this.properties && this.properties.size > 0);
    }
}
 
/**
 * Metadata for REST service methods
 */
export class ServiceMethod {
    name: string;
    path: string;
    resolvedPath: string;
    httpMethod: HttpMethod;
    parameters: Array<MethodParam> = new Array<MethodParam>();
    mustParseCookies: boolean = false;
    files: Array<FileParam> = new Array<FileParam>();
    mustParseBody: boolean = false;
    bodyParserOptions: any;
    mustParseForms: boolean = false;
    acceptMultiTypedParam: boolean = false;
    languages: Array<string>;
    accepts: Array<string>;
    resolvedLanguages: Array<string>;
    resolvedAccepts: Array<string>;
}
 
/**
 * Metadata for File parameters on REST methods
 */
export class FileParam {
    constructor(name: string, singleFile: boolean) {
        this.name = name;
        this.singleFile = singleFile;
    }
 
    name: string;
    singleFile: boolean;
}
 
/**
 * Metadata for REST service method parameters
 */
export class MethodParam {
    constructor(name: string, type: Function, paramType: ParamType) {
        this.name = name;
        this.type = type;
        this.paramType = paramType;
    }
 
    name: string;
    type: Function;
    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
}