New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@http-query/core

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@http-query/core

This project contain the http query pattern to filter data in backend by url.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
2
Created
Source

Http Query

This project contain the http query pattern to filter data in backend by url.

Features:

  • Search
  • Pagination
  • Sorting
  • Limit by page
  • Get filter from url
  • Relations with TypeORM pattern (array)
  • Operators contract

Databases Support

  • MySQL

Coming soon

Features:

  • Relations to prisma pattern (objects with includes)

Support:

  • Postgres Database
  • Mongodb Database
  • Redis Database
  • SQL Server Database
  • Oracle Database

Installation

NPM:

npm install @http-query/core

yarn:

yarn add @http-query/core

Now implement the bind and getAlias code in your repository.

Sample bind method for typeorm

private bind({ query, relations }: IFind) {
  const order = {};

  query.sort.forEach((item) => {
    order[item.property] = item.order;
  });

  const rules = {
    AND: (qb: SelectQueryBuilder<Entity>, whereQuery: string) => {
      qb.andWhere(whereQuery);
    },
    OR: (qb: SelectQueryBuilder<Entity>, whereQuery: string) => {
      qb.orWhere(whereQuery);
    },
  };

  const where = (qb: SelectQueryBuilder<Entity>) => {
    query.q.forEach((item) => {
      const parsedEntity = this.getAlias(item.entity);
      const property = `${parsedEntity}.${item.property}`;
      const operator = operators[item.operator];
      const value =
        item.operator === 'LIKE' ? `'%${item.value}%'` : `'${item.value}'`;

      rules[item.rule](qb, `${property} ${operator} ${value}`);
    });
  };

  return {
    relations,
    take: query.limit,
    skip: (query.page - 1) * query.limit,
    order,
    where,
  };
}

Sample getAlias method for typeorm

private getAlias(entity: string): string {
  const { targetName } = this.orm.metadata;

  const parsedEntity = entity.replace(/\w{1}/, (match) =>
    match.toUpperCase(),
  );

  if (parsedEntity === targetName) return parsedEntity;

  return `${targetName}__${entity}`;
}

Keywords

http-query

FAQs

Package last updated on 26 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts