@hello.nrfcloud.com/proto-map 12.0.0 → 12.1.1
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/README.md +0 -2
- package/dist/generator/generateLwM2MDefinitions.js +1 -0
- package/dist/generator/generateLwM2MDefinitions.spec.js +11 -0
- package/dist/generator/generateType.js +7 -1
- package/dist/generator/generateValidator.js +8 -2
- package/dist/lwm2m/LWM2MObjectDefinition.js +4 -1
- package/dist/lwm2m/LwM2MObjectID.js +7 -1
- package/dist/lwm2m/definitions.js +81 -0
- package/dist/lwm2m/object/14401.d.js +5 -0
- package/dist/lwm2m/object/validate14401.js +12 -0
- package/dist/lwm2m/objects.js +1 -0
- package/dist/lwm2m/timestampResources.js +4 -0
- package/dist/lwm2m/validate.spec.js +17 -2
- package/dist/lwm2m/validation.js +16 -4
- package/dist/lwm2m/validation.spec.js +39 -0
- package/dist/lwm2m/validators.js +2 -0
- package/lwm2m/14401.xml +34 -0
- package/lwm2m/LWM2MObjectDefinition.ts +4 -1
- package/lwm2m/LWM2MObjectInfo.ts +1 -0
- package/lwm2m/LwM2MObjectID.ts +10 -2
- package/lwm2m/LwM2MObjectInstance.ts +8 -1
- package/lwm2m/ParsedLwM2MObjectDefinition.ts +1 -1
- package/lwm2m/definitions.ts +65 -50
- package/lwm2m/object/14401.d.ts +25 -0
- package/lwm2m/object/validate14401.ts +14 -0
- package/lwm2m/objects.ts +3 -1
- package/lwm2m/timestampResources.ts +1 -1
- package/lwm2m/validate.spec.ts +14 -2
- package/lwm2m/validation.spec.ts +55 -0
- package/lwm2m/validation.ts +18 -11
- package/lwm2m/validators.ts +3 -1
- package/package.json +5 -5
package/lwm2m/validate.spec.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { describe, it } from 'node:test'
|
|
2
2
|
import { validate } from './validate.js'
|
|
3
3
|
import { validators } from './validators.js'
|
|
4
|
-
import { LwM2MObjectID } from './LwM2MObjectID.js'
|
|
5
4
|
import assert from 'node:assert'
|
|
6
5
|
|
|
7
6
|
void describe('validate()', () => {
|
|
8
7
|
const v = validate(validators)
|
|
9
8
|
void it('should validate a LwM2M object instance', () => {
|
|
10
9
|
const object = {
|
|
11
|
-
ObjectID:
|
|
10
|
+
ObjectID: 14201,
|
|
12
11
|
ObjectVersion: '1.0',
|
|
13
12
|
Resources: {
|
|
14
13
|
'0': 62.469414,
|
|
@@ -45,4 +44,17 @@ void describe('validate()', () => {
|
|
|
45
44
|
const maybeValid = v(object)
|
|
46
45
|
assert.deepEqual('object' in maybeValid && maybeValid.object, object)
|
|
47
46
|
})
|
|
47
|
+
|
|
48
|
+
void it('should validate an object with multiple instance resource', () => {
|
|
49
|
+
const object = {
|
|
50
|
+
ObjectID: 14401,
|
|
51
|
+
ObjectVersion: '1.0',
|
|
52
|
+
Resources: {
|
|
53
|
+
'0': ['BOOT', 'MODEM', 'APP'],
|
|
54
|
+
'99': 1717409966000,
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
const maybeValid = v(object)
|
|
58
|
+
assert.deepEqual('object' in maybeValid && maybeValid.object, object)
|
|
59
|
+
})
|
|
48
60
|
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { describe, it } from 'node:test'
|
|
3
|
+
import {
|
|
4
|
+
MultipleInstanceResource,
|
|
5
|
+
OptionalResource,
|
|
6
|
+
StringResource,
|
|
7
|
+
} from './validation.js'
|
|
8
|
+
|
|
9
|
+
void describe('MultipleInstanceResource()', () => {
|
|
10
|
+
void it('should validate a multiple instance resource', () => {
|
|
11
|
+
assert.equal(
|
|
12
|
+
true,
|
|
13
|
+
MultipleInstanceResource(StringResource)(['BOOT', 'MODEM', 'APP']),
|
|
14
|
+
)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
void describe('StringResource()', () => {
|
|
19
|
+
void it('should validate a string', () => {
|
|
20
|
+
assert.equal(true, StringResource('test'))
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
void describe('OptionalResource()', () => {
|
|
25
|
+
void it('should validate an undefined resource', () => {
|
|
26
|
+
assert.equal(true, OptionalResource(StringResource)(undefined))
|
|
27
|
+
})
|
|
28
|
+
void it('should validate an defined resource', () => {
|
|
29
|
+
assert.equal(true, OptionalResource(StringResource)('foo'))
|
|
30
|
+
})
|
|
31
|
+
void it('should not validate an invalid defined resource', () => {
|
|
32
|
+
assert.equal(false, OptionalResource(StringResource)(true))
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
void describe('combination', () => {
|
|
37
|
+
void it('should validate OptionalResource(MultipleInstanceResource(StringResource))', () => {
|
|
38
|
+
assert.equal(
|
|
39
|
+
true,
|
|
40
|
+
OptionalResource(MultipleInstanceResource(StringResource))([
|
|
41
|
+
'BOOT',
|
|
42
|
+
'MODEM',
|
|
43
|
+
'APP',
|
|
44
|
+
]),
|
|
45
|
+
)
|
|
46
|
+
assert.equal(
|
|
47
|
+
true,
|
|
48
|
+
OptionalResource(MultipleInstanceResource(StringResource))(undefined),
|
|
49
|
+
)
|
|
50
|
+
assert.equal(
|
|
51
|
+
false,
|
|
52
|
+
OptionalResource(MultipleInstanceResource(StringResource))('foo'),
|
|
53
|
+
)
|
|
54
|
+
})
|
|
55
|
+
})
|
package/lwm2m/validation.ts
CHANGED
|
@@ -50,15 +50,23 @@ export const isLwM2MObject = (
|
|
|
50
50
|
return error(`All resource IDs must be a number`)
|
|
51
51
|
// All values must be number, string, boolean
|
|
52
52
|
for (const v of Object.values(object.Resources)) {
|
|
53
|
-
if (v
|
|
54
|
-
if (
|
|
55
|
-
if (typeof v === 'boolean') continue
|
|
56
|
-
if (typeof v === 'number') continue
|
|
53
|
+
if (isSimpleResource(v)) continue
|
|
54
|
+
if (Array.isArray(v) && v.every((v) => isSimpleResource(v))) continue
|
|
57
55
|
return error(`Invalid value type ${typeof v}`)
|
|
58
56
|
}
|
|
59
57
|
return { object: object as LwM2MObjectInstance }
|
|
60
58
|
}
|
|
61
59
|
|
|
60
|
+
const isSimpleResource = (
|
|
61
|
+
v?: unknown,
|
|
62
|
+
): v is number | string | boolean | undefined => {
|
|
63
|
+
if (v === undefined) return true
|
|
64
|
+
if (typeof v === 'string') return true
|
|
65
|
+
if (typeof v === 'boolean') return true
|
|
66
|
+
if (typeof v === 'number') return true
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
|
|
62
70
|
export const validateInstance =
|
|
63
71
|
<O extends LwM2MObjectInstance>(
|
|
64
72
|
ObjectID: LwM2MObjectID,
|
|
@@ -99,12 +107,11 @@ export const BooleanResource = (r: unknown): r is boolean =>
|
|
|
99
107
|
typeof r === 'boolean'
|
|
100
108
|
|
|
101
109
|
export const OptionalResource =
|
|
102
|
-
(
|
|
103
|
-
validator:
|
|
104
|
-
| typeof NumberResource
|
|
105
|
-
| typeof TimeResource
|
|
106
|
-
| typeof StringResource
|
|
107
|
-
| typeof BooleanResource,
|
|
108
|
-
) =>
|
|
110
|
+
(validator: (r: unknown) => boolean) =>
|
|
109
111
|
(r: unknown): boolean =>
|
|
110
112
|
r === undefined ? true : validator(r)
|
|
113
|
+
|
|
114
|
+
export const MultipleInstanceResource =
|
|
115
|
+
(validator: (r: unknown) => boolean) =>
|
|
116
|
+
(r: unknown): boolean =>
|
|
117
|
+
Array.isArray(r) && r.every(validator)
|
package/lwm2m/validators.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { validate14220 } from "./object/validate14220.js";
|
|
|
10
10
|
import { validate14230 } from "./object/validate14230.js";
|
|
11
11
|
import { validate14240 } from "./object/validate14240.js";
|
|
12
12
|
import { validate14301 } from "./object/validate14301.js";
|
|
13
|
+
import { validate14401 } from "./object/validate14401.js";
|
|
13
14
|
/**
|
|
14
15
|
* Contains the validators for all registered LwM2M objects.
|
|
15
16
|
*/
|
|
@@ -27,4 +28,5 @@ validators.set(LwM2MObjectID.SolarCharge_14210, validate14210)
|
|
|
27
28
|
validators.set(LwM2MObjectID.ButtonPress_14220, validate14220)
|
|
28
29
|
validators.set(LwM2MObjectID.SeaWaterLevel_14230, validate14230)
|
|
29
30
|
validators.set(LwM2MObjectID.RGBLED_14240, validate14240)
|
|
30
|
-
validators.set(LwM2MObjectID.ApplicationConfiguration_14301, validate14301)
|
|
31
|
+
validators.set(LwM2MObjectID.ApplicationConfiguration_14301, validate14301)
|
|
32
|
+
validators.set(LwM2MObjectID.NRFCloudServiceInfo_14401, validate14401)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hello.nrfcloud.com/proto-map",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.1.1",
|
|
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": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@bifravst/eslint-config-typescript": "6.1.2",
|
|
39
|
-
"@bifravst/prettier-config": "1.0.
|
|
39
|
+
"@bifravst/prettier-config": "1.0.2",
|
|
40
40
|
"@commitlint/config-conventional": "19.2.2",
|
|
41
41
|
"@swc/cli": "0.3.12",
|
|
42
|
-
"@swc/core": "1.5.
|
|
43
|
-
"@types/node": "20.14.
|
|
42
|
+
"@swc/core": "1.5.25",
|
|
43
|
+
"@types/node": "20.14.2",
|
|
44
44
|
"@types/xml2js": "0.4.14",
|
|
45
45
|
"chalk": "5.3.0",
|
|
46
46
|
"globstar": "1.0.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"remark": "15.0.1",
|
|
51
51
|
"remark-frontmatter": "5.0.0",
|
|
52
52
|
"tsmatchers": "5.0.2",
|
|
53
|
-
"tsx": "4.
|
|
53
|
+
"tsx": "4.13.2",
|
|
54
54
|
"xml2js": "0.6.2",
|
|
55
55
|
"yaml": "2.4.3"
|
|
56
56
|
},
|