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

easy-odatajs

v1.0.3

Published

easy to generate the odata URLs

Downloads

2

Readme

esay-odaajs

It can be used as the URL generater to genarete the query for doata service

Install it

npm i easy-odatajs

How to genreate the odata service URL

create an query object which simplify the odata query.

query template:

<value> : normally is string value, can be null

<fieldName> : the field name you want to select

<Integer>: integer value

<operator>: here is the allowed operater ge,le,gt,lt,lt,ne, eq

<format> : format value can be json, xml

<sortOption> : sortOption can be asc, desc

{
  "filter":{
    "<fieldName>" : "<value>",
    "<fieldName>" : "<value>",
    "<fieldName>" : ["<value>","<value>","<value>"...]
  },
  "fitlerOption": {
    "<fieldName>": "<operator>",
    "<fieldName>" : {
      "low":  { "operator" : "<operator>", "value": "<value>"  },
      "high": { "operator" : "<operator>", "value": "<value>"  }
    }
  },
  "pagination": { 
    "current" :  <Integer>,  
    "pageSize" : <Integer> 
  },
  "select":["<fieldName>", "<fieldName>", "<fieldName>", "<fieldName>"...],
  "orderby": { 
    "<fieldName>": "<sortOption>", 
    "<fieldName>": "<sortOption>" 
  },
  "format": "<format>",
  "search": "<value>"
}

here is odata query example, and here is the How to use

{
  "filter": { 
    "Country" : "Germany", 
    "City": "Berlin" ,
    "PostalCode":null,
    },
  "filterOption" : {
    "City" : "ne",
    "PostalCode" : {
      "low"  : { "operator" : "ge", "value": "100" },
      "high" : { "operator" : "le", "value": "102" }
    }
  },
  "pagination": {
    "current" : 1, 
    "pageSize" : 10 
  },
  "orderby": {
    "Country" : "asc",
    "CustomerID" : "desc"
  },
  "select" : ["CustomerID", "CompanyName", "ContactName", "ContactTitle", "Address", "City", "Region", "PostalCode"],
  "format" : "json"
}

Example Code :

  
  //initialize the odate service URL
  let testOdataServiceURL = "https://services.odata.org/V2/Northwind/Northwind.svc";
  let entity = "Customers";
  let odataQuery = new ODataQuery(testOdataServiceURL, entity);

  //prepreate the query infoimation base on the template request
  let query = {
    "filter" : { 
      "Country" : "Germany",
      "City": "Berlin" 
    }
    ...
  }

  //get odata query URL
  let odataQueryURL = odataQuery.createQuery(query).getOdataQueryURL();
  ...
  //user the ajax or other javascript library to get the corresponding response from odata request
  ..

How to genreate the odata batch body

if we want to create mutiple enitites or update multiple entities in one time , we could use odata batch functionanlites

here the steps to genter the odata batch :

batch request Template :

<method> : http method , can be POST, PATCH, DELETE

<entity> : entity name

<request>: the request which create new entity or update entity, if method is DELETE, the request can be null

{
  "method" : "<method>",
  "entity" : "<entity>",
  "request": "<request>"
}

Example Code


//prepre the correspoding request

let odataBatch = new OdataBatch();

//get headerinfo and add header to request
let header  = odataBatch.getHeaderInfo();

//prepare the batch request base on the reuqest

  let postRequest = {
      method : "POST",
      entity : "Customers",
      request : {
          "CompanyName" : "Wolfgong",
          "ContactName" : "Smith"
      }
  }
  let patchRequest = {
      method : "PATCH",
      entity : "Customers('ALFKI')",
      request : {
          "CompanyName" : "Name1",
          "ContactName" : "Name2"
      }
  }
  
  let deleteRequest = {
      method : "DELETE",
      entity : "Customers('ALFKI')",
  }

let aBatchRequest = []
aBatchRequest.push(postRequest, patchRequest, deleteRequest); // add the corresponding request 

//creat the batch data for the request body
let odataBatch = new OdataBatch();
let batchData = odataBatch.createBatchData(aBatchRequest).getBatchData();

//set the header and body and set the request to do the create / update / delete operations 
...