@hello.nrfcloud.com/proto-map 5.6.2 → 5.6.3
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 +1 -1
- package/api/{ResourceUpdate.spec.ts → ObjectUpdate.spec.ts} +5 -5
- package/api/{ResourceUpdate.ts → ObjectUpdate.ts} +4 -4
- package/dist/api/Context.js +1 -1
- package/dist/api/DeviceId.js +7 -7
- package/dist/api/Devices.js +11 -11
- package/dist/api/History.js +10 -10
- package/dist/api/History.spec.js +17 -17
- package/dist/api/LwM2M.js +11 -11
- package/dist/api/ObjectUpdate.js +17 -0
- package/dist/api/ObjectUpdate.spec.js +26 -0
- package/dist/api/ShareDeviceOwnershipConfirmed.js +4 -4
- package/dist/api/ShareDeviceRequest.js +4 -4
- package/dist/api/Timestamp.js +3 -3
- package/dist/api/Timestamp.spec.js +9 -9
- package/dist/api/index.js +8 -8
- package/dist/generator/addDocBlock.js +2 -2
- package/dist/generator/generateLwM2MDefinitions.js +27 -27
- package/dist/generator/generateLwM2MDefinitions.spec.js +32 -32
- package/dist/generator/generateLwm2mTimestampResources.js +7 -7
- package/dist/generator/generateModels.js +37 -37
- package/dist/generator/generateType.js +21 -21
- package/dist/generator/generateValidator.js +29 -29
- package/dist/generator/generateValidators.js +9 -9
- package/dist/generator/isDir.js +1 -1
- package/dist/generator/isDir.spec.js +13 -13
- package/dist/generator/lwm2m.js +23 -23
- package/dist/generator/models.js +23 -23
- package/dist/generator/printNode.js +2 -2
- package/dist/generator/tokenizeName.js +2 -2
- package/dist/generator/tokenizeName.spec.js +20 -20
- package/dist/generator/types.js +37 -37
- package/dist/lwm2m/LWM2MObjectDefinition.js +30 -30
- package/dist/lwm2m/check-lwm2m-rules.js +34 -34
- package/dist/lwm2m/definitions.js +4 -4
- package/dist/lwm2m/fromXML2JSON.js +4 -4
- package/dist/lwm2m/instanceTs.js +2 -2
- package/dist/lwm2m/instanceTs.spec.js +10 -10
- package/dist/lwm2m/isRegisteredLwM2MObject.js +2 -2
- package/dist/lwm2m/isRegisteredLwM2MObject.spec.js +12 -12
- package/dist/lwm2m/parseRangeEnumeration.js +1 -1
- package/dist/lwm2m/parseRangeEnumeration.spec.js +11 -11
- package/dist/lwm2m/unwrapNestedArray.js +2 -2
- package/dist/lwm2m/unwrapNestedArray.spec.js +155 -155
- package/dist/lwm2m/validate.js +1 -1
- package/dist/lwm2m/validation.js +16 -16
- package/dist/markdown/getCodeBlock.js +5 -5
- package/dist/markdown/getFrontMatter.js +6 -6
- package/dist/markdown/parseREADME.js +5 -5
- package/dist/models/asset_tracker_v2+AWS/examples/examples.spec.js +21 -21
- package/dist/models/check-model-rules.js +42 -42
- package/dist/models/models.js +20 -20
- package/dist/models/types.js +3 -3
- package/dist/senml/SenMLSchema.js +16 -16
- package/dist/senml/SenMLSchema.spec.js +11 -11
- package/dist/senml/hasValue.js +2 -2
- package/dist/senml/hasValue.spec.js +4 -4
- package/dist/senml/lwm2mToSenML.js +8 -8
- package/dist/senml/lwm2mToSenML.spec.js +42 -42
- package/dist/senml/parseResourceId.js +1 -1
- package/dist/senml/parseResourceId.spec.js +6 -6
- package/dist/senml/senMLtoLwM2M.js +14 -14
- package/dist/senml/senMLtoLwM2M.spec.js +53 -53
- package/dist/senml/validateSenML.js +2 -2
- package/dist/senml/validateSenML.spec.js +11 -11
- package/package.json +4 -8
- package/dist/api/ResourceUpdate.js +0 -17
- package/dist/api/ResourceUpdate.spec.js +0 -26
package/api/Context.ts
CHANGED
|
@@ -10,6 +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
|
-
|
|
13
|
+
objectUpdate: new URL(`${baseURL}/object/update`),
|
|
14
14
|
named: (name: string): URL => new URL(`${baseURL}/${name}`),
|
|
15
15
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { describe, it } from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
3
|
import { validate } from '../validate.js'
|
|
4
|
-
import {
|
|
4
|
+
import { ObjectUpdate } from './ObjectUpdate.js'
|
|
5
5
|
import type { Static } from '@sinclair/typebox'
|
|
6
6
|
|
|
7
|
-
void describe('
|
|
7
|
+
void describe('ObjectUpdate', () => {
|
|
8
8
|
void it('should validate', () => {
|
|
9
|
-
const input: Static<typeof
|
|
10
|
-
'@context': 'https://github.com/hello-nrfcloud/proto-map/
|
|
9
|
+
const input: Static<typeof ObjectUpdate> = {
|
|
10
|
+
'@context': 'https://github.com/hello-nrfcloud/proto-map/object/update',
|
|
11
11
|
ObjectID: 14201,
|
|
12
12
|
ObjectVersion: '1.0',
|
|
13
13
|
ObjectInstanceID: 0,
|
|
@@ -21,7 +21,7 @@ void describe('ResourceUpdate', () => {
|
|
|
21
21
|
deviceId: 'bassetto-ennobler-toilless',
|
|
22
22
|
ts: '2024-04-19T08:30:00.000Z',
|
|
23
23
|
}
|
|
24
|
-
const maybeValid = validate(
|
|
24
|
+
const maybeValid = validate(ObjectUpdate)(input)
|
|
25
25
|
assert.equal('errors' in maybeValid, false)
|
|
26
26
|
assert.deepEqual('value' in maybeValid && maybeValid.value, input)
|
|
27
27
|
})
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
import { PublicDeviceId } from './DeviceId.js'
|
|
10
10
|
import { Timestamp } from './Timestamp.js'
|
|
11
11
|
|
|
12
|
-
export const
|
|
12
|
+
export const ObjectUpdate = Type.Object(
|
|
13
13
|
{
|
|
14
|
-
'@context': Type.Literal(Context.
|
|
14
|
+
'@context': Type.Literal(Context.objectUpdate.toString()),
|
|
15
15
|
ObjectID,
|
|
16
16
|
ObjectInstanceID: Type.Optional(ObjectInstanceID),
|
|
17
17
|
ObjectVersion: Type.Optional(ObjectVersion),
|
|
@@ -20,7 +20,7 @@ export const ResourceUpdate = Type.Object(
|
|
|
20
20
|
deviceId: PublicDeviceId,
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
title: '
|
|
24
|
-
description: 'Describes an update to a LwM2M
|
|
23
|
+
title: 'Object update',
|
|
24
|
+
description: 'Describes an update to a LwM2M object for a device.',
|
|
25
25
|
},
|
|
26
26
|
)
|
package/dist/api/Context.js
CHANGED
|
@@ -9,7 +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
|
-
|
|
12
|
+
objectUpdate: new URL("".concat(baseURL, "/object/update")),
|
|
13
13
|
named: function(name) {
|
|
14
14
|
return new URL("".concat(baseURL, "/").concat(name));
|
|
15
15
|
}
|
package/dist/api/DeviceId.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Type } from
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
2
|
export var DeviceId = Type.RegExp(/^[a-zA-Z0-9:_-]{1,128}$/, {
|
|
3
|
-
title:
|
|
4
|
-
description:
|
|
3
|
+
title: 'Device ID',
|
|
4
|
+
description: 'Must follow the AWS IoT limitations for Thing names.',
|
|
5
5
|
examples: [
|
|
6
|
-
|
|
6
|
+
'oob-352656166666905'
|
|
7
7
|
]
|
|
8
8
|
});
|
|
9
9
|
export var PublicDeviceId = Type.RegExp(/^[a-z]{8}-[a-z]{8}-[a-z]{8}$/, {
|
|
10
|
-
title:
|
|
11
|
-
description:
|
|
10
|
+
title: 'Public Device ID',
|
|
11
|
+
description: 'This is the format of @nordicsemiconductor/random-words which is used for public IDs.',
|
|
12
12
|
examples: [
|
|
13
|
-
|
|
13
|
+
'pentacid-coxalgia-backheel'
|
|
14
14
|
]
|
|
15
15
|
});
|
package/dist/api/Devices.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Type } from
|
|
2
|
-
import { Context } from
|
|
3
|
-
import { PublicDeviceId } from
|
|
4
|
-
import { models } from
|
|
5
|
-
import { ObjectID, ObjectInstanceID, ObjectVersion, Resources } from
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { Context } from './Context.js';
|
|
3
|
+
import { PublicDeviceId } from './DeviceId.js';
|
|
4
|
+
import { models } from '@hello.nrfcloud.com/proto-map';
|
|
5
|
+
import { ObjectID, ObjectInstanceID, ObjectVersion, Resources } from './LwM2M.js';
|
|
6
6
|
export var LwM2MObjectInstance = Type.Object({
|
|
7
7
|
ObjectID: ObjectID,
|
|
8
8
|
ObjectVersion: Type.Optional(ObjectVersion),
|
|
@@ -12,19 +12,19 @@ export var LwM2MObjectInstance = Type.Object({
|
|
|
12
12
|
export var Model = Type.Union(Object.keys(models).map(function(s) {
|
|
13
13
|
return Type.Literal(s);
|
|
14
14
|
}), {
|
|
15
|
-
title:
|
|
16
|
-
description:
|
|
15
|
+
title: 'Model',
|
|
16
|
+
description: 'Must be one of the models defined in @hello.nrfcloud.com/proto-map'
|
|
17
17
|
});
|
|
18
18
|
export var PublicDevice = Type.Object({
|
|
19
|
-
|
|
19
|
+
'@context': Type.Literal(Context.device.toString()),
|
|
20
20
|
id: PublicDeviceId,
|
|
21
21
|
model: Model,
|
|
22
22
|
state: Type.Optional(Type.Array(LwM2MObjectInstance))
|
|
23
23
|
}, {
|
|
24
|
-
title:
|
|
25
|
-
description:
|
|
24
|
+
title: 'Public device',
|
|
25
|
+
description: 'A device that is publicly visible.'
|
|
26
26
|
});
|
|
27
27
|
export var Devices = Type.Object({
|
|
28
|
-
|
|
28
|
+
'@context': Type.Literal(Context.devices.toString()),
|
|
29
29
|
devices: Type.Array(PublicDevice)
|
|
30
30
|
});
|
package/dist/api/History.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Type } from
|
|
2
|
-
import { Context } from
|
|
3
|
-
import { ObjectID, ObjectInstanceID, ObjectVersion, Resources } from
|
|
4
|
-
import { PublicDeviceId } from
|
|
5
|
-
import { Timestamp } from
|
|
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
6
|
export var ResourceHistory = Type.Object({
|
|
7
|
-
|
|
7
|
+
'@context': Type.Literal(Context.history.resource.toString()),
|
|
8
8
|
partialInstances: Type.Array(Type.Intersect([
|
|
9
9
|
Resources,
|
|
10
10
|
Type.Object({
|
|
11
11
|
ts: Timestamp
|
|
12
12
|
})
|
|
13
13
|
], {
|
|
14
|
-
title:
|
|
14
|
+
title: 'The resources of the object instance and the timestamp the data was received.'
|
|
15
15
|
})),
|
|
16
16
|
query: Type.Object({
|
|
17
17
|
ObjectID: ObjectID,
|
|
@@ -19,7 +19,7 @@ export var ResourceHistory = Type.Object({
|
|
|
19
19
|
ObjectVersion: ObjectVersion,
|
|
20
20
|
binIntervalMinutes: Type.Number({
|
|
21
21
|
minimum: 1,
|
|
22
|
-
title:
|
|
22
|
+
title: 'The number of minutes the results are binned to.',
|
|
23
23
|
examples: [
|
|
24
24
|
15
|
|
25
25
|
]
|
|
@@ -29,6 +29,6 @@ export var ResourceHistory = Type.Object({
|
|
|
29
29
|
title: "The query that was used"
|
|
30
30
|
})
|
|
31
31
|
}, {
|
|
32
|
-
title:
|
|
33
|
-
description:
|
|
32
|
+
title: 'Resource history',
|
|
33
|
+
description: 'Contains historical values of an LwM2M resource for a device.'
|
|
34
34
|
});
|
package/dist/api/History.spec.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { describe, it } from
|
|
2
|
-
import assert from
|
|
3
|
-
import { validate } from
|
|
4
|
-
import { ResourceHistory } from
|
|
5
|
-
void describe(
|
|
6
|
-
void it(
|
|
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
7
|
var input = {
|
|
8
|
-
|
|
8
|
+
'@context': 'https://github.com/hello-nrfcloud/proto-map/history/resource',
|
|
9
9
|
query: {
|
|
10
10
|
ObjectID: 14230,
|
|
11
|
-
ObjectVersion:
|
|
11
|
+
ObjectVersion: '1.0',
|
|
12
12
|
ObjectInstanceID: 0,
|
|
13
|
-
deviceId:
|
|
13
|
+
deviceId: 'bassetto-ennobler-toilless',
|
|
14
14
|
binIntervalMinutes: 15
|
|
15
15
|
},
|
|
16
16
|
partialInstances: [
|
|
17
17
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ts:
|
|
18
|
+
'0': 92.2,
|
|
19
|
+
'99': 1713510000000,
|
|
20
|
+
ts: '2024-04-19T08:45:00.000Z'
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
ts:
|
|
23
|
+
'0': 113.8,
|
|
24
|
+
'99': 1713515400000,
|
|
25
|
+
ts: '2024-04-19T08:30:00.000Z'
|
|
26
26
|
}
|
|
27
27
|
]
|
|
28
28
|
};
|
|
29
29
|
var maybeValid = validate(ResourceHistory)(input);
|
|
30
|
-
assert.equal(
|
|
31
|
-
assert.deepEqual(
|
|
30
|
+
assert.equal('errors' in maybeValid, false);
|
|
31
|
+
assert.deepEqual('value' in maybeValid && maybeValid.value, input);
|
|
32
32
|
});
|
|
33
33
|
});
|
package/dist/api/LwM2M.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { Type } from
|
|
2
|
-
import { LwM2MObjectID } from
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { LwM2MObjectID } from '../lwm2m/LwM2MObjectID.js';
|
|
3
3
|
export var ObjectVersion = Type.String({
|
|
4
|
-
pattern:
|
|
5
|
-
default:
|
|
4
|
+
pattern: '^[0-9]+.[0-9]+$',
|
|
5
|
+
default: '1.0',
|
|
6
6
|
examples: [
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
'1.0',
|
|
8
|
+
'1.1'
|
|
9
9
|
],
|
|
10
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
11
|
});
|
|
12
12
|
export var ObjectID = Type.Enum(LwM2MObjectID, {
|
|
13
|
-
description:
|
|
13
|
+
description: 'The LwM2M Object IDs defined in @hello.nrfcloud.com/proto-map'
|
|
14
14
|
});
|
|
15
15
|
export var ObjectInstanceID = Type.Integer({
|
|
16
16
|
minimum: 0,
|
|
17
17
|
default: 0,
|
|
18
|
-
description:
|
|
18
|
+
description: 'The LwM2M Object Instance ID',
|
|
19
19
|
examples: [
|
|
20
20
|
0,
|
|
21
21
|
1
|
|
@@ -26,12 +26,12 @@ export var Resources = Type.Record(Type.Integer({
|
|
|
26
26
|
}), Type.Union([
|
|
27
27
|
Type.String({
|
|
28
28
|
minLength: 1,
|
|
29
|
-
title:
|
|
29
|
+
title: 'LwM2M string value'
|
|
30
30
|
}),
|
|
31
31
|
Type.Number({
|
|
32
|
-
title:
|
|
32
|
+
title: 'LwM2M number value'
|
|
33
33
|
}),
|
|
34
34
|
Type.Boolean({
|
|
35
|
-
title:
|
|
35
|
+
title: 'LwM2M boolean value'
|
|
36
36
|
})
|
|
37
37
|
]));
|
|
@@ -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 ObjectUpdate = Type.Object({
|
|
7
|
+
'@context': Type.Literal(Context.objectUpdate.toString()),
|
|
8
|
+
ObjectID: ObjectID,
|
|
9
|
+
ObjectInstanceID: Type.Optional(ObjectInstanceID),
|
|
10
|
+
ObjectVersion: Type.Optional(ObjectVersion),
|
|
11
|
+
Resources: Resources,
|
|
12
|
+
ts: Timestamp,
|
|
13
|
+
deviceId: PublicDeviceId
|
|
14
|
+
}, {
|
|
15
|
+
title: 'Object update',
|
|
16
|
+
description: 'Describes an update to a LwM2M object 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 { ObjectUpdate } from './ObjectUpdate.js';
|
|
5
|
+
void describe('ObjectUpdate', function() {
|
|
6
|
+
void it('should validate', function() {
|
|
7
|
+
var input = {
|
|
8
|
+
'@context': 'https://github.com/hello-nrfcloud/proto-map/object/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(ObjectUpdate)(input);
|
|
23
|
+
assert.equal('errors' in maybeValid, false);
|
|
24
|
+
assert.deepEqual('value' in maybeValid && maybeValid.value, input);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Type } from
|
|
2
|
-
import { Context } from
|
|
3
|
-
import { DeviceId } from
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { Context } from './Context.js';
|
|
3
|
+
import { DeviceId } from './DeviceId.js';
|
|
4
4
|
export var ShareDeviceOwnershipConfirmed = Type.Object({
|
|
5
|
-
|
|
5
|
+
'@context': Type.Literal(Context.shareDevice.ownershipConfirmed.toString()),
|
|
6
6
|
id: DeviceId
|
|
7
7
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Type } from
|
|
2
|
-
import { Context } from
|
|
3
|
-
import { DeviceId, PublicDeviceId } from
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { Context } from './Context.js';
|
|
3
|
+
import { DeviceId, PublicDeviceId } from './DeviceId.js';
|
|
4
4
|
export var ShareDeviceRequest = Type.Object({
|
|
5
|
-
|
|
5
|
+
'@context': Type.Literal(Context.shareDevice.request.toString()),
|
|
6
6
|
id: PublicDeviceId,
|
|
7
7
|
deviceId: DeviceId
|
|
8
8
|
});
|
package/dist/api/Timestamp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Type } from
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
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:
|
|
3
|
+
title: 'Time when the update was received, formatted as ISO 8601',
|
|
4
4
|
examples: [
|
|
5
|
-
|
|
5
|
+
'2024-04-19T08:45:00.000Z'
|
|
6
6
|
]
|
|
7
7
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { describe, it } from
|
|
2
|
-
import assert from
|
|
3
|
-
import { validate } from
|
|
4
|
-
import { Timestamp } from
|
|
5
|
-
void describe(
|
|
6
|
-
void it(
|
|
7
|
-
var input =
|
|
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
8
|
var maybeValid = validate(Timestamp)(input);
|
|
9
|
-
assert.equal(
|
|
10
|
-
assert.deepEqual(
|
|
9
|
+
assert.equal('errors' in maybeValid, false);
|
|
10
|
+
assert.deepEqual('value' in maybeValid && maybeValid.value, input);
|
|
11
11
|
});
|
|
12
12
|
});
|
package/dist/api/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
1
|
+
export * from './Context.js';
|
|
2
|
+
export * from './DeviceId.js';
|
|
3
|
+
export * from './Devices.js';
|
|
4
|
+
export * from './ShareDeviceOwnershipConfirmed.js';
|
|
5
|
+
export * from './ShareDeviceRequest.js';
|
|
6
|
+
export * from './History.js';
|
|
7
|
+
export * from './LwM2M.js';
|
|
8
|
+
export * from './Timestamp.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import ts from
|
|
1
|
+
import ts from 'typescript';
|
|
2
2
|
export var addDocBlock = function(comment, node) {
|
|
3
|
-
ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, "*\n * ".concat(comment.join(
|
|
3
|
+
ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, "*\n * ".concat(comment.join('\n * '), " \n "), true);
|
|
4
4
|
return node;
|
|
5
5
|
};
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import ts from
|
|
2
|
-
import { addDocBlock } from
|
|
3
|
-
import { generateName } from
|
|
4
|
-
import { parseRangeEnumeration } from
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { addDocBlock } from './addDocBlock.js';
|
|
3
|
+
import { generateName } from './generateType.js';
|
|
4
|
+
import { parseRangeEnumeration } from '../lwm2m/parseRangeEnumeration.js';
|
|
5
5
|
export var generateLwM2MDefinitions = function(definitions) {
|
|
6
6
|
var importLWM2MObjectInfo = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
7
7
|
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier("LWM2MObjectInfo")),
|
|
8
8
|
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("ResourceType"))
|
|
9
|
-
])), ts.factory.createStringLiteral(
|
|
9
|
+
])), ts.factory.createStringLiteral('./LWM2MObjectInfo.js'));
|
|
10
10
|
var importLwM2MObjectID = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
11
11
|
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObjectID"))
|
|
12
|
-
])), ts.factory.createStringLiteral(
|
|
12
|
+
])), ts.factory.createStringLiteral('./LwM2MObjectID.js'));
|
|
13
13
|
var type = ts.factory.createVariableStatement([
|
|
14
14
|
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
15
15
|
], ts.factory.createVariableDeclarationList([
|
|
16
|
-
ts.factory.createVariableDeclaration(ts.factory.createIdentifier("definitions"), undefined, ts.factory.createTypeReferenceNode(
|
|
17
|
-
ts.factory.createTypeReferenceNode(
|
|
18
|
-
ts.factory.createTypeReferenceNode(
|
|
16
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier("definitions"), undefined, ts.factory.createTypeReferenceNode('Record', [
|
|
17
|
+
ts.factory.createTypeReferenceNode('LwM2MObjectID'),
|
|
18
|
+
ts.factory.createTypeReferenceNode('LWM2MObjectInfo')
|
|
19
19
|
]), ts.factory.createObjectLiteralExpression(definitions.map(function(definition) {
|
|
20
20
|
var _definition_ObjectVersion;
|
|
21
|
-
var objectDef = ts.factory.createPropertyAssignment(ts.factory.createComputedPropertyName(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(
|
|
22
|
-
ts.factory.createPropertyAssignment(
|
|
23
|
-
ts.factory.createPropertyAssignment(
|
|
24
|
-
ts.factory.createPropertyAssignment(
|
|
25
|
-
ts.factory.createPropertyAssignment(
|
|
26
|
-
ts.factory.createPropertyAssignment(
|
|
21
|
+
var objectDef = ts.factory.createPropertyAssignment(ts.factory.createComputedPropertyName(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('LwM2MObjectID'), generateName(definition))), ts.factory.createObjectLiteralExpression([
|
|
22
|
+
ts.factory.createPropertyAssignment('ObjectID', ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('LwM2MObjectID'), generateName(definition))),
|
|
23
|
+
ts.factory.createPropertyAssignment('ObjectVersion', ts.factory.createStringLiteral((_definition_ObjectVersion = definition.ObjectVersion) !== null && _definition_ObjectVersion !== void 0 ? _definition_ObjectVersion : '1.0')),
|
|
24
|
+
ts.factory.createPropertyAssignment('Name', ts.factory.createStringLiteral(definition.Name)),
|
|
25
|
+
ts.factory.createPropertyAssignment('Description', ts.factory.createStringLiteral(definition.Description1)),
|
|
26
|
+
ts.factory.createPropertyAssignment('Resources', ts.factory.createObjectLiteralExpression(definition.Resources.Item.map(function(Resource) {
|
|
27
27
|
var range = undefined;
|
|
28
28
|
if (Resource.RangeEnumeration.length > 0) {
|
|
29
29
|
var maybeRange = parseRangeEnumeration(Resource.RangeEnumeration);
|
|
30
|
-
if (
|
|
30
|
+
if ('error' in maybeRange) throw maybeRange.error;
|
|
31
31
|
range = maybeRange.range;
|
|
32
32
|
}
|
|
33
33
|
var props = [
|
|
34
|
-
ts.factory.createPropertyAssignment(
|
|
35
|
-
ts.factory.createPropertyAssignment(
|
|
36
|
-
ts.factory.createPropertyAssignment(
|
|
37
|
-
ts.factory.createPropertyAssignment(
|
|
38
|
-
ts.factory.createPropertyAssignment(
|
|
34
|
+
ts.factory.createPropertyAssignment('ResourceID', ts.factory.createNumericLiteral(Resource.$.ID)),
|
|
35
|
+
ts.factory.createPropertyAssignment('Name', ts.factory.createStringLiteral(Resource.Name)),
|
|
36
|
+
ts.factory.createPropertyAssignment('Mandatory', ts.factory.createIdentifier(Resource.Mandatory === 'Mandatory' ? 'true' : 'false')),
|
|
37
|
+
ts.factory.createPropertyAssignment('Type', ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('ResourceType'), Resource.Type)),
|
|
38
|
+
ts.factory.createPropertyAssignment('Description', ts.factory.createStringLiteral(Resource.Description))
|
|
39
39
|
];
|
|
40
40
|
if (Resource.RangeEnumeration.length > 0) {
|
|
41
41
|
var maybeRange1 = parseRangeEnumeration(Resource.RangeEnumeration);
|
|
42
|
-
if (
|
|
42
|
+
if ('error' in maybeRange1) throw maybeRange1.error;
|
|
43
43
|
var _maybeRange_range = maybeRange1.range, min = _maybeRange_range.min, max = _maybeRange_range.max;
|
|
44
|
-
props.push(ts.factory.createPropertyAssignment(
|
|
45
|
-
ts.factory.createPropertyAssignment(
|
|
46
|
-
ts.factory.createPropertyAssignment(
|
|
44
|
+
props.push(ts.factory.createPropertyAssignment('RangeEnumeration', ts.factory.createObjectLiteralExpression([
|
|
45
|
+
ts.factory.createPropertyAssignment('min', createNumber(min)),
|
|
46
|
+
ts.factory.createPropertyAssignment('max', createNumber(max))
|
|
47
47
|
])));
|
|
48
48
|
}
|
|
49
|
-
if (Resource.Units.length > 0) props.push(ts.factory.createPropertyAssignment(
|
|
49
|
+
if (Resource.Units.length > 0) props.push(ts.factory.createPropertyAssignment('Units', ts.factory.createStringLiteral(Resource.Units)));
|
|
50
50
|
var resourceDef = ts.factory.createPropertyAssignment(ts.factory.createNumericLiteral(Resource.$.ID), ts.factory.createObjectLiteralExpression(props));
|
|
51
51
|
var docStrings = [
|
|
52
52
|
"".concat(Resource.Name, " (").concat(Resource.Type, ")"),
|
|
@@ -69,7 +69,7 @@ export var generateLwM2MDefinitions = function(definitions) {
|
|
|
69
69
|
})))
|
|
70
70
|
], ts.NodeFlags.Const));
|
|
71
71
|
addDocBlock([
|
|
72
|
-
|
|
72
|
+
'Contains the ID of the resource that defines the timestamp for each LwM2M object definition'
|
|
73
73
|
], type);
|
|
74
74
|
return [
|
|
75
75
|
importLWM2MObjectInfo,
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { describe, it } from
|
|
2
|
-
import assert from
|
|
3
|
-
import { definitions } from
|
|
4
|
-
import { LwM2MObjectID } from
|
|
5
|
-
import { ResourceType } from
|
|
6
|
-
void describe(
|
|
7
|
-
void it(
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { definitions } from '../lwm2m/definitions.js';
|
|
4
|
+
import { LwM2MObjectID } from '../lwm2m/LwM2MObjectID.js';
|
|
5
|
+
import { ResourceType } from '../lwm2m/LWM2MObjectInfo.js';
|
|
6
|
+
void describe('generateLwM2MDefinitions()', function() {
|
|
7
|
+
void it('should have generated definitions from the XML files', function() {
|
|
8
8
|
assert.deepEqual(definitions[LwM2MObjectID.Geolocation_14201], {
|
|
9
9
|
ObjectID: 14201,
|
|
10
|
-
ObjectVersion:
|
|
11
|
-
Name:
|
|
12
|
-
Description:
|
|
10
|
+
ObjectVersion: '1.0',
|
|
11
|
+
Name: 'Geolocation',
|
|
12
|
+
Description: 'Describes the geo location of a device',
|
|
13
13
|
Resources: {
|
|
14
14
|
0: {
|
|
15
15
|
ResourceID: 0,
|
|
16
|
-
Name:
|
|
16
|
+
Name: 'Latitude',
|
|
17
17
|
Mandatory: true,
|
|
18
18
|
Type: ResourceType.Float,
|
|
19
|
-
Description:
|
|
20
|
-
Units:
|
|
19
|
+
Description: 'The decimal notation of latitude in degrees, e.g. -43.5723 [World Geodetic System 1984].',
|
|
20
|
+
Units: '°',
|
|
21
21
|
RangeEnumeration: {
|
|
22
22
|
max: 90,
|
|
23
23
|
min: -90
|
|
@@ -25,11 +25,11 @@ void describe("generateLwM2MDefinitions()", function() {
|
|
|
25
25
|
},
|
|
26
26
|
1: {
|
|
27
27
|
ResourceID: 1,
|
|
28
|
-
Name:
|
|
28
|
+
Name: 'Longitude',
|
|
29
29
|
Mandatory: true,
|
|
30
30
|
Type: ResourceType.Float,
|
|
31
|
-
Description:
|
|
32
|
-
Units:
|
|
31
|
+
Description: 'The decimal notation of longitude in degrees, e.g. 153.21760 [World Geodetic System 1984].',
|
|
32
|
+
Units: '°',
|
|
33
33
|
RangeEnumeration: {
|
|
34
34
|
max: 180,
|
|
35
35
|
min: -180
|
|
@@ -37,35 +37,35 @@ void describe("generateLwM2MDefinitions()", function() {
|
|
|
37
37
|
},
|
|
38
38
|
2: {
|
|
39
39
|
ResourceID: 2,
|
|
40
|
-
Name:
|
|
40
|
+
Name: 'Altitude',
|
|
41
41
|
Mandatory: false,
|
|
42
42
|
Type: ResourceType.Float,
|
|
43
|
-
Description:
|
|
44
|
-
Units:
|
|
43
|
+
Description: 'The decimal notation of altitude in meters above sea level.',
|
|
44
|
+
Units: 'm'
|
|
45
45
|
},
|
|
46
46
|
3: {
|
|
47
47
|
ResourceID: 3,
|
|
48
|
-
Name:
|
|
48
|
+
Name: 'Radius',
|
|
49
49
|
Mandatory: false,
|
|
50
50
|
Type: ResourceType.Float,
|
|
51
|
-
Description:
|
|
52
|
-
Units:
|
|
51
|
+
Description: 'The value in this resource indicates the radius of a circular area in meters. The circular area is used to describe uncertainty about a point for coordinates in a two-dimensional coordinate reference systems (CRS). The center point of a circular area is specified by using the Latitude and the Longitude Resources.',
|
|
52
|
+
Units: 'm'
|
|
53
53
|
},
|
|
54
54
|
4: {
|
|
55
55
|
ResourceID: 4,
|
|
56
|
-
Name:
|
|
56
|
+
Name: 'Speed',
|
|
57
57
|
Mandatory: false,
|
|
58
58
|
Type: ResourceType.Float,
|
|
59
|
-
Description:
|
|
60
|
-
Units:
|
|
59
|
+
Description: 'Speed is the time rate of change in position.',
|
|
60
|
+
Units: 'm/s'
|
|
61
61
|
},
|
|
62
62
|
5: {
|
|
63
63
|
ResourceID: 5,
|
|
64
|
-
Name:
|
|
64
|
+
Name: 'Heading',
|
|
65
65
|
Mandatory: false,
|
|
66
66
|
Type: ResourceType.Float,
|
|
67
|
-
Description:
|
|
68
|
-
Units:
|
|
67
|
+
Description: 'The angle of movement in degrees.',
|
|
68
|
+
Units: '°',
|
|
69
69
|
RangeEnumeration: {
|
|
70
70
|
min: 0,
|
|
71
71
|
max: 360
|
|
@@ -73,17 +73,17 @@ void describe("generateLwM2MDefinitions()", function() {
|
|
|
73
73
|
},
|
|
74
74
|
6: {
|
|
75
75
|
ResourceID: 6,
|
|
76
|
-
Name:
|
|
76
|
+
Name: 'Source',
|
|
77
77
|
Mandatory: true,
|
|
78
78
|
Type: ResourceType.String,
|
|
79
|
-
Description:
|
|
79
|
+
Description: 'The source of the geo location, e.g. GNSS, SCELL, MCELL, WIFI.'
|
|
80
80
|
},
|
|
81
81
|
99: {
|
|
82
82
|
ResourceID: 99,
|
|
83
|
-
Name:
|
|
83
|
+
Name: 'Timestamp',
|
|
84
84
|
Mandatory: true,
|
|
85
85
|
Type: ResourceType.Time,
|
|
86
|
-
Description:
|
|
86
|
+
Description: 'The timestamp of when the location measurement was performed.'
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
});
|