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

@json-api/query-parser

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@json-api/query-parser - npm Package Compare versions

Comparing version 2.0.1 to 3.1.0

build/src/parsing/filter-param-parser.d.ts

32

build/src/helpers.d.ts

@@ -1,4 +0,2 @@

/// <reference types="ramda" />
import R = require("ramda");
import { RawFieldExpression } from './parser';
import { FieldExpression, SortField, FieldExpressionEntry } from './parsing/parser';
export declare type Identifier = {

@@ -8,3 +6,7 @@ type: "Identifier";

};
export declare const isId: (it: any) => it is Identifier;
export declare const isIdentifier: (it: any) => it is Identifier;
export { FieldExpression };
export declare const isFieldExpression: (it: any) => it is FieldExpression;
export { SortField };
export declare const isSortField: (it: any) => it is SortField;
export declare type OperatorsConfig = {

@@ -16,22 +18,2 @@ [operatorName: string]: {

};
export declare type FieldExpression = {
type: "FieldExpression";
operator: string;
args: any[];
};
export declare type SortField = ({
field: string;
} | {
expression: FieldExpression;
}) & {
direction: "ASC" | "DESC";
};
export declare const isKnownOperator: R.CurriedTypeGuard2<OperatorsConfig, any, Identifier>;
export declare const isBinaryOperator: R.CurriedFunction2<OperatorsConfig, any, boolean>;
export declare const isNaryOperator: R.CurriedFunction2<OperatorsConfig, any, boolean>;
export declare const toFieldExpression: R.CurriedFunction2<OperatorsConfig, any, FieldExpression>;
export declare function finalizeFieldExpression(operators: OperatorsConfig, it: RawFieldExpression): {
args: any[];
type: "FieldExpression";
operator: string;
};
export { FieldExpressionEntry };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const R = require("ramda");
exports.isId = (it) => it && it.type === "Identifier";
exports.isKnownOperator = R.curry((operators, node) => {
return exports.isId(node) && Boolean(operators[node.value]);
});
exports.isBinaryOperator = R.curry((operators, node) => {
return exports.isKnownOperator(operators, node) && operators[node.value].arity === 2;
});
exports.isNaryOperator = R.curry((operators, node) => {
return exports.isKnownOperator(operators, node) && operators[node.value].arity !== 2;
});
exports.toFieldExpression = R.curry((operators, it) => {
if (!(it && it.type === "RawFieldExpression")) {
throw new SyntaxError("Expected a parenthesized list.");
}
const list = it.items;
if (list.length === 3 && exports.isBinaryOperator(operators, list[1])) {
return {
type: "FieldExpression",
operator: list[1].value,
args: [list[0], list[2]]
};
}
else if (exports.isNaryOperator(operators, list[0])) {
return {
type: "FieldExpression",
operator: list[0].value,
args: list.slice(1)
};
}
else if (list.length === 2 && operators["eq"]) {
return {
type: "FieldExpression",
operator: "eq",
args: list
};
}
if (exports.isBinaryOperator(operators, list[1])) {
throw new SyntaxError(`"${list[1].value}" is a binary operator, so the field expression ` +
"must have exactly three items.");
}
if (exports.isBinaryOperator(operators, list[0])) {
throw new SyntaxError(`"${list[0].value}" is a binary operator, so it must be infixed as ` +
"the second item in your field expression.");
}
throw new SyntaxError("Field expressions must have a valid operator symbol as their first " +
"item (for non-binary operators) or second item (for binary operators), " +
"or must be a two-item list without any operators (in which case the " +
"`eq` operator is inferred, if it's supported).");
});
function finalizeFieldExpression(operators, it) {
const finalizedExp = exports.toFieldExpression(operators, it);
const finalArgs = operators[finalizedExp.operator].finalizeArgs(operators, finalizedExp.operator, finalizedExp.args.map((arg) => {
if (arg && arg.type === 'RawFieldExpression') {
return finalizeFieldExpression(operators, arg);
}
return arg;
}));
return Object.assign({}, finalizedExp, { args: finalArgs });
}
exports.finalizeFieldExpression = finalizeFieldExpression;
exports.isIdentifier = (it) => it && it.type === "Identifier";
exports.isFieldExpression = (it) => it && it.type === "FieldExpression";
exports.isSortField = (it) => it && it.type === "SortField";

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

import parseFilter from './filter-param-parser';
import parseSort from './sort-param-parser';
export { parseFilter, parseSort };
import parseFilter from './parsing/filter-param-parser';
import parseSort from './parsing/sort-param-parser';
import serializeFilter from './serialization/filter-param-serializer';
import serializeSort from './serialization/sort-param-serializer';
export { parseFilter, parseSort, serializeFilter, serializeSort };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const filter_param_parser_1 = require("./filter-param-parser");
const filter_param_parser_1 = require("./parsing/filter-param-parser");
exports.parseFilter = filter_param_parser_1.default;
const sort_param_parser_1 = require("./sort-param-parser");
const sort_param_parser_1 = require("./parsing/sort-param-parser");
exports.parseSort = sort_param_parser_1.default;
const filter_param_serializer_1 = require("./serialization/filter-param-serializer");
exports.serializeFilter = filter_param_serializer_1.default;
const sort_param_serializer_1 = require("./serialization/sort-param-serializer");
exports.serializeSort = sort_param_serializer_1.default;
{
"name": "@json-api/query-parser",
"version": "2.0.1",
"version": "3.1.0",
"description": "A query parser for the ?filter and ?sort param syntax used by @json-api/server",

@@ -9,3 +9,4 @@ "main": "build/src/index.js",

"clean": "rimraf build",
"build:parser": "pegjs --allowed-start-rules Sort,Filter -o src/parser.js src/grammar.pegjs",
"copy-parser": "cpr src/parsing/parser.js build/src/parsing/parser.js && cpr src/parsing/parser.d.ts build/src/parsing/parser.d.ts",
"build:parser": "pegjs --allowed-start-rules Sort,Filter -o src/parsing/parser.js src/parsing/grammar.pegjs",
"build:ts": "echo Using TypeScript && tsc --version && tsc --pretty",

@@ -15,3 +16,3 @@ "build": "npm run clean && npm run build:parser && npm run build:ts",

"test:built": "NODE_ENV=testing mocha --compilers ts:ts-node/register --recursive test/ --full-trace --check-leaks",
"prepare": "npm run build && cpr src/parser.js build/src/parser.js && cpr src/parser.d.ts build/src/parser.d.ts"
"prepare": "npm run build && npm run copy-parser"
},

@@ -18,0 +19,0 @@ "author": "Ethan Resnick <ethan.resnick@gmail.com>",

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