@hello.nrfcloud.com/proto-map 5.6.2 → 5.6.3
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/api/Context.ts +1 -1
- package/api/{ResourceUpdate.spec.ts → ObjectUpdate.spec.ts} +5 -5
- package/api/{ResourceUpdate.ts → ObjectUpdate.ts} +4 -4
- package/dist/api/Context.js +1 -1
- package/dist/api/DeviceId.js +7 -7
- package/dist/api/Devices.js +11 -11
- package/dist/api/History.js +10 -10
- package/dist/api/History.spec.js +17 -17
- package/dist/api/LwM2M.js +11 -11
- package/dist/api/ObjectUpdate.js +17 -0
- package/dist/api/ObjectUpdate.spec.js +26 -0
- package/dist/api/ShareDeviceOwnershipConfirmed.js +4 -4
- package/dist/api/ShareDeviceRequest.js +4 -4
- package/dist/api/Timestamp.js +3 -3
- package/dist/api/Timestamp.spec.js +9 -9
- package/dist/api/index.js +8 -8
- package/dist/generator/addDocBlock.js +2 -2
- package/dist/generator/generateLwM2MDefinitions.js +27 -27
- package/dist/generator/generateLwM2MDefinitions.spec.js +32 -32
- package/dist/generator/generateLwm2mTimestampResources.js +7 -7
- package/dist/generator/generateModels.js +37 -37
- package/dist/generator/generateType.js +21 -21
- package/dist/generator/generateValidator.js +29 -29
- package/dist/generator/generateValidators.js +9 -9
- package/dist/generator/isDir.js +1 -1
- package/dist/generator/isDir.spec.js +13 -13
- package/dist/generator/lwm2m.js +23 -23
- package/dist/generator/models.js +23 -23
- package/dist/generator/printNode.js +2 -2
- package/dist/generator/tokenizeName.js +2 -2
- package/dist/generator/tokenizeName.spec.js +20 -20
- package/dist/generator/types.js +37 -37
- package/dist/lwm2m/LWM2MObjectDefinition.js +30 -30
- package/dist/lwm2m/check-lwm2m-rules.js +34 -34
- package/dist/lwm2m/definitions.js +4 -4
- package/dist/lwm2m/fromXML2JSON.js +4 -4
- package/dist/lwm2m/instanceTs.js +2 -2
- package/dist/lwm2m/instanceTs.spec.js +10 -10
- package/dist/lwm2m/isRegisteredLwM2MObject.js +2 -2
- package/dist/lwm2m/isRegisteredLwM2MObject.spec.js +12 -12
- package/dist/lwm2m/parseRangeEnumeration.js +1 -1
- package/dist/lwm2m/parseRangeEnumeration.spec.js +11 -11
- package/dist/lwm2m/unwrapNestedArray.js +2 -2
- package/dist/lwm2m/unwrapNestedArray.spec.js +155 -155
- package/dist/lwm2m/validate.js +1 -1
- package/dist/lwm2m/validation.js +16 -16
- package/dist/markdown/getCodeBlock.js +5 -5
- package/dist/markdown/getFrontMatter.js +6 -6
- package/dist/markdown/parseREADME.js +5 -5
- package/dist/models/asset_tracker_v2+AWS/examples/examples.spec.js +21 -21
- package/dist/models/check-model-rules.js +42 -42
- package/dist/models/models.js +20 -20
- package/dist/models/types.js +3 -3
- package/dist/senml/SenMLSchema.js +16 -16
- package/dist/senml/SenMLSchema.spec.js +11 -11
- package/dist/senml/hasValue.js +2 -2
- package/dist/senml/hasValue.spec.js +4 -4
- package/dist/senml/lwm2mToSenML.js +8 -8
- package/dist/senml/lwm2mToSenML.spec.js +42 -42
- package/dist/senml/parseResourceId.js +1 -1
- package/dist/senml/parseResourceId.spec.js +6 -6
- package/dist/senml/senMLtoLwM2M.js +14 -14
- package/dist/senml/senMLtoLwM2M.spec.js +53 -53
- package/dist/senml/validateSenML.js +2 -2
- package/dist/senml/validateSenML.spec.js +11 -11
- package/package.json +4 -8
- package/dist/api/ResourceUpdate.js +0 -17
- package/dist/api/ResourceUpdate.spec.js +0 -26
package/dist/generator/models.js
CHANGED
|
@@ -150,16 +150,16 @@ function _ts_generator(thisArg, body) {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
var _path;
|
|
153
|
-
import chalk from
|
|
154
|
-
import { readFile, readdir, stat, writeFile } from
|
|
155
|
-
import os from
|
|
156
|
-
import path from
|
|
157
|
-
import { getCodeBlock } from
|
|
158
|
-
import { getFrontMatter } from
|
|
159
|
-
import { generateModels } from
|
|
160
|
-
import { printNode } from
|
|
161
|
-
import { FrontMatter } from
|
|
162
|
-
import { isDir } from
|
|
153
|
+
import chalk from 'chalk';
|
|
154
|
+
import { readFile, readdir, stat, writeFile } from 'node:fs/promises';
|
|
155
|
+
import os from 'node:os';
|
|
156
|
+
import path from 'node:path';
|
|
157
|
+
import { getCodeBlock } from '../markdown/getCodeBlock.js';
|
|
158
|
+
import { getFrontMatter } from '../markdown/getFrontMatter.js';
|
|
159
|
+
import { generateModels } from './generateModels.js';
|
|
160
|
+
import { printNode } from './printNode.js';
|
|
161
|
+
import { FrontMatter } from '../models/types.js';
|
|
162
|
+
import { isDir } from './isDir.js';
|
|
163
163
|
var baseDir = process.cwd();
|
|
164
164
|
var subDir = function() {
|
|
165
165
|
for(var _len = arguments.length, tree = new Array(_len), _key = 0; _key < _len; _key++){
|
|
@@ -169,14 +169,14 @@ var subDir = function() {
|
|
|
169
169
|
baseDir
|
|
170
170
|
].concat(_to_consumable_array(tree)));
|
|
171
171
|
};
|
|
172
|
-
console.log(chalk.gray(
|
|
172
|
+
console.log(chalk.gray('Models'));
|
|
173
173
|
var loadModelTransforms = function() {
|
|
174
174
|
var _ref = _async_to_generator(function(model) {
|
|
175
175
|
var transformersDir, _;
|
|
176
176
|
return _ts_generator(this, function(_state) {
|
|
177
177
|
switch(_state.label){
|
|
178
178
|
case 0:
|
|
179
|
-
transformersDir = subDir(
|
|
179
|
+
transformersDir = subDir('models', model, 'transforms');
|
|
180
180
|
return [
|
|
181
181
|
4,
|
|
182
182
|
isDir(transformersDir)
|
|
@@ -198,7 +198,7 @@ var loadModelTransforms = function() {
|
|
|
198
198
|
_state.sent()
|
|
199
199
|
]).then(function(entries) {
|
|
200
200
|
return entries.filter(function(e) {
|
|
201
|
-
return e.endsWith(
|
|
201
|
+
return e.endsWith('.md');
|
|
202
202
|
});
|
|
203
203
|
}).then(function() {
|
|
204
204
|
var _ref = _async_to_generator(function(expressions) {
|
|
@@ -210,7 +210,7 @@ var loadModelTransforms = function() {
|
|
|
210
210
|
return _ts_generator(this, function(_state) {
|
|
211
211
|
return [
|
|
212
212
|
2,
|
|
213
|
-
readFile(subDir(
|
|
213
|
+
readFile(subDir('models', model, 'transforms', expression), 'utf-8')
|
|
214
214
|
];
|
|
215
215
|
});
|
|
216
216
|
});
|
|
@@ -229,8 +229,8 @@ var loadModelTransforms = function() {
|
|
|
229
229
|
var findBlock = getCodeBlock(markdown);
|
|
230
230
|
return {
|
|
231
231
|
type: getFrontMatter(markdown, FrontMatter).type,
|
|
232
|
-
match: findBlock(
|
|
233
|
-
transform: findBlock(
|
|
232
|
+
match: findBlock('jsonata', 'Match Expression'),
|
|
233
|
+
transform: findBlock('jsonata', 'Transform Expression')
|
|
234
234
|
};
|
|
235
235
|
});
|
|
236
236
|
})
|
|
@@ -242,7 +242,7 @@ var loadModelTransforms = function() {
|
|
|
242
242
|
return _ref.apply(this, arguments);
|
|
243
243
|
};
|
|
244
244
|
}();
|
|
245
|
-
var models = await Promise.all((await Promise.all((await readdir(subDir(
|
|
245
|
+
var models = await Promise.all((await Promise.all((await readdir(subDir('models'))).map(function() {
|
|
246
246
|
var _ref = _async_to_generator(function(f) {
|
|
247
247
|
var _tmp;
|
|
248
248
|
return _ts_generator(this, function(_state) {
|
|
@@ -253,7 +253,7 @@ var models = await Promise.all((await Promise.all((await readdir(subDir("models"
|
|
|
253
253
|
};
|
|
254
254
|
return [
|
|
255
255
|
4,
|
|
256
|
-
stat(subDir(
|
|
256
|
+
stat(subDir('models', f))
|
|
257
257
|
];
|
|
258
258
|
case 1:
|
|
259
259
|
return [
|
|
@@ -275,7 +275,7 @@ var models = await Promise.all((await Promise.all((await readdir(subDir("models"
|
|
|
275
275
|
return _ts_generator(this, function(_state) {
|
|
276
276
|
switch(_state.label){
|
|
277
277
|
case 0:
|
|
278
|
-
console.log(chalk.gray(
|
|
278
|
+
console.log(chalk.gray('·'), chalk.white(model.name));
|
|
279
279
|
_tmp = {
|
|
280
280
|
id: model.name
|
|
281
281
|
};
|
|
@@ -287,7 +287,7 @@ var models = await Promise.all((await Promise.all((await readdir(subDir("models"
|
|
|
287
287
|
_tmp.transforms = _state.sent();
|
|
288
288
|
return [
|
|
289
289
|
4,
|
|
290
|
-
readFile(path.join(subDir(
|
|
290
|
+
readFile(path.join(subDir('models'), model.name, 'README.md'), 'utf-8')
|
|
291
291
|
];
|
|
292
292
|
case 2:
|
|
293
293
|
return [
|
|
@@ -301,6 +301,6 @@ var models = await Promise.all((await Promise.all((await readdir(subDir("models"
|
|
|
301
301
|
return _ref.apply(this, arguments);
|
|
302
302
|
};
|
|
303
303
|
}()));
|
|
304
|
-
var modelsFile = subDir(
|
|
305
|
-
console.log(chalk.green(
|
|
306
|
-
await writeFile(modelsFile, generateModels(models).map(printNode).join(os.EOL),
|
|
304
|
+
var modelsFile = subDir('models', 'models.ts');
|
|
305
|
+
console.log(chalk.green('Writing'), chalk.blue(modelsFile.replace(baseDir, '')));
|
|
306
|
+
await writeFile(modelsFile, generateModels(models).map(printNode).join(os.EOL), 'utf-8');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import ts from
|
|
2
|
-
var resultFile = ts.createSourceFile("stub.ts",
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
var resultFile = ts.createSourceFile("stub.ts", '', ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
|
|
3
3
|
var printer = ts.createPrinter({
|
|
4
4
|
newLine: ts.NewLineKind.LineFeed
|
|
5
5
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export var tokenizeName = function(name) {
|
|
2
|
-
return name.split(
|
|
2
|
+
return name.split(' ').map(function(s) {
|
|
3
3
|
return "".concat(s.slice(0, 1).toUpperCase()).concat(s.slice(1));
|
|
4
|
-
}).join(
|
|
4
|
+
}).join(' ').replaceAll(' ', '').replaceAll('&', 'and').replace(/^(\d)(.+)/, 'n$1$2').replaceAll(/[^a-z0-9]/gi, '_').replaceAll(/_{2,}/g, '_').replaceAll(/_+$/g, '').trim();
|
|
5
5
|
};
|
|
@@ -44,10 +44,10 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
44
44
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
45
45
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
46
46
|
}
|
|
47
|
-
import { tokenizeName } from
|
|
48
|
-
import { describe, it } from
|
|
49
|
-
import assert from
|
|
50
|
-
void describe(
|
|
47
|
+
import { tokenizeName } from './tokenizeName.js';
|
|
48
|
+
import { describe, it } from 'node:test';
|
|
49
|
+
import assert from 'node:assert/strict';
|
|
50
|
+
void describe('tokenizeName', function() {
|
|
51
51
|
var _loop = function(_i, _iter) {
|
|
52
52
|
var _iter__i = _sliced_to_array(_iter[_i], 2), name = _iter__i[0], expected = _iter__i[1];
|
|
53
53
|
void it("should replaced ".concat(name, " to ").concat(expected), function() {
|
|
@@ -57,42 +57,42 @@ void describe("tokenizeName", function() {
|
|
|
57
57
|
for(var _i = 0, _iter = [
|
|
58
58
|
// Uppercase words
|
|
59
59
|
[
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
'Battery and Power',
|
|
61
|
+
'BatteryAndPower'
|
|
62
62
|
],
|
|
63
63
|
[
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
'LwM2M Server',
|
|
65
|
+
'LwM2MServer'
|
|
66
66
|
],
|
|
67
67
|
// Dash -> underline
|
|
68
68
|
[
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
'LTE-MTC Band Config',
|
|
70
|
+
'LTE_MTCBandConfig'
|
|
71
71
|
],
|
|
72
72
|
// Number at the Beginning, prefix with n
|
|
73
73
|
[
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
'5GNR Connectivity',
|
|
75
|
+
'n5GNRConnectivity'
|
|
76
76
|
],
|
|
77
77
|
// Slash -> underline
|
|
78
78
|
[
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
'On/Off Switch',
|
|
80
|
+
'On_OffSwitch'
|
|
81
81
|
],
|
|
82
82
|
// Dot -> underline
|
|
83
83
|
[
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
'LwM2M v1.1 Test Object',
|
|
85
|
+
'LwM2MV1_1TestObject'
|
|
86
86
|
],
|
|
87
87
|
// & -> and
|
|
88
88
|
[
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
'AT&T Connectivity Extension',
|
|
90
|
+
'ATandTConnectivityExtension'
|
|
91
91
|
],
|
|
92
92
|
// Remove whitespace
|
|
93
93
|
[
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
' Server ',
|
|
95
|
+
'Server'
|
|
96
96
|
]
|
|
97
97
|
]; _i < _iter.length; _i++)_loop(_i, _iter);
|
|
98
98
|
});
|
package/dist/generator/types.js
CHANGED
|
@@ -24,19 +24,19 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
24
24
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
25
25
|
}
|
|
26
26
|
var _path;
|
|
27
|
-
import chalk from
|
|
28
|
-
import { mkdir, readFile, readdir, writeFile } from
|
|
29
|
-
import path from
|
|
30
|
-
import { unwrapNestedArray } from
|
|
31
|
-
import xml2js from
|
|
32
|
-
import ts from
|
|
33
|
-
import { printNode } from
|
|
34
|
-
import os from
|
|
35
|
-
import { generateType } from
|
|
36
|
-
import { addDocBlock } from
|
|
37
|
-
import { generateName } from
|
|
38
|
-
import { generateValidator } from
|
|
39
|
-
import { generateValidators } from
|
|
27
|
+
import chalk from 'chalk';
|
|
28
|
+
import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
|
|
29
|
+
import path from 'node:path';
|
|
30
|
+
import { unwrapNestedArray } from '../lwm2m/unwrapNestedArray.js';
|
|
31
|
+
import xml2js from 'xml2js';
|
|
32
|
+
import ts from 'typescript';
|
|
33
|
+
import { printNode } from './printNode.js';
|
|
34
|
+
import os from 'node:os';
|
|
35
|
+
import { generateType } from './generateType.js';
|
|
36
|
+
import { addDocBlock } from './addDocBlock.js';
|
|
37
|
+
import { generateName } from './generateType.js';
|
|
38
|
+
import { generateValidator } from './generateValidator.js';
|
|
39
|
+
import { generateValidators } from './generateValidators.js';
|
|
40
40
|
var baseDir = process.cwd();
|
|
41
41
|
var subDir = function() {
|
|
42
42
|
for(var _len = arguments.length, tree = new Array(_len), _key = 0; _key < _len; _key++){
|
|
@@ -48,14 +48,14 @@ var subDir = function() {
|
|
|
48
48
|
};
|
|
49
49
|
var idMembers = [];
|
|
50
50
|
var objects = [];
|
|
51
|
-
console.log(chalk.gray(
|
|
51
|
+
console.log(chalk.gray('Creating TypeBox definition for LwM2M objects'));
|
|
52
52
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
53
53
|
try {
|
|
54
|
-
for(var _iterator = (await readdir(subDir(
|
|
55
|
-
return s.endsWith(
|
|
54
|
+
for(var _iterator = (await readdir(subDir('lwm2m'))).filter(function(s) {
|
|
55
|
+
return s.endsWith('.xml');
|
|
56
56
|
})[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
57
57
|
var objectDefinitionFile = _step.value;
|
|
58
|
-
var definition = unwrapNestedArray(await xml2js.parseStringPromise(await readFile(subDir(
|
|
58
|
+
var definition = unwrapNestedArray(await xml2js.parseStringPromise(await readFile(subDir('lwm2m', objectDefinitionFile), 'utf-8'))).LWM2M.Object;
|
|
59
59
|
var ObjectID = parseInt(definition.ObjectID, 10);
|
|
60
60
|
var member = ts.factory.createEnumMember(generateName(definition), ts.factory.createNumericLiteral(ObjectID));
|
|
61
61
|
addDocBlock([
|
|
@@ -65,18 +65,18 @@ try {
|
|
|
65
65
|
], member);
|
|
66
66
|
idMembers.push(member);
|
|
67
67
|
try {
|
|
68
|
-
await mkdir(subDir(
|
|
68
|
+
await mkdir(subDir('lwm2m', "object"));
|
|
69
69
|
} catch (e) {
|
|
70
70
|
// pass
|
|
71
71
|
}
|
|
72
72
|
// Type
|
|
73
|
-
var typeFile = subDir(
|
|
74
|
-
console.log(chalk.green(
|
|
75
|
-
await writeFile(typeFile, generateType(definition).map(printNode).join(os.EOL),
|
|
73
|
+
var typeFile = subDir('lwm2m', "object", "".concat(ObjectID, ".d.ts"));
|
|
74
|
+
console.log(chalk.green('Writing'), chalk.blue(typeFile.replace(baseDir, '')));
|
|
75
|
+
await writeFile(typeFile, generateType(definition).map(printNode).join(os.EOL), 'utf-8');
|
|
76
76
|
// Validator
|
|
77
|
-
var validatorFile = subDir(
|
|
78
|
-
console.log(chalk.green(
|
|
79
|
-
await writeFile(validatorFile, generateValidator(definition).map(printNode).join(os.EOL),
|
|
77
|
+
var validatorFile = subDir('lwm2m', "object", "validate".concat(ObjectID, ".ts"));
|
|
78
|
+
console.log(chalk.green('Writing'), chalk.blue(validatorFile.replace(baseDir, '')));
|
|
79
|
+
await writeFile(validatorFile, generateValidator(definition).map(printNode).join(os.EOL), 'utf-8');
|
|
80
80
|
objects.push(definition);
|
|
81
81
|
}
|
|
82
82
|
} catch (err) {
|
|
@@ -93,36 +93,36 @@ try {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
var validatorsFile = subDir(
|
|
97
|
-
console.log(chalk.green(
|
|
98
|
-
await writeFile(validatorsFile, generateValidators(objects).map(printNode).join(os.EOL),
|
|
99
|
-
var idFile = subDir(
|
|
100
|
-
console.log(chalk.green(
|
|
96
|
+
var validatorsFile = subDir('lwm2m', "validators.ts");
|
|
97
|
+
console.log(chalk.green('Writing'), chalk.blue(validatorsFile.replace(baseDir, '')));
|
|
98
|
+
await writeFile(validatorsFile, generateValidators(objects).map(printNode).join(os.EOL), 'utf-8');
|
|
99
|
+
var idFile = subDir('lwm2m', "LwM2MObjectID.ts");
|
|
100
|
+
console.log(chalk.green('Writing'), chalk.blue(idFile.replace(baseDir, '')));
|
|
101
101
|
var enumNode = ts.factory.createEnumDeclaration([
|
|
102
102
|
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
103
|
-
], ts.factory.createIdentifier(
|
|
103
|
+
], ts.factory.createIdentifier('LwM2MObjectID'), idMembers);
|
|
104
104
|
addDocBlock([
|
|
105
|
-
|
|
105
|
+
'The LwM2M Object IDs defined in this repo.'
|
|
106
106
|
], enumNode);
|
|
107
107
|
var objectIdArray = ts.factory.createVariableStatement([
|
|
108
108
|
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
109
109
|
], ts.factory.createVariableDeclarationList([
|
|
110
110
|
ts.factory.createVariableDeclaration(ts.factory.createIdentifier("LwM2MObjectIDs"), undefined, undefined, ts.factory.createArrayLiteralExpression(objects.map(function(definition) {
|
|
111
111
|
// const id = ts.factory.createNumericLiteral(ObjectID)
|
|
112
|
-
var id = ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(
|
|
112
|
+
var id = ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('LwM2MObjectID'), ts.factory.createIdentifier(generateName(definition)));
|
|
113
113
|
ts.addSyntheticLeadingComment(id, ts.SyntaxKind.SingleLineCommentTrivia, " ".concat(definition.Name, " (").concat(definition.ObjectID, ")"), true);
|
|
114
114
|
return id;
|
|
115
115
|
})))
|
|
116
116
|
], ts.NodeFlags.Const));
|
|
117
117
|
addDocBlock([
|
|
118
|
-
|
|
118
|
+
'The LwM2M Object IDs defined in this repo.'
|
|
119
119
|
], objectIdArray);
|
|
120
120
|
await writeFile(idFile, [
|
|
121
121
|
enumNode,
|
|
122
122
|
objectIdArray
|
|
123
|
-
].map(printNode).join(os.EOL),
|
|
124
|
-
var objectsFile = subDir(
|
|
125
|
-
console.log(chalk.green(
|
|
123
|
+
].map(printNode).join(os.EOL), 'utf-8');
|
|
124
|
+
var objectsFile = subDir('lwm2m', "objects.ts");
|
|
125
|
+
console.log(chalk.green('Writing'), chalk.blue(objectsFile.replace(baseDir, '')));
|
|
126
126
|
await writeFile(objectsFile, objects.map(function(param) {
|
|
127
127
|
var ObjectID = param.ObjectID, Name = param.Name;
|
|
128
128
|
var name = generateName({
|
|
@@ -137,4 +137,4 @@ await writeFile(objectsFile, objects.map(function(param) {
|
|
|
137
137
|
ts.factory.createExportSpecifier(false, undefined, ts.factory.createIdentifier("validate".concat(ObjectID)))
|
|
138
138
|
]), ts.factory.createStringLiteral("./object/validate".concat(ObjectID, ".js")))
|
|
139
139
|
];
|
|
140
|
-
}).flat().map(printNode).join(os.EOL),
|
|
140
|
+
}).flat().map(printNode).join(os.EOL), 'utf-8');
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Type } from
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
2
|
var ResourceType = Type.Union([
|
|
3
|
-
Type.Literal(
|
|
4
|
-
Type.Literal(
|
|
5
|
-
Type.Literal(
|
|
6
|
-
Type.Literal(
|
|
7
|
-
Type.Literal(
|
|
8
|
-
Type.Literal(
|
|
3
|
+
Type.Literal('String'),
|
|
4
|
+
Type.Literal('Integer'),
|
|
5
|
+
Type.Literal('Float'),
|
|
6
|
+
Type.Literal('Boolean'),
|
|
7
|
+
Type.Literal('Opaque'),
|
|
8
|
+
Type.Literal('Time')
|
|
9
9
|
]);
|
|
10
10
|
export var RangeEnumerationRegExp = RegExp("^(?<min>-?[0-9]+(?:\\.[0-9]+)?)\\.\\.(?<max>-?[0-9]+(?:\\.[0-9]+)?)$");
|
|
11
11
|
var RangeEnumeration = Type.RegExp(RangeEnumerationRegExp, {
|
|
12
|
-
title:
|
|
12
|
+
title: 'RangeEnumeration'
|
|
13
13
|
});
|
|
14
14
|
export var LWM2MObjectDefinition = Type.Object({
|
|
15
15
|
Name: Type.String({
|
|
16
16
|
minLength: 1,
|
|
17
17
|
examples: [
|
|
18
|
-
|
|
18
|
+
'Location'
|
|
19
19
|
]
|
|
20
20
|
}),
|
|
21
21
|
Description1: Type.String({
|
|
22
22
|
minLength: 1,
|
|
23
23
|
examples: [
|
|
24
|
-
|
|
24
|
+
'This LwM2M Object provides a range of location telemetry related information which can be queried by the LwM2M Server.'
|
|
25
25
|
]
|
|
26
26
|
}),
|
|
27
27
|
ObjectID: Type.RegExp(/^14[0-9]{3}$/),
|
|
28
28
|
ObjectURN: Type.RegExp(/^urn:oma:lwm2m:x:14[0-9]{3}$/),
|
|
29
|
-
LWM2MVersion: Type.Literal(
|
|
30
|
-
title:
|
|
31
|
-
description:
|
|
29
|
+
LWM2MVersion: Type.Literal('1.1', {
|
|
30
|
+
title: 'LwM2M version',
|
|
31
|
+
description: 'Defaults to 1.1'
|
|
32
32
|
}),
|
|
33
33
|
ObjectVersion: Type.Optional(Type.String({
|
|
34
34
|
minLength: 1,
|
|
35
35
|
examples: [
|
|
36
|
-
|
|
36
|
+
'1.1'
|
|
37
37
|
],
|
|
38
|
-
title:
|
|
39
|
-
description:
|
|
38
|
+
title: 'ObjectVersion',
|
|
39
|
+
description: 'Defaults to 1.0'
|
|
40
40
|
})),
|
|
41
|
-
MultipleInstances: Type.Literal(
|
|
42
|
-
Mandatory: Type.Literal(
|
|
41
|
+
MultipleInstances: Type.Literal('Multiple'),
|
|
42
|
+
Mandatory: Type.Literal('Optional'),
|
|
43
43
|
Resources: Type.Record(Type.Integer({
|
|
44
44
|
minimum: 0,
|
|
45
45
|
maximum: 65534
|
|
@@ -47,42 +47,42 @@ export var LWM2MObjectDefinition = Type.Object({
|
|
|
47
47
|
Name: Type.String({
|
|
48
48
|
minLength: 1,
|
|
49
49
|
examples: [
|
|
50
|
-
|
|
50
|
+
'Latitude'
|
|
51
51
|
]
|
|
52
52
|
}),
|
|
53
|
-
Operations: Type.Literal(
|
|
54
|
-
description:
|
|
53
|
+
Operations: Type.Literal('R', {
|
|
54
|
+
description: 'Only read-properties are supported'
|
|
55
55
|
}),
|
|
56
|
-
MultipleInstances: Type.Literal(
|
|
56
|
+
MultipleInstances: Type.Literal('Single'),
|
|
57
57
|
Mandatory: Type.Union([
|
|
58
|
-
Type.Literal(
|
|
59
|
-
Type.Literal(
|
|
58
|
+
Type.Literal('Optional'),
|
|
59
|
+
Type.Literal('Mandatory')
|
|
60
60
|
]),
|
|
61
61
|
Type: ResourceType,
|
|
62
62
|
RangeEnumeration: Type.Union([
|
|
63
63
|
Type.String({
|
|
64
64
|
maxLength: 0,
|
|
65
|
-
title:
|
|
65
|
+
title: 'an empty string'
|
|
66
66
|
}),
|
|
67
67
|
RangeEnumeration
|
|
68
68
|
]),
|
|
69
69
|
Units: Type.String({
|
|
70
70
|
examples: [
|
|
71
|
-
|
|
71
|
+
'lat'
|
|
72
72
|
],
|
|
73
|
-
title:
|
|
73
|
+
title: 'Units'
|
|
74
74
|
}),
|
|
75
75
|
Description: Type.String({
|
|
76
76
|
minLength: 1,
|
|
77
77
|
examples: [
|
|
78
|
-
|
|
78
|
+
'The decimal notation of latitude, e.g. -43.5723 [World Geodetic System 1984].'
|
|
79
79
|
]
|
|
80
80
|
})
|
|
81
81
|
}), {
|
|
82
82
|
minProperties: 1,
|
|
83
|
-
description:
|
|
83
|
+
description: 'Defines the object resources as a map'
|
|
84
84
|
}),
|
|
85
85
|
Description2: Type.String()
|
|
86
86
|
}, {
|
|
87
|
-
description:
|
|
87
|
+
description: 'LwM2M Object definitions with additional limitations applied to suit the hello.nrfcloud.com/map use-case'
|
|
88
88
|
});
|
|
@@ -261,16 +261,16 @@ function _ts_values(o) {
|
|
|
261
261
|
};
|
|
262
262
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
263
263
|
}
|
|
264
|
-
import chalk from
|
|
265
|
-
import { readFile, readdir, stat } from
|
|
266
|
-
import path, { parse } from
|
|
267
|
-
import assert from
|
|
268
|
-
import xml2js from
|
|
269
|
-
import { exec } from
|
|
270
|
-
import { unwrapNestedArray } from
|
|
271
|
-
import { LWM2MObjectDefinition } from
|
|
272
|
-
import { validate } from
|
|
273
|
-
import { parseRangeEnumeration } from
|
|
264
|
+
import chalk from 'chalk';
|
|
265
|
+
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
266
|
+
import path, { parse } from 'node:path';
|
|
267
|
+
import assert from 'node:assert/strict';
|
|
268
|
+
import xml2js from 'xml2js';
|
|
269
|
+
import { exec } from 'node:child_process';
|
|
270
|
+
import { unwrapNestedArray } from './unwrapNestedArray.js';
|
|
271
|
+
import { LWM2MObjectDefinition } from './LWM2MObjectDefinition.js';
|
|
272
|
+
import { validate } from '../validate.js';
|
|
273
|
+
import { parseRangeEnumeration } from './parseRangeEnumeration.js';
|
|
274
274
|
var v = validate(LWM2MObjectDefinition);
|
|
275
275
|
var listLwm2mDefinitions = function() {
|
|
276
276
|
var _ref = _async_to_generator(function(modelDir) {
|
|
@@ -301,13 +301,13 @@ var listLwm2mDefinitions = function() {
|
|
|
301
301
|
case 0:
|
|
302
302
|
_ref = _step.value;
|
|
303
303
|
file = _ref;
|
|
304
|
-
if (!file.endsWith(
|
|
304
|
+
if (!file.endsWith('.xml')) return [
|
|
305
305
|
2,
|
|
306
306
|
"continue"
|
|
307
307
|
];
|
|
308
|
-
console.log(chalk.white(
|
|
309
|
-
assert.match(file, /^[0-9]+\.xml$/,
|
|
310
|
-
console.log(chalk.green(
|
|
308
|
+
console.log(chalk.white('·'), chalk.white.bold(file));
|
|
309
|
+
assert.match(file, /^[0-9]+\.xml$/, 'LwM2M object definition files must only have numbers in their file names');
|
|
310
|
+
console.log(chalk.green('✔'), chalk.gray('File name is correct'));
|
|
311
311
|
objectDefinitionFile = path.join(modelDir, file);
|
|
312
312
|
return [
|
|
313
313
|
4,
|
|
@@ -321,7 +321,7 @@ var listLwm2mDefinitions = function() {
|
|
|
321
321
|
return [
|
|
322
322
|
4,
|
|
323
323
|
new Promise(function(resolve) {
|
|
324
|
-
return exec("xmllint --noout --schema ".concat(path.join(process.cwd(),
|
|
324
|
+
return exec("xmllint --noout --schema ".concat(path.join(process.cwd(), 'lwm2m', 'LWM2M-v1_1.xsd'), " ").concat(objectDefinitionFile), function(error, _, stderr) {
|
|
325
325
|
if (error) {
|
|
326
326
|
console.error(stderr);
|
|
327
327
|
return resolve(false);
|
|
@@ -332,16 +332,16 @@ var listLwm2mDefinitions = function() {
|
|
|
332
332
|
];
|
|
333
333
|
case 2:
|
|
334
334
|
schemaValidated = _state.sent();
|
|
335
|
-
assert.equal(schemaValidated, true,
|
|
336
|
-
console.log(chalk.green(
|
|
335
|
+
assert.equal(schemaValidated, true, '');
|
|
336
|
+
console.log(chalk.green('✔'), chalk.gray('Is a valid LwM2M object definition'));
|
|
337
337
|
ObjectID = parseInt(parse(objectDefinitionFile).name, 10);
|
|
338
|
-
assert.equal(ObjectID > 14200, true,
|
|
339
|
-
assert.equal(ObjectID < 15000, true,
|
|
338
|
+
assert.equal(ObjectID > 14200, true, 'ObjectID must be greater than 14200');
|
|
339
|
+
assert.equal(ObjectID < 15000, true, 'ObjectID must be smaller than 15000');
|
|
340
340
|
ObjectURN = "urn:oma:lwm2m:x:".concat(ObjectID);
|
|
341
341
|
_ = xml2js.parseStringPromise;
|
|
342
342
|
return [
|
|
343
343
|
4,
|
|
344
|
-
readFile(objectDefinitionFile,
|
|
344
|
+
readFile(objectDefinitionFile, 'utf-8')
|
|
345
345
|
];
|
|
346
346
|
case 3:
|
|
347
347
|
return [
|
|
@@ -356,9 +356,9 @@ var listLwm2mDefinitions = function() {
|
|
|
356
356
|
]).LWM2M.Object;
|
|
357
357
|
assert.equal(ObjectID.toString(), definition.ObjectID, "ObjectID must match filename");
|
|
358
358
|
assert.equal(ObjectURN, definition.ObjectURN, "ObjectURN must follow schema");
|
|
359
|
-
console.log(chalk.green(
|
|
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
|
-
LWM2MVersion:
|
|
361
|
+
LWM2MVersion: '1.1',
|
|
362
362
|
Resources: definition.Resources.Item.reduce(function(resources, _param) {
|
|
363
363
|
var $ = _param.$, item = _object_without_properties(_param, [
|
|
364
364
|
"$"
|
|
@@ -366,33 +366,33 @@ var listLwm2mDefinitions = function() {
|
|
|
366
366
|
if (resources[$.ID] !== undefined) throw new Error("Duplicate resource ID: ".concat($.ID));
|
|
367
367
|
if (item.RangeEnumeration.length > 0) {
|
|
368
368
|
var maybeRange = parseRangeEnumeration(item.RangeEnumeration);
|
|
369
|
-
if (
|
|
369
|
+
if ('error' in maybeRange) throw maybeRange.error;
|
|
370
370
|
}
|
|
371
371
|
return _object_spread_props(_object_spread({}, resources), _define_property({}, $.ID, item));
|
|
372
372
|
}, {})
|
|
373
373
|
});
|
|
374
374
|
maybeValid = v(objectDef);
|
|
375
|
-
if (
|
|
375
|
+
if ('errors' in maybeValid) {
|
|
376
376
|
console.error(maybeValid.errors);
|
|
377
377
|
throw new Error("The definition should be valid!");
|
|
378
378
|
}
|
|
379
|
-
console.log(chalk.green(
|
|
379
|
+
console.log(chalk.green('✔'), chalk.gray('LwM2M limitations are honored'));
|
|
380
380
|
defs.push(maybeValid.value);
|
|
381
381
|
_maybeValid_value = maybeValid.value, Name = _maybeValid_value.Name, Resources = _maybeValid_value.Resources;
|
|
382
382
|
TimeResources = Object.values(Resources).filter(function(param) {
|
|
383
383
|
var Type = param.Type;
|
|
384
|
-
return Type ===
|
|
384
|
+
return Type === 'Time';
|
|
385
385
|
});
|
|
386
|
-
assert.equal(TimeResources.length, 1,
|
|
387
|
-
assert.equal((_TimeResources_ = TimeResources[0]) === null || _TimeResources_ === void 0 ? void 0 : _TimeResources_.Mandatory,
|
|
388
|
-
console.log(chalk.green(
|
|
386
|
+
assert.equal(TimeResources.length, 1, 'Objects must define one Time resource');
|
|
387
|
+
assert.equal((_TimeResources_ = TimeResources[0]) === null || _TimeResources_ === void 0 ? void 0 : _TimeResources_.Mandatory, 'Mandatory', 'The Time resources must be mandatory.');
|
|
388
|
+
console.log(chalk.green('✔'), chalk.gray("Object has one time resource (".concat((_TimeResources_1 = TimeResources[0]) === null || _TimeResources_1 === void 0 ? void 0 : _TimeResources_1.Name, ")")));
|
|
389
389
|
console.log("".concat(chalk.yellow(ObjectID), ":"), chalk.white(Name));
|
|
390
390
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
391
391
|
try {
|
|
392
392
|
for(_iterator = Object.entries(Resources)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
393
393
|
_step_value = _sliced_to_array(_step1.value, 2), id = _step_value[0], resource = _step_value[1];
|
|
394
394
|
;
|
|
395
|
-
console.log("".concat(chalk.gray(ObjectID), ".").concat(chalk.yellow(id), ":"), chalk.white(resource.Name), "".concat(chalk.gray(resource.Type), " ").concat(chalk.gray("(".concat((_resource_Units = resource.Units) !== null && _resource_Units !== void 0 ? _resource_Units :
|
|
395
|
+
console.log("".concat(chalk.gray(ObjectID), ".").concat(chalk.yellow(id), ":"), chalk.white(resource.Name), "".concat(chalk.gray(resource.Type), " ").concat(chalk.gray("(".concat((_resource_Units = resource.Units) !== null && _resource_Units !== void 0 ? _resource_Units : 'no unit', ")"))));
|
|
396
396
|
}
|
|
397
397
|
} catch (err) {
|
|
398
398
|
_didIteratorError = true;
|
|
@@ -473,8 +473,8 @@ var listLwm2mDefinitions = function() {
|
|
|
473
473
|
};
|
|
474
474
|
}();
|
|
475
475
|
// LwM2M
|
|
476
|
-
console.log(chalk.gray(
|
|
477
|
-
console.log(
|
|
478
|
-
var lwm2mDir = path.join(process.cwd(),
|
|
476
|
+
console.log(chalk.gray('LwM2M rules check'));
|
|
477
|
+
console.log('');
|
|
478
|
+
var lwm2mDir = path.join(process.cwd(), 'lwm2m');
|
|
479
479
|
var lwm2mDefinitions = await listLwm2mDefinitions(lwm2mDir);
|
|
480
|
-
assert.equal(lwm2mDefinitions.length > 0, true,
|
|
480
|
+
assert.equal(lwm2mDefinitions.length > 0, true, 'LwM2M objects must be defined.');
|