@hello.nrfcloud.com/proto-map 8.1.1 → 9.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.
Files changed (58) hide show
  1. package/api/Devices.ts +1 -1
  2. package/dist/api/Devices.js +1 -1
  3. package/dist/generator/generateType.js +4 -6
  4. package/dist/generator/generateValidator.js +16 -11
  5. package/dist/generator/generateValidators.js +14 -2
  6. package/dist/lwm2m/LwM2MObjectInstance.js +1 -0
  7. package/dist/lwm2m/index.js +10 -0
  8. package/dist/lwm2m/object/validate14201.js +4 -4
  9. package/dist/lwm2m/object/validate14202.js +4 -4
  10. package/dist/lwm2m/object/validate14203.js +4 -4
  11. package/dist/lwm2m/object/validate14204.js +4 -4
  12. package/dist/lwm2m/object/validate14205.js +4 -4
  13. package/dist/lwm2m/object/validate14210.js +4 -4
  14. package/dist/lwm2m/object/validate14220.js +4 -4
  15. package/dist/lwm2m/object/validate14230.js +4 -4
  16. package/dist/lwm2m/object/validate14240.js +4 -4
  17. package/dist/lwm2m/validate.js +9 -8
  18. package/dist/lwm2m/validate.spec.js +27 -0
  19. package/dist/lwm2m/validation.js +50 -19
  20. package/dist/models/index.js +2 -0
  21. package/dist/models/models.js +10 -2
  22. package/dist/senml/index.js +4 -0
  23. package/lwm2m/LwM2MObject.d.ts +1 -1
  24. package/lwm2m/LwM2MObjectInstance.ts +35 -0
  25. package/lwm2m/index.ts +10 -0
  26. package/lwm2m/instanceTs.ts +1 -1
  27. package/lwm2m/object/14201.d.ts +3 -6
  28. package/lwm2m/object/14202.d.ts +1 -2
  29. package/lwm2m/object/14205.d.ts +1 -2
  30. package/lwm2m/object/14240.d.ts +3 -6
  31. package/lwm2m/object/validate14201.ts +7 -3
  32. package/lwm2m/object/validate14202.ts +7 -3
  33. package/lwm2m/object/validate14203.ts +7 -3
  34. package/lwm2m/object/validate14204.ts +7 -3
  35. package/lwm2m/object/validate14205.ts +7 -3
  36. package/lwm2m/object/validate14210.ts +7 -3
  37. package/lwm2m/object/validate14220.ts +7 -3
  38. package/lwm2m/object/validate14230.ts +7 -3
  39. package/lwm2m/object/validate14240.ts +7 -3
  40. package/lwm2m/validate.spec.ts +29 -0
  41. package/lwm2m/validate.ts +12 -19
  42. package/lwm2m/validation.ts +32 -41
  43. package/lwm2m/validators.ts +6 -1
  44. package/models/index.ts +2 -0
  45. package/models/models.ts +3 -2
  46. package/models/thingy91x/README.md +9 -0
  47. package/package.json +1 -7
  48. package/senml/index.ts +4 -0
  49. package/senml/lwm2mToSenML.spec.ts +1 -1
  50. package/senml/lwm2mToSenML.ts +4 -1
  51. package/senml/senMLtoLwM2M.spec.ts +2 -1
  52. package/senml/senMLtoLwM2M.ts +1 -35
  53. package/dist/lwm2m/isRegisteredLwM2MObject.js +0 -3
  54. package/dist/lwm2m/isRegisteredLwM2MObject.spec.js +0 -45
  55. package/export.js +0 -14
  56. package/index.d.ts +0 -15
  57. package/lwm2m/isRegisteredLwM2MObject.spec.ts +0 -48
  58. package/lwm2m/isRegisteredLwM2MObject.ts +0 -4
package/api/Devices.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Type } from '@sinclair/typebox'
2
2
  import { Context } from './Context.js'
3
3
  import { PublicDeviceId } from './DeviceId.js'
4
- import { models } from '@hello.nrfcloud.com/proto-map'
5
4
  import {
6
5
  ObjectID,
7
6
  ObjectInstanceID,
8
7
  ObjectVersion,
9
8
  Resources,
10
9
  } from './LwM2M.js'
10
+ import { models } from '../models/models.js'
11
11
 
12
12
  export const LwM2MObjectInstance = Type.Object({
13
13
  ObjectID,
@@ -1,8 +1,8 @@
1
1
  import { Type } from '@sinclair/typebox';
2
2
  import { Context } from './Context.js';
3
3
  import { PublicDeviceId } from './DeviceId.js';
4
- import { models } from '@hello.nrfcloud.com/proto-map';
5
4
  import { ObjectID, ObjectInstanceID, ObjectVersion, Resources } from './LwM2M.js';
5
+ import { models } from '../models/models.js';
6
6
  export var LwM2MObjectInstance = Type.Object({
7
7
  ObjectID: ObjectID,
8
8
  ObjectVersion: Type.Optional(ObjectVersion),
@@ -24,19 +24,17 @@ export var generateType = function(param) {
24
24
  ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('ObjectVersion'), undefined, ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(ObjectVersion !== null && ObjectVersion !== void 0 ? ObjectVersion : '1.0'))),
25
25
  ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('Resources'), undefined, ts.factory.createTypeLiteralNode(byImportance(Resources.Item).map(function(resource) {
26
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([
27
+ var docs = [
28
28
  "".concat(resource.Name).concat(resource.Units.length > 0 ? " (".concat(resource.Units, ")") : ''),
29
29
  "",
30
30
  resource.Description
31
- ], res);
31
+ ];
32
32
  if (resource.RangeEnumeration.length > 0) {
33
33
  var maybeRange = parseRangeEnumeration(resource.RangeEnumeration);
34
34
  if ('error' in maybeRange) throw maybeRange.error;
35
- addDocBlock([
36
- "Minimum: ".concat(maybeRange.range.min),
37
- "Maximum: ".concat(maybeRange.range.max)
38
- ], res);
35
+ docs.push("", "Minimum: ".concat(maybeRange.range.min), "Maximum: ".concat(maybeRange.range.max));
39
36
  }
37
+ addDocBlock(docs, res);
40
38
  return res;
41
39
  })))
42
40
  ])
@@ -30,8 +30,8 @@ export var generateValidator = function(param) {
30
30
  var ObjectID = param.ObjectID, ObjectVersion = param.ObjectVersion, Name = param.Name, Resources = param.Resources;
31
31
  // import type { LwM2MObject } from './LwM2MObject.js'
32
32
  var importLwM2MObject = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([
33
- ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObject"))
34
- ])), ts.factory.createStringLiteral('../LwM2MObject.js'));
33
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObjectInstance"))
34
+ ])), ts.factory.createStringLiteral('../LwM2MObjectInstance.js'));
35
35
  /*
36
36
  import {
37
37
  DateResource,
@@ -43,7 +43,7 @@ export var generateValidator = function(param) {
43
43
  */ var importValidation = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(_to_consumable_array(getResourceValidators({
44
44
  Resources: Resources
45
45
  })).concat([
46
- 'validate'
46
+ 'validateInstance'
47
47
  ]).map(function(res) {
48
48
  return ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(res));
49
49
  }))), ts.factory.createStringLiteral('../validation.js'));
@@ -64,13 +64,19 @@ export var generateValidator = function(param) {
64
64
  ts.factory.createToken(ts.SyntaxKind.ExportKeyword)
65
65
  ], ts.factory.createVariableDeclarationList([
66
66
  ts.factory.createVariableDeclaration(ts.factory.createIdentifier("validate".concat(ObjectID)), undefined, undefined, ts.factory.createArrowFunction(undefined, undefined, [
67
- ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier('o'), undefined, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)),
68
- ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier('onError'), ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createFunctionTypeNode(undefined, [
69
- ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier('error'), undefined, ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('Error')))
70
- ], ts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)))
71
- ], ts.factory.createTypePredicateNode(undefined, ts.factory.createIdentifier('o'), ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('LwM2MObject'), [
67
+ ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier('o'), undefined, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword))
68
+ ], ts.factory.createUnionTypeNode([
69
+ ts.factory.createTypeLiteralNode([
70
+ ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('error'), undefined, ts.factory.createTypeReferenceNode("Error"))
71
+ ]),
72
+ ts.factory.createTypeLiteralNode([
73
+ ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('object'), undefined, ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('LwM2MObjectInstance'), [
74
+ ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(name))
75
+ ]))
76
+ ])
77
+ ]), undefined, ts.factory.createCallExpression(ts.factory.createCallExpression(ts.factory.createIdentifier('validateInstance'), [
72
78
  ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(name))
73
- ])), undefined, ts.factory.createCallExpression(ts.factory.createCallExpression(ts.factory.createIdentifier('validate'), undefined, [
79
+ ], [
74
80
  ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('LwM2MObjectID'), ts.factory.createIdentifier(name)),
75
81
  ts.factory.createStringLiteral(ObjectVersion !== null && ObjectVersion !== void 0 ? ObjectVersion : '1.0'),
76
82
  ts.factory.createObjectLiteralExpression(Resources.Item.map(function(Resource) {
@@ -78,8 +84,7 @@ export var generateValidator = function(param) {
78
84
  return validator;
79
85
  }))
80
86
  ]), undefined, [
81
- ts.factory.createIdentifier('o'),
82
- ts.factory.createIdentifier('onError')
87
+ ts.factory.createIdentifier('o')
83
88
  ])))
84
89
  ], ts.NodeFlags.Const));
85
90
  addDocBlock([
@@ -31,6 +31,10 @@ export var generateValidators = function(objects) {
31
31
  var importLwM2MObjectID = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
32
32
  ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObjectID"))
33
33
  ])), ts.factory.createStringLiteral('./LwM2MObjectID.js'));
34
+ // import type { LwM2MObjectInstance } from "./LwM2MObjectInstance.js";
35
+ var importLwM2MObjectInstance = ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([
36
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("LwM2MObjectInstance"))
37
+ ])), ts.factory.createStringLiteral('./LwM2MObjectInstance.js'));
34
38
  var validatorImports = objects.map(function(object) {
35
39
  return ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
36
40
  ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("validate".concat(object.ObjectID)))
@@ -43,7 +47,14 @@ export var generateValidators = function(objects) {
43
47
  ts.factory.createTypeReferenceNode('LwM2MObjectID'),
44
48
  ts.factory.createFunctionTypeNode(undefined, [
45
49
  ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier('o'), undefined, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword))
46
- ], ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword))
50
+ ], ts.factory.createUnionTypeNode([
51
+ ts.factory.createTypeLiteralNode([
52
+ ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('error'), undefined, ts.factory.createTypeReferenceNode("Error"))
53
+ ]),
54
+ ts.factory.createTypeLiteralNode([
55
+ ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier('object'), undefined, ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('LwM2MObjectInstance'), []))
56
+ ])
57
+ ]))
47
58
  ], []))
48
59
  ], ts.NodeFlags.Const));
49
60
  addDocBlock([
@@ -56,7 +67,8 @@ export var generateValidators = function(objects) {
56
67
  ]);
57
68
  });
58
69
  return [
59
- importLwM2MObjectID
70
+ importLwM2MObjectID,
71
+ importLwM2MObjectInstance
60
72
  ].concat(_to_consumable_array(validatorImports), [
61
73
  validators
62
74
  ], _to_consumable_array(validatorRegistrations));
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,10 @@
1
+ export * from './validate.js';
2
+ export * from './timestampResources.js';
3
+ export * from './LwM2MObject.js';
4
+ export * from './LwM2MObjectID.js';
5
+ export * from './objects.js';
6
+ export * from './definitions.js';
7
+ export * from './LWM2MObjectInfo.js';
8
+ export * from './validators.js';
9
+ export * from './instanceTs.js';
10
+ export * from './LwM2MObjectInstance.js';
@@ -1,11 +1,11 @@
1
- import { NumberResource, StringResource, DateResource, OptionalResource, validate } from "../validation.js";
1
+ import { NumberResource, StringResource, DateResource, OptionalResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate Geolocation (14201)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14201.xml.
7
- */ export var validate14201 = function(o, onError) {
8
- return validate(LwM2MObjectID.Geolocation_14201, "1.0", {
7
+ */ export var validate14201 = function(o) {
8
+ return validateInstance(LwM2MObjectID.Geolocation_14201, "1.0", {
9
9
  0: NumberResource,
10
10
  1: NumberResource,
11
11
  6: StringResource,
@@ -14,5 +14,5 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
14
14
  3: OptionalResource(NumberResource),
15
15
  4: OptionalResource(NumberResource),
16
16
  5: OptionalResource(NumberResource)
17
- })(o, onError);
17
+ })(o);
18
18
  };
@@ -1,11 +1,11 @@
1
- import { DateResource, NumberResource, OptionalResource, validate } from "../validation.js";
1
+ import { DateResource, NumberResource, OptionalResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate Battery and Power (14202)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14202.xml.
7
- */ export var validate14202 = function(o, onError) {
8
- return validate(LwM2MObjectID.BatteryAndPower_14202, "1.0", {
7
+ */ export var validate14202 = function(o) {
8
+ return validateInstance(LwM2MObjectID.BatteryAndPower_14202, "1.0", {
9
9
  99: DateResource,
10
10
  0: OptionalResource(NumberResource),
11
11
  1: OptionalResource(NumberResource),
@@ -13,5 +13,5 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
13
13
  3: OptionalResource(NumberResource),
14
14
  4: OptionalResource(NumberResource),
15
15
  5: OptionalResource(NumberResource)
16
- })(o, onError);
16
+ })(o);
17
17
  };
@@ -1,11 +1,11 @@
1
- import { DateResource, StringResource, OptionalResource, NumberResource, validate } from "../validation.js";
1
+ import { DateResource, StringResource, OptionalResource, NumberResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate Connection information (14203)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14203.xml.
7
- */ export var validate14203 = function(o, onError) {
8
- return validate(LwM2MObjectID.ConnectionInformation_14203, "1.0", {
7
+ */ export var validate14203 = function(o) {
8
+ return validateInstance(LwM2MObjectID.ConnectionInformation_14203, "1.0", {
9
9
  99: DateResource,
10
10
  0: OptionalResource(StringResource),
11
11
  1: OptionalResource(NumberResource),
@@ -15,5 +15,5 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
15
15
  5: OptionalResource(NumberResource),
16
16
  6: OptionalResource(StringResource),
17
17
  11: OptionalResource(NumberResource)
18
- })(o, onError);
18
+ })(o);
19
19
  };
@@ -1,11 +1,11 @@
1
- import { StringResource, DateResource, OptionalResource, validate } from "../validation.js";
1
+ import { StringResource, DateResource, OptionalResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate Device information (14204)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14204.xml.
7
- */ export var validate14204 = function(o, onError) {
8
- return validate(LwM2MObjectID.DeviceInformation_14204, "1.0", {
7
+ */ export var validate14204 = function(o) {
8
+ return validateInstance(LwM2MObjectID.DeviceInformation_14204, "1.0", {
9
9
  0: StringResource,
10
10
  2: StringResource,
11
11
  3: StringResource,
@@ -13,5 +13,5 @@ import { LwM2MObjectID } from "../LwM2MObjectID.js";
13
13
  99: DateResource,
14
14
  1: OptionalResource(StringResource),
15
15
  5: OptionalResource(StringResource)
16
- })(o, onError);
16
+ })(o);
17
17
  };
@@ -1,15 +1,15 @@
1
- import { DateResource, NumberResource, OptionalResource, validate } from "../validation.js";
1
+ import { DateResource, NumberResource, OptionalResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate Environment (14205)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14205.xml.
7
- */ export var validate14205 = function(o, onError) {
8
- return validate(LwM2MObjectID.Environment_14205, "1.0", {
7
+ */ export var validate14205 = function(o) {
8
+ return validateInstance(LwM2MObjectID.Environment_14205, "1.0", {
9
9
  99: DateResource,
10
10
  0: OptionalResource(NumberResource),
11
11
  1: OptionalResource(NumberResource),
12
12
  2: OptionalResource(NumberResource),
13
13
  10: OptionalResource(NumberResource)
14
- })(o, onError);
14
+ })(o);
15
15
  };
@@ -1,13 +1,13 @@
1
- import { NumberResource, DateResource, OptionalResource, validate } from "../validation.js";
1
+ import { NumberResource, DateResource, OptionalResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate Solar charge (14210)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14210.xml.
7
- */ export var validate14210 = function(o, onError) {
8
- return validate(LwM2MObjectID.SolarCharge_14210, "1.0", {
7
+ */ export var validate14210 = function(o) {
8
+ return validateInstance(LwM2MObjectID.SolarCharge_14210, "1.0", {
9
9
  0: NumberResource,
10
10
  99: DateResource,
11
11
  1: OptionalResource(NumberResource)
12
- })(o, onError);
12
+ })(o);
13
13
  };
@@ -1,12 +1,12 @@
1
- import { NumberResource, DateResource, validate } from "../validation.js";
1
+ import { NumberResource, DateResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate Button press (14220)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14220.xml.
7
- */ export var validate14220 = function(o, onError) {
8
- return validate(LwM2MObjectID.ButtonPress_14220, "1.0", {
7
+ */ export var validate14220 = function(o) {
8
+ return validateInstance(LwM2MObjectID.ButtonPress_14220, "1.0", {
9
9
  0: NumberResource,
10
10
  99: DateResource
11
- })(o, onError);
11
+ })(o);
12
12
  };
@@ -1,13 +1,13 @@
1
- import { NumberResource, StringResource, DateResource, validate } from "../validation.js";
1
+ import { NumberResource, StringResource, DateResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate Sea Water Level (14230)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14230.xml.
7
- */ export var validate14230 = function(o, onError) {
8
- return validate(LwM2MObjectID.SeaWaterLevel_14230, "1.0", {
7
+ */ export var validate14230 = function(o) {
8
+ return validateInstance(LwM2MObjectID.SeaWaterLevel_14230, "1.0", {
9
9
  0: NumberResource,
10
10
  1: StringResource,
11
11
  99: DateResource
12
- })(o, onError);
12
+ })(o);
13
13
  };
@@ -1,14 +1,14 @@
1
- import { NumberResource, DateResource, validate } from "../validation.js";
1
+ import { NumberResource, DateResource, validateInstance } from "../validation.js";
2
2
  import { LwM2MObjectID } from "../LwM2MObjectID.js";
3
3
  /**
4
4
  * Validate RGB LED (14240)
5
5
  *
6
6
  * Ensures the given object is an LwM2M object according to the schema 14240.xml.
7
- */ export var validate14240 = function(o, onError) {
8
- return validate(LwM2MObjectID.RGBLED_14240, "1.0", {
7
+ */ export var validate14240 = function(o) {
8
+ return validateInstance(LwM2MObjectID.RGBLED_14240, "1.0", {
9
9
  0: NumberResource,
10
10
  1: NumberResource,
11
11
  2: NumberResource,
12
12
  99: DateResource
13
- })(o, onError);
13
+ })(o);
14
14
  };
@@ -1,14 +1,15 @@
1
1
  import { isLwM2MObject } from './validation.js';
2
2
  export var validate = function(validators) {
3
- return function(o, onError) {
4
- if (!isLwM2MObject(o, onError)) {
5
- return false;
6
- }
7
- var validator = validators.get(o.ObjectID);
3
+ return function(o) {
4
+ var maybeValidInstance = isLwM2MObject(o);
5
+ if ('error' in maybeValidInstance) return maybeValidInstance;
6
+ var i = maybeValidInstance.object;
7
+ var validator = validators.get(i.ObjectID);
8
8
  if (validator === undefined) {
9
- onError === null || onError === void 0 ? void 0 : onError(new Error("No validator defined for ObjectID: ".concat(o.ObjectID, "!")));
10
- return false;
9
+ return {
10
+ error: new Error("No validator defined for ObjectID: ".concat(i.ObjectID, "!"))
11
+ };
11
12
  }
12
- return validator(o, onError);
13
+ return validator(o);
13
14
  };
14
15
  };
@@ -0,0 +1,27 @@
1
+ import { describe, it } from 'node:test';
2
+ import { validate } from './validate.js';
3
+ import { validators } from './validators.js';
4
+ import { LwM2MObjectID } from './LwM2MObjectID.js';
5
+ import assert from 'node:assert';
6
+ void describe('validate()', function() {
7
+ var v = validate(validators);
8
+ void it('should validate a LwM2M object instance', function() {
9
+ var object = {
10
+ ObjectID: LwM2MObjectID.Geolocation_14201,
11
+ ObjectVersion: '1.0',
12
+ Resources: {
13
+ '0': 62.469414,
14
+ '1': 6.151946,
15
+ '6': 'Fixed',
16
+ '3': 1,
17
+ '99': new Date(1710147413003)
18
+ }
19
+ };
20
+ var maybeValid = v(object);
21
+ assert.deepEqual('object' in maybeValid && maybeValid.object, object);
22
+ });
23
+ void it('should return an error for an invalid object', function() {
24
+ var maybeValid = v({});
25
+ assert.equal('error' in maybeValid, true);
26
+ });
27
+ });
@@ -56,11 +56,12 @@ function _unsupported_iterable_to_array(o, minLen) {
56
56
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
57
57
  }
58
58
  import { LwM2MObjectIDs } from './LwM2MObjectID.js';
59
- export var isLwM2MObject = function(object, onError) {
59
+ export var isLwM2MObject = function(object) {
60
60
  var _Object_keys_find;
61
61
  var error = function(message) {
62
- onError === null || onError === void 0 ? void 0 : onError(new Error(message));
63
- return false;
62
+ return {
63
+ error: new Error(message)
64
+ };
64
65
  };
65
66
  // Must be an object
66
67
  if (typeof object !== 'object' || object === null) return error("Not an object");
@@ -70,6 +71,10 @@ export var isLwM2MObject = function(object, onError) {
70
71
  if ('ObjectVersion' in object) {
71
72
  if (typeof object.ObjectVersion !== 'string' || !/^\d+\.\d+$/.test(object.ObjectVersion)) return error("Invalid ObjectVersion");
72
73
  }
74
+ // ObjectInstanceID must be valid
75
+ if ('ObjectInstanceID' in object) {
76
+ if (typeof object.ObjectInstanceID !== 'number' || object.ObjectInstanceID < 0) return error("Invalid ObjectInstanceID");
77
+ }
73
78
  // Must have valid resources
74
79
  if (!('Resources' in object) || typeof object.Resources !== 'object' || object.Resources === null) return error("Resources must be an object");
75
80
  var _Object_keys_find_length;
@@ -102,26 +107,52 @@ export var isLwM2MObject = function(object, onError) {
102
107
  }
103
108
  }
104
109
  }
105
- return true;
110
+ return {
111
+ object: object
112
+ };
106
113
  };
107
- export var validate = function(ObjectID, ObjectVersion, Resources) {
108
- return function(o, onError) {
114
+ export var validateInstance = function(ObjectID, ObjectVersion, Resources) {
115
+ return function(o) {
109
116
  var error = function(message) {
110
- onError === null || onError === void 0 ? void 0 : onError(new Error(message));
111
- return false;
117
+ return {
118
+ error: new Error(message)
119
+ };
112
120
  };
113
- if (!isLwM2MObject(o, onError)) return false;
114
- if (o.ObjectID !== ObjectID) return error("Given Object ID ".concat(o.ObjectID, " does not match expected ").concat(ObjectID));
115
- var _o_ObjectVersion;
116
- if (((_o_ObjectVersion = o.ObjectVersion) !== null && _o_ObjectVersion !== void 0 ? _o_ObjectVersion : '1.0') !== ObjectVersion) return error("Given Object version ".concat(o.ObjectVersion, " does not match expected ").concat(ObjectVersion));
117
- return Object.entries(Resources).reduce(function(allValid, param) {
118
- var _param = _sliced_to_array(param, 2), ResourceID = _param[0], validator = _param[1];
119
- if (!allValid) return false;
120
- if (validator(o.Resources[parseInt(ResourceID, 10)]) === false) {
121
- return error("Resource ".concat(ResourceID, " is invalid."));
121
+ var maybeValidLwM2MObject = isLwM2MObject(o);
122
+ if ('error' in maybeValidLwM2MObject) return maybeValidLwM2MObject;
123
+ var i = maybeValidLwM2MObject.object;
124
+ if (i.ObjectID !== ObjectID) {
125
+ return error("Given Object ID ".concat(i.ObjectID, " does not match expected ").concat(ObjectID));
126
+ }
127
+ var _i_ObjectVersion;
128
+ if (((_i_ObjectVersion = i.ObjectVersion) !== null && _i_ObjectVersion !== void 0 ? _i_ObjectVersion : '1.0') !== ObjectVersion) {
129
+ return error("Given Object version ".concat(i.ObjectVersion, " does not match expected ").concat(ObjectVersion));
130
+ }
131
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
132
+ try {
133
+ for(var _iterator = Object.entries(Resources)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
134
+ var _step_value = _sliced_to_array(_step.value, 2), ResourceID = _step_value[0], validator = _step_value[1];
135
+ if (validator(i.Resources[parseInt(ResourceID, 10)]) === false) {
136
+ return error("Resource ".concat(ResourceID, " is invalid."));
137
+ }
138
+ }
139
+ } catch (err) {
140
+ _didIteratorError = true;
141
+ _iteratorError = err;
142
+ } finally{
143
+ try {
144
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
145
+ _iterator.return();
146
+ }
147
+ } finally{
148
+ if (_didIteratorError) {
149
+ throw _iteratorError;
150
+ }
122
151
  }
123
- return allValid;
124
- }, true);
152
+ }
153
+ return {
154
+ object: o
155
+ };
125
156
  };
126
157
  };
127
158
  export var NumberResource = function(r) {
@@ -0,0 +1,2 @@
1
+ export * from './models.js';
2
+ export * from './types.js';
@@ -16,13 +16,21 @@
16
16
  export var ModelID;
17
17
  (function(ModelID) {
18
18
  ModelID["Kartverket_vasstandsdata"] = "kartverket-vasstandsdata";
19
+ ModelID["Thingy91x"] = "thingy91x";
19
20
  })(ModelID || (ModelID = {}));
21
+ var _obj;
20
22
  /**
21
23
  * The models defined for hello.nrfcloud.com
22
- */ export var models = _define_property({}, "kartverket-vasstandsdata", {
24
+ */ export var models = (_obj = {}, _define_property(_obj, "kartverket-vasstandsdata", {
23
25
  "id": "kartverket-vasstandsdata",
24
26
  "about": {
25
27
  "title": "Kartverket Vasstandsdata",
26
28
  "description": "A simulated device reporting the current sea level as provided by the Kartverket's (Norwegian Mapping Authority) API for vasstandsdata (API for water level data).\nReports sea water level using the Object 14230.\nThe data is licensed by the Norwegian Mapping Authority\u2019s under the Creative Commons Attribution 4.0 International (CC BY 4.0) license."
27
29
  }
28
- });
30
+ }), _define_property(_obj, "thingy91x", {
31
+ "id": "thingy91x",
32
+ "about": {
33
+ "title": "Thingy:91 X",
34
+ "description": "Nordic Semiconductor\u2019s latest Cellular IoT prototyping platform, the Thingy:91 X. Built around Nordic\u2019s recently announced nRF9151 System-in-Package (SiP), Thingy:91 X supports LTE-M, NB-IoT, GNSS, and DECT NR+ connectivity. The platform also integrates Nordic\u2019s nRF7002 Companion IC for Wi-Fi locationing, the nPM1300 Power Management IC (PMIC), which features innovative system management features and efficient fuel gauging, and the nRF5340 dual-core, multiprotocol SoC."
35
+ }
36
+ }), _obj);
@@ -0,0 +1,4 @@
1
+ export * from './SenMLSchema.js';
2
+ export * from './senMLtoLwM2M.js';
3
+ export * from './lwm2mToSenML.js';
4
+ export * from './fromCBOR.js';
@@ -1,4 +1,4 @@
1
- import type { LwM2MResourceValue } from '../senml/senMLtoLwM2M.js'
1
+ import type { LwM2MResourceValue } from './LwM2MObjectInstance.ts'
2
2
  import type { LwM2MObjectID } from './LwM2MObjectID.js'
3
3
 
4
4
  export type LwM2MObject<
@@ -0,0 +1,35 @@
1
+ import type { LwM2MObjectID } from './LwM2MObjectID.js'
2
+
3
+ export type LwM2MResourceValue = string | number | boolean | Date
4
+ type GenericLwM2MObjectInstance = {
5
+ ObjectID: LwM2MObjectID
6
+ /**
7
+ * @default 0
8
+ */
9
+ ObjectInstanceID?: number
10
+ /**
11
+ * @default '1.0'
12
+ */
13
+ ObjectVersion?: string
14
+ /**
15
+ * Key range: 0..65534
16
+ */
17
+ Resources: Partial<Record<number, LwM2MResourceValue>>
18
+ }
19
+ export type LwM2MObjectInstance<
20
+ Instance extends GenericLwM2MObjectInstance = GenericLwM2MObjectInstance,
21
+ > = {
22
+ ObjectID: LwM2MObjectID
23
+ /**
24
+ * @default 0
25
+ */
26
+ ObjectInstanceID?: number
27
+ /**
28
+ * @default '1.0'
29
+ */
30
+ ObjectVersion?: Instance['ObjectVersion']
31
+ /**
32
+ * Key range: 0..65534
33
+ */
34
+ Resources: Instance['Resources']
35
+ }
package/lwm2m/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from './validate.js'
2
+ export * from './timestampResources.js'
3
+ export * from './LwM2MObject.js'
4
+ export * from './LwM2MObjectID.js'
5
+ export * from './objects.js'
6
+ export * from './definitions.js'
7
+ export * from './LWM2MObjectInfo.js'
8
+ export * from './validators.js'
9
+ export * from './instanceTs.js'
10
+ export * from './LwM2MObjectInstance.js'
@@ -1,4 +1,4 @@
1
- import type { LwM2MObjectInstance } from '../senml/senMLtoLwM2M.js'
1
+ import type { LwM2MObjectInstance } from './LwM2MObjectInstance.js'
2
2
  import { definitions } from './definitions.js'
3
3
  import { timestampResources } from './timestampResources.js'
4
4
 
@@ -13,8 +13,7 @@ export type Geolocation_14201 = LwM2MObject<{
13
13
  * Latitude (°)
14
14
  *
15
15
  * The decimal notation of latitude in degrees, e.g. -43.5723 [World Geodetic System 1984].
16
- */
17
- /**
16
+ *
18
17
  * Minimum: -90
19
18
  * Maximum: 90
20
19
  */
@@ -23,8 +22,7 @@ export type Geolocation_14201 = LwM2MObject<{
23
22
  * Longitude (°)
24
23
  *
25
24
  * The decimal notation of longitude in degrees, e.g. 153.21760 [World Geodetic System 1984].
26
- */
27
- /**
25
+ *
28
26
  * Minimum: -180
29
27
  * Maximum: 180
30
28
  */
@@ -63,8 +61,7 @@ export type Geolocation_14201 = LwM2MObject<{
63
61
  * Heading (°)
64
62
  *
65
63
  * The angle of movement in degrees.
66
- */
67
- /**
64
+ *
68
65
  * Minimum: 0
69
66
  * Maximum: 360
70
67
  */
@@ -19,8 +19,7 @@ export type BatteryAndPower_14202 = LwM2MObject<{
19
19
  * State of charge (%)
20
20
  *
21
21
  * State of charge in percent. Examples: 23, 1, 100.
22
- */
23
- /**
22
+ *
24
23
  * Minimum: 0
25
24
  * Maximum: 100
26
25
  */