@hello.nrfcloud.com/proto-map 5.4.2 → 5.6.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
@@ -10,5 +10,6 @@ export const Context = {
10
10
  request: new URL(`${baseURL}/share-device-request`),
11
11
  ownershipConfirmed: new URL(`${baseURL}/share-device-ownership-confirmed`),
12
12
  },
13
+ resourceUpdate: new URL(`${baseURL}/resource/update`),
13
14
  named: (name: string): URL => new URL(`${baseURL}/${name}`),
14
15
  }
package/api/History.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  Resources,
8
8
  } from './LwM2M.js'
9
9
  import { PublicDeviceId } from './DeviceId.js'
10
+ import { Timestamp } from './Timestamp.js'
10
11
 
11
12
  export const ResourceHistory = Type.Object(
12
13
  {
@@ -16,13 +17,7 @@ export const ResourceHistory = Type.Object(
16
17
  [
17
18
  Resources,
18
19
  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
- ),
20
+ ts: Timestamp,
26
21
  }),
27
22
  ],
28
23
  {
@@ -0,0 +1,28 @@
1
+ import { describe, it } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { validate } from '../validate.js'
4
+ import { ResourceUpdate } from './ResourceUpdate.js'
5
+ import type { Static } from '@sinclair/typebox'
6
+
7
+ void describe('ResourceUpdate', () => {
8
+ void it('should validate', () => {
9
+ const input: Static<typeof ResourceUpdate> = {
10
+ '@context': 'https://github.com/hello-nrfcloud/proto-map/resource/update',
11
+ ObjectID: 14201,
12
+ ObjectVersion: '1.0',
13
+ ObjectInstanceID: 0,
14
+ Resources: {
15
+ '0': 70.374978,
16
+ '1': 31.104015,
17
+ '3': 1,
18
+ '6': 'Fixed',
19
+ '99': '${tsISO}',
20
+ },
21
+ deviceId: 'bassetto-ennobler-toilless',
22
+ ts: '2024-04-19T08:30:00.000Z',
23
+ }
24
+ const maybeValid = validate(ResourceUpdate)(input)
25
+ assert.equal('errors' in maybeValid, false)
26
+ assert.deepEqual('value' in maybeValid && maybeValid.value, input)
27
+ })
28
+ })
@@ -0,0 +1,26 @@
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
+ import { Timestamp } from './Timestamp.js'
11
+
12
+ export const ResourceUpdate = Type.Object(
13
+ {
14
+ '@context': Type.Literal(Context.resourceUpdate.toString()),
15
+ ObjectID,
16
+ ObjectInstanceID,
17
+ ObjectVersion,
18
+ Resources,
19
+ ts: Timestamp,
20
+ deviceId: PublicDeviceId,
21
+ },
22
+ {
23
+ title: 'Resource history',
24
+ description: 'Describes an update to a LwM2M resource for a device.',
25
+ },
26
+ )
@@ -0,0 +1,14 @@
1
+ import { describe, it } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { validate } from '../validate.js'
4
+ import { Timestamp } from './Timestamp.js'
5
+ import type { Static } from '@sinclair/typebox'
6
+
7
+ void describe('Timestamp', () => {
8
+ void it('should validate', () => {
9
+ const input: Static<typeof Timestamp> = '2024-04-19T08:30:00.000Z'
10
+ const maybeValid = validate(Timestamp)(input)
11
+ assert.equal('errors' in maybeValid, false)
12
+ assert.deepEqual('value' in maybeValid && maybeValid.value, input)
13
+ })
14
+ })
@@ -0,0 +1,9 @@
1
+ import { Type } from '@sinclair/typebox'
2
+
3
+ export const Timestamp = Type.RegExp(
4
+ /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/,
5
+ {
6
+ title: 'Time when the update was received, formatted as ISO 8601',
7
+ examples: ['2024-04-19T08:45:00.000Z'],
8
+ },
9
+ )
package/api/index.ts CHANGED
@@ -5,3 +5,4 @@ export * from './ShareDeviceOwnershipConfirmed.js'
5
5
  export * from './ShareDeviceRequest.js'
6
6
  export * from './History.js'
7
7
  export * from './LwM2M.js'
8
+ export * from './Timestamp.js'
@@ -9,6 +9,7 @@ export var Context = {
9
9
  request: new URL("".concat(baseURL, "/share-device-request")),
10
10
  ownershipConfirmed: new URL("".concat(baseURL, "/share-device-ownership-confirmed"))
11
11
  },
12
+ resourceUpdate: new URL("".concat(baseURL, "/resource/update")),
12
13
  named: function(name) {
13
14
  return new URL("".concat(baseURL, "/").concat(name));
14
15
  }
@@ -2,17 +2,13 @@ import { Type } from "@sinclair/typebox";
2
2
  import { Context } from "./Context.js";
3
3
  import { ObjectID, ObjectInstanceID, ObjectVersion, Resources } from "./LwM2M.js";
4
4
  import { PublicDeviceId } from "./DeviceId.js";
5
+ import { Timestamp } from "./Timestamp.js";
5
6
  export var ResourceHistory = Type.Object({
6
7
  "@context": Type.Literal(Context.history.resource.toString()),
7
8
  partialInstances: Type.Array(Type.Intersect([
8
9
  Resources,
9
10
  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
- })
11
+ ts: Timestamp
16
12
  })
17
13
  ], {
18
14
  title: "The resources of the object instance and the timestamp the data was received."
@@ -0,0 +1,17 @@
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
+ import { Timestamp } from "./Timestamp.js";
6
+ export var ResourceUpdate = Type.Object({
7
+ "@context": Type.Literal(Context.resourceUpdate.toString()),
8
+ ObjectID: ObjectID,
9
+ ObjectInstanceID: ObjectInstanceID,
10
+ ObjectVersion: ObjectVersion,
11
+ Resources: Resources,
12
+ ts: Timestamp,
13
+ deviceId: PublicDeviceId
14
+ }, {
15
+ title: "Resource history",
16
+ description: "Describes an update to a LwM2M resource for a device."
17
+ });
@@ -0,0 +1,26 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { validate } from "../validate.js";
4
+ import { ResourceUpdate } from "./ResourceUpdate.js";
5
+ void describe("ResourceUpdate", function() {
6
+ void it("should validate", function() {
7
+ var input = {
8
+ "@context": "https://github.com/hello-nrfcloud/proto-map/resource/update",
9
+ ObjectID: 14201,
10
+ ObjectVersion: "1.0",
11
+ ObjectInstanceID: 0,
12
+ Resources: {
13
+ "0": 70.374978,
14
+ "1": 31.104015,
15
+ "3": 1,
16
+ "6": "Fixed",
17
+ "99": "${tsISO}"
18
+ },
19
+ deviceId: "bassetto-ennobler-toilless",
20
+ ts: "2024-04-19T08:30:00.000Z"
21
+ };
22
+ var maybeValid = validate(ResourceUpdate)(input);
23
+ assert.equal("errors" in maybeValid, false);
24
+ assert.deepEqual("value" in maybeValid && maybeValid.value, input);
25
+ });
26
+ });
@@ -0,0 +1,7 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ export var Timestamp = 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)/, {
3
+ title: "Time when the update was received, formatted as ISO 8601",
4
+ examples: [
5
+ "2024-04-19T08:45:00.000Z"
6
+ ]
7
+ });
@@ -0,0 +1,12 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { validate } from "../validate.js";
4
+ import { Timestamp } from "./Timestamp.js";
5
+ void describe("Timestamp", function() {
6
+ void it("should validate", function() {
7
+ var input = "2024-04-19T08:30:00.000Z";
8
+ var maybeValid = validate(Timestamp)(input);
9
+ assert.equal("errors" in maybeValid, false);
10
+ assert.deepEqual("value" in maybeValid && maybeValid.value, input);
11
+ });
12
+ });
package/dist/api/index.js CHANGED
@@ -5,3 +5,4 @@ export * from "./ShareDeviceOwnershipConfirmed.js";
5
5
  export * from "./ShareDeviceRequest.js";
6
6
  export * from "./History.js";
7
7
  export * from "./LwM2M.js";
8
+ export * from "./Timestamp.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/proto-map",
3
- "version": "5.4.2",
3
+ "version": "5.6.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": {
@@ -108,7 +108,7 @@
108
108
  "lwm2m"
109
109
  ],
110
110
  "peerDependencies": {
111
- "@sinclair/typebox": "^0.32.21",
111
+ "@sinclair/typebox": "^0.32.22",
112
112
  "ajv": "^8.12.0",
113
113
  "jsonata": "^2.0.4"
114
114
  }