@duet3d/objectmodel 3.5.0-beta.15 → 3.5.0-beta.17

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.
@@ -96,8 +96,7 @@ function initCollection(itemType, data) {
96
96
  const result = new ModelCollection(itemType);
97
97
  for (let presetItem of data) {
98
98
  const item = new itemType();
99
- item.update(presetItem);
100
- result.push(item);
99
+ result.push(item.update(presetItem));
101
100
  }
102
101
  return result;
103
102
  }
@@ -45,6 +45,7 @@ class ModelDictionary extends Map {
45
45
  if (currentItem !== newItem) {
46
46
  return super.set(key, value);
47
47
  }
48
+ return this;
48
49
  }
49
50
  return super.set(key, value);
50
51
  }
@@ -218,33 +218,6 @@ exports.default = ModelObject;
218
218
  * @returns Initialized model instance
219
219
  */
220
220
  function initObject(itemType, data) {
221
- const result = new itemType();
222
- for (let key in data) {
223
- const resultKey = result[key];
224
- if (isModelObject(resultKey)) {
225
- const updatedObject = resultKey.update(data[key]);
226
- if (resultKey !== updatedObject) {
227
- const propDescriptor = Object.getOwnPropertyDescriptor(result, key);
228
- if (propDescriptor !== undefined) {
229
- if (propDescriptor.writable) {
230
- result[key] = updatedObject;
231
- }
232
- else if (propDescriptor.set !== undefined) {
233
- propDescriptor.set(updatedObject);
234
- }
235
- else if (process.env.NODE_ENV !== "production") {
236
- console.warn(`Model object ${key} changed but it could not be set due to missing setter`);
237
- }
238
- }
239
- else if (process.env.NODE_ENV !== "production") {
240
- console.warn(`Model object ${key} changed but it lacks the property descriptor`);
241
- }
242
- }
243
- }
244
- else {
245
- result[key] = data[key];
246
- }
247
- }
248
- return result;
221
+ return new itemType().update(data);
249
222
  }
250
223
  exports.initObject = initObject;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Wrapper around a standard set to make sure it serializes to an array
3
+ */
4
+ export default class ModelSet<T> extends Set<T> {
5
+ /**
6
+ * Convert this object to JSON
7
+ * @returns JSON object
8
+ */
9
+ toJSON(): T[];
10
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Wrapper around a standard set to make sure it serializes to an array
5
+ */
6
+ class ModelSet extends Set {
7
+ /**
8
+ * Convert this object to JSON
9
+ * @returns JSON object
10
+ */
11
+ toJSON() { return Array.from(this); }
12
+ }
13
+ exports.default = ModelSet;
@@ -1,4 +1,5 @@
1
1
  import ModelObject from "../ModelObject";
2
+ import ModelSet from "../ModelSet";
2
3
  export declare enum NetworkProtocol {
3
4
  HTTP = "http",
4
5
  HTTPS = "https",
@@ -23,7 +24,7 @@ export declare enum NetworkInterfaceType {
23
24
  wifi = "wifi"
24
25
  }
25
26
  export declare class NetworkInterface extends ModelObject {
26
- activeProtocols: Set<NetworkProtocol>;
27
+ activeProtocols: ModelSet<NetworkProtocol>;
27
28
  actualIP: string | null;
28
29
  configuredIP: string | null;
29
30
  dnsServer: string | null;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NetworkInterface = exports.NetworkInterfaceType = exports.NetworkInterfaceState = exports.NetworkProtocol = void 0;
4
4
  const ModelObject_1 = require("../ModelObject");
5
+ const ModelSet_1 = require("../ModelSet");
5
6
  var NetworkProtocol;
6
7
  (function (NetworkProtocol) {
7
8
  NetworkProtocol["HTTP"] = "http";
@@ -31,7 +32,7 @@ var NetworkInterfaceType;
31
32
  class NetworkInterface extends ModelObject_1.default {
32
33
  constructor() {
33
34
  super(...arguments);
34
- this.activeProtocols = new Set();
35
+ this.activeProtocols = new ModelSet_1.default();
35
36
  this.actualIP = null;
36
37
  this.configuredIP = null;
37
38
  this.dnsServer = null;
@@ -1,4 +1,5 @@
1
1
  import ModelObject from "../ModelObject";
2
+ import ModelSet from "../ModelSet";
2
3
  export declare enum SbcPermission {
3
4
  none = "none",
4
5
  commandExecution = "commandExecution",
@@ -52,7 +53,7 @@ export declare class PluginManifest extends ModelObject {
52
53
  sbcExecutableArguments: string | null;
53
54
  sbcExtraExecutables: Array<string>;
54
55
  sbcOutputRedirected: boolean;
55
- sbcPermissions: Set<SbcPermission>;
56
+ sbcPermissions: ModelSet<SbcPermission>;
56
57
  sbcPackageDependencies: Array<string>;
57
58
  sbcPluginDependencies: Array<string>;
58
59
  sbcPythonDependencies: Array<string>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PluginManifest = exports.SbcPermission = void 0;
4
4
  const ModelObject_1 = require("../ModelObject");
5
+ const ModelSet_1 = require("../ModelSet");
5
6
  var SbcPermission;
6
7
  (function (SbcPermission) {
7
8
  SbcPermission["none"] = "none";
@@ -57,7 +58,7 @@ class PluginManifest extends ModelObject_1.default {
57
58
  this.sbcExecutableArguments = null;
58
59
  this.sbcExtraExecutables = [];
59
60
  this.sbcOutputRedirected = true;
60
- this.sbcPermissions = new Set();
61
+ this.sbcPermissions = new ModelSet_1.default();
61
62
  this.sbcPackageDependencies = [];
62
63
  this.sbcPluginDependencies = [];
63
64
  this.sbcPythonDependencies = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duet3d/objectmodel",
3
- "version": "3.5.0-beta.15",
3
+ "version": "3.5.0-beta.17",
4
4
  "description": "TypeScript implementation of the Duet3D Object Model",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",