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

odata-query-builder

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

odata-query-builder - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

2

package.json
{
"name": "odata-query-builder",
"version": "0.0.4",
"version": "0.0.5",
"description": "An eloquently fluent OData query builder.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -16,8 +16,23 @@ import { QueryBuilder } from './queryBuilder';

});
it('should only return the last order by', () => {
expect(new QueryBuilder().orderBy('old').orderBy('test').toQuery()).toEqual(
'?$orderby=test'
);
});
it('should return top', () => {
expect(new QueryBuilder().top(1).toQuery()).toEqual('?$top=1');
});
it('should only return the last top', () => {
expect(new QueryBuilder().top(5).top(1).toQuery()).toEqual(
'?$top=1'
);
});
it('should return skip', () => {
expect(new QueryBuilder().skip(1).toQuery()).toEqual('?$skip=1');
});
it('should only return the last skip', () => {
expect(new QueryBuilder().skip(5).skip(1).toQuery()).toEqual(
'?$skip=1'
);
});
it('should return expand', () => {

@@ -28,7 +43,17 @@ expect(new QueryBuilder().expand('test').toQuery()).toEqual(

});
it('should only return the last expand at the root level', () => {
expect(new QueryBuilder().expand('old').expand('test').toQuery()).toEqual(
'?$expand=test'
);
});
it('should return select', () => {
expect(new QueryBuilder().select('test').toQuery()).toEqual(
'?$select=test'
)
);
});
it('should only return the last select at the root level', () => {
expect(new QueryBuilder().select('old').select('test').toQuery()).toEqual(
'?$select=test'
);
});
it('should add a new filter expression', () => {

@@ -35,0 +60,0 @@ const testCases = new TestCaseCollection([

@@ -55,2 +55,3 @@ import { FragmentType } from './enums';

orderBy = (fields: string) => {
this.clear(FragmentType.OrderBy);
this.fragments.push(new QueryFragment(FragmentType.OrderBy, `$orderby=${fields}`));

@@ -60,2 +61,3 @@ return this;

top = (top: number) => {
this.clear(FragmentType.Top);
this.fragments.push(new QueryFragment(FragmentType.Top, `$top=${top}`));

@@ -65,2 +67,3 @@ return this;

skip = (skip: number) => {
this.clear(FragmentType.Skip);
this.fragments.push(new QueryFragment(FragmentType.Skip, `$skip=${skip}`));

@@ -70,2 +73,3 @@ return this;

count = () => {
this.clear(FragmentType.Count);
this.fragments.push(new QueryFragment(FragmentType.Count, `$count=true`));

@@ -75,2 +79,3 @@ return this;

expand = (fields: string) => {
this.clear(FragmentType.Expand);
this.fragments.push(new QueryFragment(FragmentType.Expand, `$expand=${fields}`));

@@ -80,7 +85,8 @@ return this;

select = (fields: string) => {
this.clear(FragmentType.Select);
this.fragments.push(new QueryFragment(FragmentType.Select, `$select=${fields}`));
return this;
};
filter = (predicate: (filter: FilterBuilder) => FilterBuilder, operator: string = 'and') => {
this.clear(FragmentType.Filter);
this.fragments.push(

@@ -91,2 +97,6 @@ new QueryFragment(FragmentType.Filter, predicate(new FilterBuilder()).toQuery(operator))

};
clear = (fragmentType: FragmentType) => {
this.fragments = this.fragments.filter(f => f.type !== fragmentType);
return this;
}
toQuery = () => {

@@ -93,0 +103,0 @@ if (this.fragments.length < 1) return '';

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