@routr/dispatcher 2.0.5-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/config/get_config.d.ts +3 -0
- package/dist/config/get_config.js +57 -0
- package/dist/config/schema.d.ts +82 -0
- package/dist/config/schema.js +103 -0
- package/dist/connections.d.ts +10 -0
- package/dist/connections.js +63 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.js +61 -0
- package/dist/find_processor.d.ts +5 -0
- package/dist/find_processor.js +21 -0
- package/dist/processor.d.ts +6 -0
- package/dist/processor.js +51 -0
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +33 -0
- package/dist/service.d.ts +2 -0
- package/dist/service.js +9 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.js +2 -0
- package/dist/util.d.ts +2 -0
- package/dist/util.js +37 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Fonoster Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getConfig = void 0;
|
|
37
|
+
var fs_1 = __importDefault(require("fs"));
|
|
38
|
+
var schema_1 = require("./schema");
|
|
39
|
+
var ajv_1 = __importDefault(require("ajv"));
|
|
40
|
+
var E = __importStar(require("fp-ts/Either"));
|
|
41
|
+
var ajv = new ajv_1.default();
|
|
42
|
+
var validate = ajv.compile(schema_1.schema);
|
|
43
|
+
var getConfig = function (path) {
|
|
44
|
+
var c = JSON.parse(fs_1.default.readFileSync(path, "utf8"));
|
|
45
|
+
if (!validate(__assign({}, c))) {
|
|
46
|
+
return E.left(new Error(JSON.stringify(validate.errors[0].message)));
|
|
47
|
+
}
|
|
48
|
+
// convert funcMatch to actual functions
|
|
49
|
+
var processors = c.spec.processors.map(function (p) {
|
|
50
|
+
var ref = p.ref, isFallback = p.isFallback, addr = p.addr, methods = p.methods, matchFunc = p.matchFunc;
|
|
51
|
+
return { ref: ref, isFallback: isFallback, addr: addr, methods: methods, matchFunc: eval("(" + p.matchFunc + ")") };
|
|
52
|
+
});
|
|
53
|
+
// Re-insert processors with matchFunc now as a function
|
|
54
|
+
c.spec.processors = processors;
|
|
55
|
+
return E.right(c.spec);
|
|
56
|
+
};
|
|
57
|
+
exports.getConfig = getConfig;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export declare const schema: {
|
|
2
|
+
$id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
description: string;
|
|
5
|
+
type: string;
|
|
6
|
+
properties: {
|
|
7
|
+
kind: {
|
|
8
|
+
description: string;
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
apiVersion: {
|
|
12
|
+
description: string;
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
metadata: {
|
|
16
|
+
description: string;
|
|
17
|
+
type: string;
|
|
18
|
+
properties: {
|
|
19
|
+
ref: {
|
|
20
|
+
description: string;
|
|
21
|
+
type: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
required: string[];
|
|
25
|
+
};
|
|
26
|
+
spec: {
|
|
27
|
+
description: string;
|
|
28
|
+
type: string;
|
|
29
|
+
properties: {
|
|
30
|
+
bindAddr: {
|
|
31
|
+
description: string;
|
|
32
|
+
type: string;
|
|
33
|
+
};
|
|
34
|
+
middlewares: {
|
|
35
|
+
description: string;
|
|
36
|
+
type: string;
|
|
37
|
+
items: {
|
|
38
|
+
type: string;
|
|
39
|
+
};
|
|
40
|
+
properties: {
|
|
41
|
+
ref: {
|
|
42
|
+
type: string;
|
|
43
|
+
};
|
|
44
|
+
addr: {
|
|
45
|
+
type: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
required: string[];
|
|
49
|
+
};
|
|
50
|
+
processors: {
|
|
51
|
+
description: string;
|
|
52
|
+
type: string;
|
|
53
|
+
items: {
|
|
54
|
+
type: string;
|
|
55
|
+
};
|
|
56
|
+
properties: {
|
|
57
|
+
ref: {
|
|
58
|
+
type: string;
|
|
59
|
+
};
|
|
60
|
+
isFallback: {
|
|
61
|
+
type: string;
|
|
62
|
+
};
|
|
63
|
+
addr: {
|
|
64
|
+
type: string;
|
|
65
|
+
};
|
|
66
|
+
matchFunc: {
|
|
67
|
+
type: string;
|
|
68
|
+
};
|
|
69
|
+
methods: {
|
|
70
|
+
type: string;
|
|
71
|
+
items: {
|
|
72
|
+
type: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
required: string[];
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
required: string[];
|
|
82
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/routr
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Routr
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
exports.schema = {
|
|
23
|
+
"$id": "https://json-schema.org/draft/2020-12/schema",
|
|
24
|
+
"title": "Message Dispatcher configuration",
|
|
25
|
+
"description": "Configuration for a Message Dispatcher instance",
|
|
26
|
+
"type": "object",
|
|
27
|
+
"properties": {
|
|
28
|
+
"kind": {
|
|
29
|
+
"description": "Resouce type",
|
|
30
|
+
"type": "string"
|
|
31
|
+
},
|
|
32
|
+
"apiVersion": {
|
|
33
|
+
"description": "Resource version",
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"metadata": {
|
|
37
|
+
"description": "Resource metadata",
|
|
38
|
+
"type": "object",
|
|
39
|
+
"properties": {
|
|
40
|
+
"ref": {
|
|
41
|
+
"description": "EdgePort reference",
|
|
42
|
+
"type": "string"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"required": ["ref"]
|
|
46
|
+
},
|
|
47
|
+
"spec": {
|
|
48
|
+
"description": "Operations spec for EdgePort",
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"bindAddr": {
|
|
52
|
+
"description": "Ipv4 interface to accept request on",
|
|
53
|
+
"type": "string"
|
|
54
|
+
},
|
|
55
|
+
"middlewares": {
|
|
56
|
+
"description": "Middleware Processors",
|
|
57
|
+
"type": "array",
|
|
58
|
+
"items": {
|
|
59
|
+
"type": "object"
|
|
60
|
+
},
|
|
61
|
+
"properties": {
|
|
62
|
+
"ref": {
|
|
63
|
+
"type": "string"
|
|
64
|
+
},
|
|
65
|
+
"addr": {
|
|
66
|
+
"type": "string"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"required": ["ref", "addr"]
|
|
70
|
+
},
|
|
71
|
+
"processors": {
|
|
72
|
+
"description": "Message Processors",
|
|
73
|
+
"type": "array",
|
|
74
|
+
"items": {
|
|
75
|
+
"type": "object"
|
|
76
|
+
},
|
|
77
|
+
"properties": {
|
|
78
|
+
"ref": {
|
|
79
|
+
"type": "string"
|
|
80
|
+
},
|
|
81
|
+
"isFallback": {
|
|
82
|
+
"type": "boolean"
|
|
83
|
+
},
|
|
84
|
+
"addr": {
|
|
85
|
+
"type": "string"
|
|
86
|
+
},
|
|
87
|
+
"matchFunc": {
|
|
88
|
+
"type": "string"
|
|
89
|
+
},
|
|
90
|
+
"methods": {
|
|
91
|
+
"type": "array",
|
|
92
|
+
"items": {
|
|
93
|
+
"type": "string"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"required": ["ref", "addr", "methods", "matchFunc"]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"required": ["kind", "metadata", "spec", "apiVersion"]
|
|
103
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProcessorGPRCConnection } from "./types";
|
|
2
|
+
import { ProcessorConfig } from "@routr/common";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a connection to all the backend processors. The function will
|
|
5
|
+
* fail if any of the backends is unavailable during initialization.
|
|
6
|
+
*
|
|
7
|
+
* @param processors list of backend processors
|
|
8
|
+
* @returns list of connections
|
|
9
|
+
*/
|
|
10
|
+
export default function connectToBackendProcessors(processors: ProcessorConfig[]): Map<string, ProcessorGPRCConnection>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
19
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
20
|
+
to[j] = from[i];
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __values = (this && this.__values) || function(o) {
|
|
24
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
25
|
+
if (m) return m.call(o);
|
|
26
|
+
if (o && typeof o.length === "number") return {
|
|
27
|
+
next: function () {
|
|
28
|
+
if (o && i >= o.length) o = void 0;
|
|
29
|
+
return { value: o && o[i++], done: !o };
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
var common_1 = require("@routr/common");
|
|
36
|
+
var grpc = require("@grpc/grpc-js");
|
|
37
|
+
/**
|
|
38
|
+
* Creates a connection to all the backend processors. The function will
|
|
39
|
+
* fail if any of the backends is unavailable during initialization.
|
|
40
|
+
*
|
|
41
|
+
* @param processors list of backend processors
|
|
42
|
+
* @returns list of connections
|
|
43
|
+
*/
|
|
44
|
+
function connectToBackendProcessors(processors) {
|
|
45
|
+
var e_1, _a;
|
|
46
|
+
var procs = __spreadArray([], __read(processors));
|
|
47
|
+
var connections = new Map();
|
|
48
|
+
try {
|
|
49
|
+
for (var procs_1 = __values(procs), procs_1_1 = procs_1.next(); !procs_1_1.done; procs_1_1 = procs_1.next()) {
|
|
50
|
+
var processor = procs_1_1.value;
|
|
51
|
+
connections.set(processor.ref, new common_1.PROCESSOR_OBJECT_PROTO.Processor(processor.addr, grpc.credentials.createInsecure()));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
55
|
+
finally {
|
|
56
|
+
try {
|
|
57
|
+
if (procs_1_1 && !procs_1_1.done && (_a = procs_1.return)) _a.call(procs_1);
|
|
58
|
+
}
|
|
59
|
+
finally { if (e_1) throw e_1.error; }
|
|
60
|
+
}
|
|
61
|
+
return connections;
|
|
62
|
+
}
|
|
63
|
+
exports.default = connectToBackendProcessors;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import grpc = require("@grpc/grpc-js");
|
|
2
|
+
export declare class NotMatchingProcessorFound extends Error {
|
|
3
|
+
code: grpc.status;
|
|
4
|
+
constructor(ref: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class ProcessorUnavailableError extends Error {
|
|
7
|
+
code: number;
|
|
8
|
+
constructor(ref: string);
|
|
9
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ProcessorUnavailableError = exports.NotMatchingProcessorFound = void 0;
|
|
19
|
+
/*
|
|
20
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
21
|
+
* http://github.com/fonoster/routr
|
|
22
|
+
*
|
|
23
|
+
* This file is part of Routr
|
|
24
|
+
*
|
|
25
|
+
* Licensed under the MIT License (the "License")
|
|
26
|
+
* you may not use this file except in compliance with
|
|
27
|
+
* the License. You may obtain a copy of the License at
|
|
28
|
+
*
|
|
29
|
+
* https://opensource.org/licenses/MIT
|
|
30
|
+
*
|
|
31
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
32
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
33
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
34
|
+
* See the License for the specific language governing permissions and
|
|
35
|
+
* limitations under the License.
|
|
36
|
+
*/
|
|
37
|
+
var grpc = require("@grpc/grpc-js");
|
|
38
|
+
var NotMatchingProcessorFound = /** @class */ (function (_super) {
|
|
39
|
+
__extends(NotMatchingProcessorFound, _super);
|
|
40
|
+
function NotMatchingProcessorFound(ref) {
|
|
41
|
+
var _this = _super.call(this, "not matching processor found for request ref: " + ref) || this;
|
|
42
|
+
_this.code = grpc.status.NOT_FOUND;
|
|
43
|
+
// Set the prototype explicitly.
|
|
44
|
+
Object.setPrototypeOf(_this, NotMatchingProcessorFound.prototype);
|
|
45
|
+
return _this;
|
|
46
|
+
}
|
|
47
|
+
return NotMatchingProcessorFound;
|
|
48
|
+
}(Error));
|
|
49
|
+
exports.NotMatchingProcessorFound = NotMatchingProcessorFound;
|
|
50
|
+
var ProcessorUnavailableError = /** @class */ (function (_super) {
|
|
51
|
+
__extends(ProcessorUnavailableError, _super);
|
|
52
|
+
function ProcessorUnavailableError(ref) {
|
|
53
|
+
var _this = _super.call(this, "processor ref = " + ref + " is unavailable") || this;
|
|
54
|
+
_this.code = grpc.status.UNAVAILABLE;
|
|
55
|
+
// Set the prototype explicitly.
|
|
56
|
+
Object.setPrototypeOf(_this, NotMatchingProcessorFound.prototype);
|
|
57
|
+
return _this;
|
|
58
|
+
}
|
|
59
|
+
return ProcessorUnavailableError;
|
|
60
|
+
}(Error));
|
|
61
|
+
exports.ProcessorUnavailableError = ProcessorUnavailableError;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MessageRequest, ProcessorConfig } from "@routr/common";
|
|
2
|
+
import { NotMatchingProcessorFound } from "./errors";
|
|
3
|
+
export declare const hasMethod: (config: ProcessorConfig, request: MessageRequest) => boolean;
|
|
4
|
+
export declare const filter: (request: MessageRequest, config: ProcessorConfig) => boolean;
|
|
5
|
+
export declare const findProcessor: (list: Array<ProcessorConfig>) => (request: MessageRequest) => NotMatchingProcessorFound | ProcessorConfig;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findProcessor = exports.filter = exports.hasMethod = void 0;
|
|
4
|
+
var errors_1 = require("./errors");
|
|
5
|
+
var hasMethod = function (config, request) {
|
|
6
|
+
return config.methods.includes(request.method);
|
|
7
|
+
};
|
|
8
|
+
exports.hasMethod = hasMethod;
|
|
9
|
+
// TODO: We need a way to test the matching function
|
|
10
|
+
var filter = function (request, config) {
|
|
11
|
+
return exports.hasMethod(config, request)
|
|
12
|
+
&& (config.isFallback || config.matchFunc(request));
|
|
13
|
+
};
|
|
14
|
+
exports.filter = filter;
|
|
15
|
+
var findProcessor = function (list) {
|
|
16
|
+
return function (request) {
|
|
17
|
+
return list.find(function (config) { return exports.filter(request, config); })
|
|
18
|
+
|| new errors_1.NotMatchingProcessorFound(request.ref);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.findProcessor = findProcessor;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MessageRequest, ProcessorConfig } from "@routr/common";
|
|
2
|
+
import { NotMatchingProcessorFound, ProcessorUnavailableError } from "./errors";
|
|
3
|
+
declare type CallbackErrors = NotMatchingProcessorFound | ProcessorUnavailableError | Error;
|
|
4
|
+
declare type ProcessorCallback = (err: CallbackErrors, reponse?: MessageRequest) => void;
|
|
5
|
+
export default function processor(configList: Array<ProcessorConfig>): (call: any, callback: ProcessorCallback) => void;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/*
|
|
7
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster/routr
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Routr
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License")
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
var find_processor_1 = require("./find_processor");
|
|
25
|
+
var connections_1 = __importDefault(require("./connections"));
|
|
26
|
+
var errors_1 = require("./errors");
|
|
27
|
+
var grpc = require("@grpc/grpc-js");
|
|
28
|
+
function processor(configList) {
|
|
29
|
+
var connections = connections_1.default(configList);
|
|
30
|
+
// Upstream request and callback
|
|
31
|
+
return function (call, callback) {
|
|
32
|
+
var request = call.request;
|
|
33
|
+
var matchResult = find_processor_1.findProcessor(configList)(request);
|
|
34
|
+
if ('ref' in matchResult) {
|
|
35
|
+
var conn = connections.get(matchResult.ref);
|
|
36
|
+
// Connects to downstream processor
|
|
37
|
+
conn.processMessage(request, function (err, response) {
|
|
38
|
+
if ((err === null || err === void 0 ? void 0 : err.code) === grpc.status.UNAVAILABLE) {
|
|
39
|
+
// We aument the error to indicate which processor failed
|
|
40
|
+
callback(new errors_1.ProcessorUnavailableError(matchResult.ref));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
callback(err, response);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
callback(matchResult);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.default = processor;
|
package/dist/runner.d.ts
ADDED
package/dist/runner.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/routr
|
|
10
|
+
*
|
|
11
|
+
* This file is part of Routr
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the MIT License (the "License");
|
|
14
|
+
* you may not use this file except in compliance with
|
|
15
|
+
* the License. You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* https://opensource.org/licenses/MIT
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
var service_1 = __importDefault(require("./service"));
|
|
26
|
+
var get_config_1 = require("./config/get_config");
|
|
27
|
+
var result = get_config_1.getConfig(process.env.CONFIG_PATH);
|
|
28
|
+
if (result._tag === 'Right') {
|
|
29
|
+
service_1.default(result.right);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log(result.left);
|
|
33
|
+
}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var common_1 = require("@routr/common");
|
|
4
|
+
var util_1 = require("./util");
|
|
5
|
+
function MessageDispatcher(config) {
|
|
6
|
+
var bindAddr = config.bindAddr, processors = config.processors;
|
|
7
|
+
common_1.createService(util_1.getServiceInfo(bindAddr, processors));
|
|
8
|
+
}
|
|
9
|
+
exports.default = MessageDispatcher;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ProcessorConfig } from "@routr/common";
|
|
2
|
+
export interface MessageDispatcherConfig {
|
|
3
|
+
bindAddr: string;
|
|
4
|
+
processors: Array<ProcessorConfig>;
|
|
5
|
+
}
|
|
6
|
+
export interface ProcessorGPRCConnection {
|
|
7
|
+
processMessage: (request: unknown, callback: Function) => void;
|
|
8
|
+
}
|
package/dist/types.js
ADDED
package/dist/util.d.ts
ADDED
package/dist/util.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getServiceInfo = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/routr
|
|
10
|
+
*
|
|
11
|
+
* This file is part of Routr
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the MIT License (the "License")
|
|
14
|
+
* you may not use this file except in compliance with
|
|
15
|
+
* the License. You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* https://opensource.org/licenses/MIT
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
var processor_1 = __importDefault(require("./processor"));
|
|
26
|
+
var common_1 = require("@routr/common");
|
|
27
|
+
function getServiceInfo(bindAddr, processors) {
|
|
28
|
+
return {
|
|
29
|
+
name: "dispatcher",
|
|
30
|
+
bindAddr: bindAddr,
|
|
31
|
+
service: common_1.PROCESSOR_OBJECT_PROTO.Processor.service,
|
|
32
|
+
handlers: {
|
|
33
|
+
processMessage: processor_1.default(processors)
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.getServiceInfo = getServiceInfo;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@routr/dispatcher",
|
|
3
|
+
"version": "2.0.5-alpha.2",
|
|
4
|
+
"description": "Receives SIP messages and forwards them to the corresponding Message Processor",
|
|
5
|
+
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
|
+
"homepage": "https://github.com/fonoster/routr#readme",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "dist/dispatcher",
|
|
9
|
+
"types": "dist/dispatcher",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
12
|
+
"build": "tsc -b tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"run_dispatcher": "dist/runner.js"
|
|
16
|
+
},
|
|
17
|
+
"directories": {
|
|
18
|
+
"src": "src",
|
|
19
|
+
"test": "test"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@routr/common": "^2.0.5-alpha.2",
|
|
29
|
+
"ajv": "^6.12.6",
|
|
30
|
+
"fp-ts": "^2.11.8"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/fonoster/routr.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/fonoster/routr/issues"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "3570106be9a96cb6672de4a850a377bfa7d9bb3e"
|
|
40
|
+
}
|