all files / lib/ metadata.ts

100% Statements 50/50
100% Branches 6/6
100% Functions 10/10
100% Lines 46/46
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                            10× 10×                         24×                   21× 21× 21× 21×   21× 21×                                 33× 33× 33×                      
/// <reference path="./collections.d.ts" />
"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: Function) {
		this.targetClass = targetClass;
		this.methods = new Map<string,ServiceMethod>();
	}
 
	targetClass: Function;
	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) {
		if (!this.hasProperties()) {
			this.properties = new Map<string,SeviceProperty>();
		}
		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
}