not-node 6.2.16 → 6.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.2.16",
3
+ "version": "6.2.18",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/common.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
3
  const notPath = require("not-path");
4
- const { rejects } = require("assert");
5
4
 
6
5
  /** @module Common */
7
6
  /**
@@ -157,21 +156,21 @@ module.exports.executeFunctionAsAsync = executeFunctionAsAsync;
157
156
  **/
158
157
  module.exports.executeObjectFunction = async (obj, name, params) => {
159
158
  if (obj) {
160
- if (name.indexOf(".") > -1) {
161
- const proc =
162
- typeof obj == "object"
163
- ? notPath.get(":" + name, obj)
164
- : obj[name];
165
- if (proc) {
166
- return await executeFunctionAsAsync(proc.bind(obj), params);
167
- }
168
- } else {
169
- if (obj[name] && isFunc(obj[name])) {
170
- if (isAsync(obj[name])) {
171
- return await obj[name](...params);
172
- } else {
173
- return obj[name](...params);
174
- }
159
+ return;
160
+ }
161
+ if (name.indexOf(".") > -1) {
162
+ const proc =
163
+ typeof obj == "object" ? notPath.get(":" + name, obj) : obj[name];
164
+ if (!proc) {
165
+ return;
166
+ }
167
+ return await executeFunctionAsAsync(proc.bind(obj), params);
168
+ } else {
169
+ if (obj[name] && isFunc(obj[name])) {
170
+ if (isAsync(obj[name])) {
171
+ return await obj[name](...params);
172
+ } else {
173
+ return obj[name](...params);
175
174
  }
176
175
  }
177
176
  }
@@ -293,3 +292,62 @@ module.exports.getIP = (req) => {
293
292
  return undefined;
294
293
  }
295
294
  };
295
+
296
+ const createIsStringPrefixedTester = (prefix) => {
297
+ if (!prefix || prefix.length === 0) throw Error("No prefix provided");
298
+ return (str) => {
299
+ return str && str.length > prefix.length && str.indexOf(prefix) === 0;
300
+ };
301
+ };
302
+ module.exports.createIsStringPrefixedTester = createIsStringPrefixedTester;
303
+
304
+ const stringIsPrefixed = (val, options) => {
305
+ if (typeof val === "string" && options) {
306
+ if (options.tester && typeof options.tester === "function") {
307
+ const res = options.tester(val);
308
+ if (Object.hasOwn(process.env, val)) {
309
+ return res;
310
+ }
311
+ }
312
+ if (
313
+ options.prefix &&
314
+ typeof options.prefix === "string" &&
315
+ options.prefix.length > 0
316
+ ) {
317
+ const res = createIsStringPrefixedTester(options.prefix)(val);
318
+ if (Object.hasOwn(process.env, val)) {
319
+ return res;
320
+ }
321
+ }
322
+ }
323
+ return 0;
324
+ };
325
+ module.exports.stringIsPrefixed = stringIsPrefixed;
326
+
327
+ /**
328
+ * It will get value of name from object property and then test,
329
+ * if value corresponds to a property process.ENV object. If it does -
330
+ * value from process.ENV.* will be returned, if not - just value of source[name]
331
+ * @param {object} source source object
332
+ * @param {string} name option name
333
+ * @param {object} [options] options
334
+ * @param {function} [options.tester] (str)=>integer, checks value of source[name], if returns not 0 than value is name of property in process.ENV to be returned, if number more than 0 returned and drop is set to true, returned number of chars will be droped
335
+ * @param {string} [options.prefix = 'ENV$'] prefix that indicates that source[name] value corresponds to process.ENV property
336
+ * @param {boolean} [options.drop = true] should we drop prefix from value before reach for real value in process.ENV, ENV$VALUE - process.ENV.VALUE
337
+ * @returns {*} any
338
+ */
339
+ const getValueFromEnv = (
340
+ source,
341
+ name,
342
+ options = { prefix: "ENV$", drop: true }
343
+ ) => {
344
+ if (source && Object.hasOwn(source, name)) {
345
+ const val = source[name];
346
+ const len = stringIsPrefixed(val, options);
347
+ if (len) {
348
+ return process.env[options.drop ? val.slice(0, len) : val];
349
+ }
350
+ return val;
351
+ }
352
+ };
353
+ module.exports.getValueFromEnv = getValueFromEnv;
@@ -9,11 +9,15 @@ module.exports = (form, req) => {
9
9
  `${MODULE_NAME}//${MODEL_NAME}`
10
10
  );
11
11
  if (thisSchema) {
12
- const { skip, size } = notFilter.pager.process(req), //skip,size
12
+ let skip, size;
13
+ const pager = notFilter.pager.process(req), //skip,size
13
14
  sorter = notFilter.sorter.process(req, thisSchema),
14
15
  search = notFilter.search.process(req, thisSchema);
15
16
  let filter = notFilter.filter.process(req, thisSchema);
16
-
17
+ if (pager) {
18
+ skip = pager.skip;
19
+ size = pager.size;
20
+ }
17
21
  return {
18
22
  name: "query",
19
23
  value: { skip, size, sorter, search, filter },