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

reserve-odata

v0.8.0

Published

ODATA handler for REserve

Downloads

8

Readme

REserve/ODATA

Simple ODATA v2 handler for REserve.

Travis-CI Coverage Status Maintainability Package Quality Known Vulnerabilities dependencies Status devDependencies Status reserve reserve install size MIT License

Usage

  • In the mapping :
{
  "handlers": {
    "odata": "reserve-odata"
  },
  "mappings": [{
    "match": "\\/api\\/odata\\/(.*)",
    "odata": "$1",
    "data-provider-classes": "./dpc.js"
  }]
}

Options

| Option | Type / Default Value | Explanation | |---|---|---| | service-namespace | 'ODATANS' | Service namespace | | use-sap-extension | false | true to insert SAP specific information in the $metadata | | data-provider-classes | function or string | Asynchronous function (or module exporting an asynchronous function) returning the list of data provider classes (see below) |

Data Provider Class

Entities definition and records are made available through JavaScript classes. The class not only defines the entity structure (name and members) but also it gives information about linked entities (through navigation properties). Last but not least, it contains methods to manipulate the entities.

IMPORTANT NOTE : No synchronization mechanism is in place to ensure that concurrent operations (read, create, update or delete) return consistent results. For instance, if the delete implementation takes time, it is possible to do a concurrent read that will return the entity while it is being deleted.

(optional) async EntityClass.get (request, key) : object

Retreives one entity based on its key.

Depending on the entity definition, there might be one or multiple fields in the key :

  • When only one field is composing the key, the key value is passed.
  • Otherwise, a dictionary mapping each property composing the key to the expected value is passed.

If a falsy value is returned, the entity is considered not existing.

This method is optional : when not defined, the handler will use EntityClass.list

async EntityClass.list (request, filters) : []

or async EntityClass.list (request) : []

Retreives all entities or a filtered list, expected result is an object array.

Based on the method signature, the filters might be either passed or applied internally after getting all entities.

Filters definition is based on the structure gpf.typedef.filterItem and refer to class properties (rather than ODATA properties).

NOTE : the contains operator is not implemented.

This method is used for most READ operations. The following ODATA parameters are handled internally :

  • $select for attributes selection
  • $sort for sorting entries
  • $top and $skip for paging

(optional) async EntityClass.create (request, properties) : object

Creates a new entity, it must return the created entity.

The properties parameter is a dictionary containing the deserialized values indexed by their class properties (rather than ODATA properties).

Besides basic type checking done upon deserializing the properties, no validation is applied before calling the method.

This method is optional : when not defined, the entity set is not creatable and any creation attempt will fail.

async EntityClass.update (request, entity, updates)

Updates an existing entity.

The updates parameter is a dictionary listing the class properties that are updated (rather than ODATA properties). Wheter the client call uses PUT or MERGE, only the relevant updates are passed to this method.

When the client call uses PUT and a property is missing, the updates parameter associate the class property to undefined.

Besides basic type checking done upon deserializing the updates, no validation is applied before calling the method.

This method is optional : when not defined, the entity set is not updatable and any update attempt will fail.

async EntityClass.delete (request, key)

Deletes an existing entity.

This method is optional : when not defined, the entity set is not deletable and any delete attempt will fail.

Attributes

To change the way entities are exposed through the ODATA service, several attributes (or decorators) must be used.

First, the gpf.attributes.Serializable Attribute decides which properties are exposed by defining their ODATA name and type.

The types are mapped as detailled below :

| gpf.serial.types | OData type | |---|---| | string | Edm.String | | integer | Edm.Int64 | | datetime | Edm.DateTime |

Then, the following attributes can be used to provide additional information.

reserve-odata/attributes/Entity (name, [setName])

Can be used to define the entity name as well as the entity set name.

reserve-odata/attributes/Key ()

Specifies which properties are composing the key of the entity.

NOTE : Key attributes are also filterable.

reserve-odata/attributes/Sortable ()

Can be used to flag a sortable property.

reserve-odata/attributes/Filterable ()

Can be used to flag a filterable property.

Supported APIs

GET $metadata

Returns the XML schema description.

GET <EntitySet>

Returns entities.

Supports: $filter, $sort, $select, $skip, $stop, $expand

GET <EntitySet>(<Key values>)

Returns one entity.

Supports: $select, $expand

GET <EntitySet>(<Key values>)/<navigationProperty>

Returns one or multiple entities.

Supports: $filter, $sort, $select, $skip, $stop, $expand

POST <EntitySet>

Creates a new entity.

PUT <EntitySet>(<Key values>)

Updates an entity.

MERGE <EntitySet>(<Key values>)

Updates an entity using differential update.

Examples

The code is fully tested, the mocha suite provides examples for each feature :