@hello.nrfcloud.com/proto-map 10.0.3 → 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.
@@ -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
+ };
@@ -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),
@@ -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 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);
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: 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,
@@ -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
  };
@@ -24,4 +24,22 @@ void describe('validate()', function() {
24
24
  var maybeValid = v({});
25
25
  assert.equal('error' in maybeValid, true);
26
26
  });
27
+ void it('should validate an object with undefined optional resources', function() {
28
+ var object = {
29
+ ObjectID: 14203,
30
+ ObjectVersion: '1.0',
31
+ Resources: {
32
+ '0': 'LTE-M GPS',
33
+ '1': 20,
34
+ '3': 33187,
35
+ '4': 52661514,
36
+ '5': 24201,
37
+ '6': '10.234.105.140',
38
+ 11: undefined,
39
+ '99': 1716988087000
40
+ }
41
+ };
42
+ var maybeValid = v(object);
43
+ assert.deepEqual('object' in maybeValid && maybeValid.object, object);
44
+ });
27
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) {
@@ -80,6 +80,7 @@ export var isLwM2MObject = function(object) {
80
80
  // All values must be number, string, boolean
81
81
  for(var _iterator = Object.values(object.Resources)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82
82
  var v = _step.value;
83
+ if (v === undefined) continue;
83
84
  if (typeof v === 'string') continue;
84
85
  if (typeof v === 'boolean') continue;
85
86
  if (typeof v === 'number') continue;
@@ -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>
@@ -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.
@@ -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);
@@ -26,4 +26,23 @@ void describe('validate()', () => {
26
26
  const maybeValid = v({})
27
27
  assert.equal('error' in maybeValid, true)
28
28
  })
29
+
30
+ void it('should validate an object with undefined optional resources', () => {
31
+ const object = {
32
+ ObjectID: 14203,
33
+ ObjectVersion: '1.0',
34
+ Resources: {
35
+ '0': 'LTE-M GPS',
36
+ '1': 20,
37
+ '3': 33187,
38
+ '4': 52661514,
39
+ '5': 24201,
40
+ '6': '10.234.105.140',
41
+ 11: undefined,
42
+ '99': 1716988087000,
43
+ },
44
+ }
45
+ const maybeValid = v(object)
46
+ assert.deepEqual('object' in maybeValid && maybeValid.object, object)
47
+ })
29
48
  })
@@ -50,6 +50,7 @@ export const isLwM2MObject = (
50
50
  return error(`All resource IDs must be a number`)
51
51
  // All values must be number, string, boolean
52
52
  for (const v of Object.values(object.Resources)) {
53
+ if (v === undefined) continue
53
54
  if (typeof v === 'string') continue
54
55
  if (typeof v === 'boolean') continue
55
56
  if (typeof v === 'number') continue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/proto-map",
3
- "version": "10.0.3",
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.7",
43
- "@types/node": "20.12.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",