@routr/simpledata 2.0.8-alpha.14 → 2.0.8-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/dist/api.d.ts +5 -5
- package/dist/api.js +25 -38
- package/dist/runner.js +1 -3
- package/dist/service.js +21 -9
- package/dist/types.d.ts +1 -2
- package/dist/utils.d.ts +2 -6
- package/dist/utils.js +11 -121
- 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} enclosed method with actual "
|
|
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} enclosed method with actual "
|
|
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
32
|
common_1.Assertions.assertEnvsAreSet(["PATH_TO_RESOURCES"]);
|
|
34
|
-
const resources = (0, utils_1.default)(process.env.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,16 +1,12 @@
|
|
|
1
|
-
import { BadRequest } from "./errors";
|
|
2
1
|
import { CommonConnect as CC, CommonTypes as CT } from "@routr/common";
|
|
3
2
|
/**
|
|
4
3
|
* Loads a list of resources from a file.
|
|
5
4
|
*
|
|
6
5
|
* @param {string} resourcesPath - the path to the resources
|
|
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): CC.
|
|
10
|
-
export declare function createQuery(request: CC.FindParameters): {
|
|
11
|
-
request: CC.FindParameters;
|
|
12
|
-
query: string;
|
|
13
|
-
} | BadRequest;
|
|
9
|
+
export default function loadResources(resourcesPath: string, kind?: CC.Kind): CC.RoutrResourceUnion[];
|
|
14
10
|
/**
|
|
15
11
|
* Returns UnimplementedError via callback.
|
|
16
12
|
*
|
package/dist/utils.js
CHANGED
|
@@ -1,29 +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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.nyi =
|
|
3
|
+
exports.nyi = void 0;
|
|
27
4
|
/*
|
|
28
5
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
29
6
|
* http://github.com/fonoster/routr
|
|
@@ -42,89 +19,11 @@ exports.nyi = exports.createQuery = void 0;
|
|
|
42
19
|
* See the License for the specific language governing permissions and
|
|
43
20
|
* limitations under the License.
|
|
44
21
|
*/
|
|
45
|
-
const errors_1 = require("./errors");
|
|
46
22
|
const logger_1 = require("@fonoster/logger");
|
|
47
23
|
const common_1 = require("@routr/common");
|
|
48
|
-
const protobufUtil = __importStar(require("pb-util"));
|
|
49
|
-
const jsonFromStruct = protobufUtil.struct.decode;
|
|
50
24
|
const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
|
|
51
|
-
const findCriteriaMap = {};
|
|
52
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_AGENT_BY_USERNAME] = (parameters) => `$..[?(@.spec.username=='${parameters.username}')]`;
|
|
53
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_PEER_BY_USERNAME] = (parameters) => `$..[?(@.spec.username=='${parameters.username}')]`;
|
|
54
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_CREDENTIALS_BY_REFERENCE] = (parameters) => `$..[?(@.ref=='${parameters.ref}')]`;
|
|
55
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_DOMAIN_BY_DOMAINURI] = (parameters) => `$..[?(@.spec.context.domainUri=='${parameters.domainUri}')]`;
|
|
56
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_NUMBER_BY_TELURL] = (parameters) => `$..[?(@.spec.location.telUrl=="${parameters.telUrl}")]`;
|
|
57
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_TRUNKS_WITH_SEND_REGISTER] = () => "$..[?(@.spec.outbound.sendRegister==true)]";
|
|
58
|
-
findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_TRUNK_BY_REQUEST_URI] = (parameters) => `$..[?(@.spec.inbound.uri=="${parameters.requestUri}")]`;
|
|
59
25
|
// Create function to validate reference exists for Agent
|
|
60
26
|
const checkReferences = (resources) => {
|
|
61
|
-
const referenceExist = (ref) => resources.filter((r) => r.ref === ref)[0];
|
|
62
|
-
// For every resource, check that the reference exists using a switch
|
|
63
|
-
resources.forEach((resource) => {
|
|
64
|
-
var _a;
|
|
65
|
-
switch (resource.kind.toLowerCase()) {
|
|
66
|
-
case common_1.CommonConnect.Kind.AGENT:
|
|
67
|
-
if (resource.spec.credentialsRef) {
|
|
68
|
-
if (!referenceExist(resource.spec.credentialsRef)) {
|
|
69
|
-
logger.error(`agent ${resource.ref} has a credential reference that does not exist: ${resource.spec.credentialsRef}; exiting`);
|
|
70
|
-
process.exit(1);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (resource.spec.domainRef) {
|
|
74
|
-
if (!referenceExist(resource.spec.domainRef)) {
|
|
75
|
-
logger.error(`agent ${resource.ref} has a domain reference that does not exist: ${resource.spec.domainRef}; exiting`);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
case common_1.CommonConnect.Kind.PEER:
|
|
81
|
-
if (resource.spec.credentialsRef) {
|
|
82
|
-
if (!referenceExist(resource.spec.credentialsRef)) {
|
|
83
|
-
logger.error(`peer ${resource.ref} has a credential reference that does not exist: ${resource.spec.credentialsRef}; exiting`);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
case common_1.CommonConnect.Kind.TRUNK:
|
|
89
|
-
if (resource.spec.inbound.credentialsRef) {
|
|
90
|
-
if (!referenceExist(resource.spec.inbound.credentialsRef)) {
|
|
91
|
-
logger.error(`trunk ${resource.ref} has a credential reference that does not exist: ${resource.spec.inbound.credentialsRef}; exiting`);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (resource.spec.inbound.accessControlListRef) {
|
|
96
|
-
if (!referenceExist(resource.spec.inbound.accessControlListRef)) {
|
|
97
|
-
logger.error(`trunk ${resource.ref} has an acl reference that does not exist: ${resource.spec.inbound.accessControlListRef}; exiting`);
|
|
98
|
-
process.exit(1);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
case common_1.CommonConnect.Kind.DOMAIN:
|
|
103
|
-
if (resource.spec.accessControlListRef) {
|
|
104
|
-
if (!referenceExist(resource.spec.accessControlListRef)) {
|
|
105
|
-
logger.error(`domain ${resource.ref} has an acl reference that does not exist: ${resource.spec.accessControlListRef}; exiting`);
|
|
106
|
-
process.exit(1);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if ((_a = resource.spec.context) === null || _a === void 0 ? void 0 : _a.egressPolicies) {
|
|
110
|
-
resource.spec.context.egressPolicies.forEach((policy) => {
|
|
111
|
-
if (policy.numberRef) {
|
|
112
|
-
if (!referenceExist(policy.numberRef)) {
|
|
113
|
-
logger.error(`domain ${resource.ref} has a number reference that does not exist: ${policy.numberRef}; exiting`);
|
|
114
|
-
process.exit(1);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
break;
|
|
120
|
-
case common_1.CommonConnect.Kind.NUMBER:
|
|
121
|
-
if (!referenceExist(resource.spec.trunkRef)) {
|
|
122
|
-
logger.error(`number ${resource.ref} has a trunk reference that does not exist: ${resource.spec.trunkRef}; exiting`);
|
|
123
|
-
process.exit(1);
|
|
124
|
-
}
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
27
|
// Check that reference have not been duplicated
|
|
129
28
|
const references = resources.map((r) => r.ref);
|
|
130
29
|
const duplicates = references.filter((ref, index) => references.indexOf(ref) !== index);
|
|
@@ -137,9 +36,10 @@ const checkReferences = (resources) => {
|
|
|
137
36
|
* Loads a list of resources from a file.
|
|
138
37
|
*
|
|
139
38
|
* @param {string} resourcesPath - the path to the resources
|
|
39
|
+
* @param {string} kind - the kind of resource to load
|
|
140
40
|
* @return {Resource[]} the loaded resources
|
|
141
41
|
*/
|
|
142
|
-
function loadResources(resourcesPath) {
|
|
42
|
+
function loadResources(resourcesPath, kind) {
|
|
143
43
|
const all = [];
|
|
144
44
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
145
45
|
const files = require("fs").readdirSync(resourcesPath);
|
|
@@ -147,6 +47,7 @@ function loadResources(resourcesPath) {
|
|
|
147
47
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
148
48
|
const resources = common_1.Helper.readConfigFile(`${resourcesPath}/${file}`);
|
|
149
49
|
resources.forEach((resource) => {
|
|
50
|
+
resource.kind = resource.kind.toLowerCase();
|
|
150
51
|
// Assert the reference has no spaces
|
|
151
52
|
if (resource.ref.includes(" ")) {
|
|
152
53
|
logger.error(`resource type ${resource.kind} has spaces in the reference: "${resource.ref}"; exiting`);
|
|
@@ -171,25 +72,14 @@ function loadResources(resourcesPath) {
|
|
|
171
72
|
});
|
|
172
73
|
// Referencial check
|
|
173
74
|
checkReferences(all);
|
|
174
|
-
|
|
175
|
-
|
|
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;
|
|
176
81
|
}
|
|
177
82
|
exports.default = loadResources;
|
|
178
|
-
// eslint-disable-next-line require-jsdoc
|
|
179
|
-
function createQuery(request) {
|
|
180
|
-
const findCriteria = request.criteria;
|
|
181
|
-
if (!request.criteria || !request.kind || !request.parameters) {
|
|
182
|
-
return new errors_1.BadRequest("createQuery request is missing 'criteria', 'kind', or 'parameters'");
|
|
183
|
-
}
|
|
184
|
-
if (!findCriteriaMap[findCriteria]) {
|
|
185
|
-
return new errors_1.BadRequest(`invalid find criteria ${request.criteria}`);
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
query: findCriteriaMap[findCriteria](jsonFromStruct(request.parameters)),
|
|
189
|
-
request
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
exports.createQuery = createQuery;
|
|
193
83
|
/**
|
|
194
84
|
* Returns UnimplementedError via callback.
|
|
195
85
|
*
|
|
@@ -197,6 +87,6 @@ exports.createQuery = createQuery;
|
|
|
197
87
|
* @param {GrpcCallback} callback - the grpc callback
|
|
198
88
|
*/
|
|
199
89
|
function nyi(call, callback) {
|
|
200
|
-
callback(new
|
|
90
|
+
callback(new common_1.CommonErrors.UnimplementedError());
|
|
201
91
|
}
|
|
202
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.16",
|
|
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.16",
|
|
33
|
+
"@routr/processor": "^2.0.8-alpha.16",
|
|
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": "78e8c80cd1c1a5b045d83cce6c4ec58e07618314"
|
|
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;
|