# @balena/odata-parser

> An OData parser written in OMeta

Latest version **4.3.5** (published 2026-06-27) · BSD license · 0 weekly downloads

## Install

```sh
npm install @balena/odata-parser
pnpm add @balena/odata-parser
yarn add @balena/odata-parser
bun add @balena/odata-parser
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.3.5 |
| Published | 2026-06-27 |
| First published | 2020-05-11 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.13.0 |
| Dependencies | 0 |
| Unpacked size | 271.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6 |
| Maintainers | balena.io, page |

## Links

- npm: https://www.npmjs.com/package/@balena/odata-parser
- Repository: https://github.com/balena-io-modules/odata-parser
- Homepage: https://github.com/balena-io-modules/odata-parser#readme
- Issues: https://github.com/balena-io-modules/odata-parser/issues
- npm.io page: https://npm.io/package/@balena/odata-parser

## Recent versions

- 4.3.5 (latest) — 2026-06-27
- 4.3.5-build-renovate-lint-staged-17-0-x-ee3b419f2ab388f8bc12e828f44338ceb5b3e381-1 (build-renovate-lint-staged-17-0-x) — 2026-06-27
- 4.3.4-build-renovate-lint-staged-17-x-77a7a11a8aad98983befe589c0b535bd1bdfbd08-1 (build-renovate-lint-staged-17-x) — 2026-06-11
- 4.3.3-build-joshbwlng-lintstagedrc-4830eaf70bae06c0d95411ebc7805006214324ca-1 (build-joshbwlng-lintstagedrc) — 2026-06-11
- 4.3.2-build-renovate-chai-6-x-d9a96172bab5e8091c6120cf58d03e3d5a919659-1 (build-renovate-chai-6-x) — 2026-06-10
- 4.3.1-build-renovate-pin-dependencies-e83ae536fe82f63d4f2a14908b54dc08bacf2c47-1 (build-renovate-pin-dependencies) — 2026-06-10
- 4.3.1-build-jaomaloy-groupby-via-apply-f822db9b0eb8b2b02980d0ed7be3102ca40a5343-1 (build-jaomaloy-groupby-via-apply) — 2026-06-09
- 4.3.1-build-renovate-chai-5-x-b6b03628ab482e7771384eab985df26a12c1c78a-1 (build-renovate-chai-5-x) — 2026-06-03
- 4.3.0-build-add-param-alias-bind-2f357db4d0308f7af528c071a959dea097e11a7b-1 (build-add-param-alias-bind) — 2026-06-03
- 4.2.31-build-renovate-major-6-chai-3f08fdcc2164d5d432dc7acbcf4f63fb1ca24cec-1 (build-renovate-major-6-chai) — 2026-05-08
- 4.2.30-build-avoid-duplicate-check-53902d15f20b2fe4d5e97265eeac0e5ef5186580-1 (build-avoid-duplicate-check) — 2026-05-07
- 4.2.29-build-simplify-arg-checking-6584e1b45101de7ae00506a6243e47093671e36c-1 (build-simplify-arg-checking) — 2026-05-06
- 4.2.28-build-kyle-revert-flowzone-to-master-a58f209394f140eaaa2a6d85eb5cf8249c93d48d-1 (build-kyle-revert-flowzone-to-master) — 2026-03-26
- 4.2.27-build-renovate-github-actions-cec7c302ccdb577b397d343f1ebb161d94582af8-1 (build-renovate-github-actions) — 2026-03-26
- 4.2.12-build-remove-lodash-83043192219fb01d9c7968ab633d7afb529e5aca-1 (build-remove-lodash) — 2026-03-12
- … 206 more at https://npm.io/package/@balena/odata-parser/versions

## README

## odata-parser

[![npm version](https://badge.fury.io/js/%40balena%2Fodata-parser.svg)](https://badge.fury.io/js/%40balena%2Fodata-parser)

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](http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html)


This module is a part of the [odata-compiler](https://github.com/balena-io-modules/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`

---
_Source: https://npm.io/package/@balena/odata-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
