bpmn-moddle 8.0.0 → 8.1.0

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/README.md CHANGED
@@ -9,7 +9,7 @@ __bpmn-moddle__ uses the [BPMN 2.0 meta-model](http://www.omg.org/spec/BPMN/2.0/
9
9
 
10
10
  ## Usage
11
11
 
12
- Get the library via [npm package](https://www.npmjs.org/package/bpmn-moddle). Consume it in NodeJS, via UMD or bundle it for the browser using your favorite module bundler.
12
+ Get the library via [npm package](https://www.npmjs.org/package/bpmn-moddle). Consume it in NodeJS, via UMD or bundle it using your favorite build tool.
13
13
 
14
14
  ```javascript
15
15
  import BpmnModdle from 'bpmn-moddle';
@@ -51,17 +51,13 @@ const {
51
51
 
52
52
  ## Building the Project
53
53
 
54
- To run the test suite that includes XSD schema validation you must have a Java JDK installed and properly exposed through the `JAVA_HOME` variable.
54
+ The tests include XSD schema validation. They required you to have a Java SDK installed and exposed through the `JAVA_HOME` variable.
55
55
 
56
- Execute the test via
57
-
58
- ```
56
+ ```bash
57
+ # execute the test
59
58
  npm test
60
- ```
61
59
 
62
- Perform a complete build of the application via
63
-
64
- ```
60
+ # perform a full build
65
61
  npm run all
66
62
  ```
67
63
 
@@ -19,6 +19,14 @@
19
19
  return obj === undefined;
20
20
  }
21
21
 
22
+ function isDefined(obj) {
23
+ return obj !== undefined;
24
+ }
25
+
26
+ function isNil(obj) {
27
+ return obj == null;
28
+ }
29
+
22
30
  function isArray(obj) {
23
31
  return nativeToString.call(obj) === '[object Array]';
24
32
  }
@@ -204,6 +212,54 @@
204
212
  return Object.assign(target, ...others);
205
213
  }
206
214
 
215
+ /**
216
+ * Sets a nested property of a given object to the specified value.
217
+ *
218
+ * This mutates the object and returns it.
219
+ *
220
+ * @param {Object} target The target of the set operation.
221
+ * @param {(string|number)[]} path The path to the nested value.
222
+ * @param {any} value The value to set.
223
+ */
224
+ function set(target, path, value) {
225
+
226
+ let currentTarget = target;
227
+
228
+ forEach(path, function(key, idx) {
229
+
230
+ if (typeof key !== 'number' && typeof key !== 'string') {
231
+ throw new Error('illegal key type: ' + typeof key + '. Key should be of type number or string.');
232
+ }
233
+
234
+ if (key === 'constructor') {
235
+ throw new Error('illegal key: constructor');
236
+ }
237
+
238
+ if (key === '__proto__') {
239
+ throw new Error('illegal key: __proto__');
240
+ }
241
+
242
+ let nextKey = path[idx + 1];
243
+ let nextTarget = currentTarget[key];
244
+
245
+ if (isDefined(nextKey) && isNil(nextTarget)) {
246
+ nextTarget = currentTarget[key] = isNaN(+nextKey) ? {} : [];
247
+ }
248
+
249
+ if (isUndefined$1(nextKey)) {
250
+ if (isUndefined$1(value)) {
251
+ delete currentTarget[key];
252
+ } else {
253
+ currentTarget[key] = value;
254
+ }
255
+ } else {
256
+ currentTarget = nextTarget;
257
+ }
258
+ });
259
+
260
+ return target;
261
+ }
262
+
207
263
  /**
208
264
  * Pick given properties from the target object.
209
265
  *
@@ -543,6 +599,17 @@
543
599
  this.idProperty = p;
544
600
  };
545
601
 
602
+ DescriptorBuilder.prototype.assertNotTrait = function(typeDescriptor) {
603
+
604
+ const _extends = typeDescriptor.extends || [];
605
+
606
+ if (_extends.length) {
607
+ throw new Error(
608
+ `cannot create <${ typeDescriptor.name }> extending <${ typeDescriptor.extends }>`
609
+ );
610
+ }
611
+ };
612
+
546
613
  DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
547
614
  var propertyName = p.name,
548
615
  definedProperty = this.propertiesByName[propertyName];
@@ -561,6 +628,10 @@
561
628
 
562
629
  DescriptorBuilder.prototype.addTrait = function(t, inherited) {
563
630
 
631
+ if (inherited) {
632
+ this.assertNotTrait(t);
633
+ }
634
+
564
635
  var typesByName = this.allTypesByName,
565
636
  types = this.allTypes;
566
637
 
@@ -694,7 +765,9 @@
694
765
  });
695
766
 
696
767
  forEach(type.extends, bind(function(extendsName) {
697
- var extended = this.typeMap[extendsName];
768
+ var extendsNameNs = parseName(extendsName, ns.prefix);
769
+
770
+ var extended = this.typeMap[extendsNameNs.name];
698
771
 
699
772
  extended.traits = extended.traits || [];
700
773
  extended.traits.push(name);
@@ -723,24 +796,33 @@
723
796
 
724
797
  var self = this;
725
798
 
799
+ /**
800
+ * Traverse the selected super type or trait
801
+ *
802
+ * @param {String} cls
803
+ * @param {Boolean} [trait=false]
804
+ */
805
+ function traverse(cls, trait) {
806
+ var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
807
+ self.mapTypes(parentNs, iterator, trait);
808
+ }
809
+
726
810
  /**
727
811
  * Traverse the selected trait.
728
812
  *
729
813
  * @param {String} cls
730
814
  */
731
815
  function traverseTrait(cls) {
732
- return traverseSuper(cls, true);
816
+ return traverse(cls, true);
733
817
  }
734
818
 
735
819
  /**
736
- * Traverse the selected super type or trait
820
+ * Traverse the selected super type
737
821
  *
738
822
  * @param {String} cls
739
- * @param {Boolean} [trait=false]
740
823
  */
741
- function traverseSuper(cls, trait) {
742
- var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
743
- self.mapTypes(parentNs, iterator, trait);
824
+ function traverseSuper(cls) {
825
+ return traverse(cls, false);
744
826
  }
745
827
 
746
828
  if (!type) {
@@ -823,7 +905,7 @@
823
905
  throw new TypeError('property name must be a non-empty string');
824
906
  }
825
907
 
826
- var property = this.model.getPropertyDescriptor(target, name);
908
+ var property = this.getProperty(target, name);
827
909
 
828
910
  var propertyName = property && property.name;
829
911
 
@@ -834,7 +916,7 @@
834
916
  if (property) {
835
917
  delete target[propertyName];
836
918
  } else {
837
- delete target.$attrs[name];
919
+ delete target.$attrs[stripGlobal(name)];
838
920
  }
839
921
  } else {
840
922
 
@@ -847,7 +929,7 @@
847
929
  defineProperty(target, property, value);
848
930
  }
849
931
  } else {
850
- target.$attrs[name] = value;
932
+ target.$attrs[stripGlobal(name)] = value;
851
933
  }
852
934
  }
853
935
  };
@@ -862,10 +944,10 @@
862
944
  */
863
945
  Properties.prototype.get = function(target, name) {
864
946
 
865
- var property = this.model.getPropertyDescriptor(target, name);
947
+ var property = this.getProperty(target, name);
866
948
 
867
949
  if (!property) {
868
- return target.$attrs[name];
950
+ return target.$attrs[stripGlobal(name)];
869
951
  }
870
952
 
871
953
  var propertyName = property.name;
@@ -919,6 +1001,44 @@
919
1001
  this.define(target, '$model', { value: model });
920
1002
  };
921
1003
 
1004
+ /**
1005
+ * Return property with the given name on the element.
1006
+ *
1007
+ * @param {any} target
1008
+ * @param {string} name
1009
+ *
1010
+ * @return {object | null} property
1011
+ */
1012
+ Properties.prototype.getProperty = function(target, name) {
1013
+
1014
+ var model = this.model;
1015
+
1016
+ var property = model.getPropertyDescriptor(target, name);
1017
+
1018
+ if (property) {
1019
+ return property;
1020
+ }
1021
+
1022
+ if (name.includes(':')) {
1023
+ return null;
1024
+ }
1025
+
1026
+ const strict = model.config.strict;
1027
+
1028
+ if (typeof strict !== 'undefined') {
1029
+ const error = new TypeError(`unknown property <${ name }> on <${ target.$type }>`);
1030
+
1031
+ if (strict) {
1032
+ throw error;
1033
+ } else {
1034
+
1035
+ // eslint-disable-next-line no-undef
1036
+ typeof console !== 'undefined' && console.warn(error);
1037
+ }
1038
+ }
1039
+
1040
+ return null;
1041
+ };
922
1042
 
923
1043
  function isUndefined(val) {
924
1044
  return typeof val === 'undefined';
@@ -933,6 +1053,10 @@
933
1053
  });
934
1054
  }
935
1055
 
1056
+ function stripGlobal(name) {
1057
+ return name.replace(/^:/, '');
1058
+ }
1059
+
936
1060
  // Moddle implementation /////////////////////////////////////////////////
937
1061
 
938
1062
  /**
@@ -955,8 +1079,10 @@
955
1079
  * var moddle = new Moddle([pkg]);
956
1080
  *
957
1081
  * @param {Array<Package>} packages the packages to contain
1082
+ *
1083
+ * @param { { strict?: boolean } } [config] moddle configuration
958
1084
  */
959
- function Moddle(packages) {
1085
+ function Moddle(packages, config = {}) {
960
1086
 
961
1087
  this.properties = new Properties(this);
962
1088
 
@@ -964,6 +1090,8 @@
964
1090
  this.registry = new Registry(packages, this.properties);
965
1091
 
966
1092
  this.typeCache = {};
1093
+
1094
+ this.config = config;
967
1095
  }
968
1096
 
969
1097
 
@@ -1057,6 +1185,12 @@
1057
1185
  $type: name,
1058
1186
  $instanceOf: function(type) {
1059
1187
  return type === this.$type;
1188
+ },
1189
+ get: function(key) {
1190
+ return this[key];
1191
+ },
1192
+ set: function(key, value) {
1193
+ set(this, [ key ], value);
1060
1194
  }
1061
1195
  };
1062
1196
 
@@ -1072,6 +1206,8 @@
1072
1206
 
1073
1207
  this.properties.defineDescriptor(element, descriptor);
1074
1208
  this.properties.defineModel(element, this);
1209
+ this.properties.define(element, 'get', { enumerable: false, writable: true });
1210
+ this.properties.define(element, 'set', { enumerable: false, writable: true });
1075
1211
  this.properties.define(element, '$parent', { enumerable: false, writable: true });
1076
1212
  this.properties.define(element, '$instanceOf', { enumerable: false, writable: true });
1077
1213
 
@@ -4926,7 +5062,6 @@
4926
5062
  {
4927
5063
  name: "target",
4928
5064
  type: "LinkEventDefinition",
4929
- isAttr: true,
4930
5065
  isReference: true
4931
5066
  },
4932
5067
  {
package/dist/index.cjs CHANGED
@@ -919,7 +919,6 @@ var types$5 = [
919
919
  {
920
920
  name: "target",
921
921
  type: "LinkEventDefinition",
922
- isAttr: true,
923
922
  isReference: true
924
923
  },
925
924
  {
package/dist/index.esm.js CHANGED
@@ -917,7 +917,6 @@ var types$5 = [
917
917
  {
918
918
  name: "target",
919
919
  type: "LinkEventDefinition",
920
- isAttr: true,
921
920
  isReference: true
922
921
  },
923
922
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-moddle",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "description": "A moddle wrapper for BPMN 2.0",
5
5
  "scripts": {
6
6
  "all": "run-s generate-schema lint test distro",
@@ -43,25 +43,24 @@
43
43
  "devDependencies": {
44
44
  "@babel/eslint-parser": "^7.19.1",
45
45
  "@babel/plugin-syntax-import-assertions": "^7.18.6",
46
- "@rollup/plugin-commonjs": "^22.0.2",
47
- "@rollup/plugin-json": "^4.1.0",
48
- "@rollup/plugin-node-resolve": "^14.1.0",
49
- "acorn-import-assertions": "^1.8.0",
46
+ "@rollup/plugin-commonjs": "^25.0.7",
47
+ "@rollup/plugin-json": "^6.1.0",
48
+ "@rollup/plugin-node-resolve": "^15.2.3",
49
+ "@rollup/plugin-terser": "^0.4.4",
50
50
  "bpmn-in-color-moddle": "^0.1.0",
51
- "chai": "^4.3.6",
51
+ "chai": "^4.3.10",
52
52
  "cmof-parser": "^0.5.2",
53
53
  "eslint": "^8.24.0",
54
54
  "eslint-plugin-bpmn-io": "^0.16.0",
55
- "mocha": "^10.0.0",
55
+ "mocha": "^10.2.0",
56
56
  "npm-run-all": "^4.1.5",
57
- "rollup": "^2.79.1",
58
- "rollup-plugin-terser": "^7.0.2",
57
+ "rollup": "^4.9.1",
59
58
  "xsd-schema-validator": "^0.7.0"
60
59
  },
61
60
  "dependencies": {
62
61
  "min-dash": "^4.0.0",
63
- "moddle": "^6.0.0",
64
- "moddle-xml": "^10.0.0"
62
+ "moddle": "^6.2.3",
63
+ "moddle-xml": "^10.1.0"
65
64
  },
66
65
  "files": [
67
66
  "dist",
@@ -823,7 +823,6 @@
823
823
  {
824
824
  "name": "target",
825
825
  "type": "LinkEventDefinition",
826
- "isAttr": true,
827
826
  "isReference": true
828
827
  },
829
828
  {