0.5.0 • Published 18 days ago

@odata2ts/odata-core v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
18 days ago

npm (scoped)

OData Core

Bundles central and constant information about OData as protocol, like the versions or data types. As such this package has no dependencies and can be used for any purpose.

Contains enumerations of

  • the main OData versions, i.e. V2 and V4
  • all V2 data types
  • all V4 data types

Contains interfaces for

  • V2 Response Models
  • V4 Response Models

Installation

npm install --save @odata2ts/odata-core

V4 Data Types

OData V4 TypeDescriptionURL formatURL ExampleJSON type
Edm.Booleanboolean valueliteraltruefalseboolean
Edm.Stringstring valuequoted'Some Test'string
Edm.Byteunsigned 8-bit integer valueliteral1number
Edm.SBytesigned 8-bit integer valueliteral-1number
Edm.Int16signed 16-bit integer valueliteral123number
Edm.Int32signed 32-bit integer valueliteral123number
Edm.Int64signed 64-bit integer valueliteral123number
Edm.Singlefloating point number with 7 digits precisionliteral1.1number
Edm.Doublefloating point number with 15 digits precisionliteral1.2number
Edm.Decimalnumeric values with arbitrary precision and scaleliteral12.22number
Edm.Guid16-byte (128-bit) unique identifier valueliteral...string
Edm.DurationdurationliteralPT12H59M10S P1Y PT12.123Sstring
Edm.TimeOfDayspecific time of dayliteral12:59:1012:15 12:15:03.123string
Edm.Datespecific dayliteral2022-12-31string
Edm.DateTimeOffsetspecific point in timeliteral2022-12-31T23:59:59Z 2022-12-31T23:59:59+02:00string
Edm.Binaryfixed or variable length binary database64 encoded string
Edm.Streammost filter operations don't work here also exclusive handling
Edm.Geography.*
Edm.Geometry.*

V2 Data Types

The special thing about V2 OData services is, that we have to differentiate between using OData types in the URL or in JSON, since they are formatted differently:

  • URL: values in filter queries ($filter) or function parameters (which are query parameters)
  • JSON: values in request or response bodies

The following table lists information about all V2 data types according to the official resources used.

For URL usage, see chapter 6 "Primitive Data Types" of the V2 overview document. This is the most authoritative resource despite it's lack of being a true specification.

For JSON usage, see chapter 4 "Primitive Types" of the document about the V2 JSON format.

OData V2 TypeDescriptionURL formatURL exampleJSON typeJSON example
Edm.Booleanboolean valueliteraltruebooleantrue
Edm.Stringstring valuequoted'test'string"test"
Edm.Byteunsigned 8-bit integer valueliteral1string"1"
Edm.SBytesigned 8-bit integer valueliteral-1string"-1"
Edm.Int16signed 16-bit integer valueliteral123number123
Edm.Int32signed 32-bit integer valueliteral123number123
Edm.Int64signed 64-bit integer valuetype suffix "L"123Lstring"123"
Edm.Singlefloating point number with 7 digits precisiontype suffix "f"1.1fstring"1.1"
Edm.Doublefloating point number with 15 digits precisiontype suffix "d"1.2dstring"1.2"
Edm.Decimalnumeric values with arbitrary precision and scaletype suffix "M" or "m"12.22Mstring"12.22
Edm.Guid16-byte (128-bit) unique identifier valuetype prefix "guid"guid'xxx...'string"xxx..."
Edm.Timeday time duration representing time of daytype prefix "time"time'PT12H59M10S'string"PT12H59M10S"
Edm.DateTimespecific point in timetype prefix "datetime"datetime'2022-12-31T23:59:59'string"/Date(123...)/"
Edm.DateTimeOffsetspecific point in timetype prefix "datetimeoffset"datetimeoffset'2022-12-31T23:59:59Z'string"2022-12-31T23:59:59+01:00"
Edm.Binaryfixed or variable length binary datatype prefix "X" or "binary"binary'23A'base64 encoded string"..."

Edm.DateTime is quite special in multiple ways: 1) URL and JSON representation are completely different 2) the JSON representation has quite a unique format 3) Edm.DateTime is not really consistent with Edm.DateTimeOffset

Another oddity is Edm.Time, since it is defined as duration (by the way, the static "P" stands for "period"). Now the "spec" states, that it should represent a specific time of day and refers to the "day time duration" as definition.

I think that the definition is flawed for two reasons. First, "day time duration" also allows for specifying a period of days, which doesn't overlap with time of day. Second, a duration might be able to represent a time of day, in the sense that a duration of 6 hours and 12 minutes might also represent "06:12", but both data types usually have different restrictions. Time of day requires the specification of hours and minutes, while duration might specify any of its parts, e.g. only seconds "PT12S".

Documentation

No further documentation currently.

Support, Feedback, Contributing

This project is open to feature requests, suggestions, bug reports, usage questions etc. via GitHub issues.

Contributions and feedback are encouraged and always welcome.

See the contribution guidelines for further information.

License

MIT - see License.