Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@trapi/query

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trapi/query - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

4

dist/build.d.ts

@@ -1,3 +0,3 @@

import { QueryRecord } from "./type";
export declare function buildQuery<T extends Record<string, any>>(record?: QueryRecord<T>): string;
import { QueryBuildOptions, QueryRecord } from "./type";
export declare function buildQuery<T extends Record<string, any>>(record?: QueryRecord<T>, options?: QueryBuildOptions): string;
//# sourceMappingURL=build.d.ts.map

@@ -15,21 +15,23 @@ "use strict";

const utils_1 = require("./utils");
function buildQuery(record) {
function buildQuery(record, options) {
if (typeof record === 'undefined' || record === null)
return '';
options ??= {};
options.key ??= {};
let query = {};
if (typeof record[type_1.QueryRecordKey.FIELDS] !== 'undefined') {
query[options.key[type_1.QueryRecordKey.FIELDS] ?? type_1.QueryRecordKey.FIELDS] = (0, fields_1.buildQueryFields)(record[type_1.QueryRecordKey.FIELDS]);
}
if (typeof record[type_1.QueryRecordKey.FILTER] !== 'undefined') {
query[type_1.QueryRecordKey.FILTER] = (0, utils_1.flattenNestedProperties)(record[type_1.QueryRecordKey.FILTER]);
query[options.key[type_1.QueryRecordKey.FILTER] ?? type_1.QueryRecordKey.FILTER] = (0, utils_1.flattenNestedProperties)(record[type_1.QueryRecordKey.FILTER]);
}
if (typeof record[type_1.QueryRecordKey.FIELDS] !== 'undefined') {
query[type_1.QueryRecordKey.FIELDS] = (0, fields_1.buildQueryFields)(record[type_1.QueryRecordKey.FIELDS]);
if (typeof record[type_1.QueryRecordKey.INCLUDE] !== 'undefined') {
query[options.key[type_1.QueryRecordKey.INCLUDE] ?? type_1.QueryRecordKey.INCLUDE] = (0, includes_1.buildQueryIncludes)(record[type_1.QueryRecordKey.INCLUDE]);
}
if (typeof record[type_1.QueryRecordKey.PAGE] !== 'undefined') {
query[type_1.QueryRecordKey.PAGE] = record[type_1.QueryRecordKey.PAGE];
query[options.key[type_1.QueryRecordKey.PAGE] ?? type_1.QueryRecordKey.PAGE] = record[type_1.QueryRecordKey.PAGE];
}
if (typeof record[type_1.QueryRecordKey.SORT] !== 'undefined') {
query[type_1.QueryRecordKey.SORT] = (0, sort_1.buildQuerySort)(record[type_1.QueryRecordKey.SORT]);
query[options.key[type_1.QueryRecordKey.SORT] ?? type_1.QueryRecordKey.SORT] = (0, sort_1.buildQuerySort)(record[type_1.QueryRecordKey.SORT]);
}
if (typeof record[type_1.QueryRecordKey.INCLUDE] !== 'undefined') {
query[type_1.QueryRecordKey.INCLUDE] = (0, includes_1.buildQueryIncludes)(record[type_1.QueryRecordKey.INCLUDE]);
}
return (0, utils_1.buildURLQueryString)(query);

@@ -36,0 +38,0 @@ }

@@ -6,2 +6,8 @@ import { FieldRecord } from "./fields";

import { SortRecord } from "./sort";
export declare type BuildQueryKeyOption = {
[Key in QueryRecordKey]?: string;
};
export declare type QueryBuildOptions = {
key?: BuildQueryKeyOption;
};
export declare enum QueryRecordKey {

@@ -8,0 +14,0 @@ FILTER = "filter",

{
"name": "@trapi/query",
"version": "1.0.1",
"version": "1.0.2",
"description": "An tiny library which provides utility types/functions for request and response query handling.",

@@ -10,3 +10,4 @@ "main": "./dist/index.js",

"test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js",
"test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage"
"test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage",
"prepublishOnly": "npm run build"
},

@@ -53,3 +54,3 @@ "author": {

},
"gitHead": "4355a7f0d19c3df26929981011a621e7f70590e6"
"gitHead": "fbabb84192fbfbf8744f0e17d109ecb23992ef9c"
}

@@ -108,3 +108,5 @@ # @trapi/query 🌈

// console.log(tranformQueryRecord);
const query = buildQuery(record);
// console.log(query);
// ?filter[id]=1&fields=id,name&page[limit]=20&page[offset]=10&sort=-id&include=profile

@@ -111,0 +113,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc