@duet3d/objectmodel 3.5.0-b9 → 3.5.0-beta.13

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.
@@ -24,12 +24,21 @@ export declare abstract class ModelObject implements IModelObject {
24
24
  * @returns Updated instance (may not equal the original instance)
25
25
  */
26
26
  update(jsonElement: any): IModelObject | null;
27
+ /**
28
+ * Called to check if a diverging property type may be set.
29
+ * Note that this is not applicable to null values; null is always legit
30
+ * @param key Property key
31
+ * @param oldValue Old member value
32
+ * @param newValue New member value
33
+ * @returns True if the value can be set by the update call
34
+ */
35
+ protected checkDivergingDataType<K extends keyof this>(key: K, oldValue: typeof this[K], newValue: any): boolean;
27
36
  /**
28
37
  * Wrap a nullable model object property so that type checks can be performed
29
38
  * @param key Property key of the derived class
30
39
  * @param constructor Constructor for creating new elements
31
40
  */
32
- wrapModelProperty<K extends keyof this, T extends IModelObject>(key: K, constructor: {
41
+ protected wrapModelProperty<K extends keyof this, T extends IModelObject>(key: K, constructor: {
33
42
  new (): T;
34
43
  }): void;
35
44
  }
@@ -70,6 +70,10 @@ class ModelObject {
70
70
  prop.push(value[i]);
71
71
  }
72
72
  }
73
+ else if (value === null) {
74
+ // Arrays may be assignable to null
75
+ this[ownKey] = value;
76
+ }
73
77
  else if (process.env.NODE_ENV !== "production") {
74
78
  console.warn(`Model array ${key} could not be changed because the target type ${typeof value} is invalid`);
75
79
  }
@@ -89,6 +93,10 @@ class ModelObject {
89
93
  }
90
94
  }
91
95
  }
96
+ else if (value === null) {
97
+ // Sets may be assignable to null
98
+ this[ownKey] = value;
99
+ }
92
100
  else if (process.env.NODE_ENV !== "production") {
93
101
  console.warn(`Model set ${key} could not be changed because the target type ${typeof value} is invalid`);
94
102
  }
@@ -105,7 +113,7 @@ class ModelObject {
105
113
  if (typeof value === "boolean") {
106
114
  this[ownKey] = value;
107
115
  }
108
- else if (typeof value === "number") {
116
+ else if (typeof value === "number" || this.checkDivergingDataType(ownKey, prop, value)) {
109
117
  // RRF used to report booleans as integers so convert them if necessary
110
118
  this[ownKey] = Boolean(value);
111
119
  }
@@ -114,7 +122,7 @@ class ModelObject {
114
122
  }
115
123
  }
116
124
  else if (propType === "number") {
117
- if (typeof value === "number" || typeof value === "bigint") {
125
+ if (typeof value === "number" || typeof value === "bigint" || this.checkDivergingDataType(ownKey, prop, value)) {
118
126
  this[ownKey] = value;
119
127
  }
120
128
  else if (process.env.NODE_ENV !== "production") {
@@ -122,7 +130,7 @@ class ModelObject {
122
130
  }
123
131
  }
124
132
  else if (propType === "bigint") {
125
- if (typeof value === "number" || typeof value === "bigint") {
133
+ if (typeof value === "number" || typeof value === "bigint" || this.checkDivergingDataType(ownKey, prop, value)) {
126
134
  this[ownKey] = value;
127
135
  }
128
136
  else if (process.env.NODE_ENV !== "production") {
@@ -130,7 +138,7 @@ class ModelObject {
130
138
  }
131
139
  }
132
140
  else if (propType === "string") {
133
- if (typeof value === "string") {
141
+ if (typeof value === "string" || this.checkDivergingDataType(ownKey, prop, value)) {
134
142
  this[ownKey] = value;
135
143
  }
136
144
  else if (process.env.NODE_ENV !== "production") {
@@ -138,7 +146,7 @@ class ModelObject {
138
146
  }
139
147
  }
140
148
  else if (propType === "function") {
141
- if (typeof value === "function") {
149
+ if (typeof value === "function" || this.checkDivergingDataType(ownKey, prop, value)) {
142
150
  this[ownKey] = value;
143
151
  }
144
152
  else if (process.env.NODE_ENV !== "production") {
@@ -146,7 +154,7 @@ class ModelObject {
146
154
  }
147
155
  }
148
156
  else if (propType === "object") {
149
- if (typeof value === "object") {
157
+ if (typeof value === "object" || this.checkDivergingDataType(ownKey, prop, value)) {
150
158
  this[ownKey] = value;
151
159
  }
152
160
  else if (process.env.NODE_ENV !== "production") {
@@ -161,6 +169,17 @@ class ModelObject {
161
169
  }
162
170
  return this;
163
171
  }
172
+ /**
173
+ * Called to check if a diverging property type may be set.
174
+ * Note that this is not applicable to null values; null is always legit
175
+ * @param key Property key
176
+ * @param oldValue Old member value
177
+ * @param newValue New member value
178
+ * @returns True if the value can be set by the update call
179
+ */
180
+ checkDivergingDataType(key, oldValue, newValue) {
181
+ return false;
182
+ }
164
183
  /**
165
184
  * Wrap a nullable model object property so that type checks can be performed
166
185
  * @param key Property key of the derived class
@@ -1,17 +1,17 @@
1
1
  import ModelObject from "../../ModelObject";
2
2
  export declare enum KinematicsName {
3
3
  cartesian = "cartesian",
4
- coreXY = "corexy",
5
- coreXYU = "corexyu",
6
- coreXYUV = "corexyuv",
7
- coreXZ = "corexz",
8
- markForged = "markforged",
9
- fiveBarScara = "fivebarscara",
10
- hangprinter = "hangprinter",
4
+ coreXY = "coreXY",
5
+ coreXYU = "coreXYU",
6
+ coreXYUV = "coreXYUV",
7
+ coreXZ = "coreXZ",
8
+ markForged = "markForged",
9
+ fiveBarScara = "FiveBarScara",
10
+ hangprinter = "Hangprinter",
11
11
  delta = "delta",
12
- polar = "polar",
13
- rotaryDelta = "rotary delta",
14
- scara = "scara",
12
+ polar = "Polar",
13
+ rotaryDelta = "Rotary delta",
14
+ scara = "Scara",
15
15
  unknown = "unknown"
16
16
  }
17
17
  export declare class MoveSegmentation extends ModelObject {
@@ -5,17 +5,17 @@ const ModelObject_1 = require("../../ModelObject");
5
5
  var KinematicsName;
6
6
  (function (KinematicsName) {
7
7
  KinematicsName["cartesian"] = "cartesian";
8
- KinematicsName["coreXY"] = "corexy";
9
- KinematicsName["coreXYU"] = "corexyu";
10
- KinematicsName["coreXYUV"] = "corexyuv";
11
- KinematicsName["coreXZ"] = "corexz";
12
- KinematicsName["markForged"] = "markforged";
13
- KinematicsName["fiveBarScara"] = "fivebarscara";
14
- KinematicsName["hangprinter"] = "hangprinter";
8
+ KinematicsName["coreXY"] = "coreXY";
9
+ KinematicsName["coreXYU"] = "coreXYU";
10
+ KinematicsName["coreXYUV"] = "coreXYUV";
11
+ KinematicsName["coreXZ"] = "coreXZ";
12
+ KinematicsName["markForged"] = "markForged";
13
+ KinematicsName["fiveBarScara"] = "FiveBarScara";
14
+ KinematicsName["hangprinter"] = "Hangprinter";
15
15
  KinematicsName["delta"] = "delta";
16
- KinematicsName["polar"] = "polar";
17
- KinematicsName["rotaryDelta"] = "rotary delta";
18
- KinematicsName["scara"] = "scara";
16
+ KinematicsName["polar"] = "Polar";
17
+ KinematicsName["rotaryDelta"] = "Rotary delta";
18
+ KinematicsName["scara"] = "Scara";
19
19
  KinematicsName["unknown"] = "unknown";
20
20
  })(KinematicsName = exports.KinematicsName || (exports.KinematicsName = {}));
21
21
  class MoveSegmentation extends ModelObject_1.default {
@@ -15,9 +15,31 @@ export declare enum AnalogSensorType {
15
15
  driversDuex = "driversduex",
16
16
  unknown = "unknown"
17
17
  }
18
+ export declare enum TemperatureError {
19
+ ok = "ok",
20
+ shortCircuit = "shortCircuit",
21
+ shortToVcc = "shortToVcc",
22
+ shortToGround = "shortToGround",
23
+ openCircuit = "openCircuit",
24
+ timeout = "timeout",
25
+ ioError = "ioError",
26
+ hardwareError = "hardwareError",
27
+ notReady = "notReady",
28
+ invalidOutputNumber = "invalidOutputNumber",
29
+ busBusy = "busBusy",
30
+ badResponse = "badResponse",
31
+ unknownPort = "unknownPort",
32
+ notInitialised = "notInitialised",
33
+ unknownSensor = "unknownSensor",
34
+ overOrUnderVoltage = "overOrUnderVoltage",
35
+ badVref = "badVref",
36
+ badVssa = "badVssa",
37
+ unknownError = "unknownError"
38
+ }
18
39
  export declare class AnalogSensor extends ModelObject {
19
40
  lastReading: number | null;
20
41
  name: string | null;
42
+ state: TemperatureError;
21
43
  type: AnalogSensorType;
22
44
  }
23
45
  export default AnalogSensor;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AnalogSensor = exports.AnalogSensorType = void 0;
3
+ exports.AnalogSensor = exports.TemperatureError = exports.AnalogSensorType = void 0;
4
4
  const ModelObject_1 = require("../ModelObject");
5
5
  var AnalogSensorType;
6
6
  (function (AnalogSensorType) {
@@ -19,11 +19,34 @@ var AnalogSensorType;
19
19
  AnalogSensorType["driversDuex"] = "driversduex";
20
20
  AnalogSensorType["unknown"] = "unknown";
21
21
  })(AnalogSensorType = exports.AnalogSensorType || (exports.AnalogSensorType = {}));
22
+ var TemperatureError;
23
+ (function (TemperatureError) {
24
+ TemperatureError["ok"] = "ok";
25
+ TemperatureError["shortCircuit"] = "shortCircuit";
26
+ TemperatureError["shortToVcc"] = "shortToVcc";
27
+ TemperatureError["shortToGround"] = "shortToGround";
28
+ TemperatureError["openCircuit"] = "openCircuit";
29
+ TemperatureError["timeout"] = "timeout";
30
+ TemperatureError["ioError"] = "ioError";
31
+ TemperatureError["hardwareError"] = "hardwareError";
32
+ TemperatureError["notReady"] = "notReady";
33
+ TemperatureError["invalidOutputNumber"] = "invalidOutputNumber";
34
+ TemperatureError["busBusy"] = "busBusy";
35
+ TemperatureError["badResponse"] = "badResponse";
36
+ TemperatureError["unknownPort"] = "unknownPort";
37
+ TemperatureError["notInitialised"] = "notInitialised";
38
+ TemperatureError["unknownSensor"] = "unknownSensor";
39
+ TemperatureError["overOrUnderVoltage"] = "overOrUnderVoltage";
40
+ TemperatureError["badVref"] = "badVref";
41
+ TemperatureError["badVssa"] = "badVssa";
42
+ TemperatureError["unknownError"] = "unknownError";
43
+ })(TemperatureError = exports.TemperatureError || (exports.TemperatureError = {}));
22
44
  class AnalogSensor extends ModelObject_1.default {
23
45
  constructor() {
24
46
  super(...arguments);
25
47
  this.lastReading = null;
26
48
  this.name = null;
49
+ this.state = TemperatureError.ok;
27
50
  this.type = AnalogSensorType.unknown;
28
51
  }
29
52
  }
@@ -21,5 +21,6 @@ export declare class MessageBox extends ModelObject {
21
21
  seq: number;
22
22
  timeout: number;
23
23
  title: string;
24
+ protected checkDivergingDataType<K extends keyof this>(key: K, oldValue: this[K], newValue: any): boolean;
24
25
  }
25
26
  export default MessageBox;
@@ -28,6 +28,9 @@ class MessageBox extends ModelObject_1.default {
28
28
  this.timeout = 0;
29
29
  this.title = "";
30
30
  }
31
+ checkDivergingDataType(key, oldValue, newValue) {
32
+ return key === "default" && (typeof newValue === "number" || typeof newValue === "string");
33
+ }
31
34
  }
32
35
  exports.MessageBox = MessageBox;
33
36
  exports.default = MessageBox;
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
- {
2
- "name": "@duet3d/objectmodel",
3
- "version": "3.5.0-b9",
4
- "description": "TypeScript implementation of the Duet3D Object Model",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "test": "jest --config jestconfig.json",
9
- "build": "tsc",
10
- "prepare": "npm run build",
11
- "prepublishOnly": "npm test"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/Duet3D/ObjectModel.git"
16
- },
17
- "author": "Christian Hammacher",
18
- "license": "LGPL-2.1",
19
- "bugs": {
20
- "url": "https://github.com/Duet3D/ObjectModel/issues"
21
- },
22
- "homepage": "https://github.com/Duet3D/ObjectModel#readme",
23
- "devDependencies": {
24
- "@types/jest": "^27.5.0",
25
- "jest": "^27.5.1",
26
- "ts-jest": "^27.1.4",
27
- "typescript": "^4.6.4"
28
- },
29
- "files": [
30
- "/dist"
31
- ]
32
- }
1
+ {
2
+ "name": "@duet3d/objectmodel",
3
+ "version": "3.5.0-beta.13",
4
+ "description": "TypeScript implementation of the Duet3D Object Model",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "test": "jest --config jestconfig.json",
9
+ "build": "tsc",
10
+ "prepare": "npm run build",
11
+ "prepublishOnly": "npm test"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/Duet3D/ObjectModel.git"
16
+ },
17
+ "author": "Christian Hammacher",
18
+ "license": "LGPL-2.1",
19
+ "bugs": {
20
+ "url": "https://github.com/Duet3D/ObjectModel/issues"
21
+ },
22
+ "homepage": "https://github.com/Duet3D/ObjectModel#readme",
23
+ "devDependencies": {
24
+ "@types/jest": "^27.5.0",
25
+ "jest": "^27.5.1",
26
+ "ts-jest": "^27.1.4",
27
+ "typescript": "^4.6.4"
28
+ },
29
+ "files": [
30
+ "/dist"
31
+ ]
32
+ }