Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@odata2ts/odata-query-builder
Advanced tools
Readme
The OData Query Builder allows for building type-safe OData queries for V2 and V4 services.
The query builder depends on generated models and q-objects to offer a powerful and easy-to-use API. These models and q-objects are generated via odata2ts out of an existing OData service.
The query builder offers operations which you probably know from SQL:
select
, filter
, count
, skip
, top
.
You also get the ability to expand related entities which in turn can be
filtered, selected or further expanded.
Selecting and expanding really means that the client has the power to shape the response structure. GraphQL should come to mind...
Additionally, OData V4 specifies even more functionalities like searching or aggregation.
A complex query could look like this:
import { createUriBuilderV4 } from "@odata2ts/odata-uri-builder";
import { qPerson } from "../generated-src/QTrippin.ts"
// In this minimal example the path ("People") as well as the q-object (qPerson) are provided manually.
// When using the generated service you will be provided with the builder and the proper q-object
createQueryBuilderV4("People", qPerson)
.select("lastName", "age") // typesafe: only model attributes are allowed
.filter(qPerson.userName.equals("russellwhyte")) // typesafe: only string values are allowed for comparison with string props
.expand("homeAddress") // typesafe: only expandable properties are allowed
.expanding("trips", (builder, qTrip) => { // typesafe: only expandable properties are allowed
builder
.select("tripId", "budget", "description")
.top(1)
.filter(qTrip.budget.gt(1000));
})
.build();
Result without encoding:
/People?$select=LastName,Age
&$filter=UserName eq 'russellwhyte'
&$expand=HomeAddress,Trips($select=TripId,Budget,Description;top=5;$filter=Budget gt 1000)
Be aware that the OData service you use does not have to implement all querying capabilities.
When using an unsupported operation, then the server should respond with 501: Not Implemented
(since the world's not perfect, you might face 500: Server Error
instead).
Some OData services advertise their capabilities via annotations, but this is not covered by
the OData spec. In any case odata2ts
doesn't support annotations currently.
The approach of generating certain objects to provide type-specific and type-safe query capabilities is by no means an
invention of odata2ts
. On the contrary, odata2ts
has been built in order to realize this approach for the domain
of OData queries.
For us, this concept originates in two outstanding Java libraries which are designed for the domain of database queries: QueryDsl and jOOQ.
odata2ts
diverges in some aspects from those libraries, but the similarities should be quite obvious,
especially when it comes to filtering.
Main documentation for the odata2ts eco system: https://odata2ts.github.io
See folder test for unit tests.
The example packages also contain some integration tests for querying.
This project is open to feature requests, suggestions, bug reports, usage questions etc. via GitHub issues.
Contributions and feedback are encouraged and always welcome.
See the contribution guidelines for further information.
This project and this module have been created and are maintained in the following spirit:
MIT - see License.
FAQs
Allows for building type-safe OData queries with a fluent API
The npm package @odata2ts/odata-query-builder receives a total of 1,039 weekly downloads. As such, @odata2ts/odata-query-builder popularity was classified as popular.
We found that @odata2ts/odata-query-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.