GithubHelp home page GithubHelp logo

nordicsemiconductor / lwm2m-types-js Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 3.39 MB

TypeScript type definitions and JSON schema for the objects defined in the LwM2M Object Registry.

Home Page: https://github.com/NordicSemiconductor/lwm2m-types-js#readme

License: BSD 3-Clause "New" or "Revised" License

TypeScript 99.95% Shell 0.01% JavaScript 0.03%
nrf-asset-tracker lwm2m json-schema

lwm2m-types-js's Introduction

LwM2M TypeScript type definitions and JSON schema npm version

Test and Release semantic-release Renovate Mergify Status Commitizen friendly code style: prettier ESLint: TypeScript

TypeScript type definitions and JSON schema for the objects defined in the LwM2M Object Registry.

This is useful if you need to validate a JSON representation of those objects.

Installation

npm ci
// Clone LwM2M object registry
git clone https://github.com/OpenMobileAlliance/lwm2m-registry.git --depth 1
npm test

Usage

See example.ts

JSON document structure

LwM2M values are encoded as a JSON document, where the key is an extended version of the LwM2M URN: <ObjectID>:<ObjectVersion>@<LwM2MVersion> (where ObjectVersion and/or LwM2MVersion can be omitted if it is 1.0).

Example

Building the types

git clone https://github.com/OpenMobileAlliance/lwm2m-registry.git --depth 1
npx tsx cli/generate-types.ts
npx tsx cli/generate-json-schema.ts
# Format the source
npx prettier --write ./
# Make sure result compiles
npx tsc
# Compile JS exports
npx swc -d types-dist ./types
# Make sure example runs
npx tsx ./example.ts

lwm2m-types-js's People

Contributors

coderbyheart avatar mlopezj avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

mlopezj

lwm2m-types-js's Issues

[JSON Schema] Express Time resource as custom type 'time'

Time Unix Time. A signed integer
representing the number of seconds since
Jan 1st, 1970 in the UTC time zone.
Represented as an ASCII
integer.

For example, 1476186613
seconds since Jan 01 1970,
which represents Tuesday,
11-Oct-16 11:50:13 UTC,
are represented as the
ASCII string
"1476186613", which has
10 characters/bytes.

Same representation as Integer.

Page 96 http://www.openmobilealliance.org/release/lightweightm2m/V1_0-20170208-A/OMA-TS-LightweightM2M-V1_0-20170208-A.pdf

Example

add type: time, user-defined keywords are supported in AJV: https://ajv.js.org/keywords.html

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "$id": "https://github.com/NordicSemiconductor/lwm2m-types-js/blob/saga/LwM2MDocument.schema.json",
  "title": "LwM2M JSON Schema",
  "description": "JSON schema for expressing LwM2M resources as JSON",
  "properties": {
    "6": {
      "properties": {
        "5": {
          "type": "time",
          "minimum": 1000000000,
          "title": "Timestamp",
          "description": "The timestamp of when the location measurement was performed. Unix Time. A signed integer representing the number of seconds since Jan 1 st, 1970 in the UTC time zone."
        },
      },
    },
  },
}

Update readme with steps to installation

Right now, installation steps are

npm ci
npm test

However after follow those steps, the result is

Screenshot 2023-01-23 at 19 12 06

Because it is needed to clone LwM2M object registry first before run the tests

git clone https://github.com/OpenMobileAlliance/lwm2m-registry.git  --depth 1

Bug: resources defined as multiple instances are not defined as array type

Resource with id 7 from Device object (3) has the following specifications:

/**
 * Power Source Voltage
 *
 * Present voltage for each Available Power Sources Resource Instance. The unit
 * used for this resource is in mV.
 *
 * ID: 7
 * MultipleInstances: true
 * Mandatory: false
 */

The Document Schema generated by the library defines it as an array:

"7": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "integer" },
          "title": "Power Source Voltage",
          "description": "Present voltage for each Available Power Sources Resource Instance. The unit used for this resource is in mV."
        },

But in order with its type definition, it is a number:

type PowerSourceVoltage_7 = number

When the expected would be an array of numbers

type PowerSourceVoltage_7 = number[]

because it is a multiple instance.

The schema defines it as an array, so it is not a problem when checking the veracity of it.

const input = {
     [Device_3_urn]: {
		'0': 'Nordic Semiconductor ASA',
		'1': 'Thingy:91',
		'2': '351358815340515',
		'3': '22.8.1+0',
		'7': [80],
		'11': [0],
		'13': 1675874731,
		'16': 'UQ',
		'19': '3.2.1',
	}
}

const maybeValidLwM2M = validate(input)
if ('errors' in maybeValidLwM2M)
     return { error: new Error(JSON.stringify(maybeValidLwM2M.errors)) }
return { result: true } // this returns here

But it is an issue when using the type definition

const device: Device_3 = {
	'0': 'Nordic Semiconductor ASA',
	'1': 'Thingy:91',
	'2': '351358815340515',
	'3': '22.8.1+0',
	'7': [2754], // Type 'number[]' is not assignable to type 'number'.
	'11': [0], // Type 'number[]' is not assignable to type 'number'
	'13': 1675874731,
	'16': 'UQ',
	'19': '3.2.1',
}

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Fallback to renovate.json file as a preset is deprecated, please use a default.json file instead.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/code-style.yaml
  • actions/checkout v4
  • actions/setup-node v3
  • actions/cache v3
  • peter-evans/create-pull-request v5
  • ubuntu 22.04
.github/workflows/sync-issue-labels.yaml
  • actions/checkout v4
  • ubuntu 22.04
.github/workflows/test-and-release.yaml
  • actions/checkout v4
  • actions/setup-node v3
  • actions/cache v3
.github/workflows/update-definitions.yaml
  • actions/checkout v4
  • actions/setup-node v3
  • actions/cache v3
  • peter-evans/create-pull-request v5
  • ubuntu 22.04
.github/workflows/update-repo-info.yaml
  • actions/checkout v4
  • ubuntu 22.04
npm
package.json
  • ajv 8.12.0
  • @commitlint/config-conventional 18.4.3
  • @nordicsemiconductor/asset-tracker-cloud-code-style 12.0.113
  • @nordicsemiconductor/eslint-config-asset-tracker-cloud-typescript 16.0.23
  • @sinclair/typebox 0.31.28
  • @swc/cli 0.1.63
  • @swc/core 1.3.99
  • @swc/jest 0.2.29
  • @types/jest 29.5.10
  • @types/xml2js 0.4.14
  • @typescript-eslint/eslint-plugin 6.12.0
  • chalk 5.3.0
  • eslint-config-prettier 9.0.0
  • eslint-plugin-import 2.29.0
  • eslint-plugin-prefer-arrow 1.2.3
  • eslint-plugin-unicorn 49.0.0
  • fluent-json-schema 4.2.1
  • husky 8.0.3
  • jest 29.7.0
  • prettier 3.1.0
  • tsmatchers 5.0.2
  • tsx 4.5.0
  • typescript 5.2.2
  • xml2js 0.6.2
  • node >=20
  • npm >=9

  • Check this box to trigger a request for Renovate to run again on this repository

Current range of Date type do not support valid dates

Current range is

  • Minimum: 1111111111
  • Maximum: 9999999999

However,

  • 1970-01-01T00:00:00Z is 0 in Unix Time format
  • 1960-01-01T00:00:00Z is -315619200000 in Unix Time format

Unix time has it own limitations and range should address to those.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.