@duet3d/objectmodel 3.7.0-beta.7 → 3.7.0-beta.8

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.
@@ -22,11 +22,12 @@ export declare function isModelObject(value: any): value is IModelObject;
22
22
  */
23
23
  export declare abstract class ModelObject implements IModelObject {
24
24
  /**
25
- * Reset the properties that may hold null and are missing from the given authoritative data.
26
- * Overridden where an instance never receives a complete snapshot of itself
27
- * @param jsonElement JSON data this instance is being updated from
25
+ * Whether an authoritative update may reset the properties of this class that are missing from it.
26
+ * Set to false where an instance never receives a complete snapshot of itself. Deliberately static
27
+ * because an instance member would become part of the structural type and break consumers that hold
28
+ * a mapped version of the model, such as a Pinia store
28
29
  */
29
- protected resetMissingProperties(jsonElement: any): void;
30
+ static readonly resetsMissingProperties: boolean;
30
31
  /**
31
32
  * Update this instance from the given data
32
33
  * @param jsonElement JSON data to upgrade this instance from
@@ -40,18 +40,6 @@ export function isModelObject(value) {
40
40
  * Base class for object model classes
41
41
  */
42
42
  export class ModelObject {
43
- /**
44
- * Reset the properties that may hold null and are missing from the given authoritative data.
45
- * Overridden where an instance never receives a complete snapshot of itself
46
- * @param jsonElement JSON data this instance is being updated from
47
- */
48
- resetMissingProperties(jsonElement) {
49
- for (const key of getNullableProperties(this)) {
50
- if (!(key in jsonElement)) {
51
- this[key] = null;
52
- }
53
- }
54
- }
55
43
  /**
56
44
  * Update this instance from the given data
57
45
  * @param jsonElement JSON data to upgrade this instance from
@@ -62,8 +50,12 @@ export class ModelObject {
62
50
  if (jsonElement === null) {
63
51
  return null;
64
52
  }
65
- if (authoritative) {
66
- this.resetMissingProperties(jsonElement);
53
+ if (authoritative && this.constructor.resetsMissingProperties) {
54
+ for (const key of getNullableProperties(this)) {
55
+ if (!(key in jsonElement)) {
56
+ this[key] = null;
57
+ }
58
+ }
67
59
  }
68
60
  for (const [key, value] of Object.entries(jsonElement)) {
69
61
  if (key in this) {
@@ -265,6 +257,13 @@ export class ModelObject {
265
257
  });
266
258
  }
267
259
  }
260
+ /**
261
+ * Whether an authoritative update may reset the properties of this class that are missing from it.
262
+ * Set to false where an instance never receives a complete snapshot of itself. Deliberately static
263
+ * because an instance member would become part of the structural type and break consumers that hold
264
+ * a mapped version of the model, such as a Pinia store
265
+ */
266
+ ModelObject.resetsMissingProperties = true;
268
267
  export default ModelObject;
269
268
  /**
270
269
  * Initialize a model object from the given data
@@ -28,7 +28,7 @@ export declare class ObjectModel extends ModelObject {
28
28
  * A payload handed to the root always covers a subset of the top-level keys rather than the whole model,
29
29
  * so authoritative reconstruction has to start one level below it
30
30
  */
31
- protected resetMissingProperties(): void;
31
+ static readonly resetsMissingProperties: boolean;
32
32
  readonly boards: ModelCollection<Board>;
33
33
  readonly directories: Directories;
34
34
  readonly fans: ModelCollection<Fan | null>;
@@ -46,10 +46,10 @@ export class ObjectModel extends ModelObject {
46
46
  this.volumes = new ModelCollection(Volume);
47
47
  ModelObject.wrapModelProperty(this, "sbc", SBC);
48
48
  }
49
- /**
50
- * A payload handed to the root always covers a subset of the top-level keys rather than the whole model,
51
- * so authoritative reconstruction has to start one level below it
52
- */
53
- resetMissingProperties() { }
54
49
  }
50
+ /**
51
+ * A payload handed to the root always covers a subset of the top-level keys rather than the whole model,
52
+ * so authoritative reconstruction has to start one level below it
53
+ */
54
+ ObjectModel.resetsMissingProperties = false;
55
55
  export default ObjectModel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duet3d/objectmodel",
3
- "version": "3.7.0-beta.7",
3
+ "version": "3.7.0-beta.8",
4
4
  "description": "TypeScript implementation of the Duet3D Object Model",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",