@routr/simpledata 2.0.8-alpha.17 → 2.0.8-alpha.18
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/dist/api.js +7 -29
- package/dist/loaders.d.ts +9 -0
- package/dist/loaders.js +118 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +5 -19
- package/package.json +4 -4
package/dist/api.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.findBy = exports.get = void 0;
|
|
27
4
|
/*
|
|
@@ -42,10 +19,9 @@ exports.findBy = exports.get = void 0;
|
|
|
42
19
|
* See the License for the specific language governing permissions and
|
|
43
20
|
* limitations under the License.
|
|
44
21
|
*/
|
|
45
|
-
const
|
|
22
|
+
const pb_util_1 = require("pb-util");
|
|
46
23
|
const common_1 = require("@routr/common");
|
|
47
24
|
const common_2 = require("@routr/common");
|
|
48
|
-
const jsonToStruct = protobufUtil.struct.encode;
|
|
49
25
|
/**
|
|
50
26
|
* Enclosure with method to obtain a resource by reference.
|
|
51
27
|
*
|
|
@@ -62,8 +38,9 @@ function get(resources) {
|
|
|
62
38
|
}
|
|
63
39
|
const resource = common_2.Helper.deepCopy(resources.find((r) => r.ref === call.request.ref));
|
|
64
40
|
// Serialize to protobuf
|
|
65
|
-
if (resource === null || resource === void 0 ? void 0 : resource.extended)
|
|
66
|
-
resource.extended =
|
|
41
|
+
if (resource === null || resource === void 0 ? void 0 : resource.extended) {
|
|
42
|
+
resource.extended = pb_util_1.struct.encode(resource.extended);
|
|
43
|
+
}
|
|
67
44
|
resource
|
|
68
45
|
? callback(null, resource)
|
|
69
46
|
: callback(new common_1.CommonErrors.ResourceNotFoundError(call.request.ref), null);
|
|
@@ -86,8 +63,9 @@ function findBy(resources) {
|
|
|
86
63
|
`${request.fieldValue}`);
|
|
87
64
|
queryResult.forEach((resource) => {
|
|
88
65
|
// Serialize to protobuf
|
|
89
|
-
if (resource.extended)
|
|
90
|
-
resource.extended =
|
|
66
|
+
if (resource.extended) {
|
|
67
|
+
resource.extended = pb_util_1.struct.encode(resource.extended);
|
|
68
|
+
}
|
|
91
69
|
return resource;
|
|
92
70
|
});
|
|
93
71
|
callback(null, {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CommonConnect as CC } from "@routr/common";
|
|
2
|
+
export declare const getLoader: (kind: string) => typeof agentLoader | typeof domainLoader | typeof peerLoader | typeof numberLoader | typeof trunkLoader | typeof credentialsLoader | typeof aclLoader;
|
|
3
|
+
export declare function agentLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Agent;
|
|
4
|
+
export declare function domainLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Domain;
|
|
5
|
+
export declare function peerLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Peer;
|
|
6
|
+
export declare function numberLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.INumber;
|
|
7
|
+
export declare function trunkLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Trunk;
|
|
8
|
+
export declare function credentialsLoader(config: CC.UserConfig): CC.Credentials;
|
|
9
|
+
export declare function aclLoader(config: CC.UserConfig): CC.AccessControlList;
|
package/dist/loaders.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aclLoader = exports.credentialsLoader = exports.trunkLoader = exports.numberLoader = exports.peerLoader = exports.domainLoader = exports.agentLoader = exports.getLoader = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster
|
|
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
|
+
/* eslint-disable require-jsdoc */
|
|
23
|
+
const logger_1 = require("@fonoster/logger");
|
|
24
|
+
const common_1 = require("@routr/common");
|
|
25
|
+
const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
|
|
26
|
+
const findByRef = (ref, list) => {
|
|
27
|
+
const resource = list.find((r) => r.ref === ref);
|
|
28
|
+
if (ref != null && resource == null) {
|
|
29
|
+
logger.error(`the resource with ref ${ref} does not exist in the configuration file; exiting`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
return resource ? (0, exports.getLoader)(resource.kind)(resource, list) : null;
|
|
33
|
+
};
|
|
34
|
+
const getLoader = (kind) => {
|
|
35
|
+
switch (kind) {
|
|
36
|
+
case common_1.CommonConnect.Kind.AGENT:
|
|
37
|
+
return agentLoader;
|
|
38
|
+
case common_1.CommonConnect.Kind.DOMAIN:
|
|
39
|
+
return domainLoader;
|
|
40
|
+
case common_1.CommonConnect.Kind.PEER:
|
|
41
|
+
return peerLoader;
|
|
42
|
+
case common_1.CommonConnect.Kind.NUMBER:
|
|
43
|
+
return numberLoader;
|
|
44
|
+
case common_1.CommonConnect.Kind.TRUNK:
|
|
45
|
+
return trunkLoader;
|
|
46
|
+
case common_1.CommonConnect.Kind.CREDENTIALS:
|
|
47
|
+
return credentialsLoader;
|
|
48
|
+
case common_1.CommonConnect.Kind.ACL:
|
|
49
|
+
return aclLoader;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.getLoader = getLoader;
|
|
53
|
+
function agentLoader(config, list) {
|
|
54
|
+
if (config.kind !== common_1.CommonConnect.Kind.AGENT)
|
|
55
|
+
throw new Error("invalid resource type `Agent`");
|
|
56
|
+
const agent = common_1.CommonConnect.mapToAgent(config);
|
|
57
|
+
agent.domain = findByRef(config.spec.domainRef, list);
|
|
58
|
+
agent.credentials = findByRef(config.spec.credentialsRef, list);
|
|
59
|
+
return agent;
|
|
60
|
+
}
|
|
61
|
+
exports.agentLoader = agentLoader;
|
|
62
|
+
function domainLoader(config, list) {
|
|
63
|
+
var _a;
|
|
64
|
+
if (config.kind !== common_1.CommonConnect.Kind.DOMAIN)
|
|
65
|
+
throw new Error("invalid resource type `Domain`");
|
|
66
|
+
const egressPolicies = (_a = config.spec.context.egressPolicies) === null || _a === void 0 ? void 0 : _a.map((policy) => {
|
|
67
|
+
return {
|
|
68
|
+
rule: policy.rule,
|
|
69
|
+
numberRef: policy.numberRef,
|
|
70
|
+
number: findByRef(policy.numberRef, list)
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
const domain = common_1.CommonConnect.mapToDomain(config);
|
|
74
|
+
domain.egressPolicies = egressPolicies;
|
|
75
|
+
domain.accessControlList = findByRef(config.spec.accessControlListRef, list);
|
|
76
|
+
return domain;
|
|
77
|
+
}
|
|
78
|
+
exports.domainLoader = domainLoader;
|
|
79
|
+
function peerLoader(config, list) {
|
|
80
|
+
if (config.kind !== common_1.CommonConnect.Kind.PEER)
|
|
81
|
+
throw new Error("invalid resource type `Peer`");
|
|
82
|
+
const peer = common_1.CommonConnect.mapToPeer(config);
|
|
83
|
+
peer.credentials = findByRef(config.spec.credentialsRef, list);
|
|
84
|
+
return peer;
|
|
85
|
+
}
|
|
86
|
+
exports.peerLoader = peerLoader;
|
|
87
|
+
function numberLoader(config, list) {
|
|
88
|
+
if (config.kind !== common_1.CommonConnect.Kind.NUMBER)
|
|
89
|
+
throw new Error("invalid resource type `Number`");
|
|
90
|
+
const number = common_1.CommonConnect.mapToNumber(config);
|
|
91
|
+
number.trunk = findByRef(config.spec.trunkRef, list);
|
|
92
|
+
return number;
|
|
93
|
+
}
|
|
94
|
+
exports.numberLoader = numberLoader;
|
|
95
|
+
function trunkLoader(config, list) {
|
|
96
|
+
if (config.kind !== common_1.CommonConnect.Kind.TRUNK)
|
|
97
|
+
throw new Error("invalid resource type `Trunk`");
|
|
98
|
+
const inbound = config.spec.inbound;
|
|
99
|
+
const outbound = config.spec.outbound;
|
|
100
|
+
const trunk = common_1.CommonConnect.mapToTrunk(config);
|
|
101
|
+
trunk.inboundCredentials = findByRef(inbound.credentialsRef, list);
|
|
102
|
+
trunk.outboundCredentials = findByRef(outbound.credentialsRef, list);
|
|
103
|
+
trunk.accessControlList = findByRef(inbound.accessControlListRef, list);
|
|
104
|
+
return trunk;
|
|
105
|
+
}
|
|
106
|
+
exports.trunkLoader = trunkLoader;
|
|
107
|
+
function credentialsLoader(config) {
|
|
108
|
+
if (config.kind !== common_1.CommonConnect.Kind.CREDENTIALS)
|
|
109
|
+
throw new Error("invalid resource type `Credentials`");
|
|
110
|
+
return common_1.CommonConnect.mapToCredentials(config);
|
|
111
|
+
}
|
|
112
|
+
exports.credentialsLoader = credentialsLoader;
|
|
113
|
+
function aclLoader(config) {
|
|
114
|
+
if (config.kind !== common_1.CommonConnect.Kind.ACL)
|
|
115
|
+
throw new Error("invalid resource type `AccessControlList`");
|
|
116
|
+
return common_1.CommonConnect.mapToACL(config);
|
|
117
|
+
}
|
|
118
|
+
exports.aclLoader = aclLoader;
|
package/dist/utils.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { CommonConnect as CC, CommonTypes as CT } from "@routr/common";
|
|
|
6
6
|
* @param {string} kind - the kind of resource to load
|
|
7
7
|
* @return {Resource[]} the loaded resources
|
|
8
8
|
*/
|
|
9
|
-
export default function loadResources(resourcesPath: string, kind?: CC.
|
|
9
|
+
export default function loadResources(resourcesPath: string, kind?: CC.KindWithoutUnknown): CC.ConnectModel[];
|
|
10
10
|
/**
|
|
11
11
|
* Returns UnimplementedError via callback.
|
|
12
12
|
*
|
package/dist/utils.js
CHANGED
|
@@ -21,6 +21,8 @@ exports.nyi = void 0;
|
|
|
21
21
|
*/
|
|
22
22
|
const logger_1 = require("@fonoster/logger");
|
|
23
23
|
const common_1 = require("@routr/common");
|
|
24
|
+
const fs_1 = require("fs");
|
|
25
|
+
const loaders_1 = require("./loaders");
|
|
24
26
|
const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
|
|
25
27
|
// Create function to validate reference exists for Agent
|
|
26
28
|
const checkReferences = (resources) => {
|
|
@@ -41,10 +43,8 @@ const checkReferences = (resources) => {
|
|
|
41
43
|
*/
|
|
42
44
|
function loadResources(resourcesPath, kind) {
|
|
43
45
|
const all = [];
|
|
44
|
-
|
|
45
|
-
const files = require("fs").readdirSync(resourcesPath);
|
|
46
|
+
const files = (0, fs_1.readdirSync)(resourcesPath);
|
|
46
47
|
files.forEach((file) => {
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
48
48
|
const resources = common_1.Helper.readConfigFile(`${resourcesPath}/${file}`);
|
|
49
49
|
resources.forEach((resource) => {
|
|
50
50
|
resource.kind = resource.kind.toLowerCase();
|
|
@@ -53,21 +53,7 @@ function loadResources(resourcesPath, kind) {
|
|
|
53
53
|
logger.error(`resource type ${resource.kind} has spaces in the reference: "${resource.ref}"; exiting`);
|
|
54
54
|
process.exit(1);
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
const validate = common_1.ConnectSchemas.schemaValidators.get(resource.kind.toLowerCase());
|
|
58
|
-
if (!validate) {
|
|
59
|
-
logger.error(`unable to find validator for ${resource.kind}; exiting`);
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
if (validate(resource)) {
|
|
63
|
-
all.push(resource);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
logger.error("found a bad resource: " +
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
-
JSON.stringify(validate.errors[0].message));
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
56
|
+
all.push(resource);
|
|
71
57
|
});
|
|
72
58
|
});
|
|
73
59
|
// Referencial check
|
|
@@ -75,7 +61,7 @@ function loadResources(resourcesPath, kind) {
|
|
|
75
61
|
// Convert to Resource
|
|
76
62
|
const allMapToResources = all
|
|
77
63
|
.filter((r) => !kind || r.kind.toLowerCase() == kind.toLowerCase())
|
|
78
|
-
.map((r) =>
|
|
64
|
+
.map((r) => (0, loaders_1.getLoader)(r.kind)(r, all));
|
|
79
65
|
logger.verbose("loaded data resources", { total: allMapToResources.length });
|
|
80
66
|
return allMapToResources;
|
|
81
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/simpledata",
|
|
3
|
-
"version": "2.0.8-alpha.
|
|
3
|
+
"version": "2.0.8-alpha.18",
|
|
4
4
|
"description": "Files-based API Server for Routr Connect",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
30
30
|
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
31
31
|
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
32
|
-
"@routr/common": "^2.0.8-alpha.
|
|
33
|
-
"@routr/processor": "^2.0.8-alpha.
|
|
32
|
+
"@routr/common": "^2.0.8-alpha.18",
|
|
33
|
+
"@routr/processor": "^2.0.8-alpha.18",
|
|
34
34
|
"google-protobuf": "^3.9.2",
|
|
35
35
|
"jsonpath": "^1.1.1",
|
|
36
36
|
"pb-util": "^1.0.3"
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"@types/google-protobuf": "^3.15.6",
|
|
53
53
|
"@types/jsonpath": "^0.2.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "66ce6b3ed832bb8c549d344b3367aceed4b6da8f"
|
|
56
56
|
}
|