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

ts-odata-v4-server

v0.4.4

Published

TS OData V4 Server

Downloads

14

Readme

TS OData V4 Server

TS OData V4 server for node.js and Typescript based on odata-v4-server

Features

  • OASIS Standard OData Version 4.0 server
  • usable as a standalone server, as an Express router, as a node.js stream or as a library
  • expose service document and service metadata - $metadata
  • setup metadata using decorators or metadata JSON
  • supported data types are Edm primitives, complex types, navigation properties
  • support create, read, update, and delete entity sets, action imports, function imports, collection and entity bound actions and functions
  • support for full OData query language using odata-v4-parser
    • filtering entities - $filter
    • sorting - $orderby
    • paging - $skip and $top
    • projection of entities - $select
    • expanding entities - $expand
  • support sync and async controller functions
  • support async controller functions using Promise, async/await or ES6 generator functions
  • support result streaming
  • support media entities

Controller and server functions parameter injection decorators

  • @odata.key
  • @odata.filter
  • @odata.query
  • @odata.context
  • @odata.body
  • @odata.result
  • @odata.stream

Example server

  • server file :
@odata.controller(ProductsController, true)
export class Server extends ODataServer {}
  • controller file :
export class ProductsController extends ODataController {
  /**
   *  Get All products
   * @param query
   * @returns products
   */
  @odata.GET
  async select(@odata.query $query: ODataQuery): Promise<Product[]> {
    const db = await connect();
    const query = createQuery($query);
    const { rows } = await db.query(query.from('"Products"'), query.parameters);
    return convertResults(rows);
  }

  /**
   *  Get one product by id
   * @param key
   * @param query
   * @returns
   */
  @odata.GET
  async selectOne(
    @odata.key key: number,
    @odata.query query: ODataQuery
  ): Promise<Product> {
    const db = await connect();
    const sqlQuery = createQuery(query);
    const { rows } = await db.query(
      `SELECT ${sqlQuery.select} FROM "Products"
                                     WHERE "Id" = $${
                                       sqlQuery.parameters.length + 1
                                     } AND
                                           (${sqlQuery.where})`,
      [...sqlQuery.parameters, key]
    );
    return convertResults(rows)[0];
  }
}
  • index file :
import { Server } from "./server";
require("dotenv").config();

// Setup metadata schema
Server.$metadata(your_schema_file);
// Start ODATA server
const port = parseInt(process.env.PORT, 10) || 3000;
Server.create("/odata", port).addListener("listening", () => {
  console.log(`Odata server listening on port ${port} 🚀`);
});

Response example

Path : http://localhost:3000/odata/Categories

Method : GET

{
  "@odata.context": "http://localhost:3000/odata/$metadata#Categories",
  "value": [
    {
      "Id": 1,
      "Name": "Beverages",
      "Description": "Soft drinks"
    },
    {
      "Id": 2,
      "Name": "Grains/Cereals",
      "Description": "Breads"
    },
    {
      "Id": 3,
      "Name": "Meat/Poultry",
      "Description": "Prepared meats"
    },
    {
      "Id": 4,
      "Name": "Produce",
      "Description": "Dried fruit and bean curd"
    },
    {
      "Id": 5,
      "Name": "Seafood",
      "Description": "Seaweed and fish"
    },
    {
      "Id": 6,
      "Name": "Condiments",
      "Description": "Sweet and savory sauces"
    },
    {
      "Id": 7,
      "Name": "Dairy Products",
      "Description": "Cheeses"
    },
    {
      "Id": 8,
      "Name": "Confections",
      "Description": "Desserts"
    }
  ]
}