@routr/simpledata 2.0.8-alpha.13 → 2.0.8-alpha.14

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 CHANGED
@@ -11,6 +11,6 @@ export declare function get(resources: CC.Resource[]): (call: CT.GrpcCall, callb
11
11
  * Enclosure with method to obtain a resource with a query.
12
12
  *
13
13
  * @param {Resource[]} resources - the resources to search from
14
- * @return {Function } enclosed method with actual "find" logic
14
+ * @return {Function} enclosed method with actual "find" logic
15
15
  */
16
16
  export declare function findBy(resources: CC.Resource[]): (call: CT.GrpcCall, callback: CT.GrpcCallback) => void;
package/dist/api.js CHANGED
@@ -79,7 +79,7 @@ exports.get = get;
79
79
  * Enclosure with method to obtain a resource with a query.
80
80
  *
81
81
  * @param {Resource[]} resources - the resources to search from
82
- * @return {Function } enclosed method with actual "find" logic
82
+ * @return {Function} enclosed method with actual "find" logic
83
83
  */
84
84
  function findBy(resources) {
85
85
  return (call, callback) => {
package/dist/runner.js CHANGED
@@ -30,8 +30,8 @@ const utils_1 = __importDefault(require("./utils"));
30
30
  const common_1 = require("@routr/common");
31
31
  const logger_1 = require("@fonoster/logger");
32
32
  const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
33
- common_1.Assertions.assertEnvsAreSet(["PATH_TO_SCHEMAS", "PATH_TO_RESOURCES"]);
34
- const resources = (0, utils_1.default)(process.env.PATH_TO_SCHEMAS, process.env.PATH_TO_RESOURCES);
33
+ common_1.Assertions.assertEnvsAreSet(["PATH_TO_RESOURCES"]);
34
+ const resources = (0, utils_1.default)(process.env.PATH_TO_RESOURCES);
35
35
  try {
36
36
  (0, service_1.default)({
37
37
  bindAddr: (_a = process.env.BIND_ADDR) !== null && _a !== void 0 ? _a : "0.0.0.0:51907",
package/dist/utils.d.ts CHANGED
@@ -1,20 +1,12 @@
1
1
  import { BadRequest } from "./errors";
2
2
  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
3
  /**
11
4
  * Loads a list of resources from a file.
12
5
  *
13
- * @param {string} validatorsPath - the path to the validators
14
6
  * @param {string} resourcesPath - the path to the resources
15
7
  * @return {Resource[]} the loaded resources
16
8
  */
17
- export default function loadResources(validatorsPath: string, resourcesPath: string): CC.Resource[];
9
+ export default function loadResources(resourcesPath: string): CC.Resource[];
18
10
  export declare function createQuery(request: CC.FindParameters): {
19
11
  request: CC.FindParameters;
20
12
  query: string;
package/dist/utils.js CHANGED
@@ -22,11 +22,8 @@ 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
- exports.nyi = exports.createQuery = exports.createValidators = void 0;
26
+ exports.nyi = exports.createQuery = void 0;
30
27
  /*
31
28
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
32
29
  * http://github.com/fonoster/routr
@@ -46,7 +43,6 @@ exports.nyi = exports.createQuery = exports.createValidators = void 0;
46
43
  * limitations under the License.
47
44
  */
48
45
  const errors_1 = require("./errors");
49
- const ajv_1 = __importDefault(require("ajv"));
50
46
  const logger_1 = require("@fonoster/logger");
51
47
  const common_1 = require("@routr/common");
52
48
  const protobufUtil = __importStar(require("pb-util"));
@@ -55,38 +51,18 @@ const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __file
55
51
  const findCriteriaMap = {};
56
52
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_AGENT_BY_USERNAME] = (parameters) => `$..[?(@.spec.username=='${parameters.username}')]`;
57
53
  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}')]`;
54
+ findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_CREDENTIALS_BY_REFERENCE] = (parameters) => `$..[?(@.ref=='${parameters.ref}')]`;
59
55
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_DOMAIN_BY_DOMAINURI] = (parameters) => `$..[?(@.spec.context.domainUri=='${parameters.domainUri}')]`;
60
56
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_NUMBER_BY_TELURL] = (parameters) => `$..[?(@.spec.location.telUrl=="${parameters.telUrl}")]`;
61
57
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_TRUNKS_WITH_SEND_REGISTER] = () => "$..[?(@.spec.outbound.sendRegister==true)]";
62
58
  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
59
  // Create function to validate reference exists for Agent
84
60
  const checkReferences = (resources) => {
85
61
  const referenceExist = (ref) => resources.filter((r) => r.ref === ref)[0];
86
62
  // For every resource, check that the reference exists using a switch
87
63
  resources.forEach((resource) => {
88
64
  var _a;
89
- switch (resource.kind.toLocaleLowerCase()) {
65
+ switch (resource.kind.toLowerCase()) {
90
66
  case common_1.CommonConnect.Kind.AGENT:
91
67
  if (resource.spec.credentialsRef) {
92
68
  if (!referenceExist(resource.spec.credentialsRef)) {
@@ -160,12 +136,10 @@ const checkReferences = (resources) => {
160
136
  /**
161
137
  * Loads a list of resources from a file.
162
138
  *
163
- * @param {string} validatorsPath - the path to the validators
164
139
  * @param {string} resourcesPath - the path to the resources
165
140
  * @return {Resource[]} the loaded resources
166
141
  */
167
- function loadResources(validatorsPath, resourcesPath) {
168
- const validators = createValidators(validatorsPath);
142
+ function loadResources(resourcesPath) {
169
143
  const all = [];
170
144
  // eslint-disable-next-line @typescript-eslint/no-var-requires
171
145
  const files = require("fs").readdirSync(resourcesPath);
@@ -179,7 +153,7 @@ function loadResources(validatorsPath, resourcesPath) {
179
153
  process.exit(1);
180
154
  }
181
155
  // Check if is valid using jsonschema
182
- const validate = validators.get(resource.kind.toLocaleLowerCase());
156
+ const validate = common_1.ConnectSchemas.schemaValidators.get(resource.kind.toLowerCase());
183
157
  if (!validate) {
184
158
  logger.error(`unable to find validator for ${resource.kind}; exiting`);
185
159
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/simpledata",
3
- "version": "2.0.8-alpha.13",
3
+ "version": "2.0.8-alpha.14",
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.13",
33
- "@routr/processor": "^2.0.8-alpha.13",
32
+ "@routr/common": "^2.0.8-alpha.14",
33
+ "@routr/processor": "^2.0.8-alpha.14",
34
34
  "ajv": "^6.12.6",
35
35
  "google-protobuf": "^3.9.2",
36
36
  "jsonpath": "^1.1.1",
@@ -53,5 +53,5 @@
53
53
  "@types/google-protobuf": "^3.15.6",
54
54
  "@types/jsonpath": "^0.2.0"
55
55
  },
56
- "gitHead": "d866d6c03c5ea7e8fc3ee074804005df3a5be42f"
56
+ "gitHead": "e91abb1fd9bc49ede80dd7fc8a13f97362f4c1f1"
57
57
  }