@duet3d/objectmodel 3.5.0-beta.29 → 3.5.0-beta.30

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 (127) hide show
  1. package/LICENSE +504 -504
  2. package/README.md +17 -17
  3. package/dist/ModelCollection.d.ts +37 -37
  4. package/dist/ModelCollection.js +103 -103
  5. package/dist/ModelDictionary.d.ts +46 -46
  6. package/dist/ModelDictionary.js +108 -108
  7. package/dist/ModelObject.d.ts +47 -47
  8. package/dist/ModelObject.js +212 -212
  9. package/dist/ModelSet.d.ts +11 -11
  10. package/dist/ModelSet.js +15 -15
  11. package/dist/ObjectModel.d.ts +46 -46
  12. package/dist/ObjectModel.js +53 -53
  13. package/dist/boards/index.d.ts +52 -52
  14. package/dist/boards/index.js +81 -81
  15. package/dist/directories/index.d.ts +12 -12
  16. package/dist/directories/index.js +19 -19
  17. package/dist/fans/index.d.ts +19 -19
  18. package/dist/fans/index.js +30 -30
  19. package/dist/heat/Heater.d.ts +28 -28
  20. package/dist/heat/Heater.js +36 -36
  21. package/dist/heat/HeaterModel.d.ts +21 -21
  22. package/dist/heat/HeaterModel.js +32 -32
  23. package/dist/heat/HeaterMonitor.d.ts +18 -18
  24. package/dist/heat/HeaterMonitor.js +27 -27
  25. package/dist/heat/index.d.ts +14 -14
  26. package/dist/heat/index.js +35 -35
  27. package/dist/httpEndpoints/index.d.ts +19 -19
  28. package/dist/httpEndpoints/index.js +27 -27
  29. package/dist/index.d.ts +26 -26
  30. package/dist/index.js +55 -55
  31. package/dist/inputs/CodeChannel.d.ts +18 -18
  32. package/dist/inputs/CodeChannel.js +22 -22
  33. package/dist/inputs/Compatibility.d.ts +10 -10
  34. package/dist/inputs/Compatibility.js +14 -14
  35. package/dist/inputs/InputChannel.d.ts +30 -30
  36. package/dist/inputs/InputChannel.js +39 -39
  37. package/dist/inputs/index.d.ts +3 -3
  38. package/dist/inputs/index.js +19 -19
  39. package/dist/job/Build.d.ts +15 -15
  40. package/dist/job/Build.js +26 -26
  41. package/dist/job/GCodeFileInfo.d.ts +17 -17
  42. package/dist/job/GCodeFileInfo.js +24 -24
  43. package/dist/job/ThumbnailInfo.d.ts +15 -15
  44. package/dist/job/ThumbnailInfo.js +23 -23
  45. package/dist/job/index.d.ts +40 -40
  46. package/dist/job/index.js +70 -70
  47. package/dist/limits/index.d.ts +29 -29
  48. package/dist/limits/index.js +36 -36
  49. package/dist/messages/index.d.ts +13 -13
  50. package/dist/messages/index.js +27 -27
  51. package/dist/move/Axis.d.ts +47 -46
  52. package/dist/move/Axis.js +55 -54
  53. package/dist/move/DriverId.d.ts +10 -10
  54. package/dist/move/DriverId.js +49 -49
  55. package/dist/move/Extruder.d.ts +28 -28
  56. package/dist/move/Extruder.js +39 -39
  57. package/dist/move/InputShaping.d.ts +20 -20
  58. package/dist/move/InputShaping.js +28 -28
  59. package/dist/move/KeepoutZone.d.ts +10 -0
  60. package/dist/move/KeepoutZone.js +21 -0
  61. package/dist/move/Microstepping.d.ts +6 -6
  62. package/dist/move/Microstepping.js +13 -13
  63. package/dist/move/MoveCalibration.d.ts +11 -11
  64. package/dist/move/MoveCalibration.js +22 -22
  65. package/dist/move/MoveCompensation.d.ts +30 -30
  66. package/dist/move/MoveCompensation.js +47 -47
  67. package/dist/move/index.d.ts +60 -56
  68. package/dist/move/index.js +97 -93
  69. package/dist/move/kinematics/CoreKinematics.d.ts +9 -9
  70. package/dist/move/kinematics/CoreKinematics.js +31 -31
  71. package/dist/move/kinematics/DeltaKinematics.d.ts +20 -20
  72. package/dist/move/kinematics/DeltaKinematics.js +40 -40
  73. package/dist/move/kinematics/HangprinterKinematics.d.ts +9 -9
  74. package/dist/move/kinematics/HangprinterKinematics.js +28 -28
  75. package/dist/move/kinematics/KinematicsBase.d.ts +37 -37
  76. package/dist/move/kinematics/KinematicsBase.js +56 -56
  77. package/dist/move/kinematics/PolarKinematics.d.ts +7 -7
  78. package/dist/move/kinematics/PolarKinematics.js +21 -21
  79. package/dist/move/kinematics/ScaraKinematics.d.ts +6 -6
  80. package/dist/move/kinematics/ScaraKinematics.js +18 -18
  81. package/dist/move/kinematics/index.d.ts +14 -14
  82. package/dist/move/kinematics/index.js +70 -70
  83. package/dist/network/NetworkInterface.d.ts +41 -41
  84. package/dist/network/NetworkInterface.js +51 -51
  85. package/dist/network/index.d.ts +14 -14
  86. package/dist/network/index.js +35 -35
  87. package/dist/plugins/PluginManifest.d.ts +64 -64
  88. package/dist/plugins/PluginManifest.js +114 -114
  89. package/dist/plugins/index.d.ts +9 -9
  90. package/dist/plugins/index.js +30 -30
  91. package/dist/sensors/AnalogSensor.d.ts +48 -45
  92. package/dist/sensors/AnalogSensor.js +57 -54
  93. package/dist/sensors/Endstop.d.ts +14 -14
  94. package/dist/sensors/Endstop.js +22 -22
  95. package/dist/sensors/FilamentMonitors/FilamentMonitorBase.d.ts +24 -24
  96. package/dist/sensors/FilamentMonitors/FilamentMonitorBase.js +32 -32
  97. package/dist/sensors/FilamentMonitors/LaserFilamentMonitor.d.ts +22 -22
  98. package/dist/sensors/FilamentMonitors/LaserFilamentMonitor.js +46 -46
  99. package/dist/sensors/FilamentMonitors/PulsedFilamentMonitor.d.ts +21 -21
  100. package/dist/sensors/FilamentMonitors/PulsedFilamentMonitor.js +45 -45
  101. package/dist/sensors/FilamentMonitors/RotatingMagnetFilamentMonitor.d.ts +22 -22
  102. package/dist/sensors/FilamentMonitors/RotatingMagnetFilamentMonitor.js +46 -46
  103. package/dist/sensors/FilamentMonitors/index.d.ts +11 -11
  104. package/dist/sensors/FilamentMonitors/index.js +51 -51
  105. package/dist/sensors/Probe.d.ts +33 -33
  106. package/dist/sensors/Probe.js +41 -41
  107. package/dist/sensors/index.d.ts +21 -21
  108. package/dist/sensors/index.js +46 -46
  109. package/dist/spindles/index.d.ts +20 -20
  110. package/dist/spindles/index.js +28 -28
  111. package/dist/state/MachineStatus.d.ts +17 -17
  112. package/dist/state/MachineStatus.js +21 -21
  113. package/dist/state/MessageBox.d.ts +26 -26
  114. package/dist/state/MessageBox.js +39 -39
  115. package/dist/state/RestorePoint.d.ts +12 -12
  116. package/dist/state/RestorePoint.js +19 -19
  117. package/dist/state/index.d.ts +63 -63
  118. package/dist/state/index.js +100 -100
  119. package/dist/tools/index.d.ts +26 -26
  120. package/dist/tools/index.js +34 -34
  121. package/dist/userSessions/index.d.ts +18 -18
  122. package/dist/userSessions/index.js +27 -27
  123. package/dist/volumes/index.d.ts +11 -11
  124. package/dist/volumes/index.js +18 -18
  125. package/package.json +32 -32
  126. package/dist/scanner/index.d.ts +0 -14
  127. package/dist/scanner/index.js +0 -22
@@ -1,47 +1,47 @@
1
- /**
2
- * Interface for updating model objects using JSON data
3
- */
4
- export interface IModelObject {
5
- /**
6
- * Update this instance from the given data
7
- * @param jsonElement JSON data to upgrade this instance from
8
- * @returns Updated instance (may not equal the original instance)
9
- */
10
- update(jsonElement: any): IModelObject | null;
11
- }
12
- /**
13
- * Check whether a given value provides model update functionality
14
- * @param value Value to check
15
- */
16
- export declare function isModelObject(value: any): value is IModelObject;
17
- /**
18
- * Base class for object model classes
19
- */
20
- export declare abstract class ModelObject implements IModelObject {
21
- /**
22
- * Update this instance from the given data
23
- * @param jsonElement JSON data to upgrade this instance from
24
- * @returns Updated instance (may not equal the original instance)
25
- */
26
- update(jsonElement: any): IModelObject | null;
27
- /**
28
- * Wrap a nullable model object property so that type checks can be performed
29
- * @param key Property key of the derived class
30
- * @param constructor Constructor for creating new elements
31
- */
32
- static wrapModelProperty<S extends IModelObject, K extends keyof S, T extends IModelObject>(self: S, key: K, constructor: {
33
- new (): T;
34
- }): void;
35
- }
36
- export default ModelObject;
37
- /**
38
- * Initialize a model object from the given data
39
- * @param itemType Model type to create
40
- * @param data Data to assign
41
- * @returns Initialized model instance
42
- */
43
- export declare function initObject<T>(itemType: {
44
- new (): T;
45
- }, data: {
46
- [Property in keyof T]?: T[Property];
47
- }): T;
1
+ /**
2
+ * Interface for updating model objects using JSON data
3
+ */
4
+ export interface IModelObject {
5
+ /**
6
+ * Update this instance from the given data
7
+ * @param jsonElement JSON data to upgrade this instance from
8
+ * @returns Updated instance (may not equal the original instance)
9
+ */
10
+ update(jsonElement: any): IModelObject | null;
11
+ }
12
+ /**
13
+ * Check whether a given value provides model update functionality
14
+ * @param value Value to check
15
+ */
16
+ export declare function isModelObject(value: any): value is IModelObject;
17
+ /**
18
+ * Base class for object model classes
19
+ */
20
+ export declare abstract class ModelObject implements IModelObject {
21
+ /**
22
+ * Update this instance from the given data
23
+ * @param jsonElement JSON data to upgrade this instance from
24
+ * @returns Updated instance (may not equal the original instance)
25
+ */
26
+ update(jsonElement: any): IModelObject | null;
27
+ /**
28
+ * Wrap a nullable model object property so that type checks can be performed
29
+ * @param key Property key of the derived class
30
+ * @param constructor Constructor for creating new elements
31
+ */
32
+ static wrapModelProperty<S extends IModelObject, K extends keyof S, T extends IModelObject>(self: S, key: K, constructor: {
33
+ new (): T;
34
+ }): void;
35
+ }
36
+ export default ModelObject;
37
+ /**
38
+ * Initialize a model object from the given data
39
+ * @param itemType Model type to create
40
+ * @param data Data to assign
41
+ * @returns Initialized model instance
42
+ */
43
+ export declare function initObject<T>(itemType: {
44
+ new (): T;
45
+ }, data: {
46
+ [Property in keyof T]?: T[Property];
47
+ }): T;
@@ -1,212 +1,212 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initObject = exports.ModelObject = exports.isModelObject = void 0;
4
- const index_1 = require("./index");
5
- /**
6
- * Check whether a given value provides model update functionality
7
- * @param value Value to check
8
- */
9
- function isModelObject(value) {
10
- return (value instanceof Object) && value.update !== undefined;
11
- }
12
- exports.isModelObject = isModelObject;
13
- /**
14
- * Base class for object model classes
15
- */
16
- class ModelObject {
17
- /**
18
- * Update this instance from the given data
19
- * @param jsonElement JSON data to upgrade this instance from
20
- * @returns Updated instance (may not equal the original instance)
21
- */
22
- update(jsonElement) {
23
- if (jsonElement === null) {
24
- return null;
25
- }
26
- for (const [key, value] of Object.entries(jsonElement)) {
27
- if (key in this) {
28
- const ownKey = key;
29
- const prop = this[ownKey];
30
- if (isModelObject(prop)) {
31
- // Update model objects
32
- const updatedObject = prop.update(value);
33
- if (prop !== updatedObject) {
34
- const propDescriptor = Object.getOwnPropertyDescriptor(this, key);
35
- if (propDescriptor !== undefined) {
36
- if (propDescriptor.writable) {
37
- this[ownKey] = updatedObject;
38
- }
39
- else if (propDescriptor.set !== undefined) {
40
- propDescriptor.set(updatedObject);
41
- }
42
- else if (process.env.NODE_ENV !== "production") {
43
- console.warn(`Model object ${key} changed but it could not be set due to missing setter`);
44
- }
45
- }
46
- else if (process.env.NODE_ENV !== "production") {
47
- console.warn(`Model object ${key} changed but it lacks the property descriptor`);
48
- }
49
- }
50
- }
51
- else if (prop instanceof Array) {
52
- if (value instanceof Array) {
53
- // Remove deleted items
54
- prop.splice(value.length);
55
- // Update existing items
56
- for (let i = 0; i < Math.min(prop.length, value.length); i++) {
57
- const propItem = prop[i];
58
- if (propItem === null) {
59
- (0, index_1.setArrayItem)(prop, i, value[i]);
60
- }
61
- else {
62
- const newItem = value[i];
63
- if (propItem !== newItem) {
64
- (0, index_1.setArrayItem)(prop, i, newItem);
65
- }
66
- }
67
- }
68
- // Add new items
69
- for (let i = prop.length; i < value.length; i++) {
70
- prop.push(value[i]);
71
- }
72
- }
73
- else if (value === null) {
74
- // Arrays may be assignable to null
75
- this[ownKey] = value;
76
- }
77
- else if (process.env.NODE_ENV !== "production") {
78
- console.warn(`Model array ${key} could not be changed because the target type ${typeof value} is invalid`);
79
- }
80
- }
81
- else if (prop instanceof Set) {
82
- if (value instanceof Array || value instanceof Set) {
83
- // Remove deleted items
84
- for (let item of new Set(prop)) {
85
- if (!prop.has(item)) {
86
- prop.delete(item);
87
- }
88
- }
89
- // Add new items
90
- for (let item of value) {
91
- if (!prop.has(item)) {
92
- prop.add(item);
93
- }
94
- }
95
- }
96
- else if (value === null) {
97
- // Sets may be assignable to null
98
- this[ownKey] = value;
99
- }
100
- else if (process.env.NODE_ENV !== "production") {
101
- console.warn(`Model set ${key} could not be changed because the target type ${typeof value} is invalid`);
102
- }
103
- }
104
- else if (prop === null || value === null) {
105
- // Unfortunately we cannot do type checks during runtime without excessive extra work and possibly
106
- // third-party libraries, so skip them for null values until there is a better solution.
107
- // FWIW, we would just need "typeof prop" but TS does not seem to be capable of providing this.
108
- this[ownKey] = value;
109
- }
110
- else {
111
- const propType = typeof prop;
112
- if (propType === "boolean") {
113
- if (typeof value === "boolean") {
114
- this[ownKey] = value;
115
- }
116
- else if (typeof value === "number") {
117
- // RRF used to report booleans as integers so convert them if necessary
118
- this[ownKey] = Boolean(value);
119
- }
120
- else if (process.env.NODE_ENV !== "production") {
121
- console.warn(`Incompatible bool target type ${typeof value} for property ${key}`);
122
- }
123
- }
124
- else if (propType === "number") {
125
- if (typeof value === "number" || typeof value === "bigint") {
126
- this[ownKey] = value;
127
- }
128
- else if (process.env.NODE_ENV !== "production") {
129
- console.warn(`Incompatible number target type ${typeof value} for property ${key}`);
130
- }
131
- }
132
- else if (propType === "bigint") {
133
- if (typeof value === "number" || typeof value === "bigint") {
134
- this[ownKey] = value;
135
- }
136
- else if (process.env.NODE_ENV !== "production") {
137
- console.warn(`Incompatible bigint target type ${typeof value} for property ${key}`);
138
- }
139
- }
140
- else if (propType === "string") {
141
- if (typeof value === "string") {
142
- this[ownKey] = value;
143
- }
144
- else if (process.env.NODE_ENV !== "production") {
145
- console.warn(`Incompatible string target type ${typeof value} for property ${key}`);
146
- }
147
- }
148
- else if (propType === "function") {
149
- if (typeof value === "function") {
150
- this[ownKey] = value;
151
- }
152
- else if (process.env.NODE_ENV !== "production") {
153
- console.warn(`Incompatible function target type ${typeof value} for property ${key}`);
154
- }
155
- }
156
- else if (propType === "object") {
157
- if (typeof value === "object") {
158
- this[ownKey] = value;
159
- }
160
- else if (process.env.NODE_ENV !== "production") {
161
- console.warn(`Incompatible object target type ${typeof value} for property ${key}`);
162
- }
163
- }
164
- else if (process.env.NODE_ENV !== "production") {
165
- console.warn(`Incompatible type ${propType} for property ${key} (${typeof value})`);
166
- }
167
- }
168
- }
169
- }
170
- return this;
171
- }
172
- /**
173
- * Wrap a nullable model object property so that type checks can be performed
174
- * @param key Property key of the derived class
175
- * @param constructor Constructor for creating new elements
176
- */
177
- static wrapModelProperty(self, key, constructor) {
178
- let propertyValue = self[key];
179
- Object.defineProperty(self, key, {
180
- get() { return propertyValue; },
181
- set(newValue) {
182
- if (newValue === null) {
183
- propertyValue = null;
184
- }
185
- else if (propertyValue !== null) {
186
- const newModel = propertyValue.update(newValue);
187
- if (propertyValue !== newModel) {
188
- propertyValue = newModel;
189
- }
190
- }
191
- else {
192
- const newModel = new constructor();
193
- propertyValue = newModel.update(newValue);
194
- }
195
- },
196
- configurable: true,
197
- enumerable: true
198
- });
199
- }
200
- }
201
- exports.ModelObject = ModelObject;
202
- exports.default = ModelObject;
203
- /**
204
- * Initialize a model object from the given data
205
- * @param itemType Model type to create
206
- * @param data Data to assign
207
- * @returns Initialized model instance
208
- */
209
- function initObject(itemType, data) {
210
- return new itemType().update(data);
211
- }
212
- exports.initObject = initObject;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initObject = exports.ModelObject = exports.isModelObject = void 0;
4
+ const index_1 = require("./index");
5
+ /**
6
+ * Check whether a given value provides model update functionality
7
+ * @param value Value to check
8
+ */
9
+ function isModelObject(value) {
10
+ return (value instanceof Object) && value.update !== undefined;
11
+ }
12
+ exports.isModelObject = isModelObject;
13
+ /**
14
+ * Base class for object model classes
15
+ */
16
+ class ModelObject {
17
+ /**
18
+ * Update this instance from the given data
19
+ * @param jsonElement JSON data to upgrade this instance from
20
+ * @returns Updated instance (may not equal the original instance)
21
+ */
22
+ update(jsonElement) {
23
+ if (jsonElement === null) {
24
+ return null;
25
+ }
26
+ for (const [key, value] of Object.entries(jsonElement)) {
27
+ if (key in this) {
28
+ const ownKey = key;
29
+ const prop = this[ownKey];
30
+ if (isModelObject(prop)) {
31
+ // Update model objects
32
+ const updatedObject = prop.update(value);
33
+ if (prop !== updatedObject) {
34
+ const propDescriptor = Object.getOwnPropertyDescriptor(this, key);
35
+ if (propDescriptor !== undefined) {
36
+ if (propDescriptor.writable) {
37
+ this[ownKey] = updatedObject;
38
+ }
39
+ else if (propDescriptor.set !== undefined) {
40
+ propDescriptor.set(updatedObject);
41
+ }
42
+ else if (process.env.NODE_ENV !== "production") {
43
+ console.warn(`Model object ${key} changed but it could not be set due to missing setter`);
44
+ }
45
+ }
46
+ else if (process.env.NODE_ENV !== "production") {
47
+ console.warn(`Model object ${key} changed but it lacks the property descriptor`);
48
+ }
49
+ }
50
+ }
51
+ else if (prop instanceof Array) {
52
+ if (value instanceof Array) {
53
+ // Remove deleted items
54
+ prop.splice(value.length);
55
+ // Update existing items
56
+ for (let i = 0; i < Math.min(prop.length, value.length); i++) {
57
+ const propItem = prop[i];
58
+ if (propItem === null) {
59
+ (0, index_1.setArrayItem)(prop, i, value[i]);
60
+ }
61
+ else {
62
+ const newItem = value[i];
63
+ if (propItem !== newItem) {
64
+ (0, index_1.setArrayItem)(prop, i, newItem);
65
+ }
66
+ }
67
+ }
68
+ // Add new items
69
+ for (let i = prop.length; i < value.length; i++) {
70
+ prop.push(value[i]);
71
+ }
72
+ }
73
+ else if (value === null) {
74
+ // Arrays may be assignable to null
75
+ this[ownKey] = value;
76
+ }
77
+ else if (process.env.NODE_ENV !== "production") {
78
+ console.warn(`Model array ${key} could not be changed because the target type ${typeof value} is invalid`);
79
+ }
80
+ }
81
+ else if (prop instanceof Set) {
82
+ if (value instanceof Array || value instanceof Set) {
83
+ // Remove deleted items
84
+ for (let item of new Set(prop)) {
85
+ if (!prop.has(item)) {
86
+ prop.delete(item);
87
+ }
88
+ }
89
+ // Add new items
90
+ for (let item of value) {
91
+ if (!prop.has(item)) {
92
+ prop.add(item);
93
+ }
94
+ }
95
+ }
96
+ else if (value === null) {
97
+ // Sets may be assignable to null
98
+ this[ownKey] = value;
99
+ }
100
+ else if (process.env.NODE_ENV !== "production") {
101
+ console.warn(`Model set ${key} could not be changed because the target type ${typeof value} is invalid`);
102
+ }
103
+ }
104
+ else if (prop === null || value === null) {
105
+ // Unfortunately we cannot do type checks during runtime without excessive extra work and possibly
106
+ // third-party libraries, so skip them for null values until there is a better solution.
107
+ // FWIW, we would just need "typeof prop" but TS does not seem to be capable of providing this.
108
+ this[ownKey] = value;
109
+ }
110
+ else {
111
+ const propType = typeof prop;
112
+ if (propType === "boolean") {
113
+ if (typeof value === "boolean") {
114
+ this[ownKey] = value;
115
+ }
116
+ else if (typeof value === "number") {
117
+ // RRF used to report booleans as integers so convert them if necessary
118
+ this[ownKey] = Boolean(value);
119
+ }
120
+ else if (process.env.NODE_ENV !== "production") {
121
+ console.warn(`Incompatible bool target type ${typeof value} for property ${key}`);
122
+ }
123
+ }
124
+ else if (propType === "number") {
125
+ if (typeof value === "number" || typeof value === "bigint") {
126
+ this[ownKey] = value;
127
+ }
128
+ else if (process.env.NODE_ENV !== "production") {
129
+ console.warn(`Incompatible number target type ${typeof value} for property ${key}`);
130
+ }
131
+ }
132
+ else if (propType === "bigint") {
133
+ if (typeof value === "number" || typeof value === "bigint") {
134
+ this[ownKey] = value;
135
+ }
136
+ else if (process.env.NODE_ENV !== "production") {
137
+ console.warn(`Incompatible bigint target type ${typeof value} for property ${key}`);
138
+ }
139
+ }
140
+ else if (propType === "string") {
141
+ if (typeof value === "string") {
142
+ this[ownKey] = value;
143
+ }
144
+ else if (process.env.NODE_ENV !== "production") {
145
+ console.warn(`Incompatible string target type ${typeof value} for property ${key}`);
146
+ }
147
+ }
148
+ else if (propType === "function") {
149
+ if (typeof value === "function") {
150
+ this[ownKey] = value;
151
+ }
152
+ else if (process.env.NODE_ENV !== "production") {
153
+ console.warn(`Incompatible function target type ${typeof value} for property ${key}`);
154
+ }
155
+ }
156
+ else if (propType === "object") {
157
+ if (typeof value === "object") {
158
+ this[ownKey] = value;
159
+ }
160
+ else if (process.env.NODE_ENV !== "production") {
161
+ console.warn(`Incompatible object target type ${typeof value} for property ${key}`);
162
+ }
163
+ }
164
+ else if (process.env.NODE_ENV !== "production") {
165
+ console.warn(`Incompatible type ${propType} for property ${key} (${typeof value})`);
166
+ }
167
+ }
168
+ }
169
+ }
170
+ return this;
171
+ }
172
+ /**
173
+ * Wrap a nullable model object property so that type checks can be performed
174
+ * @param key Property key of the derived class
175
+ * @param constructor Constructor for creating new elements
176
+ */
177
+ static wrapModelProperty(self, key, constructor) {
178
+ let propertyValue = self[key];
179
+ Object.defineProperty(self, key, {
180
+ get() { return propertyValue; },
181
+ set(newValue) {
182
+ if (newValue === null) {
183
+ propertyValue = null;
184
+ }
185
+ else if (propertyValue !== null) {
186
+ const newModel = propertyValue.update(newValue);
187
+ if (propertyValue !== newModel) {
188
+ propertyValue = newModel;
189
+ }
190
+ }
191
+ else {
192
+ const newModel = new constructor();
193
+ propertyValue = newModel.update(newValue);
194
+ }
195
+ },
196
+ configurable: true,
197
+ enumerable: true
198
+ });
199
+ }
200
+ }
201
+ exports.ModelObject = ModelObject;
202
+ exports.default = ModelObject;
203
+ /**
204
+ * Initialize a model object from the given data
205
+ * @param itemType Model type to create
206
+ * @param data Data to assign
207
+ * @returns Initialized model instance
208
+ */
209
+ function initObject(itemType, data) {
210
+ return new itemType().update(data);
211
+ }
212
+ exports.initObject = initObject;
@@ -1,11 +1,11 @@
1
- /**
2
- * Wrapper around a standard set to make sure it serializes to an array
3
- */
4
- export declare class ModelSet<T> extends Set<T> {
5
- /**
6
- * Convert this object to JSON
7
- * @returns JSON object
8
- */
9
- toJSON(): T[];
10
- }
11
- export default ModelSet;
1
+ /**
2
+ * Wrapper around a standard set to make sure it serializes to an array
3
+ */
4
+ export declare class ModelSet<T> extends Set<T> {
5
+ /**
6
+ * Convert this object to JSON
7
+ * @returns JSON object
8
+ */
9
+ toJSON(): T[];
10
+ }
11
+ export default ModelSet;
package/dist/ModelSet.js CHANGED
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModelSet = void 0;
4
- /**
5
- * Wrapper around a standard set to make sure it serializes to an array
6
- */
7
- class ModelSet extends Set {
8
- /**
9
- * Convert this object to JSON
10
- * @returns JSON object
11
- */
12
- toJSON() { return Array.from(this); }
13
- }
14
- exports.ModelSet = ModelSet;
15
- exports.default = ModelSet;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModelSet = void 0;
4
+ /**
5
+ * Wrapper around a standard set to make sure it serializes to an array
6
+ */
7
+ class ModelSet extends Set {
8
+ /**
9
+ * Convert this object to JSON
10
+ * @returns JSON object
11
+ */
12
+ toJSON() { return Array.from(this); }
13
+ }
14
+ exports.ModelSet = ModelSet;
15
+ exports.default = ModelSet;