@hello.nrfcloud.com/proto-map 4.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/LICENSE +29 -0
- package/README.md +122 -0
- package/dist/generator/addDocBlock.js +5 -0
- package/dist/generator/generateLwM2MDefinitions.js +82 -0
- package/dist/generator/generateLwM2MDefinitions.spec.js +91 -0
- package/dist/generator/generateLwm2mTimestampResources.js +69 -0
- package/dist/generator/generateModels.js +142 -0
- package/dist/generator/generateType.js +90 -0
- package/dist/generator/generateValidator.js +132 -0
- package/dist/generator/generateValidators.js +63 -0
- package/dist/generator/isDir.js +163 -0
- package/dist/generator/isDir.spec.js +212 -0
- package/dist/generator/lwm2m.js +106 -0
- package/dist/generator/models.js +306 -0
- package/dist/generator/printNode.js +8 -0
- package/dist/generator/tokenizeName.js +5 -0
- package/dist/generator/tokenizeName.spec.js +98 -0
- package/dist/generator/types.js +140 -0
- package/dist/lwm2m/LWM2MObjectDefinition.js +88 -0
- package/dist/lwm2m/LWM2MObjectInfo.js +9 -0
- package/dist/lwm2m/LwM2MObject.d.js +1 -0
- package/dist/lwm2m/LwM2MObjectID.js +57 -0
- package/dist/lwm2m/ParsedLwM2MObjectDefinition.js +1 -0
- package/dist/lwm2m/check-lwm2m-rules.js +480 -0
- package/dist/lwm2m/definitions.js +596 -0
- package/dist/lwm2m/fromXML2JSON.js +194 -0
- package/dist/lwm2m/instanceTs.js +9 -0
- package/dist/lwm2m/instanceTs.spec.js +16 -0
- package/dist/lwm2m/isRegisteredLwM2MObject.js +3 -0
- package/dist/lwm2m/isRegisteredLwM2MObject.spec.js +45 -0
- package/dist/lwm2m/object/14201.d.js +5 -0
- package/dist/lwm2m/object/14202.d.js +5 -0
- package/dist/lwm2m/object/14203.d.js +5 -0
- package/dist/lwm2m/object/14204.d.js +5 -0
- package/dist/lwm2m/object/14205.d.js +5 -0
- package/dist/lwm2m/object/14210.d.js +5 -0
- package/dist/lwm2m/object/14220.d.js +5 -0
- package/dist/lwm2m/object/14230.d.js +5 -0
- package/dist/lwm2m/object/validate14201.js +18 -0
- package/dist/lwm2m/object/validate14202.js +17 -0
- package/dist/lwm2m/object/validate14203.js +19 -0
- package/dist/lwm2m/object/validate14204.js +17 -0
- package/dist/lwm2m/object/validate14205.js +15 -0
- package/dist/lwm2m/object/validate14210.js +13 -0
- package/dist/lwm2m/object/validate14220.js +12 -0
- package/dist/lwm2m/object/validate14230.js +13 -0
- package/dist/lwm2m/objects.js +8 -0
- package/dist/lwm2m/parseRangeEnumeration.js +20 -0
- package/dist/lwm2m/parseRangeEnumeration.spec.js +27 -0
- package/dist/lwm2m/resourceType.js +12 -0
- package/dist/lwm2m/timestampResources.js +12 -0
- package/dist/lwm2m/unwrapNestedArray.js +114 -0
- package/dist/lwm2m/unwrapNestedArray.spec.js +374 -0
- package/dist/lwm2m/validate.js +14 -0
- package/dist/lwm2m/validation.js +146 -0
- package/dist/lwm2m/validators.js +20 -0
- package/dist/markdown/getCodeBlock.js +74 -0
- package/dist/markdown/getFrontMatter.js +15 -0
- package/dist/markdown/parseREADME.js +19 -0
- package/dist/models/asset_tracker_v2+AWS/examples/examples.spec.js +489 -0
- package/dist/models/check-model-rules.js +137 -0
- package/dist/models/models.js +137 -0
- package/dist/models/types.js +13 -0
- package/dist/senml/SenMLSchema.js +79 -0
- package/dist/senml/SenMLSchema.spec.js +23 -0
- package/dist/senml/hasValue.js +8 -0
- package/dist/senml/hasValue.spec.js +103 -0
- package/dist/senml/lwm2mToSenML.js +137 -0
- package/dist/senml/lwm2mToSenML.spec.js +104 -0
- package/dist/senml/parseResourceId.js +58 -0
- package/dist/senml/parseResourceId.spec.js +13 -0
- package/dist/senml/senMLtoLwM2M.js +126 -0
- package/dist/senml/senMLtoLwM2M.spec.js +226 -0
- package/dist/senml/validateSenML.js +6 -0
- package/dist/senml/validateSenML.spec.js +31 -0
- package/export.js +13 -0
- package/index.d.ts +14 -0
- package/lwm2m/14201.xml +94 -0
- package/lwm2m/14202.xml +84 -0
- package/lwm2m/14203.xml +104 -0
- package/lwm2m/14204.xml +84 -0
- package/lwm2m/14205.xml +64 -0
- package/lwm2m/14210.xml +44 -0
- package/lwm2m/14220.xml +34 -0
- package/lwm2m/14230.xml +44 -0
- package/lwm2m/LWM2M-v1_1.xsd +168 -0
- package/lwm2m/LWM2MObjectDefinition.ts +84 -0
- package/lwm2m/LWM2MObjectInfo.ts +42 -0
- package/lwm2m/LwM2MObject.d.ts +19 -0
- package/lwm2m/LwM2MObjectID.ts +73 -0
- package/lwm2m/ParsedLwM2MObjectDefinition.ts +28 -0
- package/lwm2m/check-lwm2m-rules.ts +160 -0
- package/lwm2m/definitions.ts +278 -0
- package/lwm2m/format.sh +3 -0
- package/lwm2m/fromXML2JSON.ts +44 -0
- package/lwm2m/instanceTs.spec.ts +19 -0
- package/lwm2m/instanceTs.ts +10 -0
- package/lwm2m/isRegisteredLwM2MObject.spec.ts +48 -0
- package/lwm2m/isRegisteredLwM2MObject.ts +4 -0
- package/lwm2m/object/14201.d.ts +73 -0
- package/lwm2m/object/14202.d.ts +59 -0
- package/lwm2m/object/14203.d.ts +67 -0
- package/lwm2m/object/14204.d.ts +55 -0
- package/lwm2m/object/14205.d.ts +43 -0
- package/lwm2m/object/14210.d.ts +31 -0
- package/lwm2m/object/14220.d.ts +25 -0
- package/lwm2m/object/14230.d.ts +31 -0
- package/lwm2m/object/validate14201.ts +10 -0
- package/lwm2m/object/validate14202.ts +10 -0
- package/lwm2m/object/validate14203.ts +10 -0
- package/lwm2m/object/validate14204.ts +10 -0
- package/lwm2m/object/validate14205.ts +10 -0
- package/lwm2m/object/validate14210.ts +10 -0
- package/lwm2m/object/validate14220.ts +10 -0
- package/lwm2m/object/validate14230.ts +10 -0
- package/lwm2m/objects.ts +16 -0
- package/lwm2m/parseRangeEnumeration.spec.ts +34 -0
- package/lwm2m/parseRangeEnumeration.ts +29 -0
- package/lwm2m/resourceType.ts +11 -0
- package/lwm2m/timestampResources.ts +4 -0
- package/lwm2m/unwrapNestedArray.spec.ts +241 -0
- package/lwm2m/unwrapNestedArray.ts +27 -0
- package/lwm2m/validate.ts +30 -0
- package/lwm2m/validation.ts +120 -0
- package/lwm2m/validators.ts +21 -0
- package/models/PCA20035+solar/README.md +10 -0
- package/models/PCA20035+solar/transforms/airQuality.md +48 -0
- package/models/PCA20035+solar/transforms/battery.md +46 -0
- package/models/PCA20035+solar/transforms/button.md +45 -0
- package/models/PCA20035+solar/transforms/deviceInfo.md +72 -0
- package/models/PCA20035+solar/transforms/gain.md +45 -0
- package/models/PCA20035+solar/transforms/geolocationFromGroundfix.md +67 -0
- package/models/PCA20035+solar/transforms/geolocationFromMessage.md +80 -0
- package/models/PCA20035+solar/transforms/humidity.md +43 -0
- package/models/PCA20035+solar/transforms/networkInfo.md +84 -0
- package/models/PCA20035+solar/transforms/pressure.md +43 -0
- package/models/PCA20035+solar/transforms/temperature.md +43 -0
- package/models/README.md +10 -0
- package/models/asset_tracker_v2+AWS/README.md +6 -0
- package/models/asset_tracker_v2+AWS/examples/examples.spec.ts +229 -0
- package/models/asset_tracker_v2+AWS/examples/shadow/example-1.json +24 -0
- package/models/asset_tracker_v2+AWS/examples/shadow/example-2.json +30 -0
- package/models/asset_tracker_v2+AWS/examples/shadow/example-3.json +37 -0
- package/models/asset_tracker_v2+AWS/examples/shadow/example-4.json +48 -0
- package/models/asset_tracker_v2+AWS/examples/shadow/example-5.json +43 -0
- package/models/asset_tracker_v2+AWS/transforms/GNSS.md +66 -0
- package/models/asset_tracker_v2+AWS/transforms/battery-voltage.md +50 -0
- package/models/asset_tracker_v2+AWS/transforms/device-info.md +61 -0
- package/models/asset_tracker_v2+AWS/transforms/env.md +69 -0
- package/models/asset_tracker_v2+AWS/transforms/fuel-gauge.md +62 -0
- package/models/asset_tracker_v2+AWS/transforms/roam.md +100 -0
- package/models/asset_tracker_v2+AWS/transforms/solar.md +58 -0
- package/models/check-model-rules.ts +125 -0
- package/models/kartverket-vasstandsdata/README.md +13 -0
- package/models/models.ts +36 -0
- package/models/types.ts +17 -0
- package/package.json +111 -0
- package/senml/SenMLSchema.spec.ts +21 -0
- package/senml/SenMLSchema.ts +74 -0
- package/senml/hasValue.spec.ts +19 -0
- package/senml/hasValue.ts +12 -0
- package/senml/lwm2mToSenML.spec.ts +74 -0
- package/senml/lwm2mToSenML.ts +62 -0
- package/senml/parseResourceId.spec.ts +13 -0
- package/senml/parseResourceId.ts +23 -0
- package/senml/senMLtoLwM2M.spec.ts +181 -0
- package/senml/senMLtoLwM2M.ts +121 -0
- package/senml/validateSenML.spec.ts +16 -0
- package/senml/validateSenML.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-2024, Nordic Semiconductor ASA | nordicsemi.no
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# `hello.nrfcloud.com/map` Protocols [](https://www.npmjs.com/package/@hello.nrfcloud.com/proto-map)
|
|
2
|
+
|
|
3
|
+
[](https://github.com/hello-nrfcloud/proto-map/actions/workflows/build-and-publish.yaml)
|
|
4
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
5
|
+
[](https://renovatebot.com)
|
|
6
|
+
[](https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional)
|
|
7
|
+
[](https://github.com/prettier/prettier/)
|
|
8
|
+
[](https://github.com/typescript-eslint/typescript-eslint)
|
|
9
|
+
|
|
10
|
+
Documents the communication protocol between devices, the
|
|
11
|
+
`hello.nrfcloud.com/map` backend and web application.
|
|
12
|
+
|
|
13
|
+
The [`lwm2m`](./lwm2m/) folder contains the LwM2M objects that devices publish.
|
|
14
|
+
|
|
15
|
+
LwM2M object definitions are shared between models and can be re-used. Some
|
|
16
|
+
objects provide special behavior (for example object
|
|
17
|
+
[`14201` (Geolocation)](./lwm2m/14201.xml) will place the device's location on
|
|
18
|
+
the map).
|
|
19
|
+
|
|
20
|
+
Devices publish LwM2M objects using
|
|
21
|
+
[SenML](https://datatracker.ietf.org/doc/html/rfc8428) directly, which needs to
|
|
22
|
+
map to the defined LwM2M objects ([example](./senml/SenMLSchema.spec.ts)).
|
|
23
|
+
|
|
24
|
+
The SenML payload will be [expanded](./senml/senMLtoLwM2M.spec.ts] to fully
|
|
25
|
+
qualified LwM2M object representations which can then be processed further, e.g.
|
|
26
|
+
stored in a database.
|
|
27
|
+
|
|
28
|
+
This allows the `hello.nrfcloud.com/map` web application to visualize this data
|
|
29
|
+
in a meaningful way to users without the need for custom implementation.
|
|
30
|
+
|
|
31
|
+
## LwM2M rules
|
|
32
|
+
|
|
33
|
+
- `LWM2MVersion` must be `1.1`
|
|
34
|
+
- LwM2M objects are defined in the ID range from `14200` to `15000`
|
|
35
|
+
(non-inclusively).
|
|
36
|
+
- The URN must have the prefix `urn:oma:lwm2m:x:`.
|
|
37
|
+
- The `ObjectVersion` must be appended if it is not `1.0`, which is the default.
|
|
38
|
+
- All objects must define one `Time` property.
|
|
39
|
+
- Objects must be `Multiple` instance.
|
|
40
|
+
- Objects must be `Optional`.
|
|
41
|
+
- Resources must be `Single` instance. `Multiple` could be useful in some cases,
|
|
42
|
+
e.g. IP addresses, but until it is really needed, we do not support it.
|
|
43
|
+
- Resources should only be marked as mandatory in case they must be published
|
|
44
|
+
together (e.g. latitude and longitude). This allows devices to only update the
|
|
45
|
+
values that have changed.
|
|
46
|
+
- `RangeEnumeration` is only supported for `Float` and `Integer` and must be
|
|
47
|
+
specified as `<min>..<max>`, where `min` must be smaller than `max` and both
|
|
48
|
+
must be a number.
|
|
49
|
+
- `Objlnk` resource type is not supported
|
|
50
|
+
|
|
51
|
+
The conformity to the rules is checked using the script
|
|
52
|
+
[`./lwm2m/check-lwm2m-rules.ts`](./lwm2m/check-lwm2m-rules.ts).
|
|
53
|
+
|
|
54
|
+
## SenML rules
|
|
55
|
+
|
|
56
|
+
- The implementation follows the recommendation outline in section 7.4.5. of the
|
|
57
|
+
[LwM2M v1.1.1 Technical Specification](https://openmobilealliance.org/release/LightweightM2M/V1_1_1-20190617-A/OMA-TS-LightweightM2M_Core-V1_1_1-20190617-A.pdf):
|
|
58
|
+
`bn` and `n` fields are combined to form the unique identifier for a resource
|
|
59
|
+
in the form of `/<object ID>/<object instance ID>/<resource ID>/0`. The
|
|
60
|
+
resource instance ID `0` is always appended, because multiple resource
|
|
61
|
+
instances are not supported right now.
|
|
62
|
+
- Use the custom property `blv` to specify the object version, `1.0` is the
|
|
63
|
+
default and should not be specified.
|
|
64
|
+
- Timestamps are to be expressed in the **base time** property `bt` and are
|
|
65
|
+
mapped to the LwM2M object's timestamp property and must not be send as a
|
|
66
|
+
property.
|
|
67
|
+
|
|
68
|
+
## Model transform definitions
|
|
69
|
+
|
|
70
|
+
Optionally, a set of [JSONata](https://jsonata.org/) expression can be defined
|
|
71
|
+
[per model](./models/) which allows to convert from the data format that is
|
|
72
|
+
published by the devices to the SenML data format used to describe LwM2M objects
|
|
73
|
+
([example mapping](./models/PCA20035+solar/transforms/geolocation.md).
|
|
74
|
+
|
|
75
|
+
### Model definition rules
|
|
76
|
+
|
|
77
|
+
- **device models** are identified using a model name, for example
|
|
78
|
+
`PCA20035+solar`
|
|
79
|
+
- a [`README.md`](./models/PCA20035+solar/README.md) must be provided that
|
|
80
|
+
describes the model
|
|
81
|
+
- transforms may define transforms that convert the data sent by the device
|
|
82
|
+
using JSONata for JSON payloads in one or more Markdown files
|
|
83
|
+
([Example](./models/PCA20035+solar/transforms/geolocationFromGroundfix.md)):
|
|
84
|
+
- The `Match Expression` the must evaluate to `true` for the
|
|
85
|
+
`Transform Expression` to be applied to the input message
|
|
86
|
+
- an `Input Example` and a `Result Example` must be supplied to validate the
|
|
87
|
+
expression
|
|
88
|
+
- The result of the Transform Expression must be SenML according to the rules
|
|
89
|
+
outlined below.
|
|
90
|
+
|
|
91
|
+
The conformity to the rules is checked using the script
|
|
92
|
+
[`./models/check-model-rules.ts`](./models/check-model-rules.ts).
|
|
93
|
+
|
|
94
|
+
## Usage
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm i --save-exact @hello.nrfcloud.com/proto-map
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Setup
|
|
101
|
+
|
|
102
|
+
Install the dependencies:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npm ci
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Install [xmllint](https://github.com/GNOME/libxml2).
|
|
109
|
+
|
|
110
|
+
## Run tests
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm test
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Update generated code
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npx tsx generator/lwm2m.ts
|
|
120
|
+
npx tsx generator/models.ts
|
|
121
|
+
npx tsx generator/types.ts
|
|
122
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { addDocBlock } from "./addDocBlock.js";
|
|
3
|
+
import { generateName } from "./generateType.js";
|
|
4
|
+
import { parseRangeEnumeration } from "../lwm2m/parseRangeEnumeration.js";
|
|
5
|
+
export var generateLwM2MDefinitions = function(definitions) {
|
|
6
|
+
var importLWM2MObjectInfo = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
7
|
+
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier("LWM2MObjectInfo")),
|
|
8
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("ResourceType"))
|
|
9
|
+
])), ts.factory.createStringLiteral("./LWM2MObjectInfo.js"));
|
|
10
|
+
var importLwM2MObjectID = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
11
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObjectID"))
|
|
12
|
+
])), ts.factory.createStringLiteral("./LwM2MObjectID.js"));
|
|
13
|
+
var type = ts.factory.createVariableStatement([
|
|
14
|
+
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
15
|
+
], ts.factory.createVariableDeclarationList([
|
|
16
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier("definitions"), undefined, ts.factory.createTypeReferenceNode("Record", [
|
|
17
|
+
ts.factory.createTypeReferenceNode("LwM2MObjectID"),
|
|
18
|
+
ts.factory.createTypeReferenceNode("LWM2MObjectInfo")
|
|
19
|
+
]), ts.factory.createObjectLiteralExpression(definitions.map(function(definition) {
|
|
20
|
+
var _definition_ObjectVersion;
|
|
21
|
+
var objectDef = ts.factory.createPropertyAssignment(ts.factory.createComputedPropertyName(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("LwM2MObjectID"), generateName(definition))), ts.factory.createObjectLiteralExpression([
|
|
22
|
+
ts.factory.createPropertyAssignment("ObjectID", ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("LwM2MObjectID"), generateName(definition))),
|
|
23
|
+
ts.factory.createPropertyAssignment("ObjectVersion", ts.factory.createStringLiteral((_definition_ObjectVersion = definition.ObjectVersion) !== null && _definition_ObjectVersion !== void 0 ? _definition_ObjectVersion : "1.0")),
|
|
24
|
+
ts.factory.createPropertyAssignment("Name", ts.factory.createStringLiteral(definition.Name)),
|
|
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
|
+
})))
|
|
62
|
+
]));
|
|
63
|
+
addDocBlock([
|
|
64
|
+
"".concat(definition.Name, " (").concat(definition.ObjectID, ")"),
|
|
65
|
+
"",
|
|
66
|
+
definition.Description1
|
|
67
|
+
], objectDef);
|
|
68
|
+
return objectDef;
|
|
69
|
+
})))
|
|
70
|
+
], ts.NodeFlags.Const));
|
|
71
|
+
addDocBlock([
|
|
72
|
+
"Contains the ID of the resource that defines the timestamp for each LwM2M object definition"
|
|
73
|
+
], type);
|
|
74
|
+
return [
|
|
75
|
+
importLWM2MObjectInfo,
|
|
76
|
+
importLwM2MObjectID,
|
|
77
|
+
type
|
|
78
|
+
];
|
|
79
|
+
};
|
|
80
|
+
var createNumber = function(n) {
|
|
81
|
+
return n < 0 ? ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(-n)) : ts.factory.createNumericLiteral(n);
|
|
82
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, it } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { definitions } from "../lwm2m/definitions.js";
|
|
4
|
+
import { LwM2MObjectID } from "../lwm2m/LwM2MObjectID.js";
|
|
5
|
+
import { ResourceType } from "../lwm2m/LWM2MObjectInfo.js";
|
|
6
|
+
void describe("generateLwM2MDefinitions()", function() {
|
|
7
|
+
void it("should have generated definitions from the XML files", function() {
|
|
8
|
+
assert.deepEqual(definitions[LwM2MObjectID.Geolocation_14201], {
|
|
9
|
+
ObjectID: 14201,
|
|
10
|
+
ObjectVersion: "1.0",
|
|
11
|
+
Name: "Geolocation",
|
|
12
|
+
Description: "Describes the geo location of a device",
|
|
13
|
+
Resources: {
|
|
14
|
+
0: {
|
|
15
|
+
ResourceID: 0,
|
|
16
|
+
Name: "Latitude",
|
|
17
|
+
Mandatory: true,
|
|
18
|
+
Type: ResourceType.Float,
|
|
19
|
+
Description: "The decimal notation of latitude in degrees, e.g. -43.5723 [World Geodetic System 1984].",
|
|
20
|
+
Units: "\xb0",
|
|
21
|
+
RangeEnumeration: {
|
|
22
|
+
max: 90,
|
|
23
|
+
min: -90
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
1: {
|
|
27
|
+
ResourceID: 1,
|
|
28
|
+
Name: "Longitude",
|
|
29
|
+
Mandatory: true,
|
|
30
|
+
Type: ResourceType.Float,
|
|
31
|
+
Description: "The decimal notation of longitude in degrees, e.g. 153.21760 [World Geodetic System 1984].",
|
|
32
|
+
Units: "\xb0",
|
|
33
|
+
RangeEnumeration: {
|
|
34
|
+
max: 180,
|
|
35
|
+
min: -180
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
2: {
|
|
39
|
+
ResourceID: 2,
|
|
40
|
+
Name: "Altitude",
|
|
41
|
+
Mandatory: false,
|
|
42
|
+
Type: ResourceType.Float,
|
|
43
|
+
Description: "The decimal notation of altitude in meters above sea level.",
|
|
44
|
+
Units: "m"
|
|
45
|
+
},
|
|
46
|
+
3: {
|
|
47
|
+
ResourceID: 3,
|
|
48
|
+
Name: "Radius",
|
|
49
|
+
Mandatory: false,
|
|
50
|
+
Type: ResourceType.Float,
|
|
51
|
+
Description: "The value in this resource indicates the radius of a circular area in meters. The circular area is used to describe uncertainty about a point for coordinates in a two-dimensional coordinate reference systems (CRS). The center point of a circular area is specified by using the Latitude and the Longitude Resources.",
|
|
52
|
+
Units: "m"
|
|
53
|
+
},
|
|
54
|
+
4: {
|
|
55
|
+
ResourceID: 4,
|
|
56
|
+
Name: "Speed",
|
|
57
|
+
Mandatory: false,
|
|
58
|
+
Type: ResourceType.Float,
|
|
59
|
+
Description: "Speed is the time rate of change in position.",
|
|
60
|
+
Units: "m/s"
|
|
61
|
+
},
|
|
62
|
+
5: {
|
|
63
|
+
ResourceID: 5,
|
|
64
|
+
Name: "Heading",
|
|
65
|
+
Mandatory: false,
|
|
66
|
+
Type: ResourceType.Float,
|
|
67
|
+
Description: "The angle of movement in degrees.",
|
|
68
|
+
Units: "\xb0",
|
|
69
|
+
RangeEnumeration: {
|
|
70
|
+
min: 0,
|
|
71
|
+
max: 360
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
6: {
|
|
75
|
+
ResourceID: 6,
|
|
76
|
+
Name: "Source",
|
|
77
|
+
Mandatory: true,
|
|
78
|
+
Type: ResourceType.String,
|
|
79
|
+
Description: "The source of the geo location, e.g. GNSS, SCELL, MCELL, WIFI."
|
|
80
|
+
},
|
|
81
|
+
99: {
|
|
82
|
+
ResourceID: 99,
|
|
83
|
+
Name: "Timestamp",
|
|
84
|
+
Mandatory: true,
|
|
85
|
+
Type: ResourceType.Time,
|
|
86
|
+
Description: "The timestamp of when the location measurement was performed."
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -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 ts from "typescript";
|
|
48
|
+
import { addDocBlock } from "./addDocBlock.js";
|
|
49
|
+
export var generateLwm2mTimestampResources = function(timestampResources) {
|
|
50
|
+
var type = ts.factory.createVariableStatement([
|
|
51
|
+
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
52
|
+
], ts.factory.createVariableDeclarationList([
|
|
53
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier("timestampResources"), undefined, ts.factory.createTypeReferenceNode("Readonly", [
|
|
54
|
+
ts.factory.createTypeReferenceNode("Record", [
|
|
55
|
+
ts.factory.createTypeReferenceNode("number"),
|
|
56
|
+
ts.factory.createTypeReferenceNode("number")
|
|
57
|
+
])
|
|
58
|
+
]), ts.factory.createObjectLiteralExpression(Object.entries(timestampResources).map(function(param) {
|
|
59
|
+
var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
|
|
60
|
+
return ts.factory.createPropertyAssignment(k, ts.factory.createNumericLiteral(v));
|
|
61
|
+
})))
|
|
62
|
+
], ts.NodeFlags.Const));
|
|
63
|
+
addDocBlock([
|
|
64
|
+
"Contains the ID of the resource that defines the timestamp for each LwM2M object definition"
|
|
65
|
+
], type);
|
|
66
|
+
return [
|
|
67
|
+
type
|
|
68
|
+
];
|
|
69
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
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 ts from "typescript";
|
|
48
|
+
import { addDocBlock } from "./addDocBlock.js";
|
|
49
|
+
import { tokenizeName } from "./tokenizeName.js";
|
|
50
|
+
import { parseREADME } from "markdown/parseREADME.js";
|
|
51
|
+
export var generateModels = function(models) {
|
|
52
|
+
var types = [];
|
|
53
|
+
types.push(ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
54
|
+
ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier("Transform")),
|
|
55
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("TransformType"))
|
|
56
|
+
])), ts.factory.createStringLiteral("./types.js")));
|
|
57
|
+
types.push(addDocBlock([
|
|
58
|
+
"The Model IDs defined in this repo."
|
|
59
|
+
], ts.factory.createEnumDeclaration([
|
|
60
|
+
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
61
|
+
], ts.factory.createIdentifier("ModelID"), models.map(function(param) {
|
|
62
|
+
var id = param.id;
|
|
63
|
+
return ts.factory.createEnumMember(tokenizeName(id), ts.factory.createStringLiteral(id));
|
|
64
|
+
}))));
|
|
65
|
+
types.push(ts.factory.createTypeAliasDeclaration([
|
|
66
|
+
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
67
|
+
], ts.factory.createIdentifier("Model"), undefined, ts.factory.createTypeLiteralNode([
|
|
68
|
+
addDocBlock([
|
|
69
|
+
"The Model ID"
|
|
70
|
+
], ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral("id"), undefined, ts.factory.createTypeReferenceNode("ModelID"))),
|
|
71
|
+
addDocBlock([
|
|
72
|
+
"The transforms defined for this model."
|
|
73
|
+
], ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral("transforms"), undefined, ts.factory.createTypeReferenceNode("Array", [
|
|
74
|
+
ts.factory.createTypeReferenceNode("Transform")
|
|
75
|
+
]))),
|
|
76
|
+
addDocBlock([
|
|
77
|
+
"Description of the Model from the README.md"
|
|
78
|
+
], ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral("about"), undefined, ts.factory.createTypeLiteralNode([
|
|
79
|
+
addDocBlock([
|
|
80
|
+
"The text of the H1 headline"
|
|
81
|
+
], ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral("title"), undefined, ts.factory.createTypeReferenceNode("string"))),
|
|
82
|
+
addDocBlock([
|
|
83
|
+
"The text of the paragraphs following the H1 headline"
|
|
84
|
+
], ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral("description"), undefined, ts.factory.createTypeReferenceNode("string")))
|
|
85
|
+
])))
|
|
86
|
+
])));
|
|
87
|
+
types.push(addDocBlock([
|
|
88
|
+
"The models defined for hello.nrfcloud.com"
|
|
89
|
+
], ts.factory.createVariableStatement([
|
|
90
|
+
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
91
|
+
], ts.factory.createVariableDeclarationList([
|
|
92
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier("models"), undefined, ts.factory.createTypeReferenceNode("Readonly", [
|
|
93
|
+
ts.factory.createTypeReferenceNode("Record", [
|
|
94
|
+
ts.factory.createTypeReferenceNode("ModelID", []),
|
|
95
|
+
ts.factory.createTypeReferenceNode("Model", [])
|
|
96
|
+
])
|
|
97
|
+
]), ts.factory.createAsExpression(ts.factory.createObjectLiteralExpression(models.map(function(model) {
|
|
98
|
+
var readme = parseREADME(model.readmeMarkdown);
|
|
99
|
+
return ts.factory.createPropertyAssignment(ts.factory.createComputedPropertyName(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ModelID"), ts.factory.createIdentifier(tokenizeName(model.id)))), // The model object
|
|
100
|
+
ts.factory.createObjectLiteralExpression([
|
|
101
|
+
// id
|
|
102
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral("id"), ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ModelID"), ts.factory.createIdentifier(tokenizeName(model.id)))),
|
|
103
|
+
// transforms
|
|
104
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral("transforms"), ts.factory.createArrayLiteralExpression(model.transforms.map(function(transform) {
|
|
105
|
+
return ts.factory.createObjectLiteralExpression([
|
|
106
|
+
// type
|
|
107
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral("type"), transform.type === "messages" ? ts.factory.createIdentifier("TransformType.Messages") : ts.factory.createIdentifier("TransformType.Shadow")),
|
|
108
|
+
// match
|
|
109
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral("match"), createAssignment(transform.match)),
|
|
110
|
+
// transform
|
|
111
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral("transform"), createAssignment(transform.transform))
|
|
112
|
+
]);
|
|
113
|
+
}))),
|
|
114
|
+
// About
|
|
115
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral("about"), ts.factory.createObjectLiteralExpression([
|
|
116
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral("title"), ts.factory.createStringLiteral(readme.heading)),
|
|
117
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral("description"), ts.factory.createStringLiteral(readme.description.join("\n")))
|
|
118
|
+
]))
|
|
119
|
+
]));
|
|
120
|
+
})), ts.factory.createTypeReferenceNode("const")))
|
|
121
|
+
], ts.NodeFlags.Const))));
|
|
122
|
+
return types;
|
|
123
|
+
};
|
|
124
|
+
var createAssignment = function(v) {
|
|
125
|
+
if (v === null) return ts.factory.createNull();
|
|
126
|
+
if (typeof v === "string") {
|
|
127
|
+
return ts.factory.createStringLiteral(v);
|
|
128
|
+
}
|
|
129
|
+
if (Array.isArray(v)) {
|
|
130
|
+
return ts.factory.createArrayLiteralExpression(v.map(function(el) {
|
|
131
|
+
return createAssignment(el);
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
if (typeof v === "object") return ts.factory.createObjectLiteralExpression(Object.entries(v).map(function(param) {
|
|
135
|
+
var _param = _sliced_to_array(param, 2), k = _param[0], _$v = _param[1];
|
|
136
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(k), createAssignment(_$v));
|
|
137
|
+
}));
|
|
138
|
+
return addDocBlock([
|
|
139
|
+
"Could not convert node",
|
|
140
|
+
JSON.stringify(v)
|
|
141
|
+
], ts.factory.createNull());
|
|
142
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { addDocBlock } from "./addDocBlock.js";
|
|
3
|
+
import { LwM2MType } from "../lwm2m/resourceType.js";
|
|
4
|
+
import { tokenizeName } from "./tokenizeName.js";
|
|
5
|
+
import { parseRangeEnumeration } from "lwm2m/parseRangeEnumeration.js";
|
|
6
|
+
export var generateType = function(param) {
|
|
7
|
+
var ObjectID = param.ObjectID, ObjectVersion = param.ObjectVersion, Name = param.Name, Description1 = param.Description1, Resources = param.Resources;
|
|
8
|
+
var name = generateName({
|
|
9
|
+
Name: Name,
|
|
10
|
+
ObjectID: ObjectID
|
|
11
|
+
});
|
|
12
|
+
var importLwM2MObject = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([
|
|
13
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObject"))
|
|
14
|
+
])), ts.factory.createStringLiteral("../LwM2MObject.js"));
|
|
15
|
+
var importLwM2MObjectID = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
16
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObjectID"))
|
|
17
|
+
])), ts.factory.createStringLiteral("../LwM2MObjectID.js"));
|
|
18
|
+
// Generate the type
|
|
19
|
+
var exportType = ts.factory.createTypeAliasDeclaration([
|
|
20
|
+
ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
21
|
+
], ts.factory.createIdentifier(name), undefined, ts.factory.createTypeReferenceNode("LwM2MObject", [
|
|
22
|
+
ts.factory.createTypeLiteralNode([
|
|
23
|
+
ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier("ObjectID"), undefined, ts.factory.createTypeReferenceNode("LwM2MObjectID.".concat(name), undefined)),
|
|
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) {
|
|
26
|
+
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
|
+
addDocBlock([
|
|
28
|
+
"".concat(resource.Name).concat(resource.Units.length > 0 ? " (".concat(resource.Units, ")") : ""),
|
|
29
|
+
"",
|
|
30
|
+
resource.Description
|
|
31
|
+
], res);
|
|
32
|
+
if (resource.RangeEnumeration.length > 0) {
|
|
33
|
+
var maybeRange = parseRangeEnumeration(resource.RangeEnumeration);
|
|
34
|
+
if ("error" in maybeRange) throw maybeRange.error;
|
|
35
|
+
addDocBlock([
|
|
36
|
+
"Minimum: ".concat(maybeRange.range.min),
|
|
37
|
+
"Maximum: ".concat(maybeRange.range.max)
|
|
38
|
+
], res);
|
|
39
|
+
}
|
|
40
|
+
return res;
|
|
41
|
+
})))
|
|
42
|
+
])
|
|
43
|
+
]));
|
|
44
|
+
addDocBlock([
|
|
45
|
+
"".concat(Name, " (").concat(ObjectID, ")"),
|
|
46
|
+
"",
|
|
47
|
+
Description1
|
|
48
|
+
], exportType);
|
|
49
|
+
return [
|
|
50
|
+
importLwM2MObject,
|
|
51
|
+
importLwM2MObjectID,
|
|
52
|
+
exportType
|
|
53
|
+
];
|
|
54
|
+
};
|
|
55
|
+
export var generateName = function(param) {
|
|
56
|
+
var Name = param.Name, ObjectID = param.ObjectID;
|
|
57
|
+
return "".concat(tokenizeName(Name), "_").concat(ObjectID);
|
|
58
|
+
};
|
|
59
|
+
var typeScriptResourceType = function(type) {
|
|
60
|
+
switch(type){
|
|
61
|
+
case LwM2MType.Float:
|
|
62
|
+
case LwM2MType.Integer:
|
|
63
|
+
case LwM2MType.UnsignedInteger:
|
|
64
|
+
return ts.factory.createTypeReferenceNode("number");
|
|
65
|
+
case LwM2MType.Boolean:
|
|
66
|
+
return ts.factory.createTypeReferenceNode("boolean");
|
|
67
|
+
case LwM2MType.String:
|
|
68
|
+
case LwM2MType.Opaque:
|
|
69
|
+
case LwM2MType.Corelnk:
|
|
70
|
+
case LwM2MType.Objlnk:
|
|
71
|
+
return ts.factory.createTypeReferenceNode("string");
|
|
72
|
+
case LwM2MType.Time:
|
|
73
|
+
return ts.factory.createTypeReferenceNode("Date");
|
|
74
|
+
default:
|
|
75
|
+
throw new Error("Unexpected resource type: ".concat(type));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var byImportance = function(resources) {
|
|
79
|
+
return resources// sort by id
|
|
80
|
+
.sort(function(param, param1) {
|
|
81
|
+
var _param_$ = param.$, id1 = _param_$.ID, _param_$1 = param1.$, id2 = _param_$1.ID;
|
|
82
|
+
return parseInt(id1, 10) - parseInt(id2, 10);
|
|
83
|
+
})// sort mandatory up
|
|
84
|
+
.sort(function(param, param1) {
|
|
85
|
+
var m1 = param.Mandatory, m2 = param1.Mandatory;
|
|
86
|
+
if (m1 === "Mandatory" && m2 === "Mandatory") return 0;
|
|
87
|
+
if (m1 === "Mandatory") return -1;
|
|
88
|
+
return 1;
|
|
89
|
+
});
|
|
90
|
+
};
|