rpcapi
Advanced tools
Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "rpcapi", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Provides a struture for hosting RPC style APIs, supports both http and websocket access out of the box", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -11,2 +11,3 @@ /// <reference types="node" /> | ||
server: http.Server; | ||
customCreateEndpointInstance: (epClass: typeof APIEndpoint) => APIEndpoint; | ||
private endpoints; | ||
@@ -13,0 +14,0 @@ registerEndpoint(endpointName: string, endpointClass: new () => APIEndpoint): void; |
@@ -14,2 +14,3 @@ "use strict"; | ||
this.server = null; | ||
this.customCreateEndpointInstance = null; | ||
this.endpoints = Object.create(null); | ||
@@ -27,4 +28,8 @@ } | ||
endpointName = endpointName.toLowerCase(); | ||
if (this.endpoints[endpointName]) { | ||
return new (this.endpoints[endpointName])(); | ||
var endpointClass = this.endpoints[endpointName]; | ||
if (endpointClass) { | ||
if (typeof this.customCreateEndpointInstance === 'function') { | ||
return this.customCreateEndpointInstance(endpointClass); | ||
} | ||
return new (endpointClass)(); | ||
} | ||
@@ -31,0 +36,0 @@ return null; |
@@ -90,2 +90,27 @@ "use strict"; | ||
}); }); | ||
ava_1.default('Allows using a custom ep constructor', function (t) { return __awaiter(_this, void 0, void 0, function () { | ||
var TestEndpoint1, api, inst1; | ||
return __generator(this, function (_a) { | ||
TestEndpoint1 = /** @class */ (function (_super) { | ||
__extends(TestEndpoint1, _super); | ||
function TestEndpoint1() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.setMe = 0; | ||
return _this; | ||
} | ||
return TestEndpoint1; | ||
}(APIEndpoint_1.APIEndpoint)); | ||
api = new API_1.API(); | ||
api.customCreateEndpointInstance = function (epClass) { | ||
var ep = new epClass(); | ||
ep.setMe = 1; | ||
return ep; | ||
}; | ||
api.registerEndpoint('test1', TestEndpoint1); | ||
inst1 = api.getEndpoint('test1'); | ||
t.true(inst1 instanceof TestEndpoint1); | ||
t.is(inst1.setMe, 1); | ||
return [2 /*return*/]; | ||
}); | ||
}); }); | ||
ava_1.default('Endpoint names are case insensitive', function (t) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -92,0 +117,0 @@ var TestEndpoint, api, inst1, inst2, inst3; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
448049
4336