odata-query-builder
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"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 ''; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
311488
8614
0