@duet3d/objectmodel 3.4.0-b5 → 3.4.0-b8
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 +11 -0
- package/dist/ModelCollection.js +17 -1
- package/dist/ModelDictionary.d.ts +12 -0
- package/dist/ModelDictionary.js +23 -1
- package/dist/ModelObject.d.ts +5 -5
- package/dist/ModelObject.js +33 -8
- package/dist/ObjectModel.d.ts +2 -0
- package/dist/ObjectModel.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +30 -30
|
@@ -24,3 +24,14 @@ export declare class ModelCollection<T extends IModelObject> extends Array<T> im
|
|
|
24
24
|
update(jsonElement: any): IModelObject | null;
|
|
25
25
|
}
|
|
26
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,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelCollection = void 0;
|
|
3
|
+
exports.initCollection = exports.ModelCollection = void 0;
|
|
4
4
|
const ModelObject_1 = require("./ModelObject");
|
|
5
5
|
const index_1 = require("./index");
|
|
6
6
|
/**
|
|
@@ -79,3 +79,19 @@ class ModelCollection extends Array {
|
|
|
79
79
|
}
|
|
80
80
|
exports.ModelCollection = ModelCollection;
|
|
81
81
|
exports.default = ModelCollection;
|
|
82
|
+
/**
|
|
83
|
+
* Initialize a model collection from the given data
|
|
84
|
+
* @param itemType Item type to create
|
|
85
|
+
* @param data Data to assign
|
|
86
|
+
* @returns Initialized model collection
|
|
87
|
+
*/
|
|
88
|
+
function initCollection(itemType, data) {
|
|
89
|
+
const result = new ModelCollection(itemType);
|
|
90
|
+
for (let presetItem of data) {
|
|
91
|
+
const item = new itemType();
|
|
92
|
+
item.update(presetItem);
|
|
93
|
+
result.push(item);
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
exports.initCollection = initCollection;
|
|
@@ -27,3 +27,15 @@ export declare class ModelDictionary<T> extends Map<string, T | null> implements
|
|
|
27
27
|
update(jsonElement: any): IModelObject | null;
|
|
28
28
|
}
|
|
29
29
|
export default ModelDictionary;
|
|
30
|
+
/**
|
|
31
|
+
* Initialize a model dictionary from the given data
|
|
32
|
+
* @param nullDeletesKeys Defines whether setting values to null deletes the corresponding key
|
|
33
|
+
* @param itemConstructor Item constructor
|
|
34
|
+
* @param data Data to assign
|
|
35
|
+
* @returns Initialized model dictionary
|
|
36
|
+
*/
|
|
37
|
+
export declare function initDictionary<T>(nullDeletesKeys: boolean, itemConstructor: {
|
|
38
|
+
new (): T;
|
|
39
|
+
}, data: Record<string, {
|
|
40
|
+
[Property in keyof T]?: T[Property];
|
|
41
|
+
}>): ModelDictionary<T>;
|
package/dist/ModelDictionary.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelDictionary = void 0;
|
|
3
|
+
exports.initDictionary = exports.ModelDictionary = void 0;
|
|
4
4
|
const ModelObject_1 = require("./ModelObject");
|
|
5
5
|
/**
|
|
6
6
|
* Dictionary class to map object model data
|
|
@@ -67,3 +67,25 @@ class ModelDictionary extends Map {
|
|
|
67
67
|
}
|
|
68
68
|
exports.ModelDictionary = ModelDictionary;
|
|
69
69
|
exports.default = ModelDictionary;
|
|
70
|
+
/**
|
|
71
|
+
* Initialize a model dictionary from the given data
|
|
72
|
+
* @param nullDeletesKeys Defines whether setting values to null deletes the corresponding key
|
|
73
|
+
* @param itemConstructor Item constructor
|
|
74
|
+
* @param data Data to assign
|
|
75
|
+
* @returns Initialized model dictionary
|
|
76
|
+
*/
|
|
77
|
+
function initDictionary(nullDeletesKeys, itemConstructor, data) {
|
|
78
|
+
const result = new ModelDictionary(nullDeletesKeys, itemConstructor);
|
|
79
|
+
for (let key in data) {
|
|
80
|
+
const item = new itemConstructor();
|
|
81
|
+
if ((0, ModelObject_1.isModelObject)(item)) {
|
|
82
|
+
item.update(data[key]);
|
|
83
|
+
result.set(key, item);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
result.set(key, data[key]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
exports.initDictionary = initDictionary;
|
package/dist/ModelObject.d.ts
CHANGED
|
@@ -33,15 +33,15 @@ export declare abstract class ModelObject implements IModelObject {
|
|
|
33
33
|
new (): T;
|
|
34
34
|
}): void;
|
|
35
35
|
}
|
|
36
|
+
export default ModelObject;
|
|
36
37
|
/**
|
|
37
|
-
* Initialize a
|
|
38
|
-
* @param itemType
|
|
38
|
+
* Initialize a model object from the given data
|
|
39
|
+
* @param itemType Model type to create
|
|
39
40
|
* @param data Data to assign
|
|
40
|
-
* @returns Initialized
|
|
41
|
+
* @returns Initialized model instance
|
|
41
42
|
*/
|
|
42
|
-
export declare function
|
|
43
|
+
export declare function initObject<T>(itemType: {
|
|
43
44
|
new (): T;
|
|
44
45
|
}, data: {
|
|
45
46
|
[Property in keyof T]?: T[Property];
|
|
46
47
|
}): T;
|
|
47
|
-
export default ModelObject;
|
package/dist/ModelObject.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.initObject = exports.ModelObject = exports.isModelObject = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
/**
|
|
6
6
|
* Check whether a given value provides model update functionality
|
|
@@ -71,6 +71,25 @@ class ModelObject {
|
|
|
71
71
|
console.warn(`Model array ${key} could not be changed because the target type ${typeof value} is invalid`);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
else if (prop instanceof Set) {
|
|
75
|
+
if (value instanceof Array || value instanceof Set) {
|
|
76
|
+
// Remove deleted items
|
|
77
|
+
for (let item of new Set(prop)) {
|
|
78
|
+
if (!prop.has(item)) {
|
|
79
|
+
prop.delete(item);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Add new items
|
|
83
|
+
for (let item of value) {
|
|
84
|
+
if (!prop.has(item)) {
|
|
85
|
+
prop.add(item);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (process.env.NODE_ENV !== "production") {
|
|
90
|
+
console.warn(`Model set ${key} could not be changed because the target type ${typeof value} is invalid`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
74
93
|
else if (prop === null || value === null) {
|
|
75
94
|
// Unfortunately we cannot do type checks during runtime without excessive extra work and possibly
|
|
76
95
|
// third-party libraries, so skip them for null values until there is a better solution.
|
|
@@ -153,18 +172,24 @@ class ModelObject {
|
|
|
153
172
|
}
|
|
154
173
|
}
|
|
155
174
|
exports.ModelObject = ModelObject;
|
|
175
|
+
exports.default = ModelObject;
|
|
156
176
|
/**
|
|
157
|
-
* Initialize a
|
|
158
|
-
* @param itemType
|
|
177
|
+
* Initialize a model object from the given data
|
|
178
|
+
* @param itemType Model type to create
|
|
159
179
|
* @param data Data to assign
|
|
160
|
-
* @returns Initialized
|
|
180
|
+
* @returns Initialized model instance
|
|
161
181
|
*/
|
|
162
|
-
function
|
|
182
|
+
function initObject(itemType, data) {
|
|
163
183
|
const result = new itemType();
|
|
164
184
|
for (let key in data) {
|
|
165
|
-
|
|
185
|
+
const resultKey = result[key];
|
|
186
|
+
if (isModelObject(resultKey)) {
|
|
187
|
+
resultKey.update(data[key]);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
result[key] = data[key];
|
|
191
|
+
}
|
|
166
192
|
}
|
|
167
193
|
return result;
|
|
168
194
|
}
|
|
169
|
-
exports.
|
|
170
|
-
exports.default = ModelObject;
|
|
195
|
+
exports.initObject = initObject;
|
package/dist/ObjectModel.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import Job from "./job";
|
|
|
12
12
|
import Limits from "./limits";
|
|
13
13
|
import Message from "./messages";
|
|
14
14
|
import Move from "./move";
|
|
15
|
+
import Network from "./network";
|
|
15
16
|
import Plugin from "./plugins";
|
|
16
17
|
import Scanner from "./scanner";
|
|
17
18
|
import Sensors from "./sensors";
|
|
@@ -33,6 +34,7 @@ export declare class ObjectModel extends ModelObject {
|
|
|
33
34
|
readonly limits: Limits;
|
|
34
35
|
readonly messages: ModelCollection<Message>;
|
|
35
36
|
readonly move: Move;
|
|
37
|
+
readonly network: Network;
|
|
36
38
|
readonly plugins: ModelDictionary<Plugin>;
|
|
37
39
|
readonly scanner: Scanner;
|
|
38
40
|
readonly sensors: Sensors;
|
package/dist/ObjectModel.js
CHANGED
|
@@ -15,6 +15,7 @@ const job_1 = require("./job");
|
|
|
15
15
|
const limits_1 = require("./limits");
|
|
16
16
|
const messages_1 = require("./messages");
|
|
17
17
|
const move_1 = require("./move");
|
|
18
|
+
const network_1 = require("./network");
|
|
18
19
|
const plugins_1 = require("./plugins");
|
|
19
20
|
const scanner_1 = require("./scanner");
|
|
20
21
|
const sensors_1 = require("./sensors");
|
|
@@ -38,6 +39,7 @@ class ObjectModel extends ModelObject_1.default {
|
|
|
38
39
|
this.limits = new limits_1.default();
|
|
39
40
|
this.messages = new ModelCollection_1.default(messages_1.default); // must be manually cleared after updates
|
|
40
41
|
this.move = new move_1.default();
|
|
42
|
+
this.network = new network_1.default();
|
|
41
43
|
this.plugins = new ModelDictionary_1.default(true, plugins_1.default);
|
|
42
44
|
this.scanner = new scanner_1.default();
|
|
43
45
|
this.sensors = new sensors_1.default();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ __exportStar(require("./job"), exports);
|
|
|
30
30
|
__exportStar(require("./limits"), exports);
|
|
31
31
|
__exportStar(require("./messages"), exports);
|
|
32
32
|
__exportStar(require("./move"), exports);
|
|
33
|
+
__exportStar(require("./network"), exports);
|
|
33
34
|
__exportStar(require("./plugins"), exports);
|
|
34
35
|
__exportStar(require("./scanner"), exports);
|
|
35
36
|
__exportStar(require("./sensors"), exports);
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@duet3d/objectmodel",
|
|
3
|
-
"version": "3.4.0-
|
|
4
|
-
"description": "TypeScript implementation of the Duet3D Object Model",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "jest --config jestconfig.json",
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"prepare" : "npm run build",
|
|
11
|
-
"prepublishOnly" : "npm test"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/Duet3D/ObjectModel.git"
|
|
16
|
-
},
|
|
17
|
-
"author": "Christian Hammacher",
|
|
18
|
-
"license": "LGPL-2.1",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/Duet3D/ObjectModel/issues"
|
|
21
|
-
},
|
|
22
|
-
"homepage": "https://github.com/Duet3D/ObjectModel#readme",
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@types/jest": "^27.0.3",
|
|
25
|
-
"jest": "^27.4.5",
|
|
26
|
-
"ts-jest": "^27.1.2",
|
|
27
|
-
"typescript": "^4.5.2"
|
|
28
|
-
},
|
|
29
|
-
"files": ["/dist"]
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@duet3d/objectmodel",
|
|
3
|
+
"version": "3.4.0-b8",
|
|
4
|
+
"description": "TypeScript implementation of the Duet3D Object Model",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest --config jestconfig.json",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"prepare" : "npm run build",
|
|
11
|
+
"prepublishOnly" : "npm test"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Duet3D/ObjectModel.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "Christian Hammacher",
|
|
18
|
+
"license": "LGPL-2.1",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/Duet3D/ObjectModel/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/Duet3D/ObjectModel#readme",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/jest": "^27.0.3",
|
|
25
|
+
"jest": "^27.4.5",
|
|
26
|
+
"ts-jest": "^27.1.2",
|
|
27
|
+
"typescript": "^4.5.2"
|
|
28
|
+
},
|
|
29
|
+
"files": ["/dist"]
|
|
30
|
+
}
|