Socket
Socket
Sign inDemoInstall

@balena/odata-parser

Package Overview
Dependencies
0
Maintainers
3
Versions
80
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @balena/odata-parser

An OData parser written in OMeta


Version published
Maintainers
3
Install size
242 kB
Created

Changelog

Source

v3.0.7

(2024-04-13)

  • Update dependency husky to v9 [Self-hosted Renovate Bot]

Readme

Source

odata-parser

npm version

An OData parser written in OMeta.

OData is a protocol build on top of REST and HTTP, it's goal is to provide a uniform and reliable way to access and navigate resources.
For a full specification of the protocol refer to this link

This module is a part of the odata-compiler

The parser takes an input string representing the odata request and returns an object {tree, binds} if the parse is successful.

Imagine wanting the access a resource which is stored at as a depth two child of some other resource, the corresponding odata query would be something like /parent/child/granchild
This string is parsed into a tree where every intermediate resource is a node, each node contains the following properties

  • resource: The name of resource
  • key: An object containing the integer index at which the bind for the resource, if any, can be found
  • link: A reference to a child node if specified via the $links option
  • property: A reference to a child node if present
  • count: A boolean value representing if the $count option was specified for the resource
  • options: An object containing any other query options specified in the odata request

The binds array contains all the reference to primitive values contained in the odata request, example of such primitive values are: Reals, Booleans, Dates, Text, ecc.
These binds are stored in the binds array and are referenced in the tree by the integer index where the bind resides in this array.

Examples

input: /model

output:

{ tree:
   { resource: 'model',
     key: undefined,
     link: undefined,
     property: undefined,
     count: undefined,
     options: undefined }

input: /model(1)/child

output:

{ tree:
   { resource: 'model',
     key: { bind: 0 },
     link: undefined,
     property:
      { resource: 'child',
        key: undefined,
        link: undefined,
        property: undefined,
        count: undefined,
        options: undefined },
     count: undefined,
     options: undefined },
  binds: [ [ 'Real', 1 ] ] }

input: /model/$count?$filter=id gt 5

output:

{ tree:
   { resource: 'model',
     key: undefined,
     link: undefined,
     property: undefined,
     count: true,
     options: { '$filter': [ 'gt', { name: 'id', property: undefined }, { bind: 0 } ] } },
  binds: [ [ 'Real', 5 ] ] }

Tests

Tests can be found under the test/ folder, to run the whole suite use npm test

FAQs

Last updated on 13 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc