@duet3d/objectmodel 3.5.0-beta.42 → 3.5.0-beta.44
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.
- package/dist/ModelCollection.d.ts +37 -0
- package/dist/ModelCollection.js +103 -0
- package/dist/ModelDictionary.d.ts +46 -0
- package/dist/ModelDictionary.js +108 -0
- package/dist/ModelObject.d.ts +47 -0
- package/dist/ModelObject.js +212 -0
- package/dist/ModelSet.d.ts +11 -0
- package/dist/ModelSet.js +15 -0
- package/dist/ObjectModel.d.ts +47 -0
- package/dist/ObjectModel.js +54 -0
- package/dist/boards/index.d.ts +52 -0
- package/dist/boards/index.js +81 -0
- package/dist/directories/index.d.ts +11 -0
- package/dist/directories/index.js +18 -0
- package/dist/fans/index.d.ts +19 -0
- package/dist/fans/index.js +30 -0
- package/dist/heat/Heater.d.ts +28 -0
- package/dist/heat/Heater.js +36 -0
- package/dist/heat/HeaterModel.d.ts +21 -0
- package/dist/heat/HeaterModel.js +32 -0
- package/dist/heat/HeaterMonitor.d.ts +18 -0
- package/dist/heat/HeaterMonitor.js +27 -0
- package/dist/heat/index.d.ts +14 -0
- package/dist/heat/index.js +35 -0
- package/dist/index.d.ts +26 -0
- package/dist/inputs/CodeChannel.d.ts +18 -0
- package/dist/inputs/CodeChannel.js +22 -0
- package/dist/inputs/Compatibility.d.ts +10 -0
- package/dist/inputs/Compatibility.js +14 -0
- package/dist/inputs/InputChannel.d.ts +30 -0
- package/dist/inputs/InputChannel.js +39 -0
- package/dist/inputs/index.d.ts +3 -0
- package/dist/inputs/index.js +19 -0
- package/dist/job/Build.d.ts +15 -0
- package/dist/job/Build.js +26 -0
- package/dist/job/GCodeFileInfo.d.ts +17 -0
- package/dist/job/GCodeFileInfo.js +24 -0
- package/dist/job/ThumbnailInfo.d.ts +15 -0
- package/dist/job/ThumbnailInfo.js +23 -0
- package/dist/job/index.d.ts +40 -0
- package/dist/job/index.js +70 -0
- package/dist/limits/index.d.ts +29 -0
- package/dist/limits/index.js +36 -0
- package/dist/messages/index.d.ts +13 -0
- package/dist/messages/index.js +27 -0
- package/dist/move/Axis.d.ts +47 -0
- package/dist/move/Axis.js +55 -0
- package/dist/move/DriverId.d.ts +10 -0
- package/dist/move/DriverId.js +49 -0
- package/dist/move/Extruder.d.ts +28 -0
- package/dist/move/Extruder.js +39 -0
- package/dist/move/InputShaping.d.ts +20 -0
- package/dist/move/InputShaping.js +28 -0
- package/dist/move/KeepoutZone.d.ts +10 -0
- package/dist/move/KeepoutZone.js +21 -0
- package/dist/move/Microstepping.d.ts +6 -0
- package/dist/move/Microstepping.js +13 -0
- package/dist/move/MoveCalibration.d.ts +11 -0
- package/dist/move/MoveCalibration.js +22 -0
- package/dist/move/MoveCompensation.d.ts +30 -0
- package/dist/move/MoveCompensation.js +47 -0
- package/dist/move/index.d.ts +61 -0
- package/dist/move/index.js +98 -0
- package/dist/move/kinematics/CoreKinematics.d.ts +9 -0
- package/dist/move/kinematics/CoreKinematics.js +31 -0
- package/dist/move/kinematics/DeltaKinematics.d.ts +20 -0
- package/dist/move/kinematics/DeltaKinematics.js +40 -0
- package/dist/move/kinematics/HangprinterKinematics.d.ts +9 -0
- package/dist/move/kinematics/HangprinterKinematics.js +28 -0
- package/dist/move/kinematics/KinematicsBase.d.ts +37 -0
- package/dist/move/kinematics/KinematicsBase.js +56 -0
- package/dist/move/kinematics/PolarKinematics.d.ts +7 -0
- package/dist/move/kinematics/PolarKinematics.js +21 -0
- package/dist/move/kinematics/ScaraKinematics.d.ts +6 -0
- package/dist/move/kinematics/ScaraKinematics.js +18 -0
- package/dist/move/kinematics/index.d.ts +14 -0
- package/dist/move/kinematics/index.js +73 -0
- package/dist/network/NetworkInterface.d.ts +41 -0
- package/dist/network/NetworkInterface.js +51 -0
- package/dist/network/index.d.ts +14 -0
- package/dist/network/index.js +35 -0
- package/dist/plugins/PluginManifest.d.ts +64 -0
- package/dist/plugins/PluginManifest.js +114 -0
- package/dist/plugins/index.d.ts +9 -0
- package/dist/plugins/index.js +30 -0
- package/dist/sbc/CPU.d.ts +8 -0
- package/dist/sbc/CPU.js +15 -0
- package/dist/sbc/Memory.d.ts +6 -0
- package/dist/sbc/Memory.js +13 -0
- package/dist/sbc/dsf/HttpEndpoint.d.ts +19 -0
- package/dist/sbc/dsf/HttpEndpoint.js +27 -0
- package/dist/sbc/dsf/index.d.ts +11 -0
- package/dist/sbc/dsf/index.js +32 -0
- package/dist/sbc/index.d.ts +19 -0
- package/dist/sbc/index.js +40 -0
- package/dist/sensors/AnalogSensor.d.ts +48 -0
- package/dist/sensors/AnalogSensor.js +57 -0
- package/dist/sensors/Endstop.d.ts +15 -0
- package/dist/sensors/Endstop.js +23 -0
- package/dist/sensors/FilamentMonitors/FilamentMonitorBase.d.ts +24 -0
- package/dist/sensors/FilamentMonitors/FilamentMonitorBase.js +32 -0
- package/dist/sensors/FilamentMonitors/LaserFilamentMonitor.d.ts +22 -0
- package/dist/sensors/FilamentMonitors/LaserFilamentMonitor.js +46 -0
- package/dist/sensors/FilamentMonitors/PulsedFilamentMonitor.d.ts +21 -0
- package/dist/sensors/FilamentMonitors/PulsedFilamentMonitor.js +45 -0
- package/dist/sensors/FilamentMonitors/RotatingMagnetFilamentMonitor.d.ts +22 -0
- package/dist/sensors/FilamentMonitors/RotatingMagnetFilamentMonitor.js +46 -0
- package/dist/sensors/FilamentMonitors/index.d.ts +11 -0
- package/dist/sensors/FilamentMonitors/index.js +51 -0
- package/dist/sensors/Probe.d.ts +33 -0
- package/dist/sensors/Probe.js +41 -0
- package/dist/sensors/index.d.ts +21 -0
- package/dist/sensors/index.js +46 -0
- package/dist/spindles/index.d.ts +20 -0
- package/dist/spindles/index.js +28 -0
- package/dist/state/MachineStatus.d.ts +17 -0
- package/dist/state/MachineStatus.js +21 -0
- package/dist/state/MessageBox.d.ts +26 -0
- package/dist/state/MessageBox.js +39 -0
- package/dist/state/RestorePoint.d.ts +12 -0
- package/dist/state/RestorePoint.js +19 -0
- package/dist/state/index.d.ts +60 -0
- package/dist/state/index.js +97 -0
- package/dist/tools/index.d.ts +26 -0
- package/dist/tools/index.js +34 -0
- package/dist/userSessions/index.d.ts +18 -0
- package/dist/userSessions/index.js +27 -0
- package/dist/volumes/index.d.ts +11 -0
- package/dist/volumes/index.js +18 -0
- package/package.json +2 -2
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IModelObject } from "./ModelObject";
|
|
2
|
+
/**
|
|
3
|
+
* Class for storing model object items in an array
|
|
4
|
+
*/
|
|
5
|
+
export declare class ModelCollection<T extends IModelObject | null> extends Array<T> implements IModelObject {
|
|
6
|
+
private readonly itemConstructor;
|
|
7
|
+
/**
|
|
8
|
+
* Constructor of this class
|
|
9
|
+
* @param itemConstructor Item constructor type that items must derive from
|
|
10
|
+
*/
|
|
11
|
+
constructor(itemConstructor: {
|
|
12
|
+
new (): T;
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Overridden push method to perform better type checks
|
|
16
|
+
* @param items Items to add
|
|
17
|
+
*/
|
|
18
|
+
push(...items: T[]): number;
|
|
19
|
+
/**
|
|
20
|
+
* Update this instance from the given data
|
|
21
|
+
* @param jsonElement JSON data to upgrade this instance from
|
|
22
|
+
* @returns Updated instance
|
|
23
|
+
*/
|
|
24
|
+
update(jsonElement: any): IModelObject | null;
|
|
25
|
+
}
|
|
26
|
+
export default ModelCollection;
|
|
27
|
+
/**
|
|
28
|
+
* Initialize a model collection from the given data
|
|
29
|
+
* @param itemType Item type to create
|
|
30
|
+
* @param data Data to assign
|
|
31
|
+
* @returns Initialized model collection
|
|
32
|
+
*/
|
|
33
|
+
export declare function initCollection<T extends IModelObject>(itemType: {
|
|
34
|
+
new (): T;
|
|
35
|
+
}, data: Array<{
|
|
36
|
+
[Property in keyof T]?: T[Property];
|
|
37
|
+
}>): ModelCollection<T>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initCollection = exports.ModelCollection = void 0;
|
|
4
|
+
const ModelObject_1 = require("./ModelObject");
|
|
5
|
+
const index_1 = require("./index");
|
|
6
|
+
/**
|
|
7
|
+
* Class for storing model object items in an array
|
|
8
|
+
*/
|
|
9
|
+
class ModelCollection extends Array {
|
|
10
|
+
/**
|
|
11
|
+
* Constructor of this class
|
|
12
|
+
* @param itemConstructor Item constructor type that items must derive from
|
|
13
|
+
*/
|
|
14
|
+
constructor(itemConstructor) {
|
|
15
|
+
super();
|
|
16
|
+
this.itemConstructor = itemConstructor;
|
|
17
|
+
Object.setPrototypeOf(this, ModelCollection.prototype);
|
|
18
|
+
}
|
|
19
|
+
// Unfortunately it isn't possible to override index operators in JS/TS
|
|
20
|
+
/**
|
|
21
|
+
* Overridden push method to perform better type checks
|
|
22
|
+
* @param items Items to add
|
|
23
|
+
*/
|
|
24
|
+
push(...items) {
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
if (item === null || item instanceof this.itemConstructor) {
|
|
27
|
+
super.push(item);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const newItem = new this.itemConstructor();
|
|
31
|
+
super.push(newItem.update(item));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return this.length;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Update this instance from the given data
|
|
38
|
+
* @param jsonElement JSON data to upgrade this instance from
|
|
39
|
+
* @returns Updated instance
|
|
40
|
+
*/
|
|
41
|
+
update(jsonElement) {
|
|
42
|
+
if (!(jsonElement instanceof Array)) {
|
|
43
|
+
throw new Error(`Invalid JSON element type for model collection ${typeof jsonElement}`);
|
|
44
|
+
}
|
|
45
|
+
// Remove deleted items
|
|
46
|
+
this.splice(jsonElement.length);
|
|
47
|
+
// Update existing items
|
|
48
|
+
for (let i = 0; i < Math.min(jsonElement.length, this.length); i++) {
|
|
49
|
+
const currentItem = this[i];
|
|
50
|
+
if (currentItem === null) {
|
|
51
|
+
const newItem = jsonElement[i];
|
|
52
|
+
if (newItem instanceof this.itemConstructor) {
|
|
53
|
+
(0, index_1.setArrayItem)(this, i, jsonElement[i]);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const refItem = new this.itemConstructor();
|
|
57
|
+
(0, index_1.setArrayItem)(this, i, refItem.update(newItem));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if ((0, ModelObject_1.isModelObject)(currentItem)) {
|
|
61
|
+
const newItem = currentItem.update(jsonElement[i]);
|
|
62
|
+
if (currentItem !== newItem) {
|
|
63
|
+
(0, index_1.setArrayItem)(this, i, newItem);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const newItem = jsonElement[i];
|
|
68
|
+
if (currentItem !== newItem) {
|
|
69
|
+
(0, index_1.setArrayItem)(this, i, newItem);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Add new items
|
|
74
|
+
for (let i = this.length; i < jsonElement.length; i++) {
|
|
75
|
+
const itemToAdd = jsonElement[i];
|
|
76
|
+
if (itemToAdd === null) {
|
|
77
|
+
super.push(itemToAdd);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const newItem = new this.itemConstructor();
|
|
81
|
+
super.push(newItem.update(itemToAdd));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ModelCollection = ModelCollection;
|
|
88
|
+
exports.default = ModelCollection;
|
|
89
|
+
/**
|
|
90
|
+
* Initialize a model collection from the given data
|
|
91
|
+
* @param itemType Item type to create
|
|
92
|
+
* @param data Data to assign
|
|
93
|
+
* @returns Initialized model collection
|
|
94
|
+
*/
|
|
95
|
+
function initCollection(itemType, data) {
|
|
96
|
+
const result = new ModelCollection(itemType);
|
|
97
|
+
for (let presetItem of data) {
|
|
98
|
+
const item = new itemType();
|
|
99
|
+
result.push(item.update(presetItem));
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
exports.initCollection = initCollection;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { IModelObject } from "./ModelObject";
|
|
2
|
+
/**
|
|
3
|
+
* Dictionary class to map object model data
|
|
4
|
+
*/
|
|
5
|
+
export declare class ModelDictionary<T> extends Map<string, T | null> implements IModelObject {
|
|
6
|
+
private readonly nullDeletesKeys;
|
|
7
|
+
private readonly itemConstructor;
|
|
8
|
+
/**
|
|
9
|
+
* Constructor of this class
|
|
10
|
+
* @param nullDeletesKeys Whether setting null to items effectively deletes them
|
|
11
|
+
* @param itemConstructor Item constructor type to use for type-checking
|
|
12
|
+
*/
|
|
13
|
+
constructor(nullDeletesKeys: boolean, itemConstructor?: {
|
|
14
|
+
new (): T;
|
|
15
|
+
} | null);
|
|
16
|
+
/**
|
|
17
|
+
* Overridden set method to perform type-checks and update
|
|
18
|
+
* @param key Key to set
|
|
19
|
+
* @param value Value to set
|
|
20
|
+
*/
|
|
21
|
+
set(key: string, value: T | null): this;
|
|
22
|
+
/**
|
|
23
|
+
* Update this instance from the given data
|
|
24
|
+
* @param jsonElement JSON data to upgrade this instance from
|
|
25
|
+
* @returns Updated instance
|
|
26
|
+
*/
|
|
27
|
+
update(jsonElement: any): IModelObject | null;
|
|
28
|
+
/**
|
|
29
|
+
* Convert this object to JSON
|
|
30
|
+
* @returns JSON object
|
|
31
|
+
*/
|
|
32
|
+
toJSON(): Record<string, T | null>;
|
|
33
|
+
}
|
|
34
|
+
export default ModelDictionary;
|
|
35
|
+
/**
|
|
36
|
+
* Initialize a model dictionary from the given data
|
|
37
|
+
* @param nullDeletesKeys Defines whether setting values to null deletes the corresponding key
|
|
38
|
+
* @param itemConstructor Item constructor
|
|
39
|
+
* @param data Data to assign
|
|
40
|
+
* @returns Initialized model dictionary
|
|
41
|
+
*/
|
|
42
|
+
export declare function initDictionary<T>(nullDeletesKeys: boolean, itemConstructor: {
|
|
43
|
+
new (): T;
|
|
44
|
+
}, data: Record<string, {
|
|
45
|
+
[Property in keyof T]?: T[Property];
|
|
46
|
+
}>): ModelDictionary<T>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initDictionary = exports.ModelDictionary = void 0;
|
|
4
|
+
const ModelObject_1 = require("./ModelObject");
|
|
5
|
+
/**
|
|
6
|
+
* Dictionary class to map object model data
|
|
7
|
+
*/
|
|
8
|
+
class ModelDictionary extends Map {
|
|
9
|
+
/**
|
|
10
|
+
* Constructor of this class
|
|
11
|
+
* @param nullDeletesKeys Whether setting null to items effectively deletes them
|
|
12
|
+
* @param itemConstructor Item constructor type to use for type-checking
|
|
13
|
+
*/
|
|
14
|
+
constructor(nullDeletesKeys, itemConstructor = null) {
|
|
15
|
+
super();
|
|
16
|
+
this.itemConstructor = itemConstructor;
|
|
17
|
+
this.nullDeletesKeys = nullDeletesKeys;
|
|
18
|
+
Object.setPrototypeOf(this, ModelDictionary.prototype);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Overridden set method to perform type-checks and update
|
|
22
|
+
* @param key Key to set
|
|
23
|
+
* @param value Value to set
|
|
24
|
+
*/
|
|
25
|
+
set(key, value) {
|
|
26
|
+
if (value === null) {
|
|
27
|
+
if (this.nullDeletesKeys) {
|
|
28
|
+
this.delete(key);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
return super.set(key, value);
|
|
32
|
+
}
|
|
33
|
+
const currentItem = this.get(key);
|
|
34
|
+
if (currentItem == null) {
|
|
35
|
+
if (this.itemConstructor !== null && !(value instanceof this.itemConstructor)) {
|
|
36
|
+
const newItem = new this.itemConstructor();
|
|
37
|
+
if ((0, ModelObject_1.isModelObject)(newItem)) {
|
|
38
|
+
const updatedItem = newItem.update(value);
|
|
39
|
+
return super.set(key, updatedItem);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if ((0, ModelObject_1.isModelObject)(currentItem)) {
|
|
44
|
+
const newItem = currentItem.update(value);
|
|
45
|
+
if (currentItem !== newItem) {
|
|
46
|
+
return super.set(key, value);
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
return super.set(key, value);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Update this instance from the given data
|
|
54
|
+
* @param jsonElement JSON data to upgrade this instance from
|
|
55
|
+
* @returns Updated instance
|
|
56
|
+
*/
|
|
57
|
+
update(jsonElement) {
|
|
58
|
+
if (jsonElement === null) {
|
|
59
|
+
this.clear();
|
|
60
|
+
}
|
|
61
|
+
else if (jsonElement instanceof Map) {
|
|
62
|
+
for (const [key, value] of jsonElement.entries()) {
|
|
63
|
+
this.set(key, value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
for (const [key, value] of Object.entries(jsonElement)) {
|
|
68
|
+
this.set(key, value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Convert this object to JSON
|
|
75
|
+
* @returns JSON object
|
|
76
|
+
*/
|
|
77
|
+
toJSON() {
|
|
78
|
+
const json = {};
|
|
79
|
+
for (const [key, value] of this) {
|
|
80
|
+
json[key] = value;
|
|
81
|
+
}
|
|
82
|
+
return json;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.ModelDictionary = ModelDictionary;
|
|
86
|
+
exports.default = ModelDictionary;
|
|
87
|
+
/**
|
|
88
|
+
* Initialize a model dictionary from the given data
|
|
89
|
+
* @param nullDeletesKeys Defines whether setting values to null deletes the corresponding key
|
|
90
|
+
* @param itemConstructor Item constructor
|
|
91
|
+
* @param data Data to assign
|
|
92
|
+
* @returns Initialized model dictionary
|
|
93
|
+
*/
|
|
94
|
+
function initDictionary(nullDeletesKeys, itemConstructor, data) {
|
|
95
|
+
const result = new ModelDictionary(nullDeletesKeys, itemConstructor);
|
|
96
|
+
for (let key in data) {
|
|
97
|
+
const item = new itemConstructor();
|
|
98
|
+
if ((0, ModelObject_1.isModelObject)(item)) {
|
|
99
|
+
item.update(data[key]);
|
|
100
|
+
result.set(key, item);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
result.set(key, data[key]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
exports.initDictionary = initDictionary;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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;
|
package/dist/ModelSet.js
ADDED
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import ModelCollection from "./ModelCollection";
|
|
2
|
+
import ModelDictionary from "./ModelDictionary";
|
|
3
|
+
import ModelObject from "./ModelObject";
|
|
4
|
+
import Board from "./boards";
|
|
5
|
+
import Directories from "./directories";
|
|
6
|
+
import Fan from "./fans";
|
|
7
|
+
import Heat from "./heat";
|
|
8
|
+
import InputChannel from "./inputs/InputChannel";
|
|
9
|
+
import Job from "./job";
|
|
10
|
+
import Limits from "./limits";
|
|
11
|
+
import Message from "./messages";
|
|
12
|
+
import Move from "./move";
|
|
13
|
+
import Network from "./network";
|
|
14
|
+
import Plugin from "./plugins";
|
|
15
|
+
import SBC from "./sbc";
|
|
16
|
+
import Sensors from "./sensors";
|
|
17
|
+
import Spindle from "./spindles";
|
|
18
|
+
import State from "./state";
|
|
19
|
+
import Tool from "./tools";
|
|
20
|
+
import UserSession from "./userSessions";
|
|
21
|
+
import Volume from "./volumes";
|
|
22
|
+
/**
|
|
23
|
+
* Refer to the DSF/RRF documentation for descriptions of the object model fields
|
|
24
|
+
*/
|
|
25
|
+
export declare class ObjectModel extends ModelObject {
|
|
26
|
+
constructor();
|
|
27
|
+
readonly boards: ModelCollection<Board>;
|
|
28
|
+
readonly directories: Directories;
|
|
29
|
+
readonly fans: ModelCollection<Fan | null>;
|
|
30
|
+
readonly global: ModelDictionary<any>;
|
|
31
|
+
readonly heat: Heat;
|
|
32
|
+
readonly inputs: ModelCollection<InputChannel | null>;
|
|
33
|
+
readonly job: Job;
|
|
34
|
+
readonly limits: Limits;
|
|
35
|
+
readonly messages: ModelCollection<Message>;
|
|
36
|
+
readonly move: Move;
|
|
37
|
+
readonly network: Network;
|
|
38
|
+
readonly plugins: ModelDictionary<Plugin>;
|
|
39
|
+
sbc: SBC | null;
|
|
40
|
+
readonly sensors: Sensors;
|
|
41
|
+
readonly spindles: ModelCollection<Spindle | null>;
|
|
42
|
+
readonly state: State;
|
|
43
|
+
readonly tools: ModelCollection<Tool | null>;
|
|
44
|
+
readonly userSessions: ModelCollection<UserSession>;
|
|
45
|
+
readonly volumes: ModelCollection<Volume>;
|
|
46
|
+
}
|
|
47
|
+
export default ObjectModel;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectModel = void 0;
|
|
4
|
+
const ModelCollection_1 = require("./ModelCollection");
|
|
5
|
+
const ModelDictionary_1 = require("./ModelDictionary");
|
|
6
|
+
const ModelObject_1 = require("./ModelObject");
|
|
7
|
+
const boards_1 = require("./boards");
|
|
8
|
+
const directories_1 = require("./directories");
|
|
9
|
+
const fans_1 = require("./fans");
|
|
10
|
+
const heat_1 = require("./heat");
|
|
11
|
+
const InputChannel_1 = require("./inputs/InputChannel");
|
|
12
|
+
const job_1 = require("./job");
|
|
13
|
+
const limits_1 = require("./limits");
|
|
14
|
+
const messages_1 = require("./messages");
|
|
15
|
+
const move_1 = require("./move");
|
|
16
|
+
const network_1 = require("./network");
|
|
17
|
+
const plugins_1 = require("./plugins");
|
|
18
|
+
const sbc_1 = require("./sbc");
|
|
19
|
+
const sensors_1 = require("./sensors");
|
|
20
|
+
const spindles_1 = require("./spindles");
|
|
21
|
+
const state_1 = require("./state");
|
|
22
|
+
const tools_1 = require("./tools");
|
|
23
|
+
const userSessions_1 = require("./userSessions");
|
|
24
|
+
const volumes_1 = require("./volumes");
|
|
25
|
+
/**
|
|
26
|
+
* Refer to the DSF/RRF documentation for descriptions of the object model fields
|
|
27
|
+
*/
|
|
28
|
+
class ObjectModel extends ModelObject_1.default {
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.boards = new ModelCollection_1.default(boards_1.default);
|
|
32
|
+
this.directories = new directories_1.default();
|
|
33
|
+
this.fans = new ModelCollection_1.default(fans_1.default);
|
|
34
|
+
this.global = new ModelDictionary_1.default(false);
|
|
35
|
+
this.heat = new heat_1.default();
|
|
36
|
+
this.inputs = new ModelCollection_1.default(InputChannel_1.default);
|
|
37
|
+
this.job = new job_1.default();
|
|
38
|
+
this.limits = new limits_1.default();
|
|
39
|
+
this.messages = new ModelCollection_1.default(messages_1.default); // must be manually cleared after updates
|
|
40
|
+
this.move = new move_1.default();
|
|
41
|
+
this.network = new network_1.default();
|
|
42
|
+
this.plugins = new ModelDictionary_1.default(true, plugins_1.default);
|
|
43
|
+
this.sbc = null;
|
|
44
|
+
this.sensors = new sensors_1.default();
|
|
45
|
+
this.spindles = new ModelCollection_1.default(spindles_1.default);
|
|
46
|
+
this.state = new state_1.default();
|
|
47
|
+
this.tools = new ModelCollection_1.default(tools_1.default);
|
|
48
|
+
this.userSessions = new ModelCollection_1.default(userSessions_1.default);
|
|
49
|
+
this.volumes = new ModelCollection_1.default(volumes_1.default);
|
|
50
|
+
ModelObject_1.default.wrapModelProperty(this, "sbc", sbc_1.default);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ObjectModel = ObjectModel;
|
|
54
|
+
exports.default = ObjectModel;
|