@hello.nrfcloud.com/proto-map 11.0.0 → 12.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/dist/generator/generateLwm2mTimestampResources.js +18 -6
- package/dist/generator/lwm2m.js +2 -1
- package/dist/lwm2m/instanceTs.js +1 -1
- package/dist/lwm2m/timestampResources.js +43 -12
- package/dist/senml/lwm2mToSenML.js +1 -1
- package/dist/senml/senMLtoLwM2M.js +1 -1
- package/lwm2m/instanceTs.ts +1 -1
- package/lwm2m/timestampResources.ts +2 -1
- package/package.json +6 -6
- package/senml/lwm2mToSenML.ts +1 -1
- package/senml/senMLtoLwM2M.ts +1 -1
|
@@ -47,23 +47,35 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
47
47
|
import ts from 'typescript';
|
|
48
48
|
import { addDocBlock } from './addDocBlock.js';
|
|
49
49
|
export var generateLwm2mTimestampResources = function(timestampResources) {
|
|
50
|
+
var importLwM2MObjectID = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
51
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObjectID"))
|
|
52
|
+
])), ts.factory.createStringLiteral('./LwM2MObjectID.js'));
|
|
50
53
|
var type = ts.factory.createVariableStatement([
|
|
51
54
|
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
52
55
|
], ts.factory.createVariableDeclarationList([
|
|
53
56
|
ts.factory.createVariableDeclaration(ts.factory.createIdentifier("timestampResources"), undefined, ts.factory.createTypeReferenceNode('Readonly', [
|
|
54
|
-
ts.factory.createTypeReferenceNode('
|
|
55
|
-
ts.factory.createTypeReferenceNode('
|
|
57
|
+
ts.factory.createTypeReferenceNode('Map', [
|
|
58
|
+
ts.factory.createTypeReferenceNode('LwM2MObjectID'),
|
|
56
59
|
ts.factory.createTypeReferenceNode('number')
|
|
57
60
|
])
|
|
58
|
-
]), ts.factory.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
]), ts.factory.createNewExpression(ts.factory.createIdentifier('Map'), [
|
|
62
|
+
ts.factory.createTypeReferenceNode('LwM2MObjectID'),
|
|
63
|
+
ts.factory.createTypeReferenceNode('number')
|
|
64
|
+
], [
|
|
65
|
+
ts.factory.createArrayLiteralExpression(Object.entries(timestampResources).map(function(param) {
|
|
66
|
+
var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
|
|
67
|
+
return ts.factory.createArrayLiteralExpression([
|
|
68
|
+
ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('LwM2MObjectID'), ts.factory.createIdentifier(k)),
|
|
69
|
+
ts.factory.createNumericLiteral(v)
|
|
70
|
+
]);
|
|
71
|
+
}))
|
|
72
|
+
]))
|
|
62
73
|
], ts.NodeFlags.Const));
|
|
63
74
|
addDocBlock([
|
|
64
75
|
'Contains the ID of the resource that defines the timestamp for each LwM2M object definition'
|
|
65
76
|
], type);
|
|
66
77
|
return [
|
|
78
|
+
importLwM2MObjectID,
|
|
67
79
|
type
|
|
68
80
|
];
|
|
69
81
|
};
|
package/dist/generator/lwm2m.js
CHANGED
|
@@ -33,6 +33,7 @@ import { generateLwm2mTimestampResources } from './generateLwm2mTimestampResourc
|
|
|
33
33
|
import { printNode } from './printNode.js';
|
|
34
34
|
import os from 'node:os';
|
|
35
35
|
import { generateLwM2MDefinitions } from './generateLwM2MDefinitions.js';
|
|
36
|
+
import { generateName } from './generateType.js';
|
|
36
37
|
var baseDir = process.cwd();
|
|
37
38
|
var subDir = function() {
|
|
38
39
|
for(var _len = arguments.length, tree = new Array(_len), _key = 0; _key < _len; _key++){
|
|
@@ -87,7 +88,7 @@ try {
|
|
|
87
88
|
if (Item.Type === 'Time') ResourceId = parseInt(Item.$.ID, 10);
|
|
88
89
|
}
|
|
89
90
|
if (ResourceId === undefined) throw new Error("No Time resource found in ".concat(ObjectID, "!"));
|
|
90
|
-
timestampResources[
|
|
91
|
+
timestampResources[generateName(definition1)] = ResourceId;
|
|
91
92
|
console.log(' ', chalk.gray('·'), "".concat(chalk.white(ObjectID)).concat(chalk.gray('.')).concat(chalk.white(ResourceId)));
|
|
92
93
|
}
|
|
93
94
|
} catch (err) {
|
package/dist/lwm2m/instanceTs.js
CHANGED
|
@@ -2,7 +2,7 @@ import { definitions } from './definitions.js';
|
|
|
2
2
|
import { timestampResources } from './timestampResources.js';
|
|
3
3
|
export var instanceTs = function(instance) {
|
|
4
4
|
var definition = definitions[instance.ObjectID];
|
|
5
|
-
var tsResourceId = timestampResources
|
|
5
|
+
var tsResourceId = timestampResources.get(definition.ObjectID)// All registered objects must have a timestamp resource
|
|
6
6
|
;
|
|
7
7
|
return instance.Resources[tsResourceId];
|
|
8
8
|
};
|
|
@@ -1,14 +1,45 @@
|
|
|
1
|
+
import { LwM2MObjectID } from "./LwM2MObjectID.js";
|
|
1
2
|
/**
|
|
2
3
|
* Contains the ID of the resource that defines the timestamp for each LwM2M object definition
|
|
3
|
-
*/ export var timestampResources =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
*/ export var timestampResources = new Map([
|
|
5
|
+
[
|
|
6
|
+
LwM2MObjectID.Geolocation_14201,
|
|
7
|
+
99
|
|
8
|
+
],
|
|
9
|
+
[
|
|
10
|
+
LwM2MObjectID.BatteryAndPower_14202,
|
|
11
|
+
99
|
|
12
|
+
],
|
|
13
|
+
[
|
|
14
|
+
LwM2MObjectID.ConnectionInformation_14203,
|
|
15
|
+
99
|
|
16
|
+
],
|
|
17
|
+
[
|
|
18
|
+
LwM2MObjectID.DeviceInformation_14204,
|
|
19
|
+
99
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
LwM2MObjectID.Environment_14205,
|
|
23
|
+
99
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
LwM2MObjectID.SolarCharge_14210,
|
|
27
|
+
99
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
LwM2MObjectID.ButtonPress_14220,
|
|
31
|
+
99
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
LwM2MObjectID.SeaWaterLevel_14230,
|
|
35
|
+
99
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
LwM2MObjectID.RGBLED_14240,
|
|
39
|
+
99
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
LwM2MObjectID.ApplicationConfiguration_14301,
|
|
43
|
+
99
|
|
44
|
+
]
|
|
45
|
+
]);
|
|
@@ -84,7 +84,7 @@ import { ResourceType } from '../lwm2m/LWM2MObjectInfo.js';
|
|
|
84
84
|
*/ export var lwm2mToSenML = function(lwm2m) {
|
|
85
85
|
var def = definitions[lwm2m.ObjectID];
|
|
86
86
|
var i = instanceTs(lwm2m);
|
|
87
|
-
var tsResourceId = timestampResources
|
|
87
|
+
var tsResourceId = timestampResources.get(lwm2m.ObjectID)// All registered objects must have a timestamp resource
|
|
88
88
|
;
|
|
89
89
|
var _Object_entries_filter = _to_array(Object.entries(_object_spread_props(_object_spread({}, lwm2m.Resources), _define_property({}, tsResourceId, undefined)))// Filter out undefined values (and timestamp resource)
|
|
90
90
|
.filter(function(r) {
|
|
@@ -91,7 +91,7 @@ export var senMLtoLwM2M = function(senML) {
|
|
|
91
91
|
error: new Error("Invalid resource ID: ".concat(itemResourceId))
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
var tsRes = timestampResources
|
|
94
|
+
var tsRes = timestampResources.get(resourceId.ObjectID);
|
|
95
95
|
if (tsRes === undefined) {
|
|
96
96
|
return {
|
|
97
97
|
error: new Error("No timestamp resource defined for object: ".concat(resourceId.ObjectID))
|
package/lwm2m/instanceTs.ts
CHANGED
|
@@ -4,6 +4,6 @@ import { timestampResources } from './timestampResources.js'
|
|
|
4
4
|
|
|
5
5
|
export const instanceTs = (instance: LwM2MObjectInstance): number => {
|
|
6
6
|
const definition = definitions[instance.ObjectID]
|
|
7
|
-
const tsResourceId = timestampResources
|
|
7
|
+
const tsResourceId = timestampResources.get(definition.ObjectID) as number // All registered objects must have a timestamp resource
|
|
8
8
|
return instance.Resources[tsResourceId] as number
|
|
9
9
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { LwM2MObjectID } from "./LwM2MObjectID.js";
|
|
1
2
|
/**
|
|
2
3
|
* Contains the ID of the resource that defines the timestamp for each LwM2M object definition
|
|
3
4
|
*/
|
|
4
|
-
export const timestampResources: Readonly<
|
|
5
|
+
export const timestampResources: Readonly<Map<LwM2MObjectID, number>> = new Map<LwM2MObjectID, number>([[LwM2MObjectID.Geolocation_14201, 99], [LwM2MObjectID.BatteryAndPower_14202, 99], [LwM2MObjectID.ConnectionInformation_14203, 99], [LwM2MObjectID.DeviceInformation_14204, 99], [LwM2MObjectID.Environment_14205, 99], [LwM2MObjectID.SolarCharge_14210, 99], [LwM2MObjectID.ButtonPress_14220, 99], [LwM2MObjectID.SeaWaterLevel_14230, 99], [LwM2MObjectID.RGBLED_14240, 99], [LwM2MObjectID.ApplicationConfiguration_14301, 99]]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hello.nrfcloud.com/proto-map",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.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": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"prepublishOnly": "./compile.sh"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@bifravst/eslint-config-typescript": "6.1.
|
|
39
|
-
"@bifravst/prettier-config": "1.0.
|
|
38
|
+
"@bifravst/eslint-config-typescript": "6.1.2",
|
|
39
|
+
"@bifravst/prettier-config": "1.0.1",
|
|
40
40
|
"@commitlint/config-conventional": "19.2.2",
|
|
41
41
|
"@swc/cli": "0.3.12",
|
|
42
42
|
"@swc/core": "1.5.24",
|
|
43
|
-
"@types/node": "20.
|
|
43
|
+
"@types/node": "20.14.1",
|
|
44
44
|
"@types/xml2js": "0.4.14",
|
|
45
45
|
"chalk": "5.3.0",
|
|
46
46
|
"globstar": "1.0.0",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"remark": "15.0.1",
|
|
51
51
|
"remark-frontmatter": "5.0.0",
|
|
52
52
|
"tsmatchers": "5.0.2",
|
|
53
|
-
"tsx": "4.11.
|
|
53
|
+
"tsx": "4.11.2",
|
|
54
54
|
"xml2js": "0.6.2",
|
|
55
|
-
"yaml": "2.4.
|
|
55
|
+
"yaml": "2.4.3"
|
|
56
56
|
},
|
|
57
57
|
"lint-staged": {
|
|
58
58
|
"*.{ts,tsx}": [
|
package/senml/lwm2mToSenML.ts
CHANGED
|
@@ -16,7 +16,7 @@ export const lwm2mToSenML = (
|
|
|
16
16
|
): { senML: SenMLType } | { errors: Array<Error> } => {
|
|
17
17
|
const def = definitions[lwm2m.ObjectID]
|
|
18
18
|
const i = instanceTs(lwm2m)
|
|
19
|
-
const tsResourceId = timestampResources
|
|
19
|
+
const tsResourceId = timestampResources.get(lwm2m.ObjectID) as number // All registered objects must have a timestamp resource
|
|
20
20
|
const [first, ...rest] = Object.entries({
|
|
21
21
|
...lwm2m.Resources,
|
|
22
22
|
[tsResourceId]: undefined,
|
package/senml/senMLtoLwM2M.ts
CHANGED
|
@@ -51,7 +51,7 @@ export const senMLtoLwM2M = (
|
|
|
51
51
|
return { error: new Error(`Invalid resource ID: ${itemResourceId}`) }
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const tsRes = timestampResources
|
|
54
|
+
const tsRes = timestampResources.get(resourceId.ObjectID)
|
|
55
55
|
if (tsRes === undefined) {
|
|
56
56
|
return {
|
|
57
57
|
error: new Error(
|