@duet3d/objectmodel 3.5.0-beta.41 → 3.5.0-beta.42

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 (132) hide show
  1. package/dist/{src/index.js → index.js} +1 -4
  2. package/package.json +2 -2
  3. package/dist/package.json +0 -32
  4. package/dist/src/ModelCollection.d.ts +0 -37
  5. package/dist/src/ModelCollection.js +0 -103
  6. package/dist/src/ModelDictionary.d.ts +0 -46
  7. package/dist/src/ModelDictionary.js +0 -108
  8. package/dist/src/ModelObject.d.ts +0 -47
  9. package/dist/src/ModelObject.js +0 -212
  10. package/dist/src/ModelSet.d.ts +0 -11
  11. package/dist/src/ModelSet.js +0 -15
  12. package/dist/src/ObjectModel.d.ts +0 -52
  13. package/dist/src/ObjectModel.js +0 -64
  14. package/dist/src/boards/index.d.ts +0 -52
  15. package/dist/src/boards/index.js +0 -84
  16. package/dist/src/directories/index.d.ts +0 -11
  17. package/dist/src/directories/index.js +0 -21
  18. package/dist/src/fans/index.d.ts +0 -19
  19. package/dist/src/fans/index.js +0 -33
  20. package/dist/src/heat/Heater.d.ts +0 -28
  21. package/dist/src/heat/Heater.js +0 -39
  22. package/dist/src/heat/HeaterModel.d.ts +0 -21
  23. package/dist/src/heat/HeaterModel.js +0 -35
  24. package/dist/src/heat/HeaterMonitor.d.ts +0 -18
  25. package/dist/src/heat/HeaterMonitor.js +0 -30
  26. package/dist/src/heat/index.d.ts +0 -14
  27. package/dist/src/heat/index.js +0 -38
  28. package/dist/src/index.d.ts +0 -26
  29. package/dist/src/inputs/CodeChannel.d.ts +0 -18
  30. package/dist/src/inputs/CodeChannel.js +0 -22
  31. package/dist/src/inputs/Compatibility.d.ts +0 -10
  32. package/dist/src/inputs/Compatibility.js +0 -14
  33. package/dist/src/inputs/InputChannel.d.ts +0 -30
  34. package/dist/src/inputs/InputChannel.js +0 -42
  35. package/dist/src/inputs/index.d.ts +0 -3
  36. package/dist/src/inputs/index.js +0 -19
  37. package/dist/src/job/Build.d.ts +0 -15
  38. package/dist/src/job/Build.js +0 -29
  39. package/dist/src/job/GCodeFileInfo.d.ts +0 -17
  40. package/dist/src/job/GCodeFileInfo.js +0 -27
  41. package/dist/src/job/ThumbnailInfo.d.ts +0 -15
  42. package/dist/src/job/ThumbnailInfo.js +0 -23
  43. package/dist/src/job/index.d.ts +0 -40
  44. package/dist/src/job/index.js +0 -73
  45. package/dist/src/limits/index.d.ts +0 -29
  46. package/dist/src/limits/index.js +0 -39
  47. package/dist/src/messages/index.d.ts +0 -13
  48. package/dist/src/messages/index.js +0 -30
  49. package/dist/src/move/Axis.d.ts +0 -47
  50. package/dist/src/move/Axis.js +0 -58
  51. package/dist/src/move/DriverId.d.ts +0 -10
  52. package/dist/src/move/DriverId.js +0 -52
  53. package/dist/src/move/Extruder.d.ts +0 -28
  54. package/dist/src/move/Extruder.js +0 -42
  55. package/dist/src/move/InputShaping.d.ts +0 -20
  56. package/dist/src/move/InputShaping.js +0 -31
  57. package/dist/src/move/KeepoutZone.d.ts +0 -10
  58. package/dist/src/move/KeepoutZone.js +0 -21
  59. package/dist/src/move/Microstepping.d.ts +0 -6
  60. package/dist/src/move/Microstepping.js +0 -16
  61. package/dist/src/move/MoveCalibration.d.ts +0 -11
  62. package/dist/src/move/MoveCalibration.js +0 -25
  63. package/dist/src/move/MoveCompensation.d.ts +0 -30
  64. package/dist/src/move/MoveCompensation.js +0 -50
  65. package/dist/src/move/index.d.ts +0 -61
  66. package/dist/src/move/index.js +0 -101
  67. package/dist/src/move/kinematics/CoreKinematics.d.ts +0 -9
  68. package/dist/src/move/kinematics/CoreKinematics.js +0 -31
  69. package/dist/src/move/kinematics/DeltaKinematics.d.ts +0 -20
  70. package/dist/src/move/kinematics/DeltaKinematics.js +0 -43
  71. package/dist/src/move/kinematics/HangprinterKinematics.d.ts +0 -9
  72. package/dist/src/move/kinematics/HangprinterKinematics.js +0 -51
  73. package/dist/src/move/kinematics/KinematicsBase.d.ts +0 -37
  74. package/dist/src/move/kinematics/KinematicsBase.js +0 -59
  75. package/dist/src/move/kinematics/PolarKinematics.d.ts +0 -7
  76. package/dist/src/move/kinematics/PolarKinematics.js +0 -44
  77. package/dist/src/move/kinematics/ScaraKinematics.d.ts +0 -6
  78. package/dist/src/move/kinematics/ScaraKinematics.js +0 -18
  79. package/dist/src/move/kinematics/index.d.ts +0 -14
  80. package/dist/src/move/kinematics/index.js +0 -88
  81. package/dist/src/network/NetworkInterface.d.ts +0 -41
  82. package/dist/src/network/NetworkInterface.js +0 -54
  83. package/dist/src/network/index.d.ts +0 -14
  84. package/dist/src/network/index.js +0 -38
  85. package/dist/src/plugins/PluginManifest.d.ts +0 -64
  86. package/dist/src/plugins/PluginManifest.js +0 -117
  87. package/dist/src/plugins/index.d.ts +0 -9
  88. package/dist/src/plugins/index.js +0 -33
  89. package/dist/src/sbc/CPU.d.ts +0 -8
  90. package/dist/src/sbc/CPU.js +0 -18
  91. package/dist/src/sbc/Memory.d.ts +0 -6
  92. package/dist/src/sbc/Memory.js +0 -16
  93. package/dist/src/sbc/dsf/HttpEndpoint.d.ts +0 -19
  94. package/dist/src/sbc/dsf/HttpEndpoint.js +0 -30
  95. package/dist/src/sbc/dsf/index.d.ts +0 -11
  96. package/dist/src/sbc/dsf/index.js +0 -36
  97. package/dist/src/sbc/index.d.ts +0 -19
  98. package/dist/src/sbc/index.js +0 -43
  99. package/dist/src/sensors/AnalogSensor.d.ts +0 -48
  100. package/dist/src/sensors/AnalogSensor.js +0 -60
  101. package/dist/src/sensors/Endstop.d.ts +0 -15
  102. package/dist/src/sensors/Endstop.js +0 -26
  103. package/dist/src/sensors/FilamentMonitors/FilamentMonitorBase.d.ts +0 -24
  104. package/dist/src/sensors/FilamentMonitors/FilamentMonitorBase.js +0 -35
  105. package/dist/src/sensors/FilamentMonitors/LaserFilamentMonitor.d.ts +0 -22
  106. package/dist/src/sensors/FilamentMonitors/LaserFilamentMonitor.js +0 -72
  107. package/dist/src/sensors/FilamentMonitors/PulsedFilamentMonitor.d.ts +0 -21
  108. package/dist/src/sensors/FilamentMonitors/PulsedFilamentMonitor.js +0 -71
  109. package/dist/src/sensors/FilamentMonitors/RotatingMagnetFilamentMonitor.d.ts +0 -22
  110. package/dist/src/sensors/FilamentMonitors/RotatingMagnetFilamentMonitor.js +0 -72
  111. package/dist/src/sensors/FilamentMonitors/index.d.ts +0 -11
  112. package/dist/src/sensors/FilamentMonitors/index.js +0 -66
  113. package/dist/src/sensors/Probe.d.ts +0 -33
  114. package/dist/src/sensors/Probe.js +0 -44
  115. package/dist/src/sensors/index.d.ts +0 -21
  116. package/dist/src/sensors/index.js +0 -49
  117. package/dist/src/spindles/index.d.ts +0 -20
  118. package/dist/src/spindles/index.js +0 -31
  119. package/dist/src/state/MachineStatus.d.ts +0 -17
  120. package/dist/src/state/MachineStatus.js +0 -21
  121. package/dist/src/state/MessageBox.d.ts +0 -26
  122. package/dist/src/state/MessageBox.js +0 -42
  123. package/dist/src/state/RestorePoint.d.ts +0 -12
  124. package/dist/src/state/RestorePoint.js +0 -22
  125. package/dist/src/state/index.d.ts +0 -60
  126. package/dist/src/state/index.js +0 -100
  127. package/dist/src/tools/index.d.ts +0 -26
  128. package/dist/src/tools/index.js +0 -37
  129. package/dist/src/userSessions/index.d.ts +0 -18
  130. package/dist/src/userSessions/index.js +0 -30
  131. package/dist/src/volumes/index.d.ts +0 -11
  132. package/dist/src/volumes/index.js +0 -21
@@ -13,9 +13,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
20
17
  exports.setArrayItem = void 0;
21
18
  // Expose all the sub-exports
@@ -43,7 +40,7 @@ __exportStar(require("./userSessions"), exports);
43
40
  __exportStar(require("./volumes"), exports);
44
41
  __exportStar(require("./ObjectModel"), exports);
45
42
  // Expose ObjectModel as default export
46
- const ObjectModel_1 = __importDefault(require("./ObjectModel"));
43
+ const ObjectModel_1 = require("./ObjectModel");
47
44
  exports.default = ObjectModel_1.default;
48
45
  // Unfortunately we need to define a way to update arrays to remain compatible with Vue 2 (due to IE11).
49
46
  // This will become obsolete as soon as DWC is upgraded to Vue 3, but that isn't going to happen anytime soon.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duet3d/objectmodel",
3
- "version": "3.5.0-beta.41",
3
+ "version": "3.5.0-beta.42",
4
4
  "description": "TypeScript implementation of the Duet3D Object Model",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,6 +27,6 @@
27
27
  "typescript": "^5.0.2"
28
28
  },
29
29
  "files": [
30
- "/dist"
30
+ "/dist/src"
31
31
  ]
32
32
  }
package/dist/package.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "name": "@duet3d/objectmodel",
3
- "version": "3.5.0-beta.41",
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": "^29.4.0",
25
- "jest": "^29.4.1",
26
- "ts-jest": "^29.0.5",
27
- "typescript": "^5.0.2"
28
- },
29
- "files": [
30
- "/dist"
31
- ]
32
- }
@@ -1,37 +0,0 @@
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,103 +0,0 @@
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 +0,0 @@
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,108 +0,0 @@
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,47 +0,0 @@
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 +0,0 @@
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 +0,0 @@
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,15 +0,0 @@
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;