@routr/registry 2.0.5-alpha.16
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 +4 -0
- package/dist/config/get_config.js +77 -0
- package/dist/config/schema.d.ts +77 -0
- package/dist/config/schema.js +98 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +61 -0
- package/dist/grpc_client.d.ts +1 -0
- package/dist/grpc_client.js +56 -0
- package/dist/memory_store.d.ts +25 -0
- package/dist/memory_store.js +51 -0
- package/dist/redis_store.d.ts +22 -0
- package/dist/redis_store.js +89 -0
- package/dist/request.d.ts +10 -0
- package/dist/request.js +161 -0
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +39 -0
- package/dist/sender.d.ts +3 -0
- package/dist/sender.js +64 -0
- package/dist/service.d.ts +7 -0
- package/dist/service.js +103 -0
- package/dist/tracer.d.ts +7 -0
- package/dist/tracer.js +53 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.js +15 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.js +135 -0
- package/package.json +55 -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,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getConfig = void 0;
|
|
30
|
+
/*
|
|
31
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
32
|
+
* http://github.com/fonoster/routr
|
|
33
|
+
*
|
|
34
|
+
* This file is part of Routr
|
|
35
|
+
*
|
|
36
|
+
* Licensed under the MIT License (the "License");
|
|
37
|
+
* you may not use this file except in compliance with
|
|
38
|
+
* the License. You may obtain a copy of the License at
|
|
39
|
+
*
|
|
40
|
+
* https://opensource.org/licenses/MIT
|
|
41
|
+
*
|
|
42
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
43
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
44
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
45
|
+
* See the License for the specific language governing permissions and
|
|
46
|
+
* limitations under the License.
|
|
47
|
+
*/
|
|
48
|
+
const types_1 = require("../types");
|
|
49
|
+
const fs_1 = __importDefault(require("fs"));
|
|
50
|
+
const schema_1 = require("./schema");
|
|
51
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
52
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
53
|
+
const errors_1 = require("../errors");
|
|
54
|
+
const ajv = new ajv_1.default();
|
|
55
|
+
const validate = ajv.compile(schema_1.schema);
|
|
56
|
+
const getConfig = (path) => {
|
|
57
|
+
var _a, _b, _c;
|
|
58
|
+
const c = JSON.parse(fs_1.default.readFileSync(path, "utf8"));
|
|
59
|
+
if (!validate(Object.assign({}, c))) {
|
|
60
|
+
return E.left(new errors_1.InvalidSchemaConfiguration(JSON.stringify(validate.errors[0].message)));
|
|
61
|
+
}
|
|
62
|
+
const config = c.spec;
|
|
63
|
+
if (!((_a = config === null || config === void 0 ? void 0 : config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
|
|
64
|
+
config.cache = {
|
|
65
|
+
provider: types_1.CACHE_PROVIDER.MEMORY
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (((_b = config === null || config === void 0 ? void 0 : config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CACHE_PROVIDER.REDIS &&
|
|
69
|
+
!((_c = config === null || config === void 0 ? void 0 : config.cache) === null || _c === void 0 ? void 0 : _c.parameters)) {
|
|
70
|
+
config.cache = {
|
|
71
|
+
provider: types_1.CACHE_PROVIDER.REDIS,
|
|
72
|
+
parameters: "host=localhost,port=6379"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return E.right(config);
|
|
76
|
+
};
|
|
77
|
+
exports.getConfig = getConfig;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export declare const schema: {
|
|
2
|
+
$id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
description: string;
|
|
5
|
+
type: string;
|
|
6
|
+
properties: {
|
|
7
|
+
kind: {
|
|
8
|
+
enum: string[];
|
|
9
|
+
};
|
|
10
|
+
apiVersion: {
|
|
11
|
+
enum: string[];
|
|
12
|
+
};
|
|
13
|
+
metadata: {
|
|
14
|
+
description: string;
|
|
15
|
+
type: string;
|
|
16
|
+
};
|
|
17
|
+
spec: {
|
|
18
|
+
description: string;
|
|
19
|
+
type: string;
|
|
20
|
+
properties: {
|
|
21
|
+
bindAddr: {
|
|
22
|
+
description: string;
|
|
23
|
+
type: string;
|
|
24
|
+
};
|
|
25
|
+
requesterAddr: {
|
|
26
|
+
description: string;
|
|
27
|
+
type: string;
|
|
28
|
+
};
|
|
29
|
+
apiAddr: {
|
|
30
|
+
description: string;
|
|
31
|
+
type: string;
|
|
32
|
+
};
|
|
33
|
+
registerInterval: {
|
|
34
|
+
description: string;
|
|
35
|
+
type: string;
|
|
36
|
+
};
|
|
37
|
+
cache: {
|
|
38
|
+
type: string;
|
|
39
|
+
properties: {
|
|
40
|
+
provider: {
|
|
41
|
+
enum: string[];
|
|
42
|
+
};
|
|
43
|
+
parameters: {
|
|
44
|
+
type: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
required: string[];
|
|
48
|
+
};
|
|
49
|
+
methods: {
|
|
50
|
+
description: string;
|
|
51
|
+
type: string;
|
|
52
|
+
items: {
|
|
53
|
+
type: string;
|
|
54
|
+
};
|
|
55
|
+
uniqueItems: boolean;
|
|
56
|
+
};
|
|
57
|
+
edgePorts: {
|
|
58
|
+
description: string;
|
|
59
|
+
type: string;
|
|
60
|
+
items: {
|
|
61
|
+
type: string;
|
|
62
|
+
};
|
|
63
|
+
properties: {
|
|
64
|
+
address: {
|
|
65
|
+
type: string;
|
|
66
|
+
};
|
|
67
|
+
region: {
|
|
68
|
+
type: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
required: string[];
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
required: string[];
|
|
77
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
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: "Registry Service configuration",
|
|
25
|
+
description: "Configuration for an instance of the Registry Service",
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
kind: {
|
|
29
|
+
enum: ["Registry", "registry"]
|
|
30
|
+
},
|
|
31
|
+
apiVersion: {
|
|
32
|
+
enum: ["v2draft1"]
|
|
33
|
+
},
|
|
34
|
+
metadata: {
|
|
35
|
+
description: "Resource metadata",
|
|
36
|
+
type: "object"
|
|
37
|
+
},
|
|
38
|
+
spec: {
|
|
39
|
+
description: "Operations spec for Registry",
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
bindAddr: {
|
|
43
|
+
description: "Ipv4 interface to accept request on",
|
|
44
|
+
type: "string"
|
|
45
|
+
},
|
|
46
|
+
requesterAddr: {
|
|
47
|
+
description: "Address of service to send requests to",
|
|
48
|
+
type: "string"
|
|
49
|
+
},
|
|
50
|
+
apiAddr: {
|
|
51
|
+
description: "Address of API service",
|
|
52
|
+
type: "string"
|
|
53
|
+
},
|
|
54
|
+
registerInterval: {
|
|
55
|
+
description: "Interval to send registration requests",
|
|
56
|
+
type: "number"
|
|
57
|
+
},
|
|
58
|
+
cache: {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
provider: {
|
|
62
|
+
enum: ["memory", "redis"]
|
|
63
|
+
},
|
|
64
|
+
parameters: {
|
|
65
|
+
type: "string"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
required: ["provider"]
|
|
69
|
+
},
|
|
70
|
+
methods: {
|
|
71
|
+
description: "Acceptable SIP Methods",
|
|
72
|
+
type: "array",
|
|
73
|
+
items: {
|
|
74
|
+
type: "string"
|
|
75
|
+
},
|
|
76
|
+
uniqueItems: true
|
|
77
|
+
},
|
|
78
|
+
edgePorts: {
|
|
79
|
+
description: "List of EdgePorts for outbound registrations",
|
|
80
|
+
type: "array",
|
|
81
|
+
items: {
|
|
82
|
+
type: "object"
|
|
83
|
+
},
|
|
84
|
+
properties: {
|
|
85
|
+
address: {
|
|
86
|
+
type: "string"
|
|
87
|
+
},
|
|
88
|
+
region: {
|
|
89
|
+
type: "string"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
required: ["address"]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
required: ["kind", "spec", "apiVersion"]
|
|
98
|
+
};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as grpc from "@grpc/grpc-js";
|
|
2
|
+
export declare type InvalidConfiguration = InvalidSchemaConfiguration;
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when the Registry service finds a bad configuration.
|
|
5
|
+
*/
|
|
6
|
+
export declare class InvalidSchemaConfiguration extends Error {
|
|
7
|
+
code: grpc.status;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new InvalidSchemaConfiguration error.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} msg - Message from the validation error
|
|
12
|
+
*/
|
|
13
|
+
constructor(msg: string);
|
|
14
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.InvalidSchemaConfiguration = void 0;
|
|
27
|
+
/*
|
|
28
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
29
|
+
* http://github.com/fonoster/routr
|
|
30
|
+
*
|
|
31
|
+
* This file is part of Routr
|
|
32
|
+
*
|
|
33
|
+
* Licensed under the MIT License (the "License")
|
|
34
|
+
* you may not use this file except in compliance with
|
|
35
|
+
* the License. You may obtain a copy of the License at
|
|
36
|
+
*
|
|
37
|
+
* https://opensource.org/licenses/MIT
|
|
38
|
+
*
|
|
39
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
+
* See the License for the specific language governing permissions and
|
|
43
|
+
* limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
46
|
+
/**
|
|
47
|
+
* Error thrown when the Registry service finds a bad configuration.
|
|
48
|
+
*/
|
|
49
|
+
class InvalidSchemaConfiguration extends Error {
|
|
50
|
+
/**
|
|
51
|
+
* Create a new InvalidSchemaConfiguration error.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} msg - Message from the validation error
|
|
54
|
+
*/
|
|
55
|
+
constructor(msg) {
|
|
56
|
+
super(msg);
|
|
57
|
+
this.code = grpc.status.INVALID_ARGUMENT;
|
|
58
|
+
Object.setPrototypeOf(this, InvalidSchemaConfiguration.prototype);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.InvalidSchemaConfiguration = InvalidSchemaConfiguration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const requester: any;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.requester = void 0;
|
|
27
|
+
/*
|
|
28
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
29
|
+
* http://github.com/fonoster/routr
|
|
30
|
+
*
|
|
31
|
+
* This file is part of Routr
|
|
32
|
+
*
|
|
33
|
+
* Licensed under the MIT License (the "License");
|
|
34
|
+
* you may not use this file except in compliance with
|
|
35
|
+
* the License. You may obtain a copy of the License at
|
|
36
|
+
*
|
|
37
|
+
* https://opensource.org/licenses/MIT
|
|
38
|
+
*
|
|
39
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
+
* See the License for the specific language governing permissions and
|
|
43
|
+
* limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
46
|
+
const protoLoader = require("@grpc/proto-loader");
|
|
47
|
+
const packageDefinition = protoLoader.loadSync(__dirname + "../../../common/src/protos/requester.proto", {
|
|
48
|
+
keepCase: false,
|
|
49
|
+
longs: String,
|
|
50
|
+
enums: String,
|
|
51
|
+
defaults: true,
|
|
52
|
+
oneofs: true
|
|
53
|
+
});
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
|
|
56
|
+
exports.requester = protoDescriptor.fonoster.routr.requester;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IRegistryStore, RegistrationEntry } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory store for the registry service.
|
|
4
|
+
*/
|
|
5
|
+
export default class MemoryStore implements IRegistryStore {
|
|
6
|
+
private collections;
|
|
7
|
+
private cleanupCount;
|
|
8
|
+
private maxCyclesBeforeCleanup;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new in-memory store.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} maxCyclesBeforeCleanup - Maximum number of cycles before cleanup
|
|
13
|
+
*/
|
|
14
|
+
constructor(maxCyclesBeforeCleanup?: number);
|
|
15
|
+
/** @inheritdoc */
|
|
16
|
+
put(key: string, entry: RegistrationEntry): Promise<void>;
|
|
17
|
+
/** @inheritdoc */
|
|
18
|
+
list(): Promise<RegistrationEntry[]>;
|
|
19
|
+
/** @inheritdoc */
|
|
20
|
+
get(key: string): Promise<RegistrationEntry>;
|
|
21
|
+
/** @inheritdoc */
|
|
22
|
+
delete(key: string): Promise<void>;
|
|
23
|
+
/** @inheritdoc */
|
|
24
|
+
cleanup(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MAX_CYCLES_BEFORE_CLEANUP = 10000;
|
|
4
|
+
/**
|
|
5
|
+
* In-memory store for the registry service.
|
|
6
|
+
*/
|
|
7
|
+
class MemoryStore {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new in-memory store.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} maxCyclesBeforeCleanup - Maximum number of cycles before cleanup
|
|
12
|
+
*/
|
|
13
|
+
constructor(maxCyclesBeforeCleanup = MAX_CYCLES_BEFORE_CLEANUP) {
|
|
14
|
+
this.collections = new Map();
|
|
15
|
+
this.maxCyclesBeforeCleanup = maxCyclesBeforeCleanup;
|
|
16
|
+
}
|
|
17
|
+
/** @inheritdoc */
|
|
18
|
+
put(key, entry) {
|
|
19
|
+
this.collections.set(key, entry);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
/** @inheritdoc */
|
|
23
|
+
list() {
|
|
24
|
+
return Promise.resolve(this.collections.values ? Array.from(this.collections.values()) : []);
|
|
25
|
+
}
|
|
26
|
+
/** @inheritdoc */
|
|
27
|
+
get(key) {
|
|
28
|
+
// Cleanup every so often to avoid memory build up
|
|
29
|
+
this.cleanupCount++;
|
|
30
|
+
if (this.cleanupCount >= this.maxCyclesBeforeCleanup) {
|
|
31
|
+
this.cleanupCount = 0;
|
|
32
|
+
this.cleanup();
|
|
33
|
+
}
|
|
34
|
+
return Promise.resolve(this.collections.get(key));
|
|
35
|
+
}
|
|
36
|
+
/** @inheritdoc */
|
|
37
|
+
delete(key) {
|
|
38
|
+
this.collections.delete(key);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
/** @inheritdoc */
|
|
42
|
+
cleanup() {
|
|
43
|
+
// Remove all expired registration entries
|
|
44
|
+
this.collections.forEach((entry, key) => {
|
|
45
|
+
const timeElapsed = (Date.now() - entry.timeOfEntry) / 1000;
|
|
46
|
+
if (timeElapsed > entry.retentionTimeInSeconds)
|
|
47
|
+
this.collections.delete(key);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = MemoryStore;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IRegistryStore, RegistrationEntry } from "./types";
|
|
2
|
+
import { Redis } from "@routr/common";
|
|
3
|
+
/**
|
|
4
|
+
* Redis store for the registry service.
|
|
5
|
+
*/
|
|
6
|
+
export default class RedisStore implements IRegistryStore {
|
|
7
|
+
client: any;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new redis store.
|
|
10
|
+
*
|
|
11
|
+
* @param {Redis.RedisStoreConfig} config - Optional store config
|
|
12
|
+
*/
|
|
13
|
+
constructor(config?: Redis.RedisStoreConfig);
|
|
14
|
+
/** @inheritdoc */
|
|
15
|
+
put(key: string, entry: RegistrationEntry): Promise<void>;
|
|
16
|
+
/** @inheritdoc */
|
|
17
|
+
list(): Promise<RegistrationEntry[]>;
|
|
18
|
+
/** @inheritdoc */
|
|
19
|
+
get(key: string): Promise<RegistrationEntry>;
|
|
20
|
+
/** @inheritdoc */
|
|
21
|
+
delete(key: string): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
const redis_1 = require("redis");
|
|
20
|
+
const common_1 = require("@routr/common");
|
|
21
|
+
const logger_1 = require("@fonoster/logger");
|
|
22
|
+
const KEY_PREFIX = "registry";
|
|
23
|
+
const logger = (0, logger_1.getLogger)({ service: "registry", filePath: __filename });
|
|
24
|
+
/**
|
|
25
|
+
* Redis store for the registry service.
|
|
26
|
+
*/
|
|
27
|
+
class RedisStore {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new redis store.
|
|
30
|
+
*
|
|
31
|
+
* @param {Redis.RedisStoreConfig} config - Optional store config
|
|
32
|
+
*/
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.client = config
|
|
35
|
+
? (0, redis_1.createClient)({ url: common_1.Redis.getRedisUrlFromConfig(config) })
|
|
36
|
+
: (0, redis_1.createClient)();
|
|
37
|
+
this.client.connect();
|
|
38
|
+
this.client.on("error", (err) => logger.error("redis client error: ", err));
|
|
39
|
+
}
|
|
40
|
+
/** @inheritdoc */
|
|
41
|
+
put(key, entry) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
// Formatted the key to ensure it is unique
|
|
44
|
+
yield this.client.set(`${KEY_PREFIX}:${key}`, JSON.stringify(entry), {
|
|
45
|
+
EX: entry.retentionTimeInSeconds
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
list() {
|
|
52
|
+
var e_1, _a;
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const entries = [];
|
|
55
|
+
try {
|
|
56
|
+
// eslint-disable-next-line no-loops/no-loops
|
|
57
|
+
for (var _b = __asyncValues(yield this.client.scanIterator({
|
|
58
|
+
CURSOR: 0,
|
|
59
|
+
MATCH: `${KEY_PREFIX}:*`
|
|
60
|
+
})), _c; _c = yield _b.next(), !_c.done;) {
|
|
61
|
+
const k = _c.value;
|
|
62
|
+
entries.push(JSON.parse(yield this.client.get(k)));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
66
|
+
finally {
|
|
67
|
+
try {
|
|
68
|
+
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
|
|
69
|
+
}
|
|
70
|
+
finally { if (e_1) throw e_1.error; }
|
|
71
|
+
}
|
|
72
|
+
return entries;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** @inheritdoc */
|
|
76
|
+
get(key) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const rawEntry = yield this.client.get(`${KEY_PREFIX}:${key}`);
|
|
79
|
+
return rawEntry ? JSON.parse(rawEntry) : null;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** @inheritdoc */
|
|
83
|
+
delete(key) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
this.client.delete(`${KEY_PREFIX}:${key}`);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.default = RedisStore;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RegistrationRequest, RequestParams } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new Registration request.
|
|
4
|
+
*
|
|
5
|
+
* @param {RequestParams} params - The parameters to build the request
|
|
6
|
+
* @return {RegistrationRequest}
|
|
7
|
+
*/
|
|
8
|
+
export default function createRegistrationRequest(params: RequestParams): RegistrationRequest;
|
|
9
|
+
export declare const getHostFromAddress: (address: string) => string;
|
|
10
|
+
export declare const getPortFromAddress: (address: string) => number;
|