How to use the loopback-datasource-juggler/lib/utils.toRegExp function in loopback-datasource-juggler

To help you get started, we’ve selected a few loopback-datasource-juggler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EdgeVerve / oe-cloud / lib / loopback-datasource-juggler-wrapper / coerce.js View on Github external
break;
            case 'like':
            case 'nlike':
            case 'ilike':
            case 'nilike':
              if (!(typeof val === 'string' || val instanceof RegExp)) {
                err = new Error(g.f(
                  'The %s property has invalid clause %j: Expected a string or RegExp',
                  p,
                  where[p]));
                err.statusCode = 400;
                throw err;
              }
              break;
            case 'regexp':
              val = utils.toRegExp(val);
              if (val instanceof Error) {
                val.statusCode = 400;
                throw err;
              }
              break;
          }
          break;
        }
      }
    }

    try {
      // Coerce val into an array if it resembles an array-like object
      val = coerceArray(val);
    } catch (e) {
      // NOOP when not coercable into an array.
github EdgeVerve / oe-cloud / common / mixins / data-hierarchy-mixin.js View on Github external
if (depth === '*') {
      const regexObj = toRegExp(regexString);

      query[key] = regexObj;
      mergeQuery(ctx.query, {
        where: query
      });
    } else {
      for (let i = 0; i <= depth; i++) {
        query = {};
        if (i === 0) {
          modifiedRegex = `${regexString}$`;
        } else {
          modifiedRegex = `${modifiedRegex.substr(0, modifiedRegex.length - 1)}[[:alnum:]]*,$`;
        }
        query[key] = toRegExp(modifiedRegex);
        orParms.push(query);
      }
      mergeQuery(ctx.query, {
        where: {
          or: orParms
        }
      });
    }
  } else {
    if (depth === '*') {
      depth = regexString.split(',').length - 2;
    }
    for (let j = 0; j <= depth; j++) {
      query = {};
      if (j === 0) {
        modifiedRegex = `${regexString}$`;
github EdgeVerve / oe-cloud / common / mixins / data-hierarchy-mixin.js View on Github external
if (depth === '*') {
      depth = regexString.split(',').length - 2;
    }
    for (let j = 0; j <= depth; j++) {
      query = {};
      if (j === 0) {
        modifiedRegex = `${regexString}$`;
      } else {
        const hierarchyArray = modifiedRegex.split(',');
        hierarchyArray.splice(hierarchyArray.length - 2, 1);
        modifiedRegex = hierarchyArray.join();
      }
      if (modifiedRegex === ',$' || modifiedRegex === '$') {
        break;
      }
      query[key] = toRegExp(modifiedRegex);
      orParms.push(query);
    }
    mergeQuery(ctx.query, {
      where: {
        or: orParms
      }
    });
  }
}
github EdgeVerve / oe-cloud / common / mixins / data-hierarchy-mixin.js View on Github external
function createQuery(ctx, context, hierarchy) {
  const upward = ctx.Model.definition.settings.upward || false;
  let depth = ctx.query && ctx.query.depth ? ctx.query.depth : '0';
  let query = {};
  const key = `_hierarchyScope.${hierarchy}`;
  const regexString = context[hierarchy];
  const orParms = [];
  let modifiedRegex;

  if (!upward) {
    if (depth === '*') {
      const regexObj = toRegExp(regexString);

      query[key] = regexObj;
      mergeQuery(ctx.query, {
        where: query
      });
    } else {
      for (let i = 0; i <= depth; i++) {
        query = {};
        if (i === 0) {
          modifiedRegex = `${regexString}$`;
        } else {
          modifiedRegex = `${modifiedRegex.substr(0, modifiedRegex.length - 1)}[[:alnum:]]*,$`;
        }
        query[key] = toRegExp(modifiedRegex);
        orParms.push(query);
      }