@hello.nrfcloud.com/proto-map 5.3.2 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api/Context.ts CHANGED
@@ -3,6 +3,9 @@ const baseURL = `https://github.com/hello-nrfcloud/proto-map`
3
3
  export const Context = {
4
4
  device: new URL(`${baseURL}/device`),
5
5
  devices: new URL(`${baseURL}/devices`),
6
+ history: {
7
+ resource: new URL(`${baseURL}/history/resource`),
8
+ },
6
9
  shareDevice: {
7
10
  request: new URL(`${baseURL}/share-device-request`),
8
11
  ownershipConfirmed: new URL(`${baseURL}/share-device-ownership-confirmed`),
package/api/DeviceId.ts CHANGED
@@ -3,10 +3,12 @@ import { Type } from '@sinclair/typebox'
3
3
  export const DeviceId = Type.RegExp(/^[a-zA-Z0-9:_-]{1,128}$/, {
4
4
  title: 'Device ID',
5
5
  description: 'Must follow the AWS IoT limitations for Thing names.',
6
+ examples: ['oob-352656166666905'],
6
7
  })
7
8
 
8
9
  export const PublicDeviceId = Type.RegExp(/^[a-z]{8}-[a-z]{8}-[a-z]{8}$/, {
9
10
  title: 'Public Device ID',
10
11
  description:
11
12
  'This is the format of @nordicsemiconductor/random-words which is used for public IDs.',
13
+ examples: ['pentacid-coxalgia-backheel'],
12
14
  })
package/api/Devices.ts CHANGED
@@ -1,31 +1,19 @@
1
1
  import { Type } from '@sinclair/typebox'
2
2
  import { Context } from './Context.js'
3
3
  import { PublicDeviceId } from './DeviceId.js'
4
- import { LwM2MObjectID, models } from '@hello.nrfcloud.com/proto-map'
4
+ import { models } from '@hello.nrfcloud.com/proto-map'
5
+ import {
6
+ ObjectID,
7
+ ObjectInstanceID,
8
+ ObjectVersion,
9
+ Resources,
10
+ } from './LwM2M.js'
5
11
 
6
12
  export const LwM2MObjectInstance = Type.Object({
7
- ObjectID: Type.Enum(LwM2MObjectID, {
8
- description:
9
- 'The LwM2M Object IDs defined in @hello.nrfcloud.com/proto-map',
10
- }),
11
- ObjectVersion: Type.Optional(
12
- Type.String({
13
- pattern: '^[0-9]+.[0-9]+$',
14
- default: '1.0',
15
- description:
16
- "The Object Version of an Object is composed of 2 digits separated by a dot '.'.\nSee https://www.openmobilealliance.org/release/LightweightM2M/V1_1_1-20190617-A/OMA-TS-LightweightM2M_Core-V1_1_1-20190617-A.pdf Section 7.2.2",
17
- }),
18
- ),
19
- ObjectInstanceID: Type.Optional(
20
- Type.Integer({
21
- minimum: 0,
22
- default: 0,
23
- }),
24
- ),
25
- Resources: Type.Record(
26
- Type.Integer({ minimum: 0 }),
27
- Type.Union([Type.String(), Type.Number(), Type.Boolean()]),
28
- ),
13
+ ObjectID,
14
+ ObjectVersion: Type.Optional(ObjectVersion),
15
+ ObjectInstanceID: Type.Optional(ObjectInstanceID),
16
+ Resources,
29
17
  })
30
18
 
31
19
  export const Model = Type.Union(
@@ -0,0 +1,36 @@
1
+ import { describe, it } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { validate } from '../validate.js'
4
+ import { ResourceHistory } from './History.js'
5
+ import type { Static } from '@sinclair/typebox'
6
+
7
+ void describe('ResourceHistory', () => {
8
+ void it('should validate', () => {
9
+ const input: Static<typeof ResourceHistory> = {
10
+ '@context':
11
+ 'https://github.com/hello-nrfcloud/proto-map/history/resource',
12
+ query: {
13
+ ObjectID: 14230,
14
+ ObjectVersion: '1.0',
15
+ ObjectInstanceID: 0,
16
+ deviceId: 'bassetto-ennobler-toilless',
17
+ binIntervalMinutes: 15,
18
+ },
19
+ partialInstances: [
20
+ {
21
+ '0': 92.2,
22
+ '99': 1713510000000,
23
+ ts: '2024-04-19T08:45:00.000Z',
24
+ },
25
+ {
26
+ '0': 113.8,
27
+ '99': 1713515400000,
28
+ ts: '2024-04-19T08:30:00.000Z',
29
+ },
30
+ ],
31
+ }
32
+ const maybeValid = validate(ResourceHistory)(input)
33
+ assert.equal('errors' in maybeValid, false)
34
+ assert.deepEqual('value' in maybeValid && maybeValid.value, input)
35
+ })
36
+ })
package/api/History.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { Type } from '@sinclair/typebox'
2
+ import { Context } from './Context.js'
3
+ import {
4
+ ObjectID,
5
+ ObjectInstanceID,
6
+ ObjectVersion,
7
+ Resources,
8
+ } from './LwM2M.js'
9
+ import { PublicDeviceId } from './DeviceId.js'
10
+
11
+ export const ResourceHistory = Type.Object(
12
+ {
13
+ '@context': Type.Literal(Context.history.resource.toString()),
14
+ partialInstances: Type.Array(
15
+ Type.Intersect(
16
+ [
17
+ Resources,
18
+ Type.Object({
19
+ ts: Type.RegExp(
20
+ /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/,
21
+ {
22
+ title: 'Date formatted as ISO 8601',
23
+ examples: ['2024-04-19T08:45:00.000Z'],
24
+ },
25
+ ),
26
+ }),
27
+ ],
28
+ {
29
+ title:
30
+ 'The resources of the object instance and the timestamp the data was received.',
31
+ },
32
+ ),
33
+ ),
34
+ query: Type.Object(
35
+ {
36
+ ObjectID,
37
+ ObjectInstanceID,
38
+ ObjectVersion,
39
+ binIntervalMinutes: Type.Number({
40
+ minimum: 1,
41
+ title: 'The number of minutes the results are binned to.',
42
+ examples: [15],
43
+ }),
44
+ deviceId: PublicDeviceId,
45
+ },
46
+ { title: `The query that was used` },
47
+ ),
48
+ },
49
+ {
50
+ title: 'Resource history',
51
+ description:
52
+ 'Contains historical values of an LwM2M resource for a device.',
53
+ },
54
+ )
package/api/LwM2M.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { Type } from '@sinclair/typebox'
2
+ import { LwM2MObjectID } from 'lwm2m/LwM2MObjectID.js'
3
+
4
+ export const ObjectVersion = Type.String({
5
+ pattern: '^[0-9]+.[0-9]+$',
6
+ default: '1.0',
7
+ examples: ['1.0', '1.1'],
8
+ description:
9
+ "The Object Version of an Object is composed of 2 digits separated by a dot '.'.\nSee https://www.openmobilealliance.org/release/LightweightM2M/V1_1_1-20190617-A/OMA-TS-LightweightM2M_Core-V1_1_1-20190617-A.pdf Section 7.2.2",
10
+ })
11
+
12
+ export const ObjectID = Type.Enum(LwM2MObjectID, {
13
+ description: 'The LwM2M Object IDs defined in @hello.nrfcloud.com/proto-map',
14
+ })
15
+
16
+ export const ObjectInstanceID = Type.Integer({
17
+ minimum: 0,
18
+ default: 0,
19
+ description: 'The LwM2M Object Instance ID',
20
+ examples: [0, 1],
21
+ })
22
+
23
+ export const Resources = Type.Record(
24
+ Type.Integer({ minimum: 0 }),
25
+ Type.Union([
26
+ Type.String({ minLength: 1, title: 'LwM2M string value' }),
27
+ Type.Number({ title: 'LwM2M number value' }),
28
+ Type.Boolean({ title: 'LwM2M boolean value' }),
29
+ ]),
30
+ )
package/api/index.ts CHANGED
@@ -3,3 +3,5 @@ export * from './DeviceId.js'
3
3
  export * from './Devices.js'
4
4
  export * from './ShareDeviceOwnershipConfirmed.js'
5
5
  export * from './ShareDeviceRequest.js'
6
+ export * from './History.js'
7
+ export * from './LwM2M.js'
@@ -2,6 +2,9 @@ var baseURL = "https://github.com/hello-nrfcloud/proto-map";
2
2
  export var Context = {
3
3
  device: new URL("".concat(baseURL, "/device")),
4
4
  devices: new URL("".concat(baseURL, "/devices")),
5
+ history: {
6
+ resource: new URL("".concat(baseURL, "/history/resource"))
7
+ },
5
8
  shareDevice: {
6
9
  request: new URL("".concat(baseURL, "/share-device-request")),
7
10
  ownershipConfirmed: new URL("".concat(baseURL, "/share-device-ownership-confirmed"))
@@ -1,9 +1,15 @@
1
1
  import { Type } from "@sinclair/typebox";
2
2
  export var DeviceId = Type.RegExp(/^[a-zA-Z0-9:_-]{1,128}$/, {
3
3
  title: "Device ID",
4
- description: "Must follow the AWS IoT limitations for Thing names."
4
+ description: "Must follow the AWS IoT limitations for Thing names.",
5
+ examples: [
6
+ "oob-352656166666905"
7
+ ]
5
8
  });
6
9
  export var PublicDeviceId = Type.RegExp(/^[a-z]{8}-[a-z]{8}-[a-z]{8}$/, {
7
10
  title: "Public Device ID",
8
- description: "This is the format of @nordicsemiconductor/random-words which is used for public IDs."
11
+ description: "This is the format of @nordicsemiconductor/random-words which is used for public IDs.",
12
+ examples: [
13
+ "pentacid-coxalgia-backheel"
14
+ ]
9
15
  });
@@ -1,27 +1,13 @@
1
1
  import { Type } from "@sinclair/typebox";
2
2
  import { Context } from "./Context.js";
3
3
  import { PublicDeviceId } from "./DeviceId.js";
4
- import { LwM2MObjectID, models } from "@hello.nrfcloud.com/proto-map";
4
+ import { models } from "@hello.nrfcloud.com/proto-map";
5
+ import { ObjectID, ObjectInstanceID, ObjectVersion, Resources } from "./LwM2M.js";
5
6
  export var LwM2MObjectInstance = Type.Object({
6
- ObjectID: Type.Enum(LwM2MObjectID, {
7
- description: "The LwM2M Object IDs defined in @hello.nrfcloud.com/proto-map"
8
- }),
9
- ObjectVersion: Type.Optional(Type.String({
10
- pattern: "^[0-9]+.[0-9]+$",
11
- default: "1.0",
12
- description: "The Object Version of an Object is composed of 2 digits separated by a dot '.'.\nSee https://www.openmobilealliance.org/release/LightweightM2M/V1_1_1-20190617-A/OMA-TS-LightweightM2M_Core-V1_1_1-20190617-A.pdf Section 7.2.2"
13
- })),
14
- ObjectInstanceID: Type.Optional(Type.Integer({
15
- minimum: 0,
16
- default: 0
17
- })),
18
- Resources: Type.Record(Type.Integer({
19
- minimum: 0
20
- }), Type.Union([
21
- Type.String(),
22
- Type.Number(),
23
- Type.Boolean()
24
- ]))
7
+ ObjectID: ObjectID,
8
+ ObjectVersion: Type.Optional(ObjectVersion),
9
+ ObjectInstanceID: Type.Optional(ObjectInstanceID),
10
+ Resources: Resources
25
11
  });
26
12
  export var Model = Type.Union(Object.keys(models).map(function(s) {
27
13
  return Type.Literal(s);
@@ -0,0 +1,38 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ import { Context } from "./Context.js";
3
+ import { ObjectID, ObjectInstanceID, ObjectVersion, Resources } from "./LwM2M.js";
4
+ import { PublicDeviceId } from "./DeviceId.js";
5
+ export var ResourceHistory = Type.Object({
6
+ "@context": Type.Literal(Context.history.resource.toString()),
7
+ partialInstances: Type.Array(Type.Intersect([
8
+ Resources,
9
+ Type.Object({
10
+ ts: Type.RegExp(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/, {
11
+ title: "Date formatted as ISO 8601",
12
+ examples: [
13
+ "2024-04-19T08:45:00.000Z"
14
+ ]
15
+ })
16
+ })
17
+ ], {
18
+ title: "The resources of the object instance and the timestamp the data was received."
19
+ })),
20
+ query: Type.Object({
21
+ ObjectID: ObjectID,
22
+ ObjectInstanceID: ObjectInstanceID,
23
+ ObjectVersion: ObjectVersion,
24
+ binIntervalMinutes: Type.Number({
25
+ minimum: 1,
26
+ title: "The number of minutes the results are binned to.",
27
+ examples: [
28
+ 15
29
+ ]
30
+ }),
31
+ deviceId: PublicDeviceId
32
+ }, {
33
+ title: "The query that was used"
34
+ })
35
+ }, {
36
+ title: "Resource history",
37
+ description: "Contains historical values of an LwM2M resource for a device."
38
+ });
@@ -0,0 +1,33 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { validate } from "../validate.js";
4
+ import { ResourceHistory } from "./History.js";
5
+ void describe("ResourceHistory", function() {
6
+ void it("should validate", function() {
7
+ var input = {
8
+ "@context": "https://github.com/hello-nrfcloud/proto-map/history/resource",
9
+ query: {
10
+ ObjectID: 14230,
11
+ ObjectVersion: "1.0",
12
+ ObjectInstanceID: 0,
13
+ deviceId: "bassetto-ennobler-toilless",
14
+ binIntervalMinutes: 15
15
+ },
16
+ partialInstances: [
17
+ {
18
+ "0": 92.2,
19
+ "99": 1713510000000,
20
+ ts: "2024-04-19T08:45:00.000Z"
21
+ },
22
+ {
23
+ "0": 113.8,
24
+ "99": 1713515400000,
25
+ ts: "2024-04-19T08:30:00.000Z"
26
+ }
27
+ ]
28
+ };
29
+ var maybeValid = validate(ResourceHistory)(input);
30
+ assert.equal("errors" in maybeValid, false);
31
+ assert.deepEqual("value" in maybeValid && maybeValid.value, input);
32
+ });
33
+ });
@@ -0,0 +1,37 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ import { LwM2MObjectID } from "lwm2m/LwM2MObjectID.js";
3
+ export var ObjectVersion = Type.String({
4
+ pattern: "^[0-9]+.[0-9]+$",
5
+ default: "1.0",
6
+ examples: [
7
+ "1.0",
8
+ "1.1"
9
+ ],
10
+ description: "The Object Version of an Object is composed of 2 digits separated by a dot '.'.\nSee https://www.openmobilealliance.org/release/LightweightM2M/V1_1_1-20190617-A/OMA-TS-LightweightM2M_Core-V1_1_1-20190617-A.pdf Section 7.2.2"
11
+ });
12
+ export var ObjectID = Type.Enum(LwM2MObjectID, {
13
+ description: "The LwM2M Object IDs defined in @hello.nrfcloud.com/proto-map"
14
+ });
15
+ export var ObjectInstanceID = Type.Integer({
16
+ minimum: 0,
17
+ default: 0,
18
+ description: "The LwM2M Object Instance ID",
19
+ examples: [
20
+ 0,
21
+ 1
22
+ ]
23
+ });
24
+ export var Resources = Type.Record(Type.Integer({
25
+ minimum: 0
26
+ }), Type.Union([
27
+ Type.String({
28
+ minLength: 1,
29
+ title: "LwM2M string value"
30
+ }),
31
+ Type.Number({
32
+ title: "LwM2M number value"
33
+ }),
34
+ Type.Boolean({
35
+ title: "LwM2M boolean value"
36
+ })
37
+ ]));
package/dist/api/index.js CHANGED
@@ -3,3 +3,5 @@ export * from "./DeviceId.js";
3
3
  export * from "./Devices.js";
4
4
  export * from "./ShareDeviceOwnershipConfirmed.js";
5
5
  export * from "./ShareDeviceRequest.js";
6
+ export * from "./History.js";
7
+ export * from "./LwM2M.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/proto-map",
3
- "version": "5.3.2",
3
+ "version": "5.4.0",
4
4
  "description": "Documents the communication protocol between devices, the hello.nrfcloud.com/map backend and web application",
5
5
  "type": "module",
6
6
  "exports": {
@@ -43,7 +43,7 @@
43
43
  "@bifravst/prettier-config": "1.0.0",
44
44
  "@commitlint/config-conventional": "19.2.2",
45
45
  "@swc/cli": "0.3.12",
46
- "@swc/core": "1.4.15",
46
+ "@swc/core": "1.4.16",
47
47
  "@types/node": "20.12.7",
48
48
  "@types/xml2js": "0.4.14",
49
49
  "chalk": "5.3.0",