Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@odata2ts/converter-v2-to-v4

odata2ts29.8kMIT0.5.7TypeScript support: included

A set of odata2ts compatible converters to convert certain OData V2 types to their V4 analog

odata2ts, odata, odata v2, odata v4, converter, datetime, datetimeoffset, time, typescript, ts, javascript, js, types, data types

readme

GitHub Workflow Status Coveralls

Type Converter Package for odata2ts

This monorepo contains all modules relevant for odata2ts to realize data type conversions: From OData types to native JS types or third-party types and back:

  • the converter-runtime package realizes the loading process of converters
  • the converter-api package specifies converters and serves as contract between odata2ts and any converter implementation

It also contains converters you can use:

  • V2-to-V4 Converters
    • V2 numeric types are converted from string to number
    • Edm.Int64 and Edm.Decimal are not converted and remain type string
    • Edm.DateTime is converted to Edm.DateTimeOffset, i.e. proper ISO 8601 date and time presentation
    • Edm.Time is by default converted to Edm.TimeOfDay (ISO 8601 time), but can also be relabeled as Edm.Duration
  • Common Converters
    • Edm.DateTimeOffset: JavaScript Date type
    • Edm.Duration: simple duration object
    • Edm.Int64: JavaScript bigint type
  • Luxon Converters
    • Edm.DateTimeOffset: Luxon's DateTime type
    • Edm.Date: Luxon's DateTime type
    • Edm.TimeOfDay: Luxon's DateTime type
    • Edm.Duration: Luxon's Duration type
  • UI5 V2 Converters
    • type alignment with UI5 V2 ODataModel (sap.ui.model.odata.v2.ODataModel)

Converters can be picked as a package (using the default converter set) or individually by specifying each converter. If different converters handle the same data type, then the last converter wins.

Converters are chainable. This makes the v2-to-v4 converter utterly useful, because it spares other converters the work and headaches to cope with V2 types and lets them focus on converting V4 data types. For example, every Edm.DateTime gets converted to Edm.DateTimeOffset, so that the Luxon and the common converter only need to handle Edm.DateTimeOffset.

Background

While some OData types (Edm.String, Edm.Boolean, ...) can easily and perfectly be mapped to native JS types, more advanced types are simply strings:

  • Edm.DateTimeOffset: "1999-31-12T23:59:59Z"
  • Edm.Duration: "PT10H"

As you can imagine, there are countless third-party libs and custom data structures which could be used in these cases. Thus, the choice of how to map data types must be left open to the user.

So either use an existing converter or roll your own.

Documentation

Converter Documentation

Main Documentation of odata2ts: https://odata2ts.github.io/

Support, Feedback, Contributing

If you have any sorts of questions use GitHub Discussions of the main odata2ts repository.

This project is open to feature requests, suggestions, bug reports, and the like via GitHub issues of the main odata2ts repository.

Contributions and feedback are encouraged and always welcome.

See the contribution guidelines for further information.

Spirit

This project has been created and is maintained in the following spirit:

  • adhere to the OData specification as much as possible
    • support any OData service implementation which conforms to the spec
    • allow to work around faulty implementations if possible
  • stability matters
    • exercise Test Driven Development
    • bomb the place with unit tests (code coverage > 95%)
    • ensure that assumptions & understanding are correct by creating integration tests

License

MIT - see License.

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.5.7 (2025-02-08)

Bug Fixes

  • deployment without compiled code (#36) (b2da86c)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @odata2ts/converter-api bumped from ^0.2.5 to ^0.2.6

0.5.6 (2025-02-08)

Bug Fixes

  • pass along ISO8601 dates when using convertFrom (ae7b407)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @odata2ts/converter-api bumped from ^0.2.4 to ^0.2.5

0.5.5 (2025-02-08)

Bug Fixes

  • don't convert Edm.DateTime for URL values (#26) (311e5e4)

Dependencies

  • The following workspace dependencies were updated
    • dependencies
      • @odata2ts/converter-api bumped from ^0.2.3 to ^0.2.4

0.5.4 (2024-12-18)

Note: Version bump only for package @odata2ts/converter-v2-to-v4

0.5.3 (2024-08-25)

Note: Version bump only for package @odata2ts/converter-v2-to-v4

0.5.2 (2024-08-24)

Note: Version bump only for package @odata2ts/converter-v2-to-v4

0.5.1 (2024-08-14)

Bug Fixes

  • add ".js" to all relative imports (#21) (808d021)

0.5.0 (2024-08-13)

Code Refactoring

  • replace jest with vitest & switch to ESM (#18) (29754ab)

BREAKING CHANGES

  • switch to ES modules which might break things.

0.4.0 (2023-08-30)

Code Refactoring

  • v2-to-v4: convert Ed.Time to Edm.TimeOfDay by default instead of Edm.Duration (#16) (a3ffe54)

BREAKING CHANGES

  • v2-to-v4: different converter used by default

0.3.1 (2023-07-21)

Note: Version bump only for package @odata2ts/converter-v2-to-v4

0.3.0 (2023-07-21)

Features

  • v2-to-v4: bigNumberNoopConverter (#8) (e16c4f5)

0.2.1 (2023-05-23)

Note: Version bump only for package @odata2ts/converter-v2-to-v4

0.2.0 (2023-05-22)

Bug Fixes

  • add package test to assure ids and exports match (4c70269)
  • converter-v2-to-v4: don't convert Int64 or Decimal to number (5564504)

BREAKING CHANGES

  • converter-v2-to-v4: we don't handle Int64 and Decimal anymore. It rarely makes sense to treat them as JS numbers (possible precision loss). So here we diverge from how V4 does things, but with a good reason

0.1.4 (2023-04-13)

Note: Version bump only for package @odata2ts/converter-v2-to-v4

0.1.3 (2023-04-08)

Note: Version bump only for package @odata2ts/converter-v2-to-v4

0.1.2 (2023-01-07)

Bug Fixes

0.1.1 (2022-12-21)

Bug Fixes

  • converter-v2-to-v4: epoch time might be negative (995b9fa)

0.1.0 (2022-12-18)

Note: Version bump only for package @odata2ts/converter-v2-to-v4