npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sap/odata-v4

v1.9.0

Published

OData V4.0 server library

Downloads

37

Readme

OData V4.0 Server Library

Table of Contents

Overview

With the OData server library OData V4.0 services can be implemented based on the OASIS OData standard. The library can be directly used to build OData services and is also part of the SAP Fiori programming model as well the SAP Cloud Platform programming model, where the data model can be defined in CDS (Core data services) and the OData service be generated out of the model.

The library leaves the freedom to build OData services with any db or persistence layer. It is also possible to create services, that are calling external REST/OData services and mix up the data with your application data.

The library is modular and consists of the following main components:

  • EntityDataModel - Define your EDM in JSON format. Our provider creates the EDM out of your model and caches EDM model elements
  • Handler Dispatcher - Maps requests to handler functions for CRUD operations
  • URI parsers - Parse the request URI including the OData system query options (like $format, $select, $expand,...) and validates each URI segment against the EDM model and the OData ABNF
  • Serializers and Deserializers for the request and response payload. The deserializers validate the request payload and support type mapping between OData EDM types and JavaScript Types
  • Automatic OData Reponse generation based on provided data
  • ServiceFactory to create the OData service along with the CRUD handler registration
  • Conditional request handling for optimistic concurrency control via ETAGs
  • Batch handling - Batch request parsing, dispatching to single batch requests, Content-ID referencing and batch response generation
  • Flexible API to support all backends - The service developer has the free choice of his backend system (e.g., databases, frameworks, calling additional external OData services).

Installation

npm install @sap/odata-v4

Usage

const odata = require('@sap/odata-v4');
// Load your edm model.
const edmModel = require('./<your_edm_model>.json');

// Create the service
const service = odata.ServiceFactory.createService(edmModel)

    // Register the request handler for CRUD operations
    .on('create', function create(request, response, next){...})
    .on('update', function update(request, response, next){...})
    .on('delete', function delete(request, response, next){...})
    .on('read', function read(request, response, next){...})

//Create the server
const port = 9000;
const server = http.createServer((req, res) => service.process(req, res))
    .listen(port,
        () => console.log(`Server listens on port ${port} - Service URL: http://localhost:${port}/serviceroot.svc/`)
    );

Supported Requests

| Resource | Request | |:------------------------------|:-----------------------------------------------------------------------------------------| | Read Request | GET | | Serviceoot | GET http://host/serviceRoot/ | | Metadata | GET http://host/serviceRoot/$metadata | | EntitySet | GET http://host/serviceRoot/EntitySet | | EntitySet | GET http://host/serviceRoot/EntitySet/$count | | Entity | GET http://host/serviceRoot/EntitySet(Key) | | References | GET http://host/serviceRoot/EntitySet/$ref | | Reference | GET http://host/serviceRoot/EntitySet(Key)/$ref | | References(related) | GET http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany/$ref | | Reference(related) | GET http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany/$ref |
| Related Entity | GET http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToOne | | Related Entities | GET http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany | | Complex Property | GET http://host/serviceRoot/EntitySet(Key)/ComplexProperty | | Complex Property Collection | GET http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection | | Primitive Property | GET http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty | | Primitive Property Value | GET http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/$value | | Primitive Property Collection | GET http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection | | Create/Insert Requests | POST | | Entity | POST http://host/serviceRoot/EntitySet | | Deep Insert | POST http://host/serviceRoot/EntitySet | | Entity with bind operations | POST http://host/serviceRoot/EntitySet | | Reference | POST http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany/$ref | | Update Requests | PUT/PATCH | | Entity | PUT/PATCH http://host/serviceRoot/EntitySet(Key) | | Reference | PUT http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToOne/$ref | | Complex Property | PUT/PATCH http://host/serviceRoot/EntitySet(Key)/ComplexProperty | | Complex Property Collection | PUT http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection | | Primitive Property | PUT http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty | | Primitive Property Value | PUT http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/$value | | Primitive Property Collection | PUT http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection | | Delete Requests | DELETE | | Entity | DELETE http://host/serviceRoot/EntitySet(Key) | | Reference | DELETE http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToOne/$ref | | Reference(To Many) | DELETE http://host/serviceRoot/EntitySet(Key)/NavigationPropertyToMany(Key)/$ref | | Complex Property | DELETE http://host/serviceRoot/EntitySet(Key)/ComplexProperty | | Complex Property Collection | DELETE http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection | | Primitive Property | DELETE http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty | | Primitive Property Value | DELETE http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/$value | | Primitive Property Collection | DELETE http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection | | Actions and Functions | GET/POST | | Function Import | GET http://host/serviceRoot/FunctionImports/[Navigation- or PropertyPath] | | boundFunction | GET http://host/serviceRoot/EntitySet/boundFunction | | boundFunction | GET http://host/serviceRoot/EntitySet(Key)/boundFunction | | boundFunction | GET http://host/serviceRoot/EntitySet(Key)/ComplexProperty/boundFunction | | boundFunction | GET http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection/boundFunction | | boundFunction | GET http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/boundFunction | | boundFunction | GET http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection/boundFunction | | ActionImport | POST http://host/serviceRoot/ActionImport | | boundAction | POST http://host/serviceRoot/EntitySet/boundAction | | boundAction | POST http://host/serviceRoot/EntitySet(Key)/boundAction | | boundAction | POST http://host/serviceRoot/EntitySet(Key)/ComplexProperty/boundAction | | boundAction | POST http://host/serviceRoot/EntitySet(Key)/ComplexPropertyCollection/boundAction | | boundAction | POST http://host/serviceRoot/EntitySet(Key)/PrimitiveProperty/boundAction | | boundAction | POST http://host/serviceRoot/EntitySet(Key)/PrimitivePropertyCollection/boundAction |

Supported System Query Options

| System Query Option | OASIS OData V4.0 Errata 3 - Query Option Description | |:----------------|:-------------------------------------------------------------------------------------| | $filter | Supported values see OASIS specification | | | $expand | Supported values see OASIS specification | | | $select | Supported values see OASIS specification | | | $orderby | Supported values see OASIS specification| | $top and $skip | Supported values see OASIS specification| | $count | Supported values see OASIS specification| | $search | Supported values see OASIS specification| | $format | Supported values see OASIS specification|

Analytical Queries - $apply

| Transformation | Sample | Limitations | |:--------------------|:----------------------------------------------------------------| :---------------| | aggregate | GET ~/Sales?$apply=aggregate(Amount with sum as Total) | Keyword 'from' is not supported | | topcount | GET ~/Sales?$apply=topcount(2,Amount) | | | topsum | GET ~/Sales?$apply=topsum(15,Amount) | | | toppercent | GET ~/Sales?$apply=toppercent(50,Amount) | | | bottomcount | GET ~/Sales?$apply=bottomcount(2,Amount) | | | bottomsum | GET ~/Sales?$apply=bottomsum(7,Amount) | | | bottompercent | GET ~/Sales?$apply=bottompercent(50,Amount) | | | identity | GET ~/Sales?$apply=identity | | | concat | GET ~/Sales?$apply=concat(topcount(2,Amount),aggregate(Amount)) | | | groupby | GET ~/Sales?$apply=groupby((Customer/Country,Product/Name), aggregate(Amount with sum as Total)) | rollup and $all is not supported | | filter | GET ~/Sales?$apply=filter(Amount gt 3) | | expand | Not supported | | search | GET ~/Sales?$apply=search(coffee) |

Releases and Milestones

Changelog