all files / lib/ server-return.ts

94.12% Statements 32/34
25% Branches 2/8
66.67% Functions 8/12
100% Lines 19/19
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                                                                                                                                           
"use strict";
 
import {ReferencedResource} from "./server-types"; 
 
/**
 * Inform that a new resource was created. Server will 
 * add a Location header and set status to 201
 */
export class NewResource extends ReferencedResource {
	/**
	 * Constructor. Receives the location of the new resource created.
	 * @param location To be added to the Location header on response
	 */
	constructor(location: string) {
		super(location, 201);
	}
}
 
/**
 * Inform that the request was accepted but is not completed.
 * A Location header should inform the location where the user
 * can monitor his request processing status.
 */
export class RequestAccepted extends ReferencedResource {
	/**
	 * Constructor. Receives the location where information about the 
	 * request processing can be found.
	 * @param location To be added to the Location header on response
	 */
	constructor(location: string) {
		super(location, 202);
	}
}
 
/**
 * Inform that the resource has permanently
 * moved to a new location, and that future references should use a
 * new URI with their requests.
 */
export class MovedPermanently extends ReferencedResource {
	/**
	 * Constructor. Receives the location where the resource can be found.
	 * @param location To be added to the Location header on response
	 */
	constructor(location: string) {
		super(location, 301);
	}
}
 
/**
 * Inform that the resource has temporarily
 * moved to another location, but that future references should
 * still use the original URI to access the resource.
 */
export class MovedTemporarily extends ReferencedResource {
	/**
	 * Constructor. Receives the location where the resource can be found.
	 * @param location To be added to the Location header on response
	 */
	constructor(location: string) {
		super(location, 302);
	}
}
 
/**
 * Used to download a resource.
 */
export class DownloadResource {
	/**
	 * Constructor. 
	 * @param filePath The file path to download.
	 * @param fileName The file name
	 */
	constructor(public filePath: string, public fileName: string) {}
}
 
/**
 * Used to download binary data as a file.
 */
export class DownloadBinaryData {
	/**
	 * Constructor. Receives the location of the resource.
	 * @param content The binary data to be downloaded as a file.
	 * @param mimeType The mime-type to be passed on Content-Type header.
	 * @param fileName The file name
	 */
	constructor(public content: Buffer, public mimeType: string, public fileName: string) {}
}