@duet3d/objectmodel 3.5.0-beta.30 → 3.5.0-beta.32
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/LICENSE +504 -504
- package/README.md +17 -17
- package/dist/ModelCollection.d.ts +37 -37
- package/dist/ModelCollection.js +103 -103
- package/dist/ModelDictionary.d.ts +46 -46
- package/dist/ModelDictionary.js +108 -108
- package/dist/ModelObject.d.ts +47 -47
- package/dist/ModelObject.js +212 -212
- package/dist/ModelSet.d.ts +11 -11
- package/dist/ModelSet.js +15 -15
- package/dist/ObjectModel.d.ts +46 -46
- package/dist/ObjectModel.js +53 -53
- package/dist/boards/index.d.ts +52 -52
- package/dist/boards/index.js +81 -81
- package/dist/directories/index.d.ts +12 -12
- package/dist/directories/index.js +19 -19
- package/dist/fans/index.d.ts +19 -19
- package/dist/fans/index.js +30 -30
- package/dist/heat/Heater.d.ts +28 -28
- package/dist/heat/Heater.js +36 -36
- package/dist/heat/HeaterModel.d.ts +21 -21
- package/dist/heat/HeaterModel.js +32 -32
- package/dist/heat/HeaterMonitor.d.ts +18 -18
- package/dist/heat/HeaterMonitor.js +27 -27
- package/dist/heat/index.d.ts +14 -14
- package/dist/heat/index.js +35 -35
- package/dist/httpEndpoints/index.d.ts +19 -19
- package/dist/httpEndpoints/index.js +27 -27
- package/dist/index.d.ts +26 -26
- package/dist/index.js +55 -55
- package/dist/inputs/CodeChannel.d.ts +18 -18
- package/dist/inputs/CodeChannel.js +22 -22
- package/dist/inputs/Compatibility.d.ts +10 -10
- package/dist/inputs/Compatibility.js +14 -14
- package/dist/inputs/InputChannel.d.ts +30 -30
- package/dist/inputs/InputChannel.js +39 -39
- package/dist/inputs/index.d.ts +3 -3
- package/dist/inputs/index.js +19 -19
- package/dist/job/Build.d.ts +15 -15
- package/dist/job/Build.js +26 -26
- package/dist/job/GCodeFileInfo.d.ts +17 -17
- package/dist/job/GCodeFileInfo.js +24 -24
- package/dist/job/ThumbnailInfo.d.ts +15 -15
- package/dist/job/ThumbnailInfo.js +23 -23
- package/dist/job/index.d.ts +40 -40
- package/dist/job/index.js +70 -70
- package/dist/limits/index.d.ts +29 -29
- package/dist/limits/index.js +36 -36
- package/dist/messages/index.d.ts +13 -13
- package/dist/messages/index.js +27 -27
- package/dist/move/Axis.d.ts +47 -47
- package/dist/move/Axis.js +55 -55
- package/dist/move/DriverId.d.ts +10 -10
- package/dist/move/DriverId.js +49 -49
- package/dist/move/Extruder.d.ts +28 -28
- package/dist/move/Extruder.js +39 -39
- package/dist/move/InputShaping.d.ts +20 -20
- package/dist/move/InputShaping.js +28 -28
- package/dist/move/KeepoutZone.d.ts +10 -10
- package/dist/move/KeepoutZone.js +21 -21
- package/dist/move/Microstepping.d.ts +6 -6
- package/dist/move/Microstepping.js +13 -13
- package/dist/move/MoveCalibration.d.ts +11 -11
- package/dist/move/MoveCalibration.js +22 -22
- package/dist/move/MoveCompensation.d.ts +30 -30
- package/dist/move/MoveCompensation.js +47 -47
- package/dist/move/index.d.ts +60 -60
- package/dist/move/index.js +97 -97
- package/dist/move/kinematics/CoreKinematics.d.ts +9 -9
- package/dist/move/kinematics/CoreKinematics.js +31 -31
- package/dist/move/kinematics/DeltaKinematics.d.ts +20 -20
- package/dist/move/kinematics/DeltaKinematics.js +40 -40
- package/dist/move/kinematics/HangprinterKinematics.d.ts +9 -9
- package/dist/move/kinematics/HangprinterKinematics.js +28 -28
- package/dist/move/kinematics/KinematicsBase.d.ts +37 -37
- package/dist/move/kinematics/KinematicsBase.js +56 -56
- package/dist/move/kinematics/PolarKinematics.d.ts +7 -7
- package/dist/move/kinematics/PolarKinematics.js +21 -21
- package/dist/move/kinematics/ScaraKinematics.d.ts +6 -6
- package/dist/move/kinematics/ScaraKinematics.js +18 -18
- package/dist/move/kinematics/index.d.ts +14 -14
- package/dist/move/kinematics/index.js +70 -70
- package/dist/network/NetworkInterface.d.ts +41 -41
- package/dist/network/NetworkInterface.js +51 -51
- package/dist/network/index.d.ts +14 -14
- package/dist/network/index.js +35 -35
- package/dist/plugins/PluginManifest.d.ts +64 -64
- package/dist/plugins/PluginManifest.js +114 -114
- package/dist/plugins/index.d.ts +9 -9
- package/dist/plugins/index.js +30 -30
- package/dist/scanner/index.d.ts +14 -0
- package/dist/scanner/index.js +22 -0
- package/dist/sensors/AnalogSensor.d.ts +48 -48
- package/dist/sensors/AnalogSensor.js +57 -57
- package/dist/sensors/Endstop.d.ts +15 -14
- package/dist/sensors/Endstop.js +23 -22
- package/dist/sensors/FilamentMonitors/FilamentMonitorBase.d.ts +24 -24
- package/dist/sensors/FilamentMonitors/FilamentMonitorBase.js +32 -32
- package/dist/sensors/FilamentMonitors/LaserFilamentMonitor.d.ts +22 -22
- package/dist/sensors/FilamentMonitors/LaserFilamentMonitor.js +46 -46
- package/dist/sensors/FilamentMonitors/PulsedFilamentMonitor.d.ts +21 -21
- package/dist/sensors/FilamentMonitors/PulsedFilamentMonitor.js +45 -45
- package/dist/sensors/FilamentMonitors/RotatingMagnetFilamentMonitor.d.ts +22 -22
- package/dist/sensors/FilamentMonitors/RotatingMagnetFilamentMonitor.js +46 -46
- package/dist/sensors/FilamentMonitors/index.d.ts +11 -11
- package/dist/sensors/FilamentMonitors/index.js +51 -51
- package/dist/sensors/Probe.d.ts +33 -33
- package/dist/sensors/Probe.js +41 -41
- package/dist/sensors/index.d.ts +21 -21
- package/dist/sensors/index.js +46 -46
- package/dist/spindles/index.d.ts +20 -20
- package/dist/spindles/index.js +28 -28
- package/dist/state/MachineStatus.d.ts +17 -17
- package/dist/state/MachineStatus.js +21 -21
- package/dist/state/MessageBox.d.ts +26 -26
- package/dist/state/MessageBox.js +39 -39
- package/dist/state/RestorePoint.d.ts +12 -12
- package/dist/state/RestorePoint.js +19 -19
- package/dist/state/index.d.ts +63 -63
- package/dist/state/index.js +100 -100
- package/dist/tools/index.d.ts +26 -26
- package/dist/tools/index.js +34 -34
- package/dist/userSessions/index.d.ts +18 -18
- package/dist/userSessions/index.js +27 -27
- package/dist/volumes/index.d.ts +11 -11
- package/dist/volumes/index.js +18 -18
- package/package.json +32 -32
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# ObjectModel
|
|
2
|
-
|
|
3
|
-
TypeScript implementation of the Duet3D Object Model.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Install via `npm install @duet3d/objectmodel`. Users of Vue 2 must also run this command after the first import:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
globalThis._duetModelSetArray = (array, index, value) => Vue.set(array, index, value);
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
This is required to make sure that change events for arrays are correctly fired.
|
|
14
|
-
|
|
15
|
-
## Bug reports
|
|
16
|
-
|
|
17
|
-
Please use the [forum](https://forum.duet3d.com) for support requests or the [DuetWebControl](https://github.com/Duet3D/DuetWebControl) GitHub repository for feature requests and bug reports.
|
|
1
|
+
# ObjectModel
|
|
2
|
+
|
|
3
|
+
TypeScript implementation of the Duet3D Object Model.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install via `npm install @duet3d/objectmodel`. Users of Vue 2 must also run this command after the first import:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
globalThis._duetModelSetArray = (array, index, value) => Vue.set(array, index, value);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This is required to make sure that change events for arrays are correctly fired.
|
|
14
|
+
|
|
15
|
+
## Bug reports
|
|
16
|
+
|
|
17
|
+
Please use the [forum](https://forum.duet3d.com) for support requests or the [DuetWebControl](https://github.com/Duet3D/DuetWebControl) GitHub repository for feature requests and bug reports.
|
|
@@ -1,37 +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>;
|
|
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>;
|
package/dist/ModelCollection.js
CHANGED
|
@@ -1,103 +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;
|
|
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;
|
|
@@ -1,46 +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>;
|
|
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>;
|
package/dist/ModelDictionary.js
CHANGED
|
@@ -1,108 +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;
|
|
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;
|