@hello.nrfcloud.com/proto-map 12.1.3 → 13.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/README.md CHANGED
@@ -35,7 +35,8 @@ in a meaningful way to users without the need for custom implementation.
35
35
  (non-inclusively).
36
36
  - The URN must have the prefix `urn:oma:lwm2m:x:`.
37
37
  - The `ObjectVersion` must be appended if it is not `1.0`, which is the default.
38
- - All objects must define one `Time` property.
38
+ - All objects must define one `Time` property. Time is a signed integer
39
+ representing the number of seconds since Jan 1 st, 1970 in the UTC time zone.
39
40
  - Objects must be `Multiple` instance.
40
41
  - Objects must be `Optional`.
41
42
  - Resources should only be marked as mandatory in case they must be published
@@ -78,6 +78,9 @@ var createResource = function(Resource) {
78
78
  "",
79
79
  Resource.Description
80
80
  ];
81
+ if (Resource.Type === 'Time') {
82
+ docStrings.push("", "Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.");
83
+ }
81
84
  if (range !== undefined) {
82
85
  docStrings.push("", "Minimum: ".concat(range.min), "Maximum: ".concat(range.max));
83
86
  }
@@ -130,6 +130,8 @@ var _obj;
130
130
  * Timestamp (Time)
131
131
  *
132
132
  * The timestamp of when the location measurement was performed.
133
+ *
134
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
133
135
  */ 99: {
134
136
  ResourceID: 99,
135
137
  Name: "Timestamp",
@@ -231,6 +233,8 @@ var _obj;
231
233
  * Timestamp (Time)
232
234
  *
233
235
  * The timestamp of when the measurement was performed.
236
+ *
237
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
234
238
  */ 99: {
235
239
  ResourceID: 99,
236
240
  Name: "Timestamp",
@@ -347,6 +351,8 @@ var _obj;
347
351
  * Timestamp (Time)
348
352
  *
349
353
  * The timestamp of when the measurement was performed.
354
+ *
355
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
350
356
  */ 99: {
351
357
  ResourceID: 99,
352
358
  Name: "Timestamp",
@@ -438,6 +444,8 @@ var _obj;
438
444
  * Timestamp (Time)
439
445
  *
440
446
  * The timestamp of when the measurement was performed.
447
+ *
448
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
441
449
  */ 99: {
442
450
  ResourceID: 99,
443
451
  Name: "Timestamp",
@@ -515,6 +523,8 @@ var _obj;
515
523
  * Timestamp (Time)
516
524
  *
517
525
  * The timestamp of when the measurement was performed.
526
+ *
527
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
518
528
  */ 99: {
519
529
  ResourceID: 99,
520
530
  Name: "Timestamp",
@@ -560,6 +570,8 @@ var _obj;
560
570
  * Timestamp (Time)
561
571
  *
562
572
  * The timestamp of when the measurement was performed.
573
+ *
574
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
563
575
  */ 99: {
564
576
  ResourceID: 99,
565
577
  Name: "Timestamp",
@@ -623,6 +635,8 @@ var _obj;
623
635
  * Timestamp (Time)
624
636
  *
625
637
  * The timestamp of when the observation was made.
638
+ *
639
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
626
640
  */ 99: {
627
641
  ResourceID: 99,
628
642
  Name: "Timestamp",
@@ -696,6 +710,8 @@ var _obj;
696
710
  * Timestamp (Time)
697
711
  *
698
712
  * The timestamp of when the LED was changed.
713
+ *
714
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
699
715
  */ 99: {
700
716
  ResourceID: 99,
701
717
  Name: "Timestamp",
@@ -743,6 +759,8 @@ var _obj;
743
759
  * Timestamp (Time)
744
760
  *
745
761
  * The timestamp of when the configuration was updated.
762
+ *
763
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
746
764
  */ 99: {
747
765
  ResourceID: 99,
748
766
  Name: "Timestamp",
@@ -774,6 +792,8 @@ var _obj;
774
792
  * Timestamp (Time)
775
793
  *
776
794
  * The timestamp of when the service info was updated.
795
+ *
796
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
777
797
  */ 99: {
778
798
  ResourceID: 99,
779
799
  Name: "Timestamp",
@@ -1,8 +1,19 @@
1
1
  import { definitions } from './definitions.js';
2
2
  import { timestampResources } from './timestampResources.js';
3
- export var instanceTs = function(instance) {
3
+ /**
4
+ * Returns the timestamp of the instance
5
+ *
6
+ * The timestamp is s signed integer representing
7
+ * the number of seconds since Jan 1, 1970 in the
8
+ * UTC time zone.
9
+ */ export var instanceTs = function(instance) {
4
10
  var definition = definitions[instance.ObjectID];
5
11
  var tsResourceId = timestampResources.get(definition.ObjectID)// All registered objects must have a timestamp resource
6
12
  ;
7
13
  return instance.Resources[tsResourceId];
8
14
  };
15
+ /**
16
+ * Returns the timestamp of the instance as a Date object
17
+ */ export var instanceTsAsDate = function(instance) {
18
+ return new Date(instanceTs(instance) * 1000);
19
+ };
@@ -1,6 +1,6 @@
1
1
  import { describe, it } from 'node:test';
2
2
  import assert from 'node:assert/strict';
3
- import { instanceTs } from './instanceTs.js';
3
+ import { instanceTs, instanceTsAsDate } from './instanceTs.js';
4
4
  void describe('instanceTs()', function() {
5
5
  void it('should return the timestamp of the instance', function() {
6
6
  return assert.equal(instanceTs({
@@ -9,8 +9,21 @@ void describe('instanceTs()', function() {
9
9
  Resources: {
10
10
  '0': 3.5399999618530273,
11
11
  '1': 4.168000221252441,
12
- '99': 1708683500474
12
+ '99': 1708683500
13
13
  }
14
- }), 1708683500474);
14
+ }), 1708683500);
15
+ });
16
+ });
17
+ void describe('instanceTsAsDate()', function() {
18
+ void it('should return the timestamp of the instance', function() {
19
+ return assert.equal(instanceTsAsDate({
20
+ ObjectID: 14210,
21
+ ObjectVersion: '1.0',
22
+ Resources: {
23
+ '0': 3.5399999618530273,
24
+ '1': 4.168000221252441,
25
+ '99': 1708683500
26
+ }
27
+ }).getTime(), 1708683500 * 1000);
15
28
  });
16
29
  });
@@ -13,7 +13,7 @@ void describe('validate()', function() {
13
13
  '1': 6.151946,
14
14
  '6': 'Fixed',
15
15
  '3': 1,
16
- '99': 1710147413003
16
+ '99': 1710147413
17
17
  }
18
18
  };
19
19
  var maybeValid = v(object);
@@ -35,7 +35,7 @@ void describe('validate()', function() {
35
35
  '5': 24201,
36
36
  '6': '10.234.105.140',
37
37
  11: undefined,
38
- '99': 1716988087000
38
+ '99': 1716988087
39
39
  }
40
40
  };
41
41
  var maybeValid = v(object);
@@ -51,7 +51,7 @@ void describe('validate()', function() {
51
51
  'MODEM',
52
52
  'APP'
53
53
  ],
54
- '99': 1717409966000
54
+ '99': 1717409966
55
55
  }
56
56
  };
57
57
  var maybeValid = v(object);
@@ -159,7 +159,7 @@ export var NumberResource = function(r) {
159
159
  return typeof r === 'number';
160
160
  };
161
161
  export var TimeResource = function(r) {
162
- return NumberResource(r) && r > 1700000000000 && r < 9999999999999;
162
+ return NumberResource(r) && r > 1700000000 && r < 9999999999;
163
163
  };
164
164
  export var StringResource = function(r) {
165
165
  return typeof r === 'string';
@@ -9,7 +9,7 @@ void describe('SenMLType', function() {
9
9
  bn: '14201/0/',
10
10
  n: '0',
11
11
  v: 33.98755678796222,
12
- bt: 1698155694999
12
+ bt: 1698155694
13
13
  },
14
14
  {
15
15
  n: '1',
@@ -21,9 +21,10 @@ void describe('fromCBOR()', function() {
21
21
  '0': '10',
22
22
  '2': 57
23
23
  },
24
+ // Converts from BigInt as well
24
25
  {
25
26
  '0': '99',
26
- '2': 1716475294528n
27
+ '2': 1716475294n
27
28
  }
28
29
  ]), [
29
30
  {
@@ -43,10 +44,9 @@ void describe('fromCBOR()', function() {
43
44
  n: '10',
44
45
  v: 57
45
46
  },
46
- // Convert bigints
47
47
  {
48
48
  n: '99',
49
- v: 1716475294528
49
+ v: 1716475294
50
50
  }
51
51
  ]);
52
52
  });
@@ -60,7 +60,7 @@ void describe('hasValue() should determine whether an object has a value', funct
60
60
  bn: 14202,
61
61
  n: 0,
62
62
  v: 99,
63
- bt: 1699049685992
63
+ bt: 1699049685
64
64
  },
65
65
  true
66
66
  ],
@@ -12,7 +12,7 @@ void describe('lwm2mToSenML()', function() {
12
12
  '1': 6.151946,
13
13
  '6': 'Fixed',
14
14
  '3': 1,
15
- '99': 1710147413003
15
+ '99': 1710147413
16
16
  }
17
17
  };
18
18
  var level1 = {
@@ -21,7 +21,7 @@ void describe('lwm2mToSenML()', function() {
21
21
  Resources: {
22
22
  '0': 84.3,
23
23
  '1': 'AES',
24
- '99': 1710140400000
24
+ '99': 1710140400
25
25
  }
26
26
  };
27
27
  var level2 = {
@@ -30,7 +30,7 @@ void describe('lwm2mToSenML()', function() {
30
30
  Resources: {
31
31
  '0': 140.4,
32
32
  '1': 'AES',
33
- '99': 1710144000000
33
+ '99': 1710144000
34
34
  }
35
35
  };
36
36
  var level3 = {
@@ -40,7 +40,7 @@ void describe('lwm2mToSenML()', function() {
40
40
  Resources: {
41
41
  '0': 140.7,
42
42
  '1': 'AES',
43
- '99': 1710144001000
43
+ '99': 1710144001
44
44
  }
45
45
  };
46
46
  var lwm2m = [
@@ -54,7 +54,7 @@ void describe('lwm2mToSenML()', function() {
54
54
  bn: '14201/0/',
55
55
  n: '0',
56
56
  v: 62.469414,
57
- bt: 1710147413003
57
+ bt: 1710147413
58
58
  },
59
59
  {
60
60
  n: '1',
@@ -72,7 +72,7 @@ void describe('lwm2mToSenML()', function() {
72
72
  bn: '14230/0/',
73
73
  n: '0',
74
74
  v: 84.3,
75
- bt: 1710140400000
75
+ bt: 1710140400
76
76
  },
77
77
  {
78
78
  n: '1',
@@ -82,7 +82,7 @@ void describe('lwm2mToSenML()', function() {
82
82
  bn: '14230/0/',
83
83
  n: '0',
84
84
  v: 140.4,
85
- bt: 1710144000000
85
+ bt: 1710144000
86
86
  },
87
87
  {
88
88
  n: '1',
@@ -92,7 +92,7 @@ void describe('lwm2mToSenML()', function() {
92
92
  bn: '14230/1/',
93
93
  n: '0',
94
94
  v: 140.7,
95
- bt: 1710144001000
95
+ bt: 1710144001
96
96
  },
97
97
  {
98
98
  n: '1',
@@ -7,7 +7,7 @@ void describe('senMLtoLwM2M()', function() {
7
7
  {
8
8
  bn: '14201/1/',
9
9
  blv: '1.1',
10
- bt: 1698155694999,
10
+ bt: 1698155694,
11
11
  n: '0',
12
12
  v: 33.98755678796222
13
13
  },
@@ -44,7 +44,7 @@ void describe('senMLtoLwM2M()', function() {
44
44
  3: 17.74077033996582,
45
45
  4: 26.376304626464844,
46
46
  5: 359.1545715332,
47
- 99: 1698155694999
47
+ 99: 1698155694
48
48
  }
49
49
  }
50
50
  ];
@@ -57,7 +57,7 @@ void describe('senMLtoLwM2M()', function() {
57
57
  bn: '14203/0/',
58
58
  n: '0',
59
59
  vs: 'LTE-M',
60
- bt: 1676369307222
60
+ bt: 1676369307
61
61
  },
62
62
  {
63
63
  n: '1',
@@ -98,7 +98,7 @@ void describe('senMLtoLwM2M()', function() {
98
98
  4: 56879116,
99
99
  5: 24001,
100
100
  6: '10.160.243.113',
101
- 99: 1676369307222
101
+ 99: 1676369307
102
102
  }
103
103
  }
104
104
  ];
@@ -111,7 +111,7 @@ void describe('senMLtoLwM2M()', function() {
111
111
  bn: '14203/0/',
112
112
  n: '0',
113
113
  vs: 'LTE-M',
114
- bt: 1699049665511
114
+ bt: 1699049665
115
115
  },
116
116
  {
117
117
  n: '1',
@@ -121,7 +121,7 @@ void describe('senMLtoLwM2M()', function() {
121
121
  bn: '14203/0/',
122
122
  n: '2',
123
123
  v: -89,
124
- bt: 1699049665511
124
+ bt: 1699049665
125
125
  },
126
126
  {
127
127
  n: '3',
@@ -143,7 +143,7 @@ void describe('senMLtoLwM2M()', function() {
143
143
  bn: '14203/0/',
144
144
  n: '11',
145
145
  v: 7,
146
- bt: 1699049665511
146
+ bt: 1699049665
147
147
  }
148
148
  ];
149
149
  var expected = [
@@ -158,7 +158,7 @@ void describe('senMLtoLwM2M()', function() {
158
158
  5: 24202,
159
159
  6: '100.81.95.75',
160
160
  11: 7,
161
- 99: 1699049665511
161
+ 99: 1699049665
162
162
  }
163
163
  }
164
164
  ];
@@ -171,25 +171,25 @@ void describe('senMLtoLwM2M()', function() {
171
171
  bn: '14205/0/',
172
172
  n: '0',
173
173
  v: 21,
174
- bt: 1699049600000
174
+ bt: 1699049600
175
175
  },
176
176
  {
177
177
  bn: '14205/1/',
178
178
  n: '0',
179
179
  v: 31,
180
- bt: 1699049600000
180
+ bt: 1699049600
181
181
  },
182
182
  {
183
183
  bn: '14205/0/',
184
184
  n: '0',
185
185
  v: 22,
186
- bt: 1699049700000
186
+ bt: 1699049700
187
187
  },
188
188
  {
189
189
  bn: '14205/1/',
190
190
  n: '0',
191
191
  v: 32,
192
- bt: 1699049700000
192
+ bt: 1699049700
193
193
  }
194
194
  ];
195
195
  var expected = [
@@ -197,7 +197,7 @@ void describe('senMLtoLwM2M()', function() {
197
197
  ObjectID: 14205,
198
198
  Resources: {
199
199
  0: 21,
200
- 99: 1699049600000
200
+ 99: 1699049600
201
201
  }
202
202
  },
203
203
  {
@@ -205,14 +205,14 @@ void describe('senMLtoLwM2M()', function() {
205
205
  ObjectInstanceID: 1,
206
206
  Resources: {
207
207
  0: 31,
208
- 99: 1699049600000
208
+ 99: 1699049600
209
209
  }
210
210
  },
211
211
  {
212
212
  ObjectID: 14205,
213
213
  Resources: {
214
214
  0: 22,
215
- 99: 1699049700000
215
+ 99: 1699049700
216
216
  }
217
217
  },
218
218
  {
@@ -220,7 +220,7 @@ void describe('senMLtoLwM2M()', function() {
220
220
  ObjectInstanceID: 1,
221
221
  Resources: {
222
222
  0: 32,
223
- 99: 1699049700000
223
+ 99: 1699049700
224
224
  }
225
225
  }
226
226
  ];
@@ -9,7 +9,7 @@ void describe('validateSenML()', function() {
9
9
  blv: '1.1',
10
10
  n: '0',
11
11
  v: 99,
12
- bt: 1699049685992
12
+ bt: 1699049685
13
13
  },
14
14
  {
15
15
  n: '1',
@@ -56,6 +56,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
56
56
  * Timestamp (Time)
57
57
  *
58
58
  * The timestamp of when the location measurement was performed.
59
+ *
60
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
59
61
  */
60
62
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the location measurement was performed." } } }, /**
61
63
  * Battery and Power (14202)
@@ -99,6 +101,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
99
101
  * Timestamp (Time)
100
102
  *
101
103
  * The timestamp of when the measurement was performed.
104
+ *
105
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
102
106
  */
103
107
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the measurement was performed." } } }, /**
104
108
  * Connection information (14203)
@@ -149,6 +153,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
149
153
  * Timestamp (Time)
150
154
  *
151
155
  * The timestamp of when the measurement was performed.
156
+ *
157
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
152
158
  */
153
159
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the measurement was performed." } } }, /**
154
160
  * Device information (14204)
@@ -189,6 +195,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
189
195
  * Timestamp (Time)
190
196
  *
191
197
  * The timestamp of when the measurement was performed.
198
+ *
199
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
192
200
  */
193
201
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the measurement was performed." } } }, /**
194
202
  * Environment (14205)
@@ -222,6 +230,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
222
230
  * Timestamp (Time)
223
231
  *
224
232
  * The timestamp of when the measurement was performed.
233
+ *
234
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
225
235
  */
226
236
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the measurement was performed." } } }, /**
227
237
  * Solar charge (14210)
@@ -242,6 +252,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
242
252
  * Timestamp (Time)
243
253
  *
244
254
  * The timestamp of when the measurement was performed.
255
+ *
256
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
245
257
  */
246
258
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the measurement was performed." } } }, /**
247
259
  * Button press (14220)
@@ -252,6 +264,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
252
264
  * Timestamp (Time)
253
265
  *
254
266
  * The timestamp of when the button was pressed.
267
+ *
268
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
255
269
  */
256
270
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the button was pressed." } } }, /**
257
271
  * Sea Water Level (14230)
@@ -272,6 +286,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
272
286
  * Timestamp (Time)
273
287
  *
274
288
  * The timestamp of when the observation was made.
289
+ *
290
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
275
291
  */
276
292
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the observation was made." } } }, /**
277
293
  * RGB LED (14240)
@@ -306,6 +322,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
306
322
  * Timestamp (Time)
307
323
  *
308
324
  * The timestamp of when the LED was changed.
325
+ *
326
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
309
327
  */
310
328
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the LED was changed." } } }, /**
311
329
  * Application Configuration (14301)
@@ -329,6 +347,8 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
329
347
  * Timestamp (Time)
330
348
  *
331
349
  * The timestamp of when the configuration was updated.
350
+ *
351
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
332
352
  */
333
353
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the configuration was updated." } } }, /**
334
354
  * nRF Cloud Service Info (14401)
@@ -344,5 +364,7 @@ export const definitions: Record<LwM2MObjectID, LWM2MObjectInfo> = { /**
344
364
  * Timestamp (Time)
345
365
  *
346
366
  * The timestamp of when the service info was updated.
367
+ *
368
+ * Time resources in LwM2M are represented as a signed integer representing the number of seconds since Jan 1, 1970 in the UTC time zone.
347
369
  */
348
370
  99: { ResourceID: 99, Name: "Timestamp", Mandatory: true, Type: ResourceType.Time, Multiple: false, Description: "The timestamp of when the service info was updated." } } } };
@@ -1,6 +1,6 @@
1
1
  import { describe, it } from 'node:test'
2
2
  import assert from 'node:assert/strict'
3
- import { instanceTs } from './instanceTs.js'
3
+ import { instanceTs, instanceTsAsDate } from './instanceTs.js'
4
4
 
5
5
  void describe('instanceTs()', () => {
6
6
  void it('should return the timestamp of the instance', () =>
@@ -11,9 +11,25 @@ void describe('instanceTs()', () => {
11
11
  Resources: {
12
12
  '0': 3.5399999618530273,
13
13
  '1': 4.168000221252441,
14
- '99': 1708683500474,
14
+ '99': 1708683500,
15
15
  },
16
16
  }),
17
- 1708683500474,
17
+ 1708683500,
18
+ ))
19
+ })
20
+
21
+ void describe('instanceTsAsDate()', () => {
22
+ void it('should return the timestamp of the instance', () =>
23
+ assert.equal(
24
+ instanceTsAsDate({
25
+ ObjectID: 14210,
26
+ ObjectVersion: '1.0',
27
+ Resources: {
28
+ '0': 3.5399999618530273,
29
+ '1': 4.168000221252441,
30
+ '99': 1708683500,
31
+ },
32
+ }).getTime(),
33
+ 1708683500 * 1000,
18
34
  ))
19
35
  })
@@ -2,8 +2,21 @@ import type { LwM2MObjectInstance } from './LwM2MObjectInstance.js'
2
2
  import { definitions } from './definitions.js'
3
3
  import { timestampResources } from './timestampResources.js'
4
4
 
5
+ /**
6
+ * Returns the timestamp of the instance
7
+ *
8
+ * The timestamp is s signed integer representing
9
+ * the number of seconds since Jan 1, 1970 in the
10
+ * UTC time zone.
11
+ */
5
12
  export const instanceTs = (instance: LwM2MObjectInstance): number => {
6
13
  const definition = definitions[instance.ObjectID]
7
14
  const tsResourceId = timestampResources.get(definition.ObjectID) as number // All registered objects must have a timestamp resource
8
15
  return instance.Resources[tsResourceId] as number
9
16
  }
17
+
18
+ /**
19
+ * Returns the timestamp of the instance as a Date object
20
+ */
21
+ export const instanceTsAsDate = (instance: LwM2MObjectInstance): Date =>
22
+ new Date(instanceTs(instance) * 1000)
@@ -14,7 +14,7 @@ void describe('validate()', () => {
14
14
  '1': 6.151946,
15
15
  '6': 'Fixed',
16
16
  '3': 1,
17
- '99': 1710147413003,
17
+ '99': 1710147413,
18
18
  },
19
19
  }
20
20
  const maybeValid = v(object)
@@ -38,7 +38,7 @@ void describe('validate()', () => {
38
38
  '5': 24201,
39
39
  '6': '10.234.105.140',
40
40
  11: undefined,
41
- '99': 1716988087000,
41
+ '99': 1716988087,
42
42
  },
43
43
  }
44
44
  const maybeValid = v(object)
@@ -51,7 +51,7 @@ void describe('validate()', () => {
51
51
  ObjectVersion: '1.0',
52
52
  Resources: {
53
53
  '0': ['BOOT', 'MODEM', 'APP'],
54
- '99': 1717409966000,
54
+ '99': 1717409966,
55
55
  },
56
56
  }
57
57
  const maybeValid = v(object)
@@ -101,7 +101,7 @@ export const validateInstance =
101
101
 
102
102
  export const NumberResource = (r: unknown): r is number => typeof r === 'number'
103
103
  export const TimeResource = (r: unknown): r is number =>
104
- NumberResource(r) && r > 1700000000000 && r < 9999999999999
104
+ NumberResource(r) && r > 1700000000 && r < 9999999999
105
105
  export const StringResource = (r: unknown): r is string => typeof r === 'string'
106
106
  export const BooleanResource = (r: unknown): r is boolean =>
107
107
  typeof r === 'boolean'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/proto-map",
3
- "version": "12.1.3",
3
+ "version": "13.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,7 +39,7 @@
39
39
  "@bifravst/prettier-config": "1.0.3",
40
40
  "@commitlint/config-conventional": "19.2.2",
41
41
  "@swc/cli": "0.3.12",
42
- "@swc/core": "1.5.28",
42
+ "@swc/core": "1.6.1",
43
43
  "@types/node": "20.14.2",
44
44
  "@types/xml2js": "0.4.14",
45
45
  "chalk": "5.3.0",
@@ -50,7 +50,7 @@
50
50
  "remark": "15.0.1",
51
51
  "remark-frontmatter": "5.0.0",
52
52
  "tsmatchers": "5.0.2",
53
- "tsx": "4.15.2",
53
+ "tsx": "4.15.5",
54
54
  "xml2js": "0.6.2",
55
55
  "yaml": "2.4.5"
56
56
  },
@@ -10,7 +10,7 @@ void describe('SenMLType', () => {
10
10
  bn: '14201/0/',
11
11
  n: '0',
12
12
  v: 33.98755678796222,
13
- bt: 1698155694999,
13
+ bt: 1698155694,
14
14
  },
15
15
  { n: '1', v: -84.506132079174634 },
16
16
  ]
@@ -10,15 +10,15 @@ void describe('fromCBOR()', () => {
10
10
  { '0': '1', '2': 17.66905 },
11
11
  { '0': '2', '2': 100562.21875 },
12
12
  { '0': '10', '2': 57 },
13
- { '0': '99', '2': 1716475294528n },
13
+ // Converts from BigInt as well
14
+ { '0': '99', '2': 1716475294n },
14
15
  ]),
15
16
  [
16
17
  { n: '0', v: 28.904369, bn: '14205/0/' },
17
18
  { n: '1', v: 17.66905 },
18
19
  { n: '2', v: 100562.21875 },
19
20
  { n: '10', v: 57 },
20
- // Convert bigints
21
- { n: '99', v: 1716475294528 },
21
+ { n: '99', v: 1716475294 },
22
22
  ],
23
23
  ))
24
24
  })
@@ -4,7 +4,7 @@ import { hasValue } from './hasValue.js'
4
4
 
5
5
  void describe('hasValue() should determine whether an object has a value', () => {
6
6
  for (const [record, expected] of [
7
- [{ bn: 14202, n: 0, v: 99, bt: 1699049685992 }, true],
7
+ [{ bn: 14202, n: 0, v: 99, bt: 1699049685 }, true],
8
8
  [{ n: 1, v: 4.179 }, true],
9
9
  [{ n: 2, v: 0 }, true],
10
10
  [{ n: 3, v: 25.7 }, true],
@@ -19,7 +19,7 @@ void describe('lwm2mToSenML()', () => {
19
19
  '1': 6.151946,
20
20
  '6': 'Fixed',
21
21
  '3': 1,
22
- '99': 1710147413003,
22
+ '99': 1710147413,
23
23
  },
24
24
  }
25
25
  const level1: LwM2MObjectInstance<SeaWaterLevel_14230> = {
@@ -28,7 +28,7 @@ void describe('lwm2mToSenML()', () => {
28
28
  Resources: {
29
29
  '0': 84.3,
30
30
  '1': 'AES',
31
- '99': 1710140400000,
31
+ '99': 1710140400,
32
32
  },
33
33
  }
34
34
  const level2: LwM2MObjectInstance<SeaWaterLevel_14230> = {
@@ -37,7 +37,7 @@ void describe('lwm2mToSenML()', () => {
37
37
  Resources: {
38
38
  '0': 140.4,
39
39
  '1': 'AES',
40
- '99': 1710144000000,
40
+ '99': 1710144000,
41
41
  },
42
42
  }
43
43
  const level3: LwM2MObjectInstance<SeaWaterLevel_14230> = {
@@ -47,7 +47,7 @@ void describe('lwm2mToSenML()', () => {
47
47
  Resources: {
48
48
  '0': 140.7,
49
49
  '1': 'AES',
50
- '99': 1710144001000,
50
+ '99': 1710144001,
51
51
  },
52
52
  }
53
53
  const lwm2m: Array<LwM2MObjectInstance<any>> = [
@@ -57,15 +57,15 @@ void describe('lwm2mToSenML()', () => {
57
57
  level3,
58
58
  ]
59
59
  const expected: SenMLType = [
60
- { bn: '14201/0/', n: '0', v: 62.469414, bt: 1710147413003 },
60
+ { bn: '14201/0/', n: '0', v: 62.469414, bt: 1710147413 },
61
61
  { n: '1', v: 6.151946 },
62
62
  { n: '3', v: 1 },
63
63
  { n: '6', vs: 'Fixed' },
64
- { bn: '14230/0/', n: '0', v: 84.3, bt: 1710140400000 },
64
+ { bn: '14230/0/', n: '0', v: 84.3, bt: 1710140400 },
65
65
  { n: '1', vs: 'AES' },
66
- { bn: '14230/0/', n: '0', v: 140.4, bt: 1710144000000 },
66
+ { bn: '14230/0/', n: '0', v: 140.4, bt: 1710144000 },
67
67
  { n: '1', vs: 'AES' },
68
- { bn: '14230/1/', n: '0', v: 140.7, bt: 1710144001000 },
68
+ { bn: '14230/1/', n: '0', v: 140.7, bt: 1710144001 },
69
69
  { n: '1', vs: 'AES' },
70
70
  ]
71
71
 
@@ -10,7 +10,7 @@ void describe('senMLtoLwM2M()', () => {
10
10
  {
11
11
  bn: '14201/1/',
12
12
  blv: '1.1',
13
- bt: 1698155694999,
13
+ bt: 1698155694,
14
14
  n: '0',
15
15
  v: 33.98755678796222,
16
16
  },
@@ -47,7 +47,7 @@ void describe('senMLtoLwM2M()', () => {
47
47
  3: 17.74077033996582,
48
48
  4: 26.376304626464844,
49
49
  5: 359.1545715332,
50
- 99: 1698155694999,
50
+ 99: 1698155694,
51
51
  },
52
52
  },
53
53
  ]
@@ -61,7 +61,7 @@ void describe('senMLtoLwM2M()', () => {
61
61
  bn: '14203/0/',
62
62
  n: '0',
63
63
  vs: 'LTE-M',
64
- bt: 1676369307222,
64
+ bt: 1676369307,
65
65
  },
66
66
  {
67
67
  n: '1',
@@ -102,7 +102,7 @@ void describe('senMLtoLwM2M()', () => {
102
102
  4: 56879116,
103
103
  5: 24001,
104
104
  6: '10.160.243.113',
105
- 99: 1676369307222,
105
+ 99: 1676369307,
106
106
  },
107
107
  },
108
108
  ]
@@ -112,14 +112,14 @@ void describe('senMLtoLwM2M()', () => {
112
112
 
113
113
  void it('should ignore repeated base properties', () => {
114
114
  const input: SenMLType = [
115
- { bn: '14203/0/', n: '0', vs: 'LTE-M', bt: 1699049665511 },
115
+ { bn: '14203/0/', n: '0', vs: 'LTE-M', bt: 1699049665 },
116
116
  { n: '1', v: 20 },
117
- { bn: '14203/0/', n: '2', v: -89, bt: 1699049665511 },
117
+ { bn: '14203/0/', n: '2', v: -89, bt: 1699049665 },
118
118
  { n: '3', v: 2305 },
119
119
  { n: '4', v: 34784790 },
120
120
  { n: '5', v: 24202 },
121
121
  { n: '6', vs: '100.81.95.75' },
122
- { bn: '14203/0/', n: '11', v: 7, bt: 1699049665511 },
122
+ { bn: '14203/0/', n: '11', v: 7, bt: 1699049665 },
123
123
  ]
124
124
  const expected: LwM2MObjectInstance[] = [
125
125
  {
@@ -133,7 +133,7 @@ void describe('senMLtoLwM2M()', () => {
133
133
  5: 24202,
134
134
  6: '100.81.95.75',
135
135
  11: 7,
136
- 99: 1699049665511,
136
+ 99: 1699049665,
137
137
  },
138
138
  },
139
139
  ]
@@ -143,17 +143,17 @@ void describe('senMLtoLwM2M()', () => {
143
143
 
144
144
  void it('should handle multiple measurements for the same resource', () => {
145
145
  const input: SenMLType = [
146
- { bn: '14205/0/', n: '0', v: 21, bt: 1699049600000 },
147
- { bn: '14205/1/', n: '0', v: 31, bt: 1699049600000 },
148
- { bn: '14205/0/', n: '0', v: 22, bt: 1699049700000 },
149
- { bn: '14205/1/', n: '0', v: 32, bt: 1699049700000 },
146
+ { bn: '14205/0/', n: '0', v: 21, bt: 1699049600 },
147
+ { bn: '14205/1/', n: '0', v: 31, bt: 1699049600 },
148
+ { bn: '14205/0/', n: '0', v: 22, bt: 1699049700 },
149
+ { bn: '14205/1/', n: '0', v: 32, bt: 1699049700 },
150
150
  ]
151
151
  const expected: LwM2MObjectInstance[] = [
152
152
  {
153
153
  ObjectID: 14205,
154
154
  Resources: {
155
155
  0: 21,
156
- 99: 1699049600000,
156
+ 99: 1699049600,
157
157
  },
158
158
  },
159
159
  {
@@ -161,14 +161,14 @@ void describe('senMLtoLwM2M()', () => {
161
161
  ObjectInstanceID: 1,
162
162
  Resources: {
163
163
  0: 31,
164
- 99: 1699049600000,
164
+ 99: 1699049600,
165
165
  },
166
166
  },
167
167
  {
168
168
  ObjectID: 14205,
169
169
  Resources: {
170
170
  0: 22,
171
- 99: 1699049700000,
171
+ 99: 1699049700,
172
172
  },
173
173
  },
174
174
  {
@@ -176,7 +176,7 @@ void describe('senMLtoLwM2M()', () => {
176
176
  ObjectInstanceID: 1,
177
177
  Resources: {
178
178
  0: 32,
179
- 99: 1699049700000,
179
+ 99: 1699049700,
180
180
  },
181
181
  },
182
182
  ]
@@ -6,7 +6,7 @@ import type { SenMLType } from './SenMLSchema.js'
6
6
  void describe('validateSenML()', () => {
7
7
  void it('should validate', () => {
8
8
  const senMl: SenMLType = [
9
- { bn: '14202/1/', blv: '1.1', n: '0', v: 99, bt: 1699049685992 },
9
+ { bn: '14202/1/', blv: '1.1', n: '0', v: 99, bt: 1699049685 },
10
10
  { n: '1', v: 4.179 },
11
11
  { n: '2', v: 0 },
12
12
  { n: '3', v: 25.7 },