@routr/simpledata 2.0.8-alpha.13 → 2.0.8-alpha.15
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.d.ts +5 -5
- package/dist/api.js +25 -38
- package/dist/runner.js +2 -4
- package/dist/service.js +21 -9
- package/dist/types.d.ts +1 -2
- package/dist/utils.d.ts +2 -14
- package/dist/utils.js +12 -148
- package/package.json +4 -5
- package/dist/errors.d.ts +0 -34
- package/dist/errors.js +0 -91
package/dist/api.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { CommonConnect as CC } from "@routr/common";
|
|
|
3
3
|
/**
|
|
4
4
|
* Enclosure with method to obtain a resource by reference.
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {CC.RoutrResourceUnion[]} resources - the resources to search from
|
|
7
7
|
* @return {Function } enclosed method with actual "get" logic
|
|
8
8
|
*/
|
|
9
|
-
export declare function get(resources: CC.
|
|
9
|
+
export declare function get(resources: CC.RoutrResourceUnion[]): (call: CT.GrpcCall, callback: CT.GrpcCallback) => void;
|
|
10
10
|
/**
|
|
11
11
|
* Enclosure with method to obtain a resource with a query.
|
|
12
12
|
*
|
|
13
|
-
* @param {
|
|
14
|
-
* @return {Function
|
|
13
|
+
* @param {CC.RoutrResourceUnion[]} resources - the resources to search from
|
|
14
|
+
* @return {Function} enclosed method with actual "findBy" logic
|
|
15
15
|
*/
|
|
16
|
-
export declare function findBy(resources: CC.
|
|
16
|
+
export declare function findBy(resources: CC.RoutrResourceUnion[]): (call: CT.GrpcCall, callback: CT.GrpcCallback) => void;
|
package/dist/api.js
CHANGED
|
@@ -22,9 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.findBy = exports.get = void 0;
|
|
30
27
|
/*
|
|
@@ -45,67 +42,57 @@ exports.findBy = exports.get = void 0;
|
|
|
45
42
|
* See the License for the specific language governing permissions and
|
|
46
43
|
* limitations under the License.
|
|
47
44
|
*/
|
|
48
|
-
const errors_1 = require("./errors");
|
|
49
|
-
const utils_1 = require("./utils");
|
|
50
|
-
const common_1 = require("@routr/common");
|
|
51
45
|
const protobufUtil = __importStar(require("pb-util"));
|
|
52
|
-
const
|
|
46
|
+
const common_1 = require("@routr/common");
|
|
47
|
+
const common_2 = require("@routr/common");
|
|
53
48
|
const jsonToStruct = protobufUtil.struct.encode;
|
|
54
49
|
/**
|
|
55
50
|
* Enclosure with method to obtain a resource by reference.
|
|
56
51
|
*
|
|
57
|
-
* @param {
|
|
52
|
+
* @param {CC.RoutrResourceUnion[]} resources - the resources to search from
|
|
58
53
|
* @return {Function } enclosed method with actual "get" logic
|
|
59
54
|
*/
|
|
60
55
|
function get(resources) {
|
|
61
56
|
return (call, callback) => {
|
|
62
57
|
if (resources == null || resources.length === 0) {
|
|
63
|
-
return callback(new
|
|
58
|
+
return callback(new common_1.CommonErrors.ResourceNotFoundError(call.request.ref), null);
|
|
64
59
|
}
|
|
65
60
|
if (call.request.ref == null) {
|
|
66
|
-
return callback(new
|
|
61
|
+
return callback(new common_1.CommonErrors.BadRequestError("parameter ref is required"), null);
|
|
67
62
|
}
|
|
68
|
-
const resource =
|
|
63
|
+
const resource = common_2.Helper.deepCopy(resources.find((r) => r.ref === call.request.ref));
|
|
69
64
|
// Serialize to protobuf
|
|
70
|
-
if (resource)
|
|
71
|
-
resource.
|
|
65
|
+
if (resource === null || resource === void 0 ? void 0 : resource.extended)
|
|
66
|
+
resource.extended = jsonToStruct(resource.extended);
|
|
72
67
|
resource
|
|
73
68
|
? callback(null, resource)
|
|
74
|
-
: callback(new
|
|
69
|
+
: callback(new common_1.CommonErrors.ResourceNotFoundError(call.request.ref), null);
|
|
75
70
|
};
|
|
76
71
|
}
|
|
77
72
|
exports.get = get;
|
|
78
73
|
/**
|
|
79
74
|
* Enclosure with method to obtain a resource with a query.
|
|
80
75
|
*
|
|
81
|
-
* @param {
|
|
82
|
-
* @return {Function
|
|
76
|
+
* @param {CC.RoutrResourceUnion[]} resources - the resources to search from
|
|
77
|
+
* @return {Function} enclosed method with actual "findBy" logic
|
|
83
78
|
*/
|
|
84
79
|
function findBy(resources) {
|
|
85
80
|
return (call, callback) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (filteredResources.length === 0) {
|
|
89
|
-
return callback(new errors_1.ResourceNotFound(""), null);
|
|
90
|
-
}
|
|
91
|
-
const queryObject = (0, utils_1.createQuery)(call.request);
|
|
92
|
-
if (queryObject instanceof errors_1.BadRequest) {
|
|
93
|
-
return callback(queryObject, null);
|
|
94
|
-
}
|
|
95
|
-
const queryResult = common_1.Helper.deepCopy(jsonpath_1.default.query(filteredResources, queryObject.query));
|
|
96
|
-
try {
|
|
97
|
-
queryResult.forEach((resource) => {
|
|
98
|
-
// Serialize to protobuf
|
|
99
|
-
resource.spec = jsonToStruct(resource.spec);
|
|
100
|
-
return resource;
|
|
101
|
-
});
|
|
102
|
-
callback(null, {
|
|
103
|
-
resources: queryResult
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
callback(new errors_1.BadRequest(`invalid JSONPath expression: ${queryObject.query}`), null);
|
|
81
|
+
if (resources.length === 0) {
|
|
82
|
+
return callback(new common_1.CommonErrors.ResourceNotFoundError(""), null);
|
|
108
83
|
}
|
|
84
|
+
const { request } = call;
|
|
85
|
+
const queryResult = resources.filter((r) => `${r[request.fieldName]}` ===
|
|
86
|
+
`${request.fieldValue}`);
|
|
87
|
+
queryResult.forEach((resource) => {
|
|
88
|
+
// Serialize to protobuf
|
|
89
|
+
if (resource.extended)
|
|
90
|
+
resource.extended = jsonToStruct(resource.extended);
|
|
91
|
+
return resource;
|
|
92
|
+
});
|
|
93
|
+
callback(null, {
|
|
94
|
+
items: queryResult
|
|
95
|
+
});
|
|
109
96
|
};
|
|
110
97
|
}
|
|
111
98
|
exports.findBy = findBy;
|
package/dist/runner.js
CHANGED
|
@@ -26,16 +26,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
27
27
|
require("./tracer").init("simpleauth");
|
|
28
28
|
const service_1 = __importDefault(require("./service"));
|
|
29
|
-
const utils_1 = __importDefault(require("./utils"));
|
|
30
29
|
const common_1 = require("@routr/common");
|
|
31
30
|
const logger_1 = require("@fonoster/logger");
|
|
32
31
|
const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
|
|
33
|
-
common_1.Assertions.assertEnvsAreSet(["
|
|
34
|
-
const resources = (0, utils_1.default)(process.env.PATH_TO_SCHEMAS, process.env.PATH_TO_RESOURCES);
|
|
32
|
+
common_1.Assertions.assertEnvsAreSet(["PATH_TO_RESOURCES"]);
|
|
35
33
|
try {
|
|
36
34
|
(0, service_1.default)({
|
|
37
35
|
bindAddr: (_a = process.env.BIND_ADDR) !== null && _a !== void 0 ? _a : "0.0.0.0:51907",
|
|
38
|
-
|
|
36
|
+
pathToResources: process.env.PATH_TO_RESOURCES
|
|
39
37
|
});
|
|
40
38
|
}
|
|
41
39
|
catch (e) {
|
package/dist/service.js
CHANGED
|
@@ -24,10 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const common_1 = require("@routr/common");
|
|
27
|
-
const utils_1 = require("./utils");
|
|
27
|
+
const utils_1 = __importStar(require("./utils"));
|
|
28
28
|
const api_1 = require("./api");
|
|
29
|
-
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
30
29
|
const logger_1 = require("@fonoster/logger");
|
|
30
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
31
31
|
const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
|
|
32
32
|
/**
|
|
33
33
|
* Starts a new simple data service.
|
|
@@ -38,13 +38,25 @@ function simpleDataService(config) {
|
|
|
38
38
|
const { bindAddr } = config;
|
|
39
39
|
logger.info("starting routr service", { bindAddr, name: "simpledata" });
|
|
40
40
|
const server = new grpc.Server();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
const kinds = [
|
|
42
|
+
common_1.CommonConnect.Kind.AGENT,
|
|
43
|
+
common_1.CommonConnect.Kind.ACL,
|
|
44
|
+
common_1.CommonConnect.Kind.CREDENTIALS,
|
|
45
|
+
common_1.CommonConnect.Kind.NUMBER,
|
|
46
|
+
common_1.CommonConnect.Kind.TRUNK,
|
|
47
|
+
common_1.CommonConnect.Kind.PEER,
|
|
48
|
+
common_1.CommonConnect.Kind.DOMAIN
|
|
49
|
+
];
|
|
50
|
+
kinds.forEach((kind) => {
|
|
51
|
+
const resources = (0, utils_1.default)(config.pathToResources, kind);
|
|
52
|
+
server.addService(common_1.CommonConnect.createService(kind), {
|
|
53
|
+
get: (0, api_1.get)(resources),
|
|
54
|
+
findBy: (0, api_1.findBy)(resources),
|
|
55
|
+
delete: utils_1.nyi,
|
|
56
|
+
update: utils_1.nyi,
|
|
57
|
+
create: utils_1.nyi,
|
|
58
|
+
list: utils_1.nyi
|
|
59
|
+
});
|
|
48
60
|
});
|
|
49
61
|
server.bindAsync(config.bindAddr, grpc.ServerCredentials.createInsecure(), () => {
|
|
50
62
|
server.start();
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import { BadRequest } from "./errors";
|
|
2
1
|
import { CommonConnect as CC, CommonTypes as CT } from "@routr/common";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a list of validators from the given schemas.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} path - the path to the resource
|
|
7
|
-
* @return {Validator} - a list of validators from the path
|
|
8
|
-
*/
|
|
9
|
-
export declare function createValidators(path: string): Map<string, (resource: CC.Resource) => unknown>;
|
|
10
2
|
/**
|
|
11
3
|
* Loads a list of resources from a file.
|
|
12
4
|
*
|
|
13
|
-
* @param {string} validatorsPath - the path to the validators
|
|
14
5
|
* @param {string} resourcesPath - the path to the resources
|
|
6
|
+
* @param {string} kind - the kind of resource to load
|
|
15
7
|
* @return {Resource[]} the loaded resources
|
|
16
8
|
*/
|
|
17
|
-
export default function loadResources(
|
|
18
|
-
export declare function createQuery(request: CC.FindParameters): {
|
|
19
|
-
request: CC.FindParameters;
|
|
20
|
-
query: string;
|
|
21
|
-
} | BadRequest;
|
|
9
|
+
export default function loadResources(resourcesPath: string, kind?: CC.Kind): CC.RoutrResourceUnion[];
|
|
22
10
|
/**
|
|
23
11
|
* Returns UnimplementedError via callback.
|
|
24
12
|
*
|
package/dist/utils.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.nyi =
|
|
3
|
+
exports.nyi = void 0;
|
|
30
4
|
/*
|
|
31
5
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
32
6
|
* http://github.com/fonoster/routr
|
|
@@ -45,110 +19,11 @@ exports.nyi = exports.createQuery = exports.createValidators = void 0;
|
|
|
45
19
|
* See the License for the specific language governing permissions and
|
|
46
20
|
* limitations under the License.
|
|
47
21
|
*/
|
|
48
|
-
const errors_1 = require("./errors");
|
|
49
|
-
const ajv_1 = __importDefault(require("ajv"));
|
|
50
22
|
const logger_1 = require("@fonoster/logger");
|
|
51
23
|
const common_1 = require("@routr/common");
|
|
52
|
-
const protobufUtil = __importStar(require("pb-util"));
|
|
53
|
-
const jsonFromStruct = protobufUtil.struct.decode;
|
|
54
24
|
const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
|
|
55
|
-
const findCriteriaMap = {};
|
|
56
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_AGENT_BY_USERNAME] = (parameters) => `$..[?(@.spec.username=='${parameters.username}')]`;
|
|
57
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_PEER_BY_USERNAME] = (parameters) => `$..[?(@.spec.username=='${parameters.username}')]`;
|
|
58
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_CREDENTIAL_BY_REFERENCE] = (parameters) => `$..[?(@.ref=='${parameters.ref}')]`;
|
|
59
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_DOMAIN_BY_DOMAINURI] = (parameters) => `$..[?(@.spec.context.domainUri=='${parameters.domainUri}')]`;
|
|
60
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_NUMBER_BY_TELURL] = (parameters) => `$..[?(@.spec.location.telUrl=="${parameters.telUrl}")]`;
|
|
61
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_TRUNKS_WITH_SEND_REGISTER] = () => "$..[?(@.spec.outbound.sendRegister==true)]";
|
|
62
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_TRUNK_BY_REQUEST_URI] = (parameters) => `$..[?(@.spec.inbound.uri=="${parameters.requestUri}")]`;
|
|
63
|
-
/**
|
|
64
|
-
* Creates a list of validators from the given schemas.
|
|
65
|
-
*
|
|
66
|
-
* @param {string} path - the path to the resource
|
|
67
|
-
* @return {Validator} - a list of validators from the path
|
|
68
|
-
*/
|
|
69
|
-
function createValidators(path) {
|
|
70
|
-
const validators = new Map();
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
72
|
-
const files = require("fs").readdirSync(path);
|
|
73
|
-
files.forEach((file) => {
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
75
|
-
const schema = require(`${path}/${file}`);
|
|
76
|
-
const ajv = new ajv_1.default();
|
|
77
|
-
const validator = ajv.compile(schema);
|
|
78
|
-
validators.set(schema.properties.kind.enum[0].toLowerCase(), validator);
|
|
79
|
-
});
|
|
80
|
-
return validators;
|
|
81
|
-
}
|
|
82
|
-
exports.createValidators = createValidators;
|
|
83
25
|
// Create function to validate reference exists for Agent
|
|
84
26
|
const checkReferences = (resources) => {
|
|
85
|
-
const referenceExist = (ref) => resources.filter((r) => r.ref === ref)[0];
|
|
86
|
-
// For every resource, check that the reference exists using a switch
|
|
87
|
-
resources.forEach((resource) => {
|
|
88
|
-
var _a;
|
|
89
|
-
switch (resource.kind.toLocaleLowerCase()) {
|
|
90
|
-
case common_1.CommonConnect.Kind.AGENT:
|
|
91
|
-
if (resource.spec.credentialsRef) {
|
|
92
|
-
if (!referenceExist(resource.spec.credentialsRef)) {
|
|
93
|
-
logger.error(`agent ${resource.ref} has a credential reference that does not exist: ${resource.spec.credentialsRef}; exiting`);
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (resource.spec.domainRef) {
|
|
98
|
-
if (!referenceExist(resource.spec.domainRef)) {
|
|
99
|
-
logger.error(`agent ${resource.ref} has a domain reference that does not exist: ${resource.spec.domainRef}; exiting`);
|
|
100
|
-
process.exit(1);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
break;
|
|
104
|
-
case common_1.CommonConnect.Kind.PEER:
|
|
105
|
-
if (resource.spec.credentialsRef) {
|
|
106
|
-
if (!referenceExist(resource.spec.credentialsRef)) {
|
|
107
|
-
logger.error(`peer ${resource.ref} has a credential reference that does not exist: ${resource.spec.credentialsRef}; exiting`);
|
|
108
|
-
process.exit(1);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
break;
|
|
112
|
-
case common_1.CommonConnect.Kind.TRUNK:
|
|
113
|
-
if (resource.spec.inbound.credentialsRef) {
|
|
114
|
-
if (!referenceExist(resource.spec.inbound.credentialsRef)) {
|
|
115
|
-
logger.error(`trunk ${resource.ref} has a credential reference that does not exist: ${resource.spec.inbound.credentialsRef}; exiting`);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (resource.spec.inbound.accessControlListRef) {
|
|
120
|
-
if (!referenceExist(resource.spec.inbound.accessControlListRef)) {
|
|
121
|
-
logger.error(`trunk ${resource.ref} has an acl reference that does not exist: ${resource.spec.inbound.accessControlListRef}; exiting`);
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
break;
|
|
126
|
-
case common_1.CommonConnect.Kind.DOMAIN:
|
|
127
|
-
if (resource.spec.accessControlListRef) {
|
|
128
|
-
if (!referenceExist(resource.spec.accessControlListRef)) {
|
|
129
|
-
logger.error(`domain ${resource.ref} has an acl reference that does not exist: ${resource.spec.accessControlListRef}; exiting`);
|
|
130
|
-
process.exit(1);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if ((_a = resource.spec.context) === null || _a === void 0 ? void 0 : _a.egressPolicies) {
|
|
134
|
-
resource.spec.context.egressPolicies.forEach((policy) => {
|
|
135
|
-
if (policy.numberRef) {
|
|
136
|
-
if (!referenceExist(policy.numberRef)) {
|
|
137
|
-
logger.error(`domain ${resource.ref} has a number reference that does not exist: ${policy.numberRef}; exiting`);
|
|
138
|
-
process.exit(1);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
break;
|
|
144
|
-
case common_1.CommonConnect.Kind.NUMBER:
|
|
145
|
-
if (!referenceExist(resource.spec.trunkRef)) {
|
|
146
|
-
logger.error(`number ${resource.ref} has a trunk reference that does not exist: ${resource.spec.trunkRef}; exiting`);
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
27
|
// Check that reference have not been duplicated
|
|
153
28
|
const references = resources.map((r) => r.ref);
|
|
154
29
|
const duplicates = references.filter((ref, index) => references.indexOf(ref) !== index);
|
|
@@ -160,12 +35,11 @@ const checkReferences = (resources) => {
|
|
|
160
35
|
/**
|
|
161
36
|
* Loads a list of resources from a file.
|
|
162
37
|
*
|
|
163
|
-
* @param {string} validatorsPath - the path to the validators
|
|
164
38
|
* @param {string} resourcesPath - the path to the resources
|
|
39
|
+
* @param {string} kind - the kind of resource to load
|
|
165
40
|
* @return {Resource[]} the loaded resources
|
|
166
41
|
*/
|
|
167
|
-
function loadResources(
|
|
168
|
-
const validators = createValidators(validatorsPath);
|
|
42
|
+
function loadResources(resourcesPath, kind) {
|
|
169
43
|
const all = [];
|
|
170
44
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
171
45
|
const files = require("fs").readdirSync(resourcesPath);
|
|
@@ -173,13 +47,14 @@ function loadResources(validatorsPath, resourcesPath) {
|
|
|
173
47
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
174
48
|
const resources = common_1.Helper.readConfigFile(`${resourcesPath}/${file}`);
|
|
175
49
|
resources.forEach((resource) => {
|
|
50
|
+
resource.kind = resource.kind.toLowerCase();
|
|
176
51
|
// Assert the reference has no spaces
|
|
177
52
|
if (resource.ref.includes(" ")) {
|
|
178
53
|
logger.error(`resource type ${resource.kind} has spaces in the reference: "${resource.ref}"; exiting`);
|
|
179
54
|
process.exit(1);
|
|
180
55
|
}
|
|
181
56
|
// Check if is valid using jsonschema
|
|
182
|
-
const validate =
|
|
57
|
+
const validate = common_1.ConnectSchemas.schemaValidators.get(resource.kind.toLowerCase());
|
|
183
58
|
if (!validate) {
|
|
184
59
|
logger.error(`unable to find validator for ${resource.kind}; exiting`);
|
|
185
60
|
process.exit(1);
|
|
@@ -197,25 +72,14 @@ function loadResources(validatorsPath, resourcesPath) {
|
|
|
197
72
|
});
|
|
198
73
|
// Referencial check
|
|
199
74
|
checkReferences(all);
|
|
200
|
-
|
|
201
|
-
|
|
75
|
+
// Convert to Resource
|
|
76
|
+
const allMapToResources = all
|
|
77
|
+
.filter((r) => !kind || r.kind.toLowerCase() == kind.toLowerCase())
|
|
78
|
+
.map((r) => common_1.CommonConnect.getConverter(r.kind)(r, all));
|
|
79
|
+
logger.verbose("loaded data resources", { total: allMapToResources.length });
|
|
80
|
+
return allMapToResources;
|
|
202
81
|
}
|
|
203
82
|
exports.default = loadResources;
|
|
204
|
-
// eslint-disable-next-line require-jsdoc
|
|
205
|
-
function createQuery(request) {
|
|
206
|
-
const findCriteria = request.criteria;
|
|
207
|
-
if (!request.criteria || !request.kind || !request.parameters) {
|
|
208
|
-
return new errors_1.BadRequest("createQuery request is missing 'criteria', 'kind', or 'parameters'");
|
|
209
|
-
}
|
|
210
|
-
if (!findCriteriaMap[findCriteria]) {
|
|
211
|
-
return new errors_1.BadRequest(`invalid find criteria ${request.criteria}`);
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
query: findCriteriaMap[findCriteria](jsonFromStruct(request.parameters)),
|
|
215
|
-
request
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
exports.createQuery = createQuery;
|
|
219
83
|
/**
|
|
220
84
|
* Returns UnimplementedError via callback.
|
|
221
85
|
*
|
|
@@ -223,6 +87,6 @@ exports.createQuery = createQuery;
|
|
|
223
87
|
* @param {GrpcCallback} callback - the grpc callback
|
|
224
88
|
*/
|
|
225
89
|
function nyi(call, callback) {
|
|
226
|
-
callback(new
|
|
90
|
+
callback(new common_1.CommonErrors.UnimplementedError());
|
|
227
91
|
}
|
|
228
92
|
exports.nyi = nyi;
|
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.15",
|
|
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,9 +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.
|
|
34
|
-
"ajv": "^6.12.6",
|
|
32
|
+
"@routr/common": "^2.0.8-alpha.15",
|
|
33
|
+
"@routr/processor": "^2.0.8-alpha.15",
|
|
35
34
|
"google-protobuf": "^3.9.2",
|
|
36
35
|
"jsonpath": "^1.1.1",
|
|
37
36
|
"pb-util": "^1.0.3"
|
|
@@ -53,5 +52,5 @@
|
|
|
53
52
|
"@types/google-protobuf": "^3.15.6",
|
|
54
53
|
"@types/jsonpath": "^0.2.0"
|
|
55
54
|
},
|
|
56
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "713d176551252a157b5a7693ef8dba4e3e798dea"
|
|
57
56
|
}
|
package/dist/errors.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thrown for unimplemented handlers.
|
|
3
|
-
*/
|
|
4
|
-
export declare class UnimplementedError extends Error {
|
|
5
|
-
code: number;
|
|
6
|
-
/**
|
|
7
|
-
* Creates an instance of UnimplementedError.
|
|
8
|
-
*/
|
|
9
|
-
constructor();
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Thrown if the resource is not found.
|
|
13
|
-
*/
|
|
14
|
-
export declare class ResourceNotFound extends Error {
|
|
15
|
-
code: number;
|
|
16
|
-
/**
|
|
17
|
-
* Creates an instance of UnimplementedError.
|
|
18
|
-
*
|
|
19
|
-
* @param {string} ref - the reference of the resource
|
|
20
|
-
*/
|
|
21
|
-
constructor(ref: string);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Thrown if the request is invalid.
|
|
25
|
-
*/
|
|
26
|
-
export declare class BadRequest extends Error {
|
|
27
|
-
code: number;
|
|
28
|
-
/**
|
|
29
|
-
* Creates an instance of UnimplementedError.
|
|
30
|
-
*
|
|
31
|
-
* @param {string} message - optional message with the error. Defaults to "bad request."
|
|
32
|
-
*/
|
|
33
|
-
constructor(message?: string);
|
|
34
|
-
}
|
package/dist/errors.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
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.BadRequest = exports.ResourceNotFound = exports.UnimplementedError = void 0;
|
|
27
|
-
/*
|
|
28
|
-
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
29
|
-
* http://github.com/fonoster
|
|
30
|
-
*
|
|
31
|
-
* This file is part of nodejs-service
|
|
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
|
-
* Thrown for unimplemented handlers.
|
|
48
|
-
*/
|
|
49
|
-
class UnimplementedError extends Error {
|
|
50
|
-
/**
|
|
51
|
-
* Creates an instance of UnimplementedError.
|
|
52
|
-
*/
|
|
53
|
-
constructor() {
|
|
54
|
-
super("this operation is not supported/enabled in this data api implementation.");
|
|
55
|
-
this.code = grpc.status.UNIMPLEMENTED;
|
|
56
|
-
Object.setPrototypeOf(this, UnimplementedError.prototype);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.UnimplementedError = UnimplementedError;
|
|
60
|
-
/**
|
|
61
|
-
* Thrown if the resource is not found.
|
|
62
|
-
*/
|
|
63
|
-
class ResourceNotFound extends Error {
|
|
64
|
-
/**
|
|
65
|
-
* Creates an instance of UnimplementedError.
|
|
66
|
-
*
|
|
67
|
-
* @param {string} ref - the reference of the resource
|
|
68
|
-
*/
|
|
69
|
-
constructor(ref) {
|
|
70
|
-
super(`resource not found: ${ref}`);
|
|
71
|
-
this.code = grpc.status.NOT_FOUND;
|
|
72
|
-
Object.setPrototypeOf(this, ResourceNotFound.prototype);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.ResourceNotFound = ResourceNotFound;
|
|
76
|
-
/**
|
|
77
|
-
* Thrown if the request is invalid.
|
|
78
|
-
*/
|
|
79
|
-
class BadRequest extends Error {
|
|
80
|
-
/**
|
|
81
|
-
* Creates an instance of UnimplementedError.
|
|
82
|
-
*
|
|
83
|
-
* @param {string} message - optional message with the error. Defaults to "bad request."
|
|
84
|
-
*/
|
|
85
|
-
constructor(message) {
|
|
86
|
-
super(message !== null && message !== void 0 ? message : "bad request");
|
|
87
|
-
this.code = grpc.status.INVALID_ARGUMENT;
|
|
88
|
-
Object.setPrototypeOf(this, BadRequest.prototype);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.BadRequest = BadRequest;
|