@hello.nrfcloud.com/proto-map 10.0.4 → 11.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/generateLwM2MDefinitions.js +39 -36
- package/dist/generator/generateType.js +3 -1
- package/dist/generator/generateValidator.js +6 -2
- package/dist/generator/lwm2m.js +12 -5
- package/dist/lwm2m/LwM2MObjectID.js +1 -1
- package/dist/lwm2m/check-lwm2m-rules.js +11 -4
- package/dist/lwm2m/definitions.js +3 -14
- package/dist/lwm2m/object/14220.d.js +1 -1
- package/dist/lwm2m/object/validate14220.js +1 -2
- package/dist/lwm2m/validation.js +2 -2
- package/dist/senml/hasValue.js +5 -1
- package/lwm2m/14220.xml +1 -11
- package/lwm2m/LwM2MObjectID.ts +1 -1
- package/lwm2m/ParsedLwM2MObjectDefinition.ts +4 -1
- package/lwm2m/check-lwm2m-rules.ts +12 -2
- package/lwm2m/definitions.ts +2 -7
- package/lwm2m/object/14220.d.ts +1 -7
- package/lwm2m/object/validate14220.ts +2 -2
- package/package.json +3 -3
|
@@ -23,42 +23,9 @@ export var generateLwM2MDefinitions = function(definitions) {
|
|
|
23
23
|
ts.factory.createPropertyAssignment('ObjectVersion', ts.factory.createStringLiteral((_definition_ObjectVersion = definition.ObjectVersion) !== null && _definition_ObjectVersion !== void 0 ? _definition_ObjectVersion : '1.0')),
|
|
24
24
|
ts.factory.createPropertyAssignment('Name', ts.factory.createStringLiteral(definition.Name)),
|
|
25
25
|
ts.factory.createPropertyAssignment('Description', ts.factory.createStringLiteral(definition.Description1)),
|
|
26
|
-
ts.factory.createPropertyAssignment('Resources', ts.factory.createObjectLiteralExpression(definition.Resources.Item.map(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var maybeRange = parseRangeEnumeration(Resource.RangeEnumeration);
|
|
30
|
-
if ('error' in maybeRange) throw maybeRange.error;
|
|
31
|
-
range = maybeRange.range;
|
|
32
|
-
}
|
|
33
|
-
var props = [
|
|
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
|
-
];
|
|
40
|
-
if (Resource.RangeEnumeration.length > 0) {
|
|
41
|
-
var maybeRange1 = parseRangeEnumeration(Resource.RangeEnumeration);
|
|
42
|
-
if ('error' in maybeRange1) throw maybeRange1.error;
|
|
43
|
-
var _maybeRange_range = maybeRange1.range, min = _maybeRange_range.min, max = _maybeRange_range.max;
|
|
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
|
-
])));
|
|
48
|
-
}
|
|
49
|
-
if (Resource.Units.length > 0) props.push(ts.factory.createPropertyAssignment('Units', ts.factory.createStringLiteral(Resource.Units)));
|
|
50
|
-
var resourceDef = ts.factory.createPropertyAssignment(ts.factory.createNumericLiteral(Resource.$.ID), ts.factory.createObjectLiteralExpression(props));
|
|
51
|
-
var docStrings = [
|
|
52
|
-
"".concat(Resource.Name, " (").concat(Resource.Type, ")"),
|
|
53
|
-
"",
|
|
54
|
-
Resource.Description
|
|
55
|
-
];
|
|
56
|
-
if (range !== undefined) {
|
|
57
|
-
docStrings.push("", "Minimum: ".concat(range.min), "Maximum: ".concat(range.max));
|
|
58
|
-
}
|
|
59
|
-
addDocBlock(docStrings, resourceDef);
|
|
60
|
-
return resourceDef;
|
|
61
|
-
})))
|
|
26
|
+
ts.factory.createPropertyAssignment('Resources', ts.factory.createObjectLiteralExpression(Array.isArray(definition.Resources.Item) ? definition.Resources.Item.map(createResource) : [
|
|
27
|
+
createResource(definition.Resources.Item)
|
|
28
|
+
]))
|
|
62
29
|
]));
|
|
63
30
|
addDocBlock([
|
|
64
31
|
"".concat(definition.Name, " (").concat(definition.ObjectID, ")"),
|
|
@@ -80,3 +47,39 @@ export var generateLwM2MDefinitions = function(definitions) {
|
|
|
80
47
|
var createNumber = function(n) {
|
|
81
48
|
return n < 0 ? ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(-n)) : ts.factory.createNumericLiteral(n);
|
|
82
49
|
};
|
|
50
|
+
var createResource = function(Resource) {
|
|
51
|
+
var range = undefined;
|
|
52
|
+
if (Resource.RangeEnumeration.length > 0) {
|
|
53
|
+
var maybeRange = parseRangeEnumeration(Resource.RangeEnumeration);
|
|
54
|
+
if ('error' in maybeRange) throw maybeRange.error;
|
|
55
|
+
range = maybeRange.range;
|
|
56
|
+
}
|
|
57
|
+
var props = [
|
|
58
|
+
ts.factory.createPropertyAssignment('ResourceID', ts.factory.createNumericLiteral(Resource.$.ID)),
|
|
59
|
+
ts.factory.createPropertyAssignment('Name', ts.factory.createStringLiteral(Resource.Name)),
|
|
60
|
+
ts.factory.createPropertyAssignment('Mandatory', ts.factory.createIdentifier(Resource.Mandatory === 'Mandatory' ? 'true' : 'false')),
|
|
61
|
+
ts.factory.createPropertyAssignment('Type', ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('ResourceType'), Resource.Type)),
|
|
62
|
+
ts.factory.createPropertyAssignment('Description', ts.factory.createStringLiteral(Resource.Description))
|
|
63
|
+
];
|
|
64
|
+
if (Resource.RangeEnumeration.length > 0) {
|
|
65
|
+
var maybeRange1 = parseRangeEnumeration(Resource.RangeEnumeration);
|
|
66
|
+
if ('error' in maybeRange1) throw maybeRange1.error;
|
|
67
|
+
var _maybeRange_range = maybeRange1.range, min = _maybeRange_range.min, max = _maybeRange_range.max;
|
|
68
|
+
props.push(ts.factory.createPropertyAssignment('RangeEnumeration', ts.factory.createObjectLiteralExpression([
|
|
69
|
+
ts.factory.createPropertyAssignment('min', createNumber(min)),
|
|
70
|
+
ts.factory.createPropertyAssignment('max', createNumber(max))
|
|
71
|
+
])));
|
|
72
|
+
}
|
|
73
|
+
if (Resource.Units.length > 0) props.push(ts.factory.createPropertyAssignment('Units', ts.factory.createStringLiteral(Resource.Units)));
|
|
74
|
+
var resourceDef = ts.factory.createPropertyAssignment(ts.factory.createNumericLiteral(Resource.$.ID), ts.factory.createObjectLiteralExpression(props));
|
|
75
|
+
var docStrings = [
|
|
76
|
+
"".concat(Resource.Name, " (").concat(Resource.Type, ")"),
|
|
77
|
+
"",
|
|
78
|
+
Resource.Description
|
|
79
|
+
];
|
|
80
|
+
if (range !== undefined) {
|
|
81
|
+
docStrings.push("", "Minimum: ".concat(range.min), "Maximum: ".concat(range.max));
|
|
82
|
+
}
|
|
83
|
+
addDocBlock(docStrings, resourceDef);
|
|
84
|
+
return resourceDef;
|
|
85
|
+
};
|
|
@@ -22,7 +22,9 @@ export var generateType = function(param) {
|
|
|
22
22
|
ts.factory.createTypeLiteralNode([
|
|
23
23
|
ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('ObjectID'), undefined, ts.factory.createTypeReferenceNode("LwM2MObjectID.".concat(name), undefined)),
|
|
24
24
|
ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('ObjectVersion'), undefined, ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(ObjectVersion !== null && ObjectVersion !== void 0 ? ObjectVersion : '1.0'))),
|
|
25
|
-
ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('Resources'), undefined, ts.factory.createTypeLiteralNode(byImportance(Resources.Item).
|
|
25
|
+
ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('Resources'), undefined, ts.factory.createTypeLiteralNode(byImportance(Array.isArray(Resources.Item) ? Resources.Item : [
|
|
26
|
+
Resources.Item
|
|
27
|
+
]).map(function(resource) {
|
|
26
28
|
var res = ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier("".concat(resource.$.ID)), resource.Mandatory === 'Mandatory' ? undefined : ts.factory.createToken(ts.SyntaxKind.QuestionToken), typeScriptResourceType(resource.Type));
|
|
27
29
|
var docs = [
|
|
28
30
|
"".concat(resource.Name).concat(resource.Units.length > 0 ? " (".concat(resource.Units, ")") : ''),
|
|
@@ -79,7 +79,9 @@ export var generateValidator = function(param) {
|
|
|
79
79
|
], [
|
|
80
80
|
ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('LwM2MObjectID'), ts.factory.createIdentifier(name)),
|
|
81
81
|
ts.factory.createStringLiteral(ObjectVersion !== null && ObjectVersion !== void 0 ? ObjectVersion : '1.0'),
|
|
82
|
-
ts.factory.createObjectLiteralExpression(Resources.Item
|
|
82
|
+
ts.factory.createObjectLiteralExpression((Array.isArray(Resources.Item) ? Resources.Item : [
|
|
83
|
+
Resources.Item
|
|
84
|
+
]).map(function(Resource) {
|
|
83
85
|
var validator = ts.factory.createPropertyAssignment(ts.factory.createNumericLiteral(Resource.$.ID), toResourceValidator(Resource));
|
|
84
86
|
return validator;
|
|
85
87
|
}))
|
|
@@ -125,7 +127,9 @@ var typeToValidator = function(Type) {
|
|
|
125
127
|
};
|
|
126
128
|
var getResourceValidators = function(param) {
|
|
127
129
|
var Resources = param.Resources;
|
|
128
|
-
return new Set(
|
|
130
|
+
return new Set((Array.isArray(Resources.Item) ? Resources.Item : [
|
|
131
|
+
Resources.Item
|
|
132
|
+
]).map(function(param) {
|
|
129
133
|
var Type = param.Type, Mandatory = param.Mandatory;
|
|
130
134
|
return [
|
|
131
135
|
typeToValidator(Type),
|
package/dist/generator/lwm2m.js
CHANGED
|
@@ -74,12 +74,19 @@ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorErro
|
|
|
74
74
|
try {
|
|
75
75
|
for(var _iterator1 = definitions[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
76
76
|
var definition1 = _step1.value;
|
|
77
|
-
var _definition_Resources_Item_find;
|
|
78
77
|
var ObjectID = parseInt(definition1.ObjectID, 10);
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
var Item = definition1.Resources.Item;
|
|
79
|
+
var ResourceId = undefined;
|
|
80
|
+
if (Array.isArray(Item)) {
|
|
81
|
+
var _Item_find;
|
|
82
|
+
ResourceId = parseInt((_Item_find = Item.find(function(param) {
|
|
83
|
+
var Type = param.Type;
|
|
84
|
+
return Type === 'Time';
|
|
85
|
+
})) === null || _Item_find === void 0 ? void 0 : _Item_find.$.ID, 10);
|
|
86
|
+
} else {
|
|
87
|
+
if (Item.Type === 'Time') ResourceId = parseInt(Item.$.ID, 10);
|
|
88
|
+
}
|
|
89
|
+
if (ResourceId === undefined) throw new Error("No Time resource found in ".concat(ObjectID, "!"));
|
|
83
90
|
timestampResources[ObjectID] = ResourceId;
|
|
84
91
|
console.log(' ', chalk.gray('·'), "".concat(chalk.white(ObjectID)).concat(chalk.gray('.')).concat(chalk.white(ResourceId)));
|
|
85
92
|
}
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/**
|
|
36
36
|
* Button press (14220)
|
|
37
37
|
*
|
|
38
|
-
* Describes a button press event.
|
|
38
|
+
* Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.
|
|
39
39
|
*/ LwM2MObjectID[LwM2MObjectID["ButtonPress_14220"] = 14220] = "ButtonPress_14220";
|
|
40
40
|
/**
|
|
41
41
|
* Sea Water Level (14230)
|
|
@@ -295,7 +295,7 @@ var listLwm2mDefinitions = function() {
|
|
|
295
295
|
9
|
|
296
296
|
]);
|
|
297
297
|
_loop = function() {
|
|
298
|
-
var _ref, file, _TimeResources_, _TimeResources_1, objectDefinitionFile, schemaValidated, ObjectID, ObjectURN, definition, _, objectDef, maybeValid, _maybeValid_value, Name, Resources, TimeResources, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step1, _step_value, id, resource, _resource_Units;
|
|
298
|
+
var _ref, file, _TimeResources_, _TimeResources_1, objectDefinitionFile, schemaValidated, ObjectID, ObjectURN, definition, _, objectDef, Item, maybeValid, _maybeValid_value, Name, Resources, TimeResources, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step1, _step_value, id, resource, _resource_Units;
|
|
299
299
|
return _ts_generator(this, function(_state) {
|
|
300
300
|
switch(_state.label){
|
|
301
301
|
case 0:
|
|
@@ -359,7 +359,11 @@ var listLwm2mDefinitions = function() {
|
|
|
359
359
|
console.log(chalk.green('✔'), chalk.blue(ObjectURN), chalk.gray('ObjectID and URN match filename and schema'));
|
|
360
360
|
objectDef = _object_spread_props(_object_spread({}, definition), {
|
|
361
361
|
LWM2MVersion: '1.1',
|
|
362
|
-
Resources:
|
|
362
|
+
Resources: {}
|
|
363
|
+
});
|
|
364
|
+
Item = definition.Resources.Item;
|
|
365
|
+
if (Array.isArray(Item)) {
|
|
366
|
+
objectDef.Resources = Item.reduce(function(resources, _param) {
|
|
363
367
|
var $ = _param.$, item = _object_without_properties(_param, [
|
|
364
368
|
"$"
|
|
365
369
|
]);
|
|
@@ -369,8 +373,11 @@ var listLwm2mDefinitions = function() {
|
|
|
369
373
|
if ('error' in maybeRange) throw maybeRange.error;
|
|
370
374
|
}
|
|
371
375
|
return _object_spread_props(_object_spread({}, resources), _define_property({}, $.ID, item));
|
|
372
|
-
}, {})
|
|
373
|
-
}
|
|
376
|
+
}, {});
|
|
377
|
+
} else {
|
|
378
|
+
// Object only has one Resource
|
|
379
|
+
objectDef.Resources = _define_property({}, Item.$.ID, Item);
|
|
380
|
+
}
|
|
374
381
|
maybeValid = v(objectDef);
|
|
375
382
|
if ('errors' in maybeValid) {
|
|
376
383
|
console.error(maybeValid.errors);
|
|
@@ -533,25 +533,14 @@ var _obj;
|
|
|
533
533
|
}), /**
|
|
534
534
|
* Button press (14220)
|
|
535
535
|
*
|
|
536
|
-
* Describes a button press event.
|
|
536
|
+
* Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.
|
|
537
537
|
*/ _define_property(_obj, LwM2MObjectID.ButtonPress_14220, {
|
|
538
538
|
ObjectID: LwM2MObjectID.ButtonPress_14220,
|
|
539
539
|
ObjectVersion: "1.0",
|
|
540
540
|
Name: "Button press",
|
|
541
|
-
Description: "Describes a button press event.",
|
|
541
|
+
Description: "Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.",
|
|
542
542
|
Resources: {
|
|
543
|
-
|
|
544
|
-
ResourceID: 0,
|
|
545
|
-
Name: "Button ID",
|
|
546
|
-
Mandatory: true,
|
|
547
|
-
Type: ResourceType.Integer,
|
|
548
|
-
Description: "The ID of the button that was pressed. Examples: 1, 2."
|
|
549
|
-
},
|
|
550
|
-
/**
|
|
551
|
-
* Timestamp (Time)
|
|
552
|
-
*
|
|
553
|
-
* The timestamp of when the button was pressed.
|
|
554
|
-
*/ 99: {
|
|
543
|
+
99: {
|
|
555
544
|
ResourceID: 99,
|
|
556
545
|
Name: "Timestamp",
|
|
557
546
|
Mandatory: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TimeResource, validateInstance } from "../validation.js";
|
|
2
2
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
3
3
|
/**
|
|
4
4
|
* Validate Button press (14220)
|
|
@@ -6,7 +6,6 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
6
6
|
* Ensures the given object is an LwM2M object according to the schema 14220.xml.
|
|
7
7
|
*/ export var validate14220 = function(o) {
|
|
8
8
|
return validateInstance(LwM2MObjectID.ButtonPress_14220, "1.0", {
|
|
9
|
-
0: NumberResource,
|
|
10
9
|
99: TimeResource
|
|
11
10
|
})(o);
|
|
12
11
|
};
|
package/dist/lwm2m/validation.js
CHANGED
|
@@ -57,7 +57,7 @@ export var isLwM2MObject = function(object) {
|
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
59
|
// Must be an object
|
|
60
|
-
if (typeof object !== 'object' || object === null) return error("Not an object");
|
|
60
|
+
if ((typeof object === "undefined" ? "undefined" : _type_of(object)) !== 'object' || object === null) return error("Not an object");
|
|
61
61
|
// Must have valid ObjectID
|
|
62
62
|
if (!('ObjectID' in object) || typeof object.ObjectID !== 'number' || object.ObjectID < 14200 || object.ObjectID > 15000 || LwM2MObjectIDs.includes(object.ObjectID) === false) return error("Not an valid Object ID: ".concat(JSON.stringify(object.ObjectID)));
|
|
63
63
|
// ObjectVersion must be valid
|
|
@@ -69,7 +69,7 @@ export var isLwM2MObject = function(object) {
|
|
|
69
69
|
if (typeof object.ObjectInstanceID !== 'number' || object.ObjectInstanceID < 0) return error("Invalid ObjectInstanceID");
|
|
70
70
|
}
|
|
71
71
|
// Must have valid resources
|
|
72
|
-
if (!('Resources' in object) ||
|
|
72
|
+
if (!('Resources' in object) || _type_of(object.Resources) !== 'object' || object.Resources === null) return error("Resources must be an object");
|
|
73
73
|
var _Object_keys_find_length;
|
|
74
74
|
// All keys must be numbers
|
|
75
75
|
if (((_Object_keys_find_length = (_Object_keys_find = Object.keys(object.Resources).find(function(k) {
|
package/dist/senml/hasValue.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
1
5
|
export var hasValue = function(m) {
|
|
2
6
|
if (m === null) return false;
|
|
3
|
-
if (typeof m !== 'object') return false;
|
|
7
|
+
if ((typeof m === "undefined" ? "undefined" : _type_of(m)) !== 'object') return false;
|
|
4
8
|
var _ref, _ref1, _ref2, _ref3;
|
|
5
9
|
var v = (_ref3 = (_ref2 = (_ref1 = (_ref = 'bv' in m ? m.bv : undefined) !== null && _ref !== void 0 ? _ref : 'v' in m ? m.v : undefined) !== null && _ref1 !== void 0 ? _ref1 : 'vs' in m ? m.vs : undefined) !== null && _ref2 !== void 0 ? _ref2 : 'vb' in m ? m.vb : undefined) !== null && _ref3 !== void 0 ? _ref3 : 'vd' in m ? m.vd : undefined;
|
|
6
10
|
if (v === null || v === undefined) return false;
|
package/lwm2m/14220.xml
CHANGED
|
@@ -2,22 +2,12 @@
|
|
|
2
2
|
<LWM2M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://openmobilealliance.org/tech/profiles/LWM2M-v1_1.xsd">
|
|
3
3
|
<Object ObjectType="MODefinition">
|
|
4
4
|
<Name>Button press</Name>
|
|
5
|
-
<Description1><![CDATA[Describes a button press event.]]></Description1>
|
|
5
|
+
<Description1><![CDATA[Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.]]></Description1>
|
|
6
6
|
<ObjectID>14220</ObjectID>
|
|
7
7
|
<ObjectURN>urn:oma:lwm2m:x:14220</ObjectURN>
|
|
8
8
|
<MultipleInstances>Multiple</MultipleInstances>
|
|
9
9
|
<Mandatory>Optional</Mandatory>
|
|
10
10
|
<Resources>
|
|
11
|
-
<Item ID="0">
|
|
12
|
-
<Name>Button ID</Name>
|
|
13
|
-
<Operations>R</Operations>
|
|
14
|
-
<MultipleInstances>Single</MultipleInstances>
|
|
15
|
-
<Mandatory>Mandatory</Mandatory>
|
|
16
|
-
<Type>Integer</Type>
|
|
17
|
-
<RangeEnumeration/>
|
|
18
|
-
<Units/>
|
|
19
|
-
<Description><![CDATA[The ID of the button that was pressed. Examples: 1, 2.]]></Description>
|
|
20
|
-
</Item>
|
|
21
11
|
<Item ID="99">
|
|
22
12
|
<Name>Timestamp</Name>
|
|
23
13
|
<Operations>R</Operations>
|
package/lwm2m/LwM2MObjectID.ts
CHANGED
|
@@ -22,7 +22,10 @@ export type ParsedLwM2MObjectDefinition = {
|
|
|
22
22
|
MultipleInstances: 'Multiple'
|
|
23
23
|
Mandatory: 'Optional'
|
|
24
24
|
Resources: {
|
|
25
|
-
Item:
|
|
25
|
+
Item:
|
|
26
|
+
| Resource[]
|
|
27
|
+
// if Object only has one Resource
|
|
28
|
+
| Resource
|
|
26
29
|
}
|
|
27
30
|
Description2: string // e.g. ''
|
|
28
31
|
}
|
|
@@ -87,7 +87,12 @@ const listLwm2mDefinitions = async (
|
|
|
87
87
|
const objectDef: LWM2MObjectDefinitionType = {
|
|
88
88
|
...definition,
|
|
89
89
|
LWM2MVersion: '1.1',
|
|
90
|
-
Resources:
|
|
90
|
+
Resources: {},
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const Item = definition.Resources.Item
|
|
94
|
+
if (Array.isArray(Item)) {
|
|
95
|
+
objectDef.Resources = Item.reduce<Record<string, any>>(
|
|
91
96
|
(resources, { $, ...item }) => {
|
|
92
97
|
if (resources[$.ID] !== undefined)
|
|
93
98
|
throw new Error(`Duplicate resource ID: ${$.ID}`)
|
|
@@ -101,7 +106,12 @@ const listLwm2mDefinitions = async (
|
|
|
101
106
|
}
|
|
102
107
|
},
|
|
103
108
|
{},
|
|
104
|
-
)
|
|
109
|
+
)
|
|
110
|
+
} else {
|
|
111
|
+
// Object only has one Resource
|
|
112
|
+
objectDef.Resources = {
|
|
113
|
+
[Item.$.ID]: Item,
|
|
114
|
+
}
|
|
105
115
|
}
|
|
106
116
|
|
|
107
117
|
const maybeValid = v(objectDef)
|
package/lwm2m/definitions.ts
CHANGED
|
@@ -246,14 +246,9 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
|
|
|
246
246
|
99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Description: "The timestamp of when the measurement was performed." } } }, /**
|
|
247
247
|
* Button press (14220)
|
|
248
248
|
*
|
|
249
|
-
* Describes a button press event.
|
|
249
|
+
* Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.
|
|
250
250
|
*/
|
|
251
|
-
[LwM2MObjectID.ButtonPress_14220]: { ObjectID: LwM2MObjectID.ButtonPress_14220, ObjectVersion: "1.0", Name: "Button press", Description: "Describes a button press event.", Resources: { /**
|
|
252
|
-
* Button ID (Integer)
|
|
253
|
-
*
|
|
254
|
-
* The ID of the button that was pressed. Examples: 1, 2.
|
|
255
|
-
*/
|
|
256
|
-
0: { ResourceID: 0, Name: "Button ID", Mandatory: true, Type: ResourceType.Integer, Description: "The ID of the button that was pressed. Examples: 1, 2." }, /**
|
|
251
|
+
[LwM2MObjectID.ButtonPress_14220]: { ObjectID: LwM2MObjectID.ButtonPress_14220, ObjectVersion: "1.0", Name: "Button press", Description: "Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.", Resources: { /**
|
|
257
252
|
* Timestamp (Time)
|
|
258
253
|
*
|
|
259
254
|
* The timestamp of when the button was pressed.
|
package/lwm2m/object/14220.d.ts
CHANGED
|
@@ -3,18 +3,12 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Button press (14220)
|
|
5
5
|
*
|
|
6
|
-
* Describes a button press event.
|
|
6
|
+
* Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.
|
|
7
7
|
*/
|
|
8
8
|
export type ButtonPress_14220 = LwM2MObject<{
|
|
9
9
|
ObjectID: LwM2MObjectID.ButtonPress_14220;
|
|
10
10
|
ObjectVersion: "1.0";
|
|
11
11
|
Resources: {
|
|
12
|
-
/**
|
|
13
|
-
* Button ID
|
|
14
|
-
*
|
|
15
|
-
* The ID of the button that was pressed. Examples: 1, 2.
|
|
16
|
-
*/
|
|
17
|
-
0: number;
|
|
18
12
|
/**
|
|
19
13
|
* Timestamp
|
|
20
14
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LwM2MObjectInstance } from "../LwM2MObjectInstance.js";
|
|
2
|
-
import {
|
|
2
|
+
import { TimeResource, validateInstance } from "../validation.js";
|
|
3
3
|
import type { ButtonPress_14220 } from "../objects.js";
|
|
4
4
|
import { LwM2MObjectID } from "../LwM2MObjectID.js";
|
|
5
5
|
/**
|
|
@@ -11,4 +11,4 @@ export const validate14220 = (o: unknown): {
|
|
|
11
11
|
error: Error;
|
|
12
12
|
} | {
|
|
13
13
|
object: LwM2MObjectInstance<ButtonPress_14220>;
|
|
14
|
-
} => validateInstance<ButtonPress_14220>(LwM2MObjectID.ButtonPress_14220, "1.0", {
|
|
14
|
+
} => validateInstance<ButtonPress_14220>(LwM2MObjectID.ButtonPress_14220, "1.0", { 99: TimeResource })(o);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hello.nrfcloud.com/proto-map",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.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": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@bifravst/prettier-config": "1.0.0",
|
|
40
40
|
"@commitlint/config-conventional": "19.2.2",
|
|
41
41
|
"@swc/cli": "0.3.12",
|
|
42
|
-
"@swc/core": "1.5.
|
|
43
|
-
"@types/node": "20.12.
|
|
42
|
+
"@swc/core": "1.5.24",
|
|
43
|
+
"@types/node": "20.12.13",
|
|
44
44
|
"@types/xml2js": "0.4.14",
|
|
45
45
|
"chalk": "5.3.0",
|
|
46
46
|
"globstar": "1.0.0",
|