ShaneGH / magic-odata

Magical OData client generation for typescript
MIT License
1 stars 0 forks source link
browser generate-code nodejs odata odata-client odatav4 typescript

magic-odata

Magical OData client generation for typescript. No more string. No more any!

Node.js CI NPM Coverage Status License

Install

npm i magic-odata-code-gen --save-dev; npm i magic-odata-client;

Generate

node node_modules/magic-odata-code-gen/dist/index.js --metadataUrl "https://raw.githubusercontent.com/ShaneGH/magic-odata/main/docs/sampleOdataMetadata.xml"

Use

// import a generated client
import { ODataClient } from "./odataClient.js"

// create a client instance
const oDataClient = new ODataClient({
    // inject a basic Http client
    request: (input, init) => fetch(input, init),

    // add a root URI
    uriRoot: "https://my.odata.server/odata"
})

// use the client!
const popularBlogPosts = oDataClient.BlogPosts
    // Use object deconstruction to choose query tools
    .withQuery((blogPost, {
        $orderby: {orderBy}, 
        $skip, 
        $top
    }) => [ 
        // Combine query tools and fluent operations to build a query
        blogPost.Comments.$count.gt(100).or(blogPost.Likes.gt(100)),
        orderBy(blogPost.Name),
        $skip(0),
        $top(10)
    ])
    .get();

Why?

Write safe, statically typed odata queries in typescript. No more string. No more any!

Features

See Features.md

Contributing

See Contributing.md