@hello.nrfcloud.com/proto-map 10.0.4 → 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.
@@ -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(function(Resource) {
27
- var range = undefined;
28
- if (Resource.RangeEnumeration.length > 0) {
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
+ };
@@ -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('Record', [
55
- ts.factory.createTypeReferenceNode('number'),
57
+ ts.factory.createTypeReferenceNode('Map', [
58
+ ts.factory.createTypeReferenceNode('LwM2MObjectID'),
56
59
  ts.factory.createTypeReferenceNode('number')
57
60
  ])
58
- ]), ts.factory.createObjectLiteralExpression(Object.entries(timestampResources).map(function(param) {
59
- var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
60
- return ts.factory.createPropertyAssignment(k, ts.factory.createNumericLiteral(v));
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
  };
@@ -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).map(function(resource) {
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.map(function(Resource) {
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(Object.values(Resources.Item).map(function(param) {
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),
@@ -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++){
@@ -74,13 +75,20 @@ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorErro
74
75
  try {
75
76
  for(var _iterator1 = definitions[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
76
77
  var definition1 = _step1.value;
77
- var _definition_Resources_Item_find;
78
78
  var ObjectID = parseInt(definition1.ObjectID, 10);
79
- var ResourceId = parseInt((_definition_Resources_Item_find = definition1.Resources.Item.find(function(param) {
80
- var Type = param.Type;
81
- return Type === 'Time';
82
- })) === null || _definition_Resources_Item_find === void 0 ? void 0 : _definition_Resources_Item_find.$.ID, 10);
83
- timestampResources[ObjectID] = ResourceId;
79
+ var Item = definition1.Resources.Item;
80
+ var ResourceId = undefined;
81
+ if (Array.isArray(Item)) {
82
+ var _Item_find;
83
+ ResourceId = parseInt((_Item_find = Item.find(function(param) {
84
+ var Type = param.Type;
85
+ return Type === 'Time';
86
+ })) === null || _Item_find === void 0 ? void 0 : _Item_find.$.ID, 10);
87
+ } else {
88
+ if (Item.Type === 'Time') ResourceId = parseInt(Item.$.ID, 10);
89
+ }
90
+ if (ResourceId === undefined) throw new Error("No Time resource found in ".concat(ObjectID, "!"));
91
+ timestampResources[generateName(definition1)] = ResourceId;
84
92
  console.log(' ', chalk.gray('·'), "".concat(chalk.white(ObjectID)).concat(chalk.gray('.')).concat(chalk.white(ResourceId)));
85
93
  }
86
94
  } catch (err) {
@@ -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: definition.Resources.Item.reduce(function(resources, _param) {
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
- 0: {
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,
@@ -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[definition.ObjectID]// All registered objects must have a timestamp resource
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,5 +1,5 @@
1
1
  /**
2
2
  * Button press (14220)
3
3
  *
4
- * Describes a button press event.
4
+ * Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.
5
5
  */ export { };
@@ -1,4 +1,4 @@
1
- import { NumberResource, TimeResource, validateInstance } from "../validation.js";
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
  };
@@ -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
- 14201: 99,
5
- 14202: 99,
6
- 14203: 99,
7
- 14204: 99,
8
- 14205: 99,
9
- 14210: 99,
10
- 14220: 99,
11
- 14230: 99,
12
- 14240: 99,
13
- 14301: 99
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
+ ]);
@@ -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) || typeof object.Resources !== 'object' || object.Resources === null) return error("Resources must be an 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) {
@@ -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;
@@ -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[lwm2m.ObjectID]// All registered objects must have a timestamp resource
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[resourceId.ObjectID];
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/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>
@@ -41,7 +41,7 @@ export enum LwM2MObjectID {
41
41
  /**
42
42
  * Button press (14220)
43
43
  *
44
- * Describes a button press event.
44
+ * Describes a button press event. The ObjectInstanceID is used to describe which button has been pressed.
45
45
  */
46
46
  ButtonPress_14220 = 14220,
47
47
  /**
@@ -22,7 +22,10 @@ export type ParsedLwM2MObjectDefinition = {
22
22
  MultipleInstances: 'Multiple'
23
23
  Mandatory: 'Optional'
24
24
  Resources: {
25
- Item: Resource[]
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: definition.Resources.Item.reduce<Record<string, any>>(
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)
@@ -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.
@@ -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[definition.ObjectID] as number // All registered objects must have a timestamp resource
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
  }
@@ -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 { NumberResource, TimeResource, validateInstance } from "../validation.js";
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", { 0: NumberResource, 99: TimeResource })(o);
14
+ } => validateInstance<ButtonPress_14220>(LwM2MObjectID.ButtonPress_14220, "1.0", { 99: TimeResource })(o);
@@ -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<Record<number, number>> = { 14201: 99, 14202: 99, 14203: 99, 14204: 99, 14205: 99, 14210: 99, 14220: 99, 14230: 99, 14240: 99, 14301: 99 };
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": "10.0.4",
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.1",
39
- "@bifravst/prettier-config": "1.0.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
- "@swc/core": "1.5.7",
43
- "@types/node": "20.12.12",
42
+ "@swc/core": "1.5.24",
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.0",
53
+ "tsx": "4.11.2",
54
54
  "xml2js": "0.6.2",
55
- "yaml": "2.4.2"
55
+ "yaml": "2.4.3"
56
56
  },
57
57
  "lint-staged": {
58
58
  "*.{ts,tsx}": [
@@ -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[lwm2m.ObjectID] as number // All registered objects must have a timestamp resource
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,
@@ -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[resourceId.ObjectID]
54
+ const tsRes = timestampResources.get(resourceId.ObjectID)
55
55
  if (tsRes === undefined) {
56
56
  return {
57
57
  error: new Error(