@hello.nrfcloud.com/proto-map 13.1.2 → 13.2.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.
@@ -0,0 +1,2 @@
1
+ export * from './objectsToShadow.js';
2
+ export * from './shadowToObjects.js';
@@ -0,0 +1,65 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _object_spread(target) {
15
+ for(var i = 1; i < arguments.length; i++){
16
+ var source = arguments[i] != null ? arguments[i] : {};
17
+ var ownKeys = Object.keys(source);
18
+ if (typeof Object.getOwnPropertySymbols === "function") {
19
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
+ }));
22
+ }
23
+ ownKeys.forEach(function(key) {
24
+ _define_property(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
+ }
29
+ function ownKeys(object, enumerableOnly) {
30
+ var keys = Object.keys(object);
31
+ if (Object.getOwnPropertySymbols) {
32
+ var symbols = Object.getOwnPropertySymbols(object);
33
+ if (enumerableOnly) {
34
+ symbols = symbols.filter(function(sym) {
35
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
36
+ });
37
+ }
38
+ keys.push.apply(keys, symbols);
39
+ }
40
+ return keys;
41
+ }
42
+ function _object_spread_props(target, source) {
43
+ source = source != null ? source : {};
44
+ if (Object.getOwnPropertyDescriptors) {
45
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
46
+ } else {
47
+ ownKeys(Object(source)).forEach(function(key) {
48
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
49
+ });
50
+ }
51
+ return target;
52
+ }
53
+ import { instanceTs } from '../instanceTs.js';
54
+ export var objectsToShadow = function(objects) {
55
+ return objects.sort(function(u1, u2) {
56
+ var d1 = instanceTs(u1);
57
+ var d2 = instanceTs(u2);
58
+ return d1 - d2 ? 1 : -1;
59
+ }).reduce(function(shadow, update) {
60
+ var _update_ObjectVersion;
61
+ var key = "".concat(update.ObjectID, ":").concat((_update_ObjectVersion = update.ObjectVersion) !== null && _update_ObjectVersion !== void 0 ? _update_ObjectVersion : '1.0');
62
+ var _update_ObjectInstanceID;
63
+ return _object_spread_props(_object_spread({}, shadow), _define_property({}, key, _define_property({}, (_update_ObjectInstanceID = update.ObjectInstanceID) !== null && _update_ObjectInstanceID !== void 0 ? _update_ObjectInstanceID : 0, update.Resources)));
64
+ }, {});
65
+ };
@@ -0,0 +1,96 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+ import { objectsToShadow } from './objectsToShadow.js';
4
+ import { LwM2MObjectID } from '../LwM2MObjectID.js';
5
+ void describe('objectsToShadow()', function() {
6
+ void it('should convert a list of LwM2M objects to a shadow document', function() {
7
+ return assert.deepEqual(objectsToShadow([
8
+ {
9
+ ObjectID: 14205,
10
+ Resources: {
11
+ '0': 27.69,
12
+ '1': 18.9,
13
+ '2': 97.271,
14
+ '99': 1699197208
15
+ }
16
+ },
17
+ {
18
+ ObjectID: 14202,
19
+ Resources: {
20
+ '0': 99,
21
+ '1': 4.174,
22
+ '2': 0,
23
+ '3': 25.9,
24
+ '99': 1699197208
25
+ }
26
+ },
27
+ {
28
+ ObjectID: 14203,
29
+ Resources: {
30
+ '0': 'LTE-M',
31
+ '1': 20,
32
+ '2': -93,
33
+ '3': 2305,
34
+ '4': 34237196,
35
+ '5': 24202,
36
+ '6': '100.81.95.75',
37
+ '11': 7,
38
+ '99': 1699197229
39
+ }
40
+ },
41
+ {
42
+ ObjectID: LwM2MObjectID.NRFCloudServiceInfo_14401,
43
+ ObjectVersion: '1.0',
44
+ Resources: {
45
+ 0: [
46
+ 'BOOT',
47
+ 'MODEM',
48
+ 'APP'
49
+ ],
50
+ 99: 1717409966 * 1000
51
+ }
52
+ }
53
+ ]), {
54
+ '14205:1.0': {
55
+ 0: {
56
+ '0': 27.69,
57
+ '1': 18.9,
58
+ '2': 97.271,
59
+ '99': 1699197208
60
+ }
61
+ },
62
+ '14203:1.0': {
63
+ 0: {
64
+ '0': 'LTE-M',
65
+ '1': 20,
66
+ '2': -93,
67
+ '3': 2305,
68
+ '4': 34237196,
69
+ '5': 24202,
70
+ '6': '100.81.95.75',
71
+ '11': 7,
72
+ '99': 1699197229
73
+ }
74
+ },
75
+ '14202:1.0': {
76
+ 0: {
77
+ '0': 99,
78
+ '1': 4.174,
79
+ '2': 0,
80
+ '3': 25.9,
81
+ '99': 1699197208
82
+ }
83
+ },
84
+ '14401:1.0': {
85
+ 0: {
86
+ 0: [
87
+ 'BOOT',
88
+ 'MODEM',
89
+ 'APP'
90
+ ],
91
+ 99: 1717409966 * 1000
92
+ }
93
+ }
94
+ });
95
+ });
96
+ });
@@ -0,0 +1,69 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _iterable_to_array_limit(arr, i) {
10
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally{
25
+ try {
26
+ if (!_n && _i["return"] != null) _i["return"]();
27
+ } finally{
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
32
+ }
33
+ function _non_iterable_rest() {
34
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ function _sliced_to_array(arr, i) {
37
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
+ }
39
+ function _unsupported_iterable_to_array(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
42
+ var n = Object.prototype.toString.call(o).slice(8, -1);
43
+ if (n === "Object" && o.constructor) n = o.constructor.name;
44
+ if (n === "Map" || n === "Set") return Array.from(n);
45
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
+ }
47
+ import { timestampResources } from '../timestampResources.js';
48
+ export var shadowToObjects = function(shadow) {
49
+ return Object.entries(shadow).map(function(param) {
50
+ var _param = _sliced_to_array(param, 2), ObjectIdAndVersion = _param[0], Instances = _param[1];
51
+ var _ObjectIdAndVersion_split = _sliced_to_array(ObjectIdAndVersion.split(':'), 2), ObjectIDString = _ObjectIdAndVersion_split[0], ObjectVersion = _ObjectIdAndVersion_split[1];
52
+ var ObjectID = parseInt(ObjectIDString, 10);
53
+ var tsResource = timestampResources.get(ObjectID);
54
+ if (tsResource === undefined) return null;
55
+ return Object.entries(Instances).map(function(param) {
56
+ var _param = _sliced_to_array(param, 2), instanceId = _param[0], Resources = _param[1];
57
+ var ObjectInstanceID = parseInt(instanceId, 10);
58
+ var objectInstance = {
59
+ ObjectID: ObjectID,
60
+ ObjectVersion: ObjectVersion,
61
+ Resources: Resources
62
+ };
63
+ if (ObjectInstanceID > 0) objectInstance.ObjectInstanceID = ObjectInstanceID;
64
+ return objectInstance;
65
+ });
66
+ }).flat().filter(function(o) {
67
+ return o !== null;
68
+ });
69
+ };
@@ -0,0 +1,112 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+ import { shadowToObjects } from './shadowToObjects.js';
4
+ import { LwM2MObjectID } from '../LwM2MObjectID.js';
5
+ void describe('shadowToObjects()', function() {
6
+ void it('should convert a shadow to LwM2M objects', function() {
7
+ return assert.deepEqual(shadowToObjects({
8
+ '14205:1.0': {
9
+ 0: {
10
+ '0': 27.63,
11
+ '1': 19.354,
12
+ '2': 97.465,
13
+ '99': 1699217636
14
+ },
15
+ 42: {
16
+ '0': 25,
17
+ '99': 1699217636
18
+ }
19
+ },
20
+ '14203:1.0': {
21
+ 0: {
22
+ '0': 'LTE-M',
23
+ '1': 20,
24
+ '2': -90,
25
+ '3': 2305,
26
+ '4': 34237196,
27
+ '5': 24202,
28
+ '6': '100.81.95.75',
29
+ '11': 7,
30
+ '99': 1699217637
31
+ }
32
+ },
33
+ '14202:1.0': {
34
+ 0: {
35
+ '0': 99,
36
+ '1': 4.174,
37
+ '2': 0,
38
+ '3': 25.9,
39
+ '99': 1699217657
40
+ }
41
+ },
42
+ '14401:1.0': {
43
+ 0: {
44
+ 0: [
45
+ 'BOOT',
46
+ 'MODEM',
47
+ 'APP'
48
+ ],
49
+ 99: 1717409966 * 1000
50
+ }
51
+ }
52
+ }), [
53
+ {
54
+ ObjectID: 14205,
55
+ ObjectVersion: '1.0',
56
+ Resources: {
57
+ '0': 27.63,
58
+ '1': 19.354,
59
+ '2': 97.465,
60
+ '99': 1699217636
61
+ }
62
+ },
63
+ {
64
+ ObjectID: 14205,
65
+ ObjectInstanceID: 42,
66
+ ObjectVersion: '1.0',
67
+ Resources: {
68
+ '0': 25,
69
+ '99': 1699217636
70
+ }
71
+ },
72
+ {
73
+ ObjectID: 14203,
74
+ ObjectVersion: '1.0',
75
+ Resources: {
76
+ '0': 'LTE-M',
77
+ '1': 20,
78
+ '2': -90,
79
+ '3': 2305,
80
+ '4': 34237196,
81
+ '5': 24202,
82
+ '6': '100.81.95.75',
83
+ '11': 7,
84
+ '99': 1699217637
85
+ }
86
+ },
87
+ {
88
+ ObjectID: 14202,
89
+ ObjectVersion: '1.0',
90
+ Resources: {
91
+ '0': 99,
92
+ '1': 4.174,
93
+ '2': 0,
94
+ '3': 25.9,
95
+ '99': 1699217657
96
+ }
97
+ },
98
+ {
99
+ ObjectID: LwM2MObjectID.NRFCloudServiceInfo_14401,
100
+ ObjectVersion: '1.0',
101
+ Resources: {
102
+ 0: [
103
+ 'BOOT',
104
+ 'MODEM',
105
+ 'APP'
106
+ ],
107
+ 99: 1717409966 * 1000
108
+ }
109
+ }
110
+ ]);
111
+ });
112
+ });
@@ -0,0 +1,2 @@
1
+ export * from './objectsToShadow.js'
2
+ export * from './shadowToObjects.js'
@@ -0,0 +1,91 @@
1
+ import assert from 'node:assert/strict'
2
+ import { describe, it } from 'node:test'
3
+ import { objectsToShadow } from './objectsToShadow.js'
4
+ import { LwM2MObjectID } from '../LwM2MObjectID.js'
5
+
6
+ void describe('objectsToShadow()', () => {
7
+ void it('should convert a list of LwM2M objects to a shadow document', () =>
8
+ assert.deepEqual(
9
+ objectsToShadow([
10
+ {
11
+ ObjectID: 14205,
12
+ Resources: {
13
+ '0': 27.69,
14
+ '1': 18.9,
15
+ '2': 97.271,
16
+ '99': 1699197208,
17
+ },
18
+ },
19
+ {
20
+ ObjectID: 14202,
21
+ Resources: {
22
+ '0': 99,
23
+ '1': 4.174,
24
+ '2': 0,
25
+ '3': 25.9,
26
+ '99': 1699197208,
27
+ },
28
+ },
29
+ {
30
+ ObjectID: 14203,
31
+ Resources: {
32
+ '0': 'LTE-M',
33
+ '1': 20,
34
+ '2': -93,
35
+ '3': 2305,
36
+ '4': 34237196,
37
+ '5': 24202,
38
+ '6': '100.81.95.75',
39
+ '11': 7,
40
+ '99': 1699197229,
41
+ },
42
+ },
43
+ {
44
+ ObjectID: LwM2MObjectID.NRFCloudServiceInfo_14401,
45
+ ObjectVersion: '1.0',
46
+ Resources: {
47
+ 0: ['BOOT', 'MODEM', 'APP'],
48
+ 99: 1717409966 * 1000,
49
+ },
50
+ },
51
+ ]),
52
+ {
53
+ '14205:1.0': {
54
+ 0: {
55
+ '0': 27.69,
56
+ '1': 18.9,
57
+ '2': 97.271,
58
+ '99': 1699197208,
59
+ },
60
+ },
61
+ '14203:1.0': {
62
+ 0: {
63
+ '0': 'LTE-M',
64
+ '1': 20,
65
+ '2': -93,
66
+ '3': 2305,
67
+ '4': 34237196,
68
+ '5': 24202,
69
+ '6': '100.81.95.75',
70
+ '11': 7,
71
+ '99': 1699197229,
72
+ },
73
+ },
74
+ '14202:1.0': {
75
+ 0: {
76
+ '0': 99,
77
+ '1': 4.174,
78
+ '2': 0,
79
+ '3': 25.9,
80
+ '99': 1699197208,
81
+ },
82
+ },
83
+ '14401:1.0': {
84
+ 0: {
85
+ 0: ['BOOT', 'MODEM', 'APP'],
86
+ 99: 1717409966 * 1000,
87
+ },
88
+ },
89
+ },
90
+ ))
91
+ })
@@ -0,0 +1,40 @@
1
+ import type { LwM2MObjectInstance } from '../LwM2MObjectInstance.js'
2
+ import { instanceTs } from '../instanceTs.js'
3
+
4
+ export type LwM2MShadow = Record<
5
+ string,
6
+ Record<
7
+ number,
8
+ Record<
9
+ number,
10
+ string | number | boolean | Array<string> | Array<number> | Array<boolean>
11
+ >
12
+ >
13
+ >
14
+
15
+ export const objectsToShadow = (
16
+ objects: Array<LwM2MObjectInstance>,
17
+ ): LwM2MShadow =>
18
+ objects
19
+ .sort((u1, u2) => {
20
+ const d1 = instanceTs(u1)
21
+ const d2 = instanceTs(u2)
22
+ return d1 - d2 ? 1 : -1
23
+ })
24
+ .reduce<LwM2MShadow>((shadow, update) => {
25
+ const key = `${update.ObjectID}:${update.ObjectVersion ?? '1.0'}`
26
+ return {
27
+ ...shadow,
28
+ [key]: {
29
+ [update.ObjectInstanceID ?? 0]: update.Resources as Record<
30
+ number,
31
+ | string
32
+ | number
33
+ | boolean
34
+ | Array<string>
35
+ | Array<number>
36
+ | Array<boolean>
37
+ >,
38
+ },
39
+ }
40
+ }, {})
@@ -0,0 +1,107 @@
1
+ import assert from 'node:assert/strict'
2
+ import { describe, it } from 'node:test'
3
+ import { shadowToObjects } from './shadowToObjects.js'
4
+ import { LwM2MObjectID } from '../LwM2MObjectID.js'
5
+
6
+ void describe('shadowToObjects()', () => {
7
+ void it('should convert a shadow to LwM2M objects', () =>
8
+ assert.deepEqual(
9
+ shadowToObjects({
10
+ '14205:1.0': {
11
+ 0: {
12
+ '0': 27.63,
13
+ '1': 19.354,
14
+ '2': 97.465,
15
+ '99': 1699217636,
16
+ },
17
+ 42: {
18
+ '0': 25,
19
+ '99': 1699217636,
20
+ },
21
+ },
22
+ '14203:1.0': {
23
+ 0: {
24
+ '0': 'LTE-M',
25
+ '1': 20,
26
+ '2': -90,
27
+ '3': 2305,
28
+ '4': 34237196,
29
+ '5': 24202,
30
+ '6': '100.81.95.75',
31
+ '11': 7,
32
+ '99': 1699217637,
33
+ },
34
+ },
35
+ '14202:1.0': {
36
+ 0: {
37
+ '0': 99,
38
+ '1': 4.174,
39
+ '2': 0,
40
+ '3': 25.9,
41
+ '99': 1699217657,
42
+ },
43
+ },
44
+ '14401:1.0': {
45
+ 0: {
46
+ 0: ['BOOT', 'MODEM', 'APP'],
47
+ 99: 1717409966 * 1000,
48
+ },
49
+ },
50
+ }),
51
+ [
52
+ {
53
+ ObjectID: 14205,
54
+ ObjectVersion: '1.0',
55
+ Resources: {
56
+ '0': 27.63,
57
+ '1': 19.354,
58
+ '2': 97.465,
59
+ '99': 1699217636,
60
+ },
61
+ },
62
+ {
63
+ ObjectID: 14205,
64
+ ObjectInstanceID: 42,
65
+ ObjectVersion: '1.0',
66
+ Resources: {
67
+ '0': 25,
68
+ '99': 1699217636,
69
+ },
70
+ },
71
+ {
72
+ ObjectID: 14203,
73
+ ObjectVersion: '1.0',
74
+ Resources: {
75
+ '0': 'LTE-M',
76
+ '1': 20,
77
+ '2': -90,
78
+ '3': 2305,
79
+ '4': 34237196,
80
+ '5': 24202,
81
+ '6': '100.81.95.75',
82
+ '11': 7,
83
+ '99': 1699217637,
84
+ },
85
+ },
86
+ {
87
+ ObjectID: 14202,
88
+ ObjectVersion: '1.0',
89
+ Resources: {
90
+ '0': 99,
91
+ '1': 4.174,
92
+ '2': 0,
93
+ '3': 25.9,
94
+ '99': 1699217657,
95
+ },
96
+ },
97
+ {
98
+ ObjectID: LwM2MObjectID.NRFCloudServiceInfo_14401,
99
+ ObjectVersion: '1.0',
100
+ Resources: {
101
+ 0: ['BOOT', 'MODEM', 'APP'],
102
+ 99: 1717409966 * 1000,
103
+ },
104
+ },
105
+ ],
106
+ ))
107
+ })
@@ -0,0 +1,28 @@
1
+ import type { LwM2MObjectInstance } from '../LwM2MObjectInstance.js'
2
+ import type { LwM2MShadow } from './objectsToShadow.js'
3
+ import { timestampResources } from '../timestampResources.js'
4
+
5
+ export const shadowToObjects = (shadow: LwM2MShadow): LwM2MObjectInstance[] =>
6
+ Object.entries(shadow)
7
+ .map(([ObjectIdAndVersion, Instances]) => {
8
+ const [ObjectIDString, ObjectVersion] = ObjectIdAndVersion.split(':') as [
9
+ string,
10
+ string,
11
+ ]
12
+ const ObjectID = parseInt(ObjectIDString, 10)
13
+ const tsResource = timestampResources.get(ObjectID)
14
+ if (tsResource === undefined) return null
15
+ return Object.entries(Instances).map(([instanceId, Resources]) => {
16
+ const ObjectInstanceID = parseInt(instanceId, 10)
17
+ const objectInstance: LwM2MObjectInstance = {
18
+ ObjectID,
19
+ ObjectVersion,
20
+ Resources,
21
+ }
22
+ if (ObjectInstanceID > 0)
23
+ objectInstance.ObjectInstanceID = ObjectInstanceID
24
+ return objectInstance
25
+ })
26
+ })
27
+ .flat()
28
+ .filter((o) => o !== null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/proto-map",
3
- "version": "13.1.2",
3
+ "version": "13.2.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": {
@@ -38,8 +38,8 @@
38
38
  "@bifravst/eslint-config-typescript": "6.1.6",
39
39
  "@bifravst/prettier-config": "1.0.3",
40
40
  "@commitlint/config-conventional": "19.2.2",
41
- "@swc/cli": "0.3.14",
42
- "@swc/core": "1.6.5",
41
+ "@swc/cli": "0.4.0",
42
+ "@swc/core": "1.6.6",
43
43
  "@types/node": "20.14.9",
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.7",
53
+ "tsx": "4.16.0",
54
54
  "xml2js": "0.6.2",
55
55
  "yaml": "2.4.5"
56
56
  },