not-node 6.2.23 → 6.2.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.2.23",
3
+ "version": "6.2.25",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,6 +2,9 @@ const notEnv = require("../env.js");
2
2
  const notCommon = require("../common");
3
3
  const { error } = require("not-log")(module, "ClusterRedis");
4
4
 
5
+ /**
6
+ * Cluster event bus driver upon Redis events
7
+ */
5
8
  module.exports = class notClusterRedisProvider {
6
9
  static #clientGetter = null;
7
10
  static #clientName = "db.redis";
@@ -1,7 +1,10 @@
1
1
  const { log } = require("not-log")(module, "notCluster");
2
2
  const notClusterRedis = require("./cluster.redis.js");
3
3
 
4
- module.exports = class notCluster {
4
+ /**
5
+ * Interface to event bus of cluster
6
+ */
7
+ class notCluster {
5
8
  static #provider = notClusterRedis;
6
9
 
7
10
  static setProvider(newProvider) {
@@ -22,4 +25,6 @@ module.exports = class notCluster {
22
25
  static emit() {
23
26
  return this.#provider.emit(...arguments);
24
27
  }
25
- };
28
+ }
29
+
30
+ module.exports = notCluster;
package/src/common.js CHANGED
@@ -25,12 +25,12 @@ module.exports.firstLetterToUpper = function (string) {
25
25
 
26
26
  /**
27
27
  * Validates if string is a ObjectId
28
- * @param {string} id ObjectId string to validate
29
- * @return {booelean} true if check is not failed
28
+ * @param {string|import('mongoose').Schema.Types.ObjectId} id ObjectId string to validate
29
+ * @return {boolean} true if check is not failed
30
30
  */
31
31
  module.exports.validateObjectId = (id) => {
32
32
  try {
33
- return id.match(/^[0-9a-fA-F]{24}$/) ? true : false;
33
+ return id.toString().match(/^[0-9a-fA-F]{24}$/) ? true : false;
34
34
  } catch (e) {
35
35
  return false;
36
36
  }
@@ -38,9 +38,9 @@ module.exports.validateObjectId = (id) => {
38
38
 
39
39
  /**
40
40
  * Validates and compares ObjectIds in string or Object form
41
- * @param {string|ObjectId} firstId first id
42
- * @param {string|ObjectId} secondId second id
43
- * @return {booelean} true if equal
41
+ * @param {string|import('mongoose').Schema.Types.ObjectId} firstId first id
42
+ * @param {string|import('mongoose').Schema.Types.ObjectId} secondId second id
43
+ * @return {boolean} true if equal
44
44
  */
45
45
  module.exports.compareObjectIds = (firstId, secondId) => {
46
46
  try {
@@ -160,7 +160,9 @@ module.exports.executeObjectFunction = async (obj, name, params) => {
160
160
  }
161
161
  if (name.indexOf(".") > -1) {
162
162
  const proc =
163
- typeof obj == "object" ? notPath.get(":" + name, obj) : obj[name];
163
+ typeof obj == "object"
164
+ ? notPath.get(":" + name, obj, {})
165
+ : obj[name];
164
166
  if (!proc) {
165
167
  return;
166
168
  }
@@ -179,9 +181,8 @@ module.exports.executeObjectFunction = async (obj, name, params) => {
179
181
  /**
180
182
  * Executes method of object in apropriate way inside Promise
181
183
  * @param {Object} from original object
182
- * @param {Object} name method name to execute
183
- * @param {Array} list array of params
184
- * @return {Promise} results of method execution
184
+ * @param {Object} to method name to execute
185
+ * @param {Array} list array of params
185
186
  **/
186
187
  module.exports.mapBind = (from, to, list) => {
187
188
  list.forEach((item) => {
@@ -210,15 +211,13 @@ module.exports.tryFile = (filePath) => {
210
211
  * @param {string} filePath full path to file
211
212
  * @return {Promise<boolean>} true if path exists and it's a file
212
213
  **/
213
- module.exports.tryFileAsync = (filePath) => {
214
- return new Promise((resolve, reject) => {
215
- try {
216
- const stat = fs.lstatSync(filePath);
217
- resolve(stat && stat.isFile());
218
- } catch (e) {
219
- reject(false);
220
- }
221
- });
214
+ module.exports.tryFileAsync = async (filePath) => {
215
+ try {
216
+ const stat = await fs.promises.lstat(filePath);
217
+ return stat && stat.isFile();
218
+ } catch (e) {
219
+ return false;
220
+ }
222
221
  };
223
222
 
224
223
  /**
@@ -264,7 +263,7 @@ module.exports.tryParseAsync = (
264
263
  * path
265
264
  * @param {Array<string>} content list of module components ['models', 'logics', 'routes',...]
266
265
  * @param {string} relative path to parent folder of components
267
- * @param {Object} paths object for module/index.js
266
+ * @returns {Object} paths object for module/index.js
268
267
  **/
269
268
  module.exports.generatePaths = (content = [], relative = "src") => {
270
269
  const toPath = (name) => path.join(relative, name);
@@ -293,31 +292,40 @@ module.exports.getIP = (req) => {
293
292
  }
294
293
  };
295
294
 
295
+ /**
296
+ *
297
+ *
298
+ * @param {string} prefix
299
+ * @return {function}
300
+ */
296
301
  const createIsStringPrefixedTester = (prefix) => {
297
302
  if (!prefix || prefix.length === 0) throw Error("No prefix provided");
298
303
  return (str) => {
299
- return str && str.length > prefix.length && str.indexOf(prefix) === 0;
304
+ return str && str.length > prefix.length && str.indexOf(prefix) === 0
305
+ ? prefix.length
306
+ : 0;
300
307
  };
301
308
  };
302
309
  module.exports.createIsStringPrefixedTester = createIsStringPrefixedTester;
303
310
 
311
+ /**
312
+ *
313
+ *
314
+ * @param {string} val
315
+ * @param {Object} options
316
+ * @return {number} prefix length
317
+ */
304
318
  const stringIsPrefixed = (val, options) => {
305
319
  if (typeof val === "string" && options) {
306
320
  if (options.tester && typeof options.tester === "function") {
307
- const res = options.tester(val);
308
- if (Object.hasOwn(process.env, val)) {
309
- return res;
310
- }
321
+ return options.tester(val);
311
322
  }
312
323
  if (
313
324
  options.prefix &&
314
325
  typeof options.prefix === "string" &&
315
326
  options.prefix.length > 0
316
327
  ) {
317
- const res = createIsStringPrefixedTester(options.prefix)(val);
318
- if (Object.hasOwn(process.env, val)) {
319
- return res;
320
- }
328
+ return createIsStringPrefixedTester(options.prefix)(val);
321
329
  }
322
330
  }
323
331
  return 0;
@@ -341,11 +349,14 @@ const getValueFromEnv = (
341
349
  name,
342
350
  options = { prefix: "ENV$", drop: true }
343
351
  ) => {
344
- if (source && Object.hasOwn(source, name)) {
352
+ if (source && objHas(source, name)) {
345
353
  const val = source[name];
346
354
  const len = stringIsPrefixed(val, options);
347
- if (len) {
348
- return process.env[options.drop ? val.slice(0, len) : val];
355
+ if (len > 0) {
356
+ const envName = options.drop ? val.slice(len) : val;
357
+ if (typeof process.env[envName] !== "undefined") {
358
+ return process.env[envName];
359
+ }
349
360
  }
350
361
  return val;
351
362
  }
@@ -54,7 +54,7 @@ module.exports = ({ expect }) => {
54
54
  });
55
55
 
56
56
  describe("tryRouteFile", function () {
57
- it("route file doesnt exists", function () {
57
+ it("route file doesnt exists,", function () {
58
58
  const res = notModuleRegistratorRoutes.tryRouteFile({
59
59
  srcDir: routesPath,
60
60
  routeBasename: "jingle",