UNPKG

service-model

Version:

An object oriented web service framework inspired by Windows Communication Foundation.

37 lines (36 loc) 1.5 kB
var annotations_1 = require("../annotations"); /** * @hidden */ var RestOperationSelector = (function () { function RestOperationSelector(description, endpoint) { this._operations = new Map(); // RestBehavior checks that the list of operations in description and endpoint matches so we don't bother // checking here. for (var i = 0; i < endpoint.operations.length; i++) { // check if method is annotated as callback through the REST api var annotation = description.contract.operations[i].method.getAnnotations(annotations_1.WebInvokeAnnotation)[0]; if (annotation) { var list = this._operations.get(annotation.method); if (!list) { list = []; this._operations.set(annotation.method, list); } list.push({ template: annotation.template.prefix(endpoint.address), operation: endpoint.operations[i] }); } } } RestOperationSelector.prototype.selectOperation = function (message) { var list = this._operations.get(message.method); if (list) { for (var i = 0; i < list.length; i++) { var candidate = list[i]; if (candidate.template.match(message.url)) { return candidate.operation; } } } }; return RestOperationSelector; })(); exports.RestOperationSelector = RestOperationSelector;