@hello.nrfcloud.com/proto-map 8.1.1 → 9.0.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/Devices.ts +1 -1
- package/dist/api/Devices.js +1 -1
- package/dist/generator/generateType.js +4 -6
- package/dist/generator/generateValidator.js +16 -11
- package/dist/generator/generateValidators.js +14 -2
- package/dist/lwm2m/LwM2MObjectInstance.js +1 -0
- package/dist/lwm2m/index.js +10 -0
- package/dist/lwm2m/object/validate14201.js +4 -4
- package/dist/lwm2m/object/validate14202.js +4 -4
- package/dist/lwm2m/object/validate14203.js +4 -4
- package/dist/lwm2m/object/validate14204.js +4 -4
- package/dist/lwm2m/object/validate14205.js +4 -4
- package/dist/lwm2m/object/validate14210.js +4 -4
- package/dist/lwm2m/object/validate14220.js +4 -4
- package/dist/lwm2m/object/validate14230.js +4 -4
- package/dist/lwm2m/object/validate14240.js +4 -4
- package/dist/lwm2m/validate.js +9 -8
- package/dist/lwm2m/validate.spec.js +27 -0
- package/dist/lwm2m/validation.js +50 -19
- package/dist/models/index.js +2 -0
- package/dist/models/models.js +10 -2
- package/dist/senml/index.js +4 -0
- package/lwm2m/LwM2MObject.d.ts +1 -1
- package/lwm2m/LwM2MObjectInstance.ts +35 -0
- package/lwm2m/index.ts +10 -0
- package/lwm2m/instanceTs.ts +1 -1
- package/lwm2m/object/14201.d.ts +3 -6
- package/lwm2m/object/14202.d.ts +1 -2
- package/lwm2m/object/14205.d.ts +1 -2
- package/lwm2m/object/14240.d.ts +3 -6
- package/lwm2m/object/validate14201.ts +7 -3
- package/lwm2m/object/validate14202.ts +7 -3
- package/lwm2m/object/validate14203.ts +7 -3
- package/lwm2m/object/validate14204.ts +7 -3
- package/lwm2m/object/validate14205.ts +7 -3
- package/lwm2m/object/validate14210.ts +7 -3
- package/lwm2m/object/validate14220.ts +7 -3
- package/lwm2m/object/validate14230.ts +7 -3
- package/lwm2m/object/validate14240.ts +7 -3
- package/lwm2m/validate.spec.ts +29 -0
- package/lwm2m/validate.ts +12 -19
- package/lwm2m/validation.ts +32 -41
- package/lwm2m/validators.ts +6 -1
- package/models/index.ts +2 -0
- package/models/models.ts +3 -2
- package/models/thingy91x/README.md +9 -0
- package/package.json +1 -7
- package/senml/index.ts +4 -0
- package/senml/lwm2mToSenML.spec.ts +1 -1
- package/senml/lwm2mToSenML.ts +4 -1
- package/senml/senMLtoLwM2M.spec.ts +2 -1
- package/senml/senMLtoLwM2M.ts +1 -35
- package/dist/lwm2m/isRegisteredLwM2MObject.js +0 -3
- package/dist/lwm2m/isRegisteredLwM2MObject.spec.js +0 -45
- package/export.js +0 -14
- package/index.d.ts +0 -15
- package/lwm2m/isRegisteredLwM2MObject.spec.ts +0 -48
- package/lwm2m/isRegisteredLwM2MObject.ts +0 -4
package/lwm2m/object/14205.d.ts
CHANGED
package/lwm2m/object/14240.d.ts
CHANGED
|
@@ -13,8 +13,7 @@ export type RGBLED_14240 = LwM2MObject<{
|
|
|
13
13
|
* Red
|
|
14
14
|
*
|
|
15
15
|
* The red brightness level of the LED.
|
|
16
|
-
|
|
17
|
-
/**
|
|
16
|
+
*
|
|
18
17
|
* Minimum: 0
|
|
19
18
|
* Maximum: 255
|
|
20
19
|
*/
|
|
@@ -23,8 +22,7 @@ export type RGBLED_14240 = LwM2MObject<{
|
|
|
23
22
|
* Green
|
|
24
23
|
*
|
|
25
24
|
* The green brightness level of the LED.
|
|
26
|
-
|
|
27
|
-
/**
|
|
25
|
+
*
|
|
28
26
|
* Minimum: 0
|
|
29
27
|
* Maximum: 255
|
|
30
28
|
*/
|
|
@@ -33,8 +31,7 @@ export type RGBLED_14240 = LwM2MObject<{
|
|
|
33
31
|
* Blue
|
|
34
32
|
*
|
|
35
33
|
* The blue brightness level of the LED.
|
|
36
|
-
|
|
37
|
-
/**
|
|
34
|
+
*
|
|
38
35
|
* Minimum: 0
|
|
39
36
|
* Maximum: 255
|
|
40
37
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { NumberResource, StringResource, DateResource, OptionalResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { NumberResource, StringResource, DateResource, OptionalResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { Geolocation_14201 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14201.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14201 = (o: unknown
|
|
10
|
+
export const validate14201 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<Geolocation_14201>;
|
|
14
|
+
} => validateInstance<Geolocation_14201>(LwM2MObjectID.Geolocation_14201, "1.0", { 0: NumberResource, 1: NumberResource, 6: StringResource, 99: DateResource, 2: OptionalResource(NumberResource), 3: OptionalResource(NumberResource), 4: OptionalResource(NumberResource), 5: OptionalResource(NumberResource) })(o);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { DateResource, NumberResource, OptionalResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { DateResource, NumberResource, OptionalResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { BatteryAndPower_14202 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14202.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14202 = (o: unknown
|
|
10
|
+
export const validate14202 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<BatteryAndPower_14202>;
|
|
14
|
+
} => validateInstance<BatteryAndPower_14202>(LwM2MObjectID.BatteryAndPower_14202, "1.0", { 99: DateResource, 0: OptionalResource(NumberResource), 1: OptionalResource(NumberResource), 2: OptionalResource(NumberResource), 3: OptionalResource(NumberResource), 4: OptionalResource(NumberResource), 5: OptionalResource(NumberResource) })(o);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { DateResource, StringResource, OptionalResource, NumberResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { DateResource, StringResource, OptionalResource, NumberResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { ConnectionInformation_14203 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14203.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14203 = (o: unknown
|
|
10
|
+
export const validate14203 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<ConnectionInformation_14203>;
|
|
14
|
+
} => validateInstance<ConnectionInformation_14203>(LwM2MObjectID.ConnectionInformation_14203, "1.0", { 99: DateResource, 0: OptionalResource(StringResource), 1: OptionalResource(NumberResource), 2: OptionalResource(NumberResource), 3: OptionalResource(NumberResource), 4: OptionalResource(NumberResource), 5: OptionalResource(NumberResource), 6: OptionalResource(StringResource), 11: OptionalResource(NumberResource) })(o);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { StringResource, DateResource, OptionalResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { StringResource, DateResource, OptionalResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { DeviceInformation_14204 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14204.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14204 = (o: unknown
|
|
10
|
+
export const validate14204 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<DeviceInformation_14204>;
|
|
14
|
+
} => validateInstance<DeviceInformation_14204>(LwM2MObjectID.DeviceInformation_14204, "1.0", { 0: StringResource, 2: StringResource, 3: StringResource, 4: StringResource, 99: DateResource, 1: OptionalResource(StringResource), 5: OptionalResource(StringResource) })(o);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { DateResource, NumberResource, OptionalResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { DateResource, NumberResource, OptionalResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { Environment_14205 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14205.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14205 = (o: unknown
|
|
10
|
+
export const validate14205 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<Environment_14205>;
|
|
14
|
+
} => validateInstance<Environment_14205>(LwM2MObjectID.Environment_14205, "1.0", { 99: DateResource, 0: OptionalResource(NumberResource), 1: OptionalResource(NumberResource), 2: OptionalResource(NumberResource), 10: OptionalResource(NumberResource) })(o);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { NumberResource, DateResource, OptionalResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { NumberResource, DateResource, OptionalResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { SolarCharge_14210 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14210.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14210 = (o: unknown
|
|
10
|
+
export const validate14210 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<SolarCharge_14210>;
|
|
14
|
+
} => validateInstance<SolarCharge_14210>(LwM2MObjectID.SolarCharge_14210, "1.0", { 0: NumberResource, 99: DateResource, 1: OptionalResource(NumberResource) })(o);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { NumberResource, DateResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { NumberResource, DateResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { ButtonPress_14220 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14220.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14220 = (o: unknown
|
|
10
|
+
export const validate14220 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<ButtonPress_14220>;
|
|
14
|
+
} => validateInstance<ButtonPress_14220>(LwM2MObjectID.ButtonPress_14220, "1.0", { 0: NumberResource, 99: DateResource })(o);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { NumberResource, StringResource, DateResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { NumberResource, StringResource, DateResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { SeaWaterLevel_14230 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14230.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14230 = (o: unknown
|
|
10
|
+
export const validate14230 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<SeaWaterLevel_14230>;
|
|
14
|
+
} => validateInstance<SeaWaterLevel_14230>(LwM2MObjectID.SeaWaterLevel_14230, "1.0", { 0: NumberResource, 1: StringResource, 99: DateResource })(o);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { NumberResource, DateResource,
|
|
1
|
+
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
+
import { NumberResource, DateResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { RGBLED_14240 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -7,4 +7,8 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Ensures the given object is an LwM2M object according to the schema 14240.xml.
|
|
9
9
|
*/
|
|
10
|
-
export const validate14240 = (o: unknown
|
|
10
|
+
export const validate14240 = (o: unknown): {
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
object: LwM2MObjectInstance<RGBLED_14240>;
|
|
14
|
+
} => validateInstance<RGBLED_14240>(LwM2MObjectID.RGBLED_14240, "1.0", { 0: NumberResource, 1: NumberResource, 2: NumberResource, 99: DateResource })(o);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, it } from 'node:test'
|
|
2
|
+
import { validate } from './validate.js'
|
|
3
|
+
import { validators } from './validators.js'
|
|
4
|
+
import { LwM2MObjectID } from './LwM2MObjectID.js'
|
|
5
|
+
import assert from 'node:assert'
|
|
6
|
+
|
|
7
|
+
void describe('validate()', () => {
|
|
8
|
+
const v = validate(validators)
|
|
9
|
+
void it('should validate a LwM2M object instance', () => {
|
|
10
|
+
const object = {
|
|
11
|
+
ObjectID: LwM2MObjectID.Geolocation_14201,
|
|
12
|
+
ObjectVersion: '1.0',
|
|
13
|
+
Resources: {
|
|
14
|
+
'0': 62.469414,
|
|
15
|
+
'1': 6.151946,
|
|
16
|
+
'6': 'Fixed',
|
|
17
|
+
'3': 1,
|
|
18
|
+
'99': new Date(1710147413003),
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
const maybeValid = v(object)
|
|
22
|
+
assert.deepEqual('object' in maybeValid && maybeValid.object, object)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
void it('should return an error for an invalid object', () => {
|
|
26
|
+
const maybeValid = v({})
|
|
27
|
+
assert.equal('error' in maybeValid, true)
|
|
28
|
+
})
|
|
29
|
+
})
|
package/lwm2m/validate.ts
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { isLwM2MObject } from './validation.js'
|
|
1
|
+
import type { LwM2MObjectInstance } from './LwM2MObjectInstance.js'
|
|
3
2
|
import { LwM2MObjectID } from './LwM2MObjectID.js'
|
|
4
|
-
import
|
|
3
|
+
import { isLwM2MObject } from './validation.js'
|
|
5
4
|
|
|
6
5
|
export const validate =
|
|
7
6
|
(
|
|
8
7
|
validators: Map<
|
|
9
8
|
LwM2MObjectID,
|
|
10
|
-
(o: unknown
|
|
9
|
+
(o: unknown) => { object: LwM2MObjectInstance } | { error: Error }
|
|
11
10
|
>,
|
|
12
11
|
) =>
|
|
13
|
-
(
|
|
14
|
-
o
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
ObjectID
|
|
18
|
-
ObjectVersion: string
|
|
19
|
-
Resources: Record<number, LwM2MResourceValue | undefined>
|
|
20
|
-
}> => {
|
|
21
|
-
if (!isLwM2MObject(o, onError)) {
|
|
22
|
-
return false
|
|
23
|
-
}
|
|
24
|
-
const validator = validators.get(o.ObjectID)
|
|
12
|
+
(o: unknown): { object: LwM2MObjectInstance } | { error: Error } => {
|
|
13
|
+
const maybeValidInstance = isLwM2MObject(o)
|
|
14
|
+
if ('error' in maybeValidInstance) return maybeValidInstance
|
|
15
|
+
const i = maybeValidInstance.object
|
|
16
|
+
const validator = validators.get(i.ObjectID)
|
|
25
17
|
if (validator === undefined) {
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
return {
|
|
19
|
+
error: new Error(`No validator defined for ObjectID: ${i.ObjectID}!`),
|
|
20
|
+
}
|
|
28
21
|
}
|
|
29
|
-
return validator(o
|
|
22
|
+
return validator(o)
|
|
30
23
|
}
|
package/lwm2m/validation.ts
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LwM2MObjectInstance } from './LwM2MObjectInstance.js'
|
|
2
2
|
import { LwM2MObjectIDs, type LwM2MObjectID } from './LwM2MObjectID.js'
|
|
3
3
|
|
|
4
4
|
export const isLwM2MObject = (
|
|
5
5
|
object: unknown,
|
|
6
|
-
|
|
7
|
-
):
|
|
8
|
-
ObjectID: LwM2MObjectID
|
|
9
|
-
/**
|
|
10
|
-
* The Object Version of an Object is composed of 2 digits separated by a dot '.'
|
|
11
|
-
*
|
|
12
|
-
* @see 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
|
-
* @default 1.0
|
|
15
|
-
*/
|
|
16
|
-
ObjectVersion?: string
|
|
17
|
-
Resources: Record<number, LwM2MResourceValue>
|
|
18
|
-
} => {
|
|
19
|
-
const error = (message: string) => {
|
|
20
|
-
onError?.(new Error(message))
|
|
21
|
-
return false
|
|
22
|
-
}
|
|
6
|
+
): { object: LwM2MObjectInstance } | { error: Error } => {
|
|
7
|
+
const error = (message: string) => ({ error: new Error(message) })
|
|
23
8
|
// Must be an object
|
|
24
9
|
if (typeof object !== 'object' || object === null)
|
|
25
10
|
return error(`Not an object`)
|
|
@@ -42,6 +27,14 @@ export const isLwM2MObject = (
|
|
|
42
27
|
)
|
|
43
28
|
return error(`Invalid ObjectVersion`)
|
|
44
29
|
}
|
|
30
|
+
// ObjectInstanceID must be valid
|
|
31
|
+
if ('ObjectInstanceID' in object) {
|
|
32
|
+
if (
|
|
33
|
+
typeof object.ObjectInstanceID !== 'number' ||
|
|
34
|
+
object.ObjectInstanceID < 0
|
|
35
|
+
)
|
|
36
|
+
return error(`Invalid ObjectInstanceID`)
|
|
37
|
+
}
|
|
45
38
|
// Must have valid resources
|
|
46
39
|
if (
|
|
47
40
|
!('Resources' in object) ||
|
|
@@ -63,39 +56,37 @@ export const isLwM2MObject = (
|
|
|
63
56
|
if (typeof v === 'object' && v instanceof Date) continue
|
|
64
57
|
return error(`Invalid value type ${typeof v}`)
|
|
65
58
|
}
|
|
66
|
-
return
|
|
59
|
+
return { object: object as LwM2MObjectInstance }
|
|
67
60
|
}
|
|
68
61
|
|
|
69
|
-
export const
|
|
70
|
-
(
|
|
62
|
+
export const validateInstance =
|
|
63
|
+
<O extends LwM2MObjectInstance>(
|
|
71
64
|
ObjectID: LwM2MObjectID,
|
|
72
65
|
ObjectVersion: string,
|
|
73
66
|
Resources: Record<number, (r: unknown) => boolean>,
|
|
74
67
|
) =>
|
|
75
|
-
(o: unknown
|
|
76
|
-
const error = (message: string) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
if (o.ObjectID !== ObjectID)
|
|
68
|
+
(o: unknown): { object: LwM2MObjectInstance<O> } | { error: Error } => {
|
|
69
|
+
const error = (message: string) => ({ error: new Error(message) })
|
|
70
|
+
const maybeValidLwM2MObject = isLwM2MObject(o)
|
|
71
|
+
if ('error' in maybeValidLwM2MObject) return maybeValidLwM2MObject
|
|
72
|
+
const i = maybeValidLwM2MObject.object
|
|
73
|
+
if (i.ObjectID !== ObjectID) {
|
|
82
74
|
return error(
|
|
83
|
-
`Given Object ID ${
|
|
75
|
+
`Given Object ID ${i.ObjectID} does not match expected ${ObjectID}`,
|
|
84
76
|
)
|
|
85
|
-
|
|
77
|
+
}
|
|
78
|
+
if ((i.ObjectVersion ?? '1.0') !== ObjectVersion) {
|
|
86
79
|
return error(
|
|
87
|
-
`Given Object version ${
|
|
80
|
+
`Given Object version ${i.ObjectVersion} does not match expected ${ObjectVersion}`,
|
|
88
81
|
)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
true,
|
|
98
|
-
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (const [ResourceID, validator] of Object.entries(Resources)) {
|
|
85
|
+
if (validator(i.Resources[parseInt(ResourceID, 10)]) === false) {
|
|
86
|
+
return error(`Resource ${ResourceID} is invalid.`)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return { object: o as LwM2MObjectInstance<O> }
|
|
99
90
|
}
|
|
100
91
|
|
|
101
92
|
export const NumberResource = (r: unknown): r is number => typeof r === 'number'
|
package/lwm2m/validators.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LwM2MObjectID } from "./LwM2MObjectID.js";
|
|
2
|
+
import type { LwM2MObjectInstance } from "./LwM2MObjectInstance.js";
|
|
2
3
|
import { validate14201 } from "./object/validate14201.js";
|
|
3
4
|
import { validate14202 } from "./object/validate14202.js";
|
|
4
5
|
import { validate14203 } from "./object/validate14203.js";
|
|
@@ -11,7 +12,11 @@ import { validate14240 } from "./object/validate14240.js";
|
|
|
11
12
|
/**
|
|
12
13
|
* Contains the validators for all registered LwM2M objects.
|
|
13
14
|
*/
|
|
14
|
-
export const validators = new Map<LwM2MObjectID, (o: unknown) =>
|
|
15
|
+
export const validators = new Map<LwM2MObjectID, (o: unknown) => {
|
|
16
|
+
error: Error;
|
|
17
|
+
} | {
|
|
18
|
+
object: LwM2MObjectInstance;
|
|
19
|
+
}>();
|
|
15
20
|
validators.set(LwM2MObjectID.Geolocation_14201, validate14201)
|
|
16
21
|
validators.set(LwM2MObjectID.BatteryAndPower_14202, validate14202)
|
|
17
22
|
validators.set(LwM2MObjectID.ConnectionInformation_14203, validate14203)
|
package/models/index.ts
ADDED
package/models/models.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* The Model IDs defined in this repo.
|
|
3
3
|
*/
|
|
4
4
|
export enum ModelID {
|
|
5
|
-
Kartverket_vasstandsdata = "kartverket-vasstandsdata"
|
|
5
|
+
Kartverket_vasstandsdata = "kartverket-vasstandsdata",
|
|
6
|
+
Thingy91x = "thingy91x"
|
|
6
7
|
}
|
|
7
8
|
export type Model = {
|
|
8
9
|
/**
|
|
@@ -26,4 +27,4 @@ export type Model = {
|
|
|
26
27
|
/**
|
|
27
28
|
* The models defined for hello.nrfcloud.com
|
|
28
29
|
*/
|
|
29
|
-
export const models: Readonly<Record<ModelID, Model>> = { [ModelID.Kartverket_vasstandsdata]: { "id": ModelID.Kartverket_vasstandsdata, "about": { "title": "Kartverket Vasstandsdata", "description": "A simulated device reporting the current sea level as provided by the Kartverket's (Norwegian Mapping Authority) API for vasstandsdata (API for water level data).\nReports sea water level using the Object 14230.\nThe data is licensed by the Norwegian Mapping Authority\u2019s under the Creative Commons Attribution 4.0 International (CC BY 4.0) license." } } } as const;
|
|
30
|
+
export const models: Readonly<Record<ModelID, Model>> = { [ModelID.Kartverket_vasstandsdata]: { "id": ModelID.Kartverket_vasstandsdata, "about": { "title": "Kartverket Vasstandsdata", "description": "A simulated device reporting the current sea level as provided by the Kartverket's (Norwegian Mapping Authority) API for vasstandsdata (API for water level data).\nReports sea water level using the Object 14230.\nThe data is licensed by the Norwegian Mapping Authority\u2019s under the Creative Commons Attribution 4.0 International (CC BY 4.0) license." } }, [ModelID.Thingy91x]: { "id": ModelID.Thingy91x, "about": { "title": "Thingy:91 X", "description": "Nordic Semiconductor\u2019s latest Cellular IoT prototyping platform, the Thingy:91 X. Built around Nordic\u2019s recently announced nRF9151 System-in-Package (SiP), Thingy:91 X supports LTE-M, NB-IoT, GNSS, and DECT NR+ connectivity. The platform also integrates Nordic\u2019s nRF7002 Companion IC for Wi-Fi locationing, the nPM1300 Power Management IC (PMIC), which features innovative system management features and efficient fuel gauging, and the nRF5340 dual-core, multiprotocol SoC." } } } as const;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Thingy:91 X
|
|
2
|
+
|
|
3
|
+
Nordic Semiconductor’s latest Cellular IoT prototyping platform, the Thingy:91
|
|
4
|
+
X. Built around Nordic’s recently announced nRF9151 System-in-Package (SiP),
|
|
5
|
+
Thingy:91 X supports LTE-M, NB-IoT, GNSS, and DECT NR+ connectivity. The
|
|
6
|
+
platform also integrates Nordic’s nRF7002 Companion IC for Wi-Fi locationing,
|
|
7
|
+
the nPM1300 Power Management IC (PMIC), which features innovative system
|
|
8
|
+
management features and efficient fuel gauging, and the nRF5340 dual-core,
|
|
9
|
+
multiprotocol SoC.
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hello.nrfcloud.com/proto-map",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.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": {
|
|
7
|
-
".": {
|
|
8
|
-
"default": "./export.js",
|
|
9
|
-
"types": "./index.d.ts"
|
|
10
|
-
},
|
|
11
7
|
"./*": {
|
|
12
8
|
"default": "./dist/*/index.js",
|
|
13
9
|
"types": "./*/index.ts"
|
|
@@ -96,8 +92,6 @@
|
|
|
96
92
|
"LICENSE",
|
|
97
93
|
"README.md",
|
|
98
94
|
"dist",
|
|
99
|
-
"export.js",
|
|
100
|
-
"index.d.ts",
|
|
101
95
|
"api",
|
|
102
96
|
"senml",
|
|
103
97
|
"models",
|
package/senml/index.ts
ADDED
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
} from '../lwm2m/objects.js'
|
|
7
7
|
import { LwM2MObjectID } from '../lwm2m/LwM2MObjectID.js'
|
|
8
8
|
import assert from 'node:assert/strict'
|
|
9
|
-
import type { LwM2MObjectInstance } from '
|
|
9
|
+
import type { LwM2MObjectInstance } from '../lwm2m/LwM2MObjectInstance.js'
|
|
10
10
|
import { lwm2mToSenML } from './lwm2mToSenML.js'
|
|
11
11
|
|
|
12
12
|
void describe('lwm2mToSenML()', () => {
|
package/senml/lwm2mToSenML.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { SenMLType } from './SenMLSchema.js'
|
|
2
2
|
import { instanceTs } from '../lwm2m/instanceTs.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
LwM2MObjectInstance,
|
|
5
|
+
LwM2MResourceValue,
|
|
6
|
+
} from '../lwm2m/LwM2MObjectInstance.js'
|
|
4
7
|
import { timestampResources } from '../lwm2m/timestampResources.js'
|
|
5
8
|
import { definitions } from '../lwm2m/definitions.js'
|
|
6
9
|
import { ResourceType, type LWM2MObjectInfo } from '../lwm2m/LWM2MObjectInfo.js'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
import { describe, it } from 'node:test'
|
|
3
|
-
import { senMLtoLwM2M
|
|
3
|
+
import { senMLtoLwM2M } from './senMLtoLwM2M.js'
|
|
4
|
+
import { type LwM2MObjectInstance } from '../lwm2m/LwM2MObjectInstance.js'
|
|
4
5
|
import type { SenMLType } from './SenMLSchema.js'
|
|
5
6
|
|
|
6
7
|
void describe('senMLtoLwM2M()', () => {
|
package/senml/senMLtoLwM2M.ts
CHANGED
|
@@ -2,41 +2,7 @@ import type { MeasurementType, SenMLType } from './SenMLSchema.js'
|
|
|
2
2
|
import { timestampResources } from '../lwm2m/timestampResources.js'
|
|
3
3
|
import { parseResourceId, type ResourceID } from './parseResourceId.js'
|
|
4
4
|
import { hasValue } from './hasValue.js'
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
export type LwM2MResourceValue = string | number | boolean | Date
|
|
8
|
-
type GenericLwM2MObjectInstance = {
|
|
9
|
-
ObjectID: LwM2MObjectID
|
|
10
|
-
/**
|
|
11
|
-
* @default 0
|
|
12
|
-
*/
|
|
13
|
-
ObjectInstanceID?: number
|
|
14
|
-
/**
|
|
15
|
-
* @default '1.0'
|
|
16
|
-
*/
|
|
17
|
-
ObjectVersion?: string
|
|
18
|
-
/**
|
|
19
|
-
* Key range: 0..65534
|
|
20
|
-
*/
|
|
21
|
-
Resources: Partial<Record<number, LwM2MResourceValue>>
|
|
22
|
-
}
|
|
23
|
-
export type LwM2MObjectInstance<
|
|
24
|
-
Instance extends GenericLwM2MObjectInstance = GenericLwM2MObjectInstance,
|
|
25
|
-
> = {
|
|
26
|
-
ObjectID: LwM2MObjectID
|
|
27
|
-
/**
|
|
28
|
-
* @default 0
|
|
29
|
-
*/
|
|
30
|
-
ObjectInstanceID?: number
|
|
31
|
-
/**
|
|
32
|
-
* @default '1.0'
|
|
33
|
-
*/
|
|
34
|
-
ObjectVersion?: Instance['ObjectVersion']
|
|
35
|
-
/**
|
|
36
|
-
* Key range: 0..65534
|
|
37
|
-
*/
|
|
38
|
-
Resources: Instance['Resources']
|
|
39
|
-
}
|
|
5
|
+
import type { LwM2MObjectInstance } from '../lwm2m/LwM2MObjectInstance.js'
|
|
40
6
|
|
|
41
7
|
const isInfoForDifferentInstance = (
|
|
42
8
|
currentObject: LwM2MObjectInstance,
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { isRegisteredLwM2MObject } from './isRegisteredLwM2MObject.js';
|
|
4
|
-
void describe('isRegisteredLwM2MObject()', function() {
|
|
5
|
-
void it('should validate a LwM2M object', function() {
|
|
6
|
-
var o = {
|
|
7
|
-
ObjectID: 14201,
|
|
8
|
-
ObjectVersion: '1.0',
|
|
9
|
-
Resources: {
|
|
10
|
-
0: 33.98771459323253,
|
|
11
|
-
1: -84.50632147267358,
|
|
12
|
-
2: 241.9342498779297,
|
|
13
|
-
3: 11.317643165588379,
|
|
14
|
-
4: 0.03478508070111275,
|
|
15
|
-
5: 90.31222534179688,
|
|
16
|
-
6: 'GNSS',
|
|
17
|
-
99: new Date(1699049744000)
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
assert.equal(isRegisteredLwM2MObject(o), true);
|
|
21
|
-
});
|
|
22
|
-
void it('should validate a LwM2M object with optional resources', function() {
|
|
23
|
-
var o = {
|
|
24
|
-
ObjectID: 14201,
|
|
25
|
-
ObjectVersion: '1.0',
|
|
26
|
-
Resources: {
|
|
27
|
-
0: 33.98771459323253,
|
|
28
|
-
1: -84.50632147267358,
|
|
29
|
-
6: 'GNSS',
|
|
30
|
-
99: new Date(1699049744000)
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
assert.equal(isRegisteredLwM2MObject(o), true);
|
|
34
|
-
});
|
|
35
|
-
void it('should not validate an unknown LwM2M object', function() {
|
|
36
|
-
var o = {
|
|
37
|
-
ObjectID: 666,
|
|
38
|
-
ObjectVersion: '1.0',
|
|
39
|
-
Resources: {
|
|
40
|
-
0: 42
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
assert.equal(isRegisteredLwM2MObject(o), false);
|
|
44
|
-
});
|
|
45
|
-
});
|
package/export.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * from './dist/senml/SenMLSchema.js'
|
|
2
|
-
export * from './dist/senml/senMLtoLwM2M.js'
|
|
3
|
-
export * from './dist/senml/lwm2mToSenML.js'
|
|
4
|
-
export * from './dist/senml/fromCBOR.js'
|
|
5
|
-
export * from './dist/models/models.js'
|
|
6
|
-
export * from './dist/models/types.js'
|
|
7
|
-
export * from './dist/lwm2m/timestampResources.js'
|
|
8
|
-
export * from './dist/lwm2m/objects.js'
|
|
9
|
-
export * from './dist/lwm2m/definitions.js'
|
|
10
|
-
export * from './dist/lwm2m/LWM2MObjectInfo.js'
|
|
11
|
-
export * from './dist/lwm2m/validators.js'
|
|
12
|
-
export * from './dist/lwm2m/LwM2MObjectID.js'
|
|
13
|
-
export * from './dist/lwm2m/validation.js'
|
|
14
|
-
export * from './dist/lwm2m/instanceTs.js'
|
package/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from './senml/SenMLSchema.js'
|
|
2
|
-
export * from './senml/senMLtoLwM2M.js'
|
|
3
|
-
export * from './senml/lwm2mToSenML.js'
|
|
4
|
-
export * from './senml/fromCBOR.js'
|
|
5
|
-
export * from './models/models.js'
|
|
6
|
-
export * from './models/types.js'
|
|
7
|
-
export * from './lwm2m/timestampResources.js'
|
|
8
|
-
export * from './lwm2m/LwM2MObject.js'
|
|
9
|
-
export * from './lwm2m/LwM2MObjectID.js'
|
|
10
|
-
export * from './lwm2m/objects.js'
|
|
11
|
-
export * from './lwm2m/definitions.js'
|
|
12
|
-
export * from './lwm2m/LWM2MObjectInfo.js'
|
|
13
|
-
export * from './lwm2m/validators.js'
|
|
14
|
-
export * from './lwm2m/validation.js'
|
|
15
|
-
export * from './lwm2m/instanceTs.js'
|