Comparing version 5.0.2 to 5.0.3
@@ -9,2 +9,7 @@ # Changelog | ||
## 5.0.3 | ||
* `FIX`: use getters for read-only properties ([#40](https://github.com/bpmn-io/moddle/pull/40)) | ||
* `CHORE`: add prepare script ([#33](https://github.com/bpmn-io/moddle/pull/33))) | ||
## 5.0.2 | ||
@@ -11,0 +16,0 @@ |
@@ -655,2 +655,16 @@ import { forEach, bind, pick, assign, isString, isObject } from 'min-dash'; | ||
Properties.prototype.define = function(target, name, options) { | ||
if (!options.writable) { | ||
var value = options.value; | ||
// use getters for read-only variables to support ES6 proxies | ||
// cf. https://github.com/bpmn-io/internal-docs/issues/386 | ||
options = assign({}, options, { | ||
get: function() { return value; } | ||
}); | ||
delete options.value; | ||
} | ||
Object.defineProperty(target, name, options); | ||
@@ -657,0 +671,0 @@ }; |
@@ -659,2 +659,16 @@ 'use strict'; | ||
Properties.prototype.define = function(target, name, options) { | ||
if (!options.writable) { | ||
var value = options.value; | ||
// use getters for read-only variables to support ES6 proxies | ||
// cf. https://github.com/bpmn-io/internal-docs/issues/386 | ||
options = minDash.assign({}, options, { | ||
get: function() { return value; } | ||
}); | ||
delete options.value; | ||
} | ||
Object.defineProperty(target, name, options); | ||
@@ -661,0 +675,0 @@ }; |
@@ -791,2 +791,16 @@ (function (global, factory) { | ||
Properties.prototype.define = function(target, name, options) { | ||
if (!options.writable) { | ||
var value = options.value; | ||
// use getters for read-only variables to support ES6 proxies | ||
// cf. https://github.com/bpmn-io/internal-docs/issues/386 | ||
options = assign({}, options, { | ||
get: function() { return value; } | ||
}); | ||
delete options.value; | ||
} | ||
Object.defineProperty(target, name, options); | ||
@@ -793,0 +807,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Moddle={})}(this,function(e){"use strict";var t=Object.prototype.toString,r=Object.prototype.hasOwnProperty;function i(e,t){return r.call(e,t)}function n(e,r){if(void 0!==e){var n=function(e){return"[object Array]"===t.call(e)}(e)?p:o;for(var s in e){if(i(e,s))if(!1===r(e[s],n(s)))return}}}function o(e){return e}function p(e){return Number(e)}function s(e,t){return e.bind(t)}var a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e};function f(e){for(var t=arguments.length,r=Array(t>1?t-1:0),i=1;i<t;i++)r[i-1]=arguments[i];return a.apply(void 0,[e].concat(r))}function y(){}function c(e,t){this.model=e,this.properties=t}y.prototype.get=function(e){return this.$model.properties.get(this,e)},y.prototype.set=function(e,t){this.$model.properties.set(this,e,t)},c.prototype.createType=function(e){var t=this.model,r=this.properties,i=Object.create(y.prototype);n(e.properties,function(e){e.isMany||void 0===e.default||(i[e.name]=e.default)}),r.defineModel(i,t),r.defineDescriptor(i,e);var o=e.ns.name;function p(e){r.define(this,"$type",{value:o,enumerable:!0}),r.define(this,"$attrs",{value:{}}),r.define(this,"$parent",{writable:!0}),n(e,s(function(e,t){this.set(t,e)},this))}return p.prototype=i,p.hasType=i.$instanceOf=this.model.hasType,r.defineModel(p,t),r.defineDescriptor(p,e),p};var u={String:!0,Boolean:!0,Integer:!0,Real:!0,Element:!0},d={String:function(e){return e},Boolean:function(e){return"true"===e},Integer:function(e){return parseInt(e,10)},Real:function(e){return parseFloat(e)}};function l(e){return!!u[e]}function h(e,t){var r,i,n=e.split(/:/);if(1===n.length)r=e,i=t;else{if(2!==n.length)throw new Error("expected <prefix:localName> or <localName>, got "+e);r=n[1],i=n[0]}return{name:e=(i?i+":":"")+r,prefix:i,localName:r}}function m(e){this.ns=e,this.name=e.name,this.allTypes=[],this.allTypesByName={},this.properties=[],this.propertiesByName={}}function g(e,t){this.packageMap={},this.typeMap={},this.packages=[],this.properties=t,n(e,s(this.registerPackage,this))}function v(e,t,r){var i=t[r];if(i in e)throw new Error("package with "+r+" <"+i+"> already defined")}function P(e){this.model=e}function b(e,t,r){Object.defineProperty(e,t.name,{enumerable:!t.isReference,writable:!0,value:r,configurable:!0})}function w(e){this.properties=new P(this),this.factory=new c(this,this.properties),this.registry=new g(e,this.properties),this.typeCache={}}m.prototype.build=function(){return e=this,t=["ns","name","allTypes","allTypesByName","properties","propertiesByName","bodyProperty","idProperty"],r={},i=Object(e),n(t,function(t){t in i&&(r[t]=e[t])}),r;var e,t,r,i},m.prototype.addProperty=function(e,t,r){"boolean"==typeof t&&(r=t,t=void 0),this.addNamedProperty(e,!1!==r);var i=this.properties;void 0!==t?i.splice(t,0,e):i.push(e)},m.prototype.replaceProperty=function(e,t,r){var i=e.ns,n=this.properties,o=this.propertiesByName,p=e.name!==t.name;if(e.isId){if(!t.isId)throw new Error("property <"+t.ns.name+"> must be id property to refine <"+e.ns.name+">");this.setIdProperty(t,!1)}if(e.isBody){if(!t.isBody)throw new Error("property <"+t.ns.name+"> must be body property to refine <"+e.ns.name+">");this.setBodyProperty(t,!1)}var s=n.indexOf(e);if(-1===s)throw new Error("property <"+i.name+"> not found in property list");n.splice(s,1),this.addProperty(t,r?void 0:s,p),o[i.name]=o[i.localName]=t},m.prototype.redefineProperty=function(e,t,r){var i=e.ns.prefix,n=t.split("#"),o=h(n[0],i),p=h(n[1],o.prefix).name,s=this.propertiesByName[p];if(!s)throw new Error("refined property <"+p+"> not found");this.replaceProperty(s,e,r),delete e.redefines},m.prototype.addNamedProperty=function(e,t){var r=e.ns,i=this.propertiesByName;t&&(this.assertNotDefined(e,r.name),this.assertNotDefined(e,r.localName)),i[r.name]=i[r.localName]=e},m.prototype.removeNamedProperty=function(e){var t=e.ns,r=this.propertiesByName;delete r[t.name],delete r[t.localName]},m.prototype.setBodyProperty=function(e,t){if(t&&this.bodyProperty)throw new Error("body property defined multiple times (<"+this.bodyProperty.ns.name+">, <"+e.ns.name+">)");this.bodyProperty=e},m.prototype.setIdProperty=function(e,t){if(t&&this.idProperty)throw new Error("id property defined multiple times (<"+this.idProperty.ns.name+">, <"+e.ns.name+">)");this.idProperty=e},m.prototype.assertNotDefined=function(e,t){var r=e.name,i=this.propertiesByName[r];if(i)throw new Error("property <"+r+"> already defined; override of <"+i.definedBy.ns.name+"#"+i.ns.name+"> by <"+e.definedBy.ns.name+"#"+e.ns.name+"> not allowed without redefines")},m.prototype.hasProperty=function(e){return this.propertiesByName[e]},m.prototype.addTrait=function(e,t){var r=this.allTypesByName,i=this.allTypes,o=e.name;o in r||(n(e.properties,s(function(r){r=f({},r,{name:r.ns.localName,inherited:t}),Object.defineProperty(r,"definedBy",{value:e});var i=r.replaces,n=r.redefines;i||n?this.redefineProperty(r,i||n,i):(r.isBody&&this.setBodyProperty(r),r.isId&&this.setIdProperty(r),this.addProperty(r))},this)),i.push(e),r[o]=e)},g.prototype.getPackage=function(e){return this.packageMap[e]},g.prototype.getPackages=function(){return this.packages},g.prototype.registerPackage=function(e){e=f({},e);var t=this.packageMap;v(t,e,"prefix"),v(t,e,"uri"),n(e.types,s(function(t){this.registerType(t,e)},this)),t[e.uri]=t[e.prefix]=e,this.packages.push(e)},g.prototype.registerType=function(e,t){var r=h((e=f({},e,{superClass:(e.superClass||[]).slice(),extends:(e.extends||[]).slice(),properties:(e.properties||[]).slice(),meta:f(e.meta||{})})).name,t.prefix),i=r.name,o={};n(e.properties,s(function(e){var t=h(e.name,r.prefix),i=t.name;l(e.type)||(e.type=h(e.type,t.prefix).name),f(e,{ns:t,name:i}),o[i]=e},this)),f(e,{ns:r,name:i,propertiesByName:o}),n(e.extends,s(function(e){var t=this.typeMap[e];t.traits=t.traits||[],t.traits.push(i)},this)),this.definePackage(e,t),this.typeMap[i]=e},g.prototype.mapTypes=function(e,t,r){var i=l(e.name)?{name:e.name}:this.typeMap[e.name],o=this;function p(e){return s(e,!0)}function s(r,i){var n=h(r,l(r)?"":e.prefix);o.mapTypes(n,t,i)}if(!i)throw new Error("unknown type <"+e.name+">");n(i.superClass,r?p:s),t(i,!r),n(i.traits,p)},g.prototype.getEffectiveDescriptor=function(e){var t=h(e),r=new m(t);this.mapTypes(t,function(e,t){r.addTrait(e,t)});var i=r.build();return this.definePackage(i,i.allTypes[i.allTypes.length-1].$pkg),i},g.prototype.definePackage=function(e,t){this.properties.define(e,"$pkg",{value:t})},P.prototype.set=function(e,t,r){var i=this.model.getPropertyDescriptor(e,t),n=i&&i.name;void 0===r?i?delete e[n]:delete e.$attrs[t]:i?n in e?e[n]=r:b(e,i,r):e.$attrs[t]=r},P.prototype.get=function(e,t){var r=this.model.getPropertyDescriptor(e,t);if(!r)return e.$attrs[t];var i=r.name;return!e[i]&&r.isMany&&b(e,r,[]),e[i]},P.prototype.define=function(e,t,r){Object.defineProperty(e,t,r)},P.prototype.defineDescriptor=function(e,t){this.define(e,"$descriptor",{value:t})},P.prototype.defineModel=function(e,t){this.define(e,"$model",{value:t})},w.prototype.create=function(e,t){var r=this.getType(e);if(!r)throw new Error("unknown type <"+e+">");return new r(t)},w.prototype.getType=function(e){var r,i=this.typeCache,n=(r=e,"[object String]"===t.call(r)?e:e.ns.name),o=i[n];return o||(e=this.registry.getEffectiveDescriptor(n),o=i[n]=this.factory.createType(e)),o},w.prototype.createAny=function(e,r,i){var o=h(e),p={$type:e,$instanceOf:function(e){return e===this.$type}},s={name:e,isGeneric:!0,ns:{prefix:o.prefix,localName:o.localName,uri:r}};return this.properties.defineDescriptor(p,s),this.properties.defineModel(p,this),this.properties.define(p,"$parent",{enumerable:!1,writable:!0}),this.properties.define(p,"$instanceOf",{enumerable:!1,writable:!0}),n(i,function(e,r){var i;i=e,"[object Object]"===t.call(i)&&void 0!==e.value?p[e.name]=e.value:p[r]=e}),p},w.prototype.getPackage=function(e){return this.registry.getPackage(e)},w.prototype.getPackages=function(){return this.registry.getPackages()},w.prototype.getElementDescriptor=function(e){return e.$descriptor},w.prototype.hasType=function(e,t){return void 0===t&&(t=e,e=this),t in e.$model.getElementDescriptor(e).allTypesByName},w.prototype.getPropertyDescriptor=function(e,t){return this.getElementDescriptor(e).propertiesByName[t]},w.prototype.getTypeDescriptor=function(e){return this.registry.typeMap[e]},e.Moddle=w,e.coerceType=function(e,t){var r=d[e];return r?r(t):t},e.isBuiltInType=l,e.isSimpleType=function(e){return!!d[e]},e.parseNameNS=h,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Moddle={})}(this,function(e){"use strict";var t=Object.prototype.toString,r=Object.prototype.hasOwnProperty;function i(e,t){return r.call(e,t)}function n(e,r){if(void 0!==e){var n=function(e){return"[object Array]"===t.call(e)}(e)?p:o;for(var s in e){if(i(e,s))if(!1===r(e[s],n(s)))return}}}function o(e){return e}function p(e){return Number(e)}function s(e,t){return e.bind(t)}var a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e};function f(e){for(var t=arguments.length,r=Array(t>1?t-1:0),i=1;i<t;i++)r[i-1]=arguments[i];return a.apply(void 0,[e].concat(r))}function y(){}function c(e,t){this.model=e,this.properties=t}y.prototype.get=function(e){return this.$model.properties.get(this,e)},y.prototype.set=function(e,t){this.$model.properties.set(this,e,t)},c.prototype.createType=function(e){var t=this.model,r=this.properties,i=Object.create(y.prototype);n(e.properties,function(e){e.isMany||void 0===e.default||(i[e.name]=e.default)}),r.defineModel(i,t),r.defineDescriptor(i,e);var o=e.ns.name;function p(e){r.define(this,"$type",{value:o,enumerable:!0}),r.define(this,"$attrs",{value:{}}),r.define(this,"$parent",{writable:!0}),n(e,s(function(e,t){this.set(t,e)},this))}return p.prototype=i,p.hasType=i.$instanceOf=this.model.hasType,r.defineModel(p,t),r.defineDescriptor(p,e),p};var u={String:!0,Boolean:!0,Integer:!0,Real:!0,Element:!0},d={String:function(e){return e},Boolean:function(e){return"true"===e},Integer:function(e){return parseInt(e,10)},Real:function(e){return parseFloat(e)}};function l(e){return!!u[e]}function h(e,t){var r,i,n=e.split(/:/);if(1===n.length)r=e,i=t;else{if(2!==n.length)throw new Error("expected <prefix:localName> or <localName>, got "+e);r=n[1],i=n[0]}return{name:e=(i?i+":":"")+r,prefix:i,localName:r}}function m(e){this.ns=e,this.name=e.name,this.allTypes=[],this.allTypesByName={},this.properties=[],this.propertiesByName={}}function v(e,t){this.packageMap={},this.typeMap={},this.packages=[],this.properties=t,n(e,s(this.registerPackage,this))}function g(e,t,r){var i=t[r];if(i in e)throw new Error("package with "+r+" <"+i+"> already defined")}function P(e){this.model=e}function b(e,t,r){Object.defineProperty(e,t.name,{enumerable:!t.isReference,writable:!0,value:r,configurable:!0})}function w(e){this.properties=new P(this),this.factory=new c(this,this.properties),this.registry=new v(e,this.properties),this.typeCache={}}m.prototype.build=function(){return e=this,t=["ns","name","allTypes","allTypesByName","properties","propertiesByName","bodyProperty","idProperty"],r={},i=Object(e),n(t,function(t){t in i&&(r[t]=e[t])}),r;var e,t,r,i},m.prototype.addProperty=function(e,t,r){"boolean"==typeof t&&(r=t,t=void 0),this.addNamedProperty(e,!1!==r);var i=this.properties;void 0!==t?i.splice(t,0,e):i.push(e)},m.prototype.replaceProperty=function(e,t,r){var i=e.ns,n=this.properties,o=this.propertiesByName,p=e.name!==t.name;if(e.isId){if(!t.isId)throw new Error("property <"+t.ns.name+"> must be id property to refine <"+e.ns.name+">");this.setIdProperty(t,!1)}if(e.isBody){if(!t.isBody)throw new Error("property <"+t.ns.name+"> must be body property to refine <"+e.ns.name+">");this.setBodyProperty(t,!1)}var s=n.indexOf(e);if(-1===s)throw new Error("property <"+i.name+"> not found in property list");n.splice(s,1),this.addProperty(t,r?void 0:s,p),o[i.name]=o[i.localName]=t},m.prototype.redefineProperty=function(e,t,r){var i=e.ns.prefix,n=t.split("#"),o=h(n[0],i),p=h(n[1],o.prefix).name,s=this.propertiesByName[p];if(!s)throw new Error("refined property <"+p+"> not found");this.replaceProperty(s,e,r),delete e.redefines},m.prototype.addNamedProperty=function(e,t){var r=e.ns,i=this.propertiesByName;t&&(this.assertNotDefined(e,r.name),this.assertNotDefined(e,r.localName)),i[r.name]=i[r.localName]=e},m.prototype.removeNamedProperty=function(e){var t=e.ns,r=this.propertiesByName;delete r[t.name],delete r[t.localName]},m.prototype.setBodyProperty=function(e,t){if(t&&this.bodyProperty)throw new Error("body property defined multiple times (<"+this.bodyProperty.ns.name+">, <"+e.ns.name+">)");this.bodyProperty=e},m.prototype.setIdProperty=function(e,t){if(t&&this.idProperty)throw new Error("id property defined multiple times (<"+this.idProperty.ns.name+">, <"+e.ns.name+">)");this.idProperty=e},m.prototype.assertNotDefined=function(e,t){var r=e.name,i=this.propertiesByName[r];if(i)throw new Error("property <"+r+"> already defined; override of <"+i.definedBy.ns.name+"#"+i.ns.name+"> by <"+e.definedBy.ns.name+"#"+e.ns.name+"> not allowed without redefines")},m.prototype.hasProperty=function(e){return this.propertiesByName[e]},m.prototype.addTrait=function(e,t){var r=this.allTypesByName,i=this.allTypes,o=e.name;o in r||(n(e.properties,s(function(r){r=f({},r,{name:r.ns.localName,inherited:t}),Object.defineProperty(r,"definedBy",{value:e});var i=r.replaces,n=r.redefines;i||n?this.redefineProperty(r,i||n,i):(r.isBody&&this.setBodyProperty(r),r.isId&&this.setIdProperty(r),this.addProperty(r))},this)),i.push(e),r[o]=e)},v.prototype.getPackage=function(e){return this.packageMap[e]},v.prototype.getPackages=function(){return this.packages},v.prototype.registerPackage=function(e){e=f({},e);var t=this.packageMap;g(t,e,"prefix"),g(t,e,"uri"),n(e.types,s(function(t){this.registerType(t,e)},this)),t[e.uri]=t[e.prefix]=e,this.packages.push(e)},v.prototype.registerType=function(e,t){var r=h((e=f({},e,{superClass:(e.superClass||[]).slice(),extends:(e.extends||[]).slice(),properties:(e.properties||[]).slice(),meta:f(e.meta||{})})).name,t.prefix),i=r.name,o={};n(e.properties,s(function(e){var t=h(e.name,r.prefix),i=t.name;l(e.type)||(e.type=h(e.type,t.prefix).name),f(e,{ns:t,name:i}),o[i]=e},this)),f(e,{ns:r,name:i,propertiesByName:o}),n(e.extends,s(function(e){var t=this.typeMap[e];t.traits=t.traits||[],t.traits.push(i)},this)),this.definePackage(e,t),this.typeMap[i]=e},v.prototype.mapTypes=function(e,t,r){var i=l(e.name)?{name:e.name}:this.typeMap[e.name],o=this;function p(e){return s(e,!0)}function s(r,i){var n=h(r,l(r)?"":e.prefix);o.mapTypes(n,t,i)}if(!i)throw new Error("unknown type <"+e.name+">");n(i.superClass,r?p:s),t(i,!r),n(i.traits,p)},v.prototype.getEffectiveDescriptor=function(e){var t=h(e),r=new m(t);this.mapTypes(t,function(e,t){r.addTrait(e,t)});var i=r.build();return this.definePackage(i,i.allTypes[i.allTypes.length-1].$pkg),i},v.prototype.definePackage=function(e,t){this.properties.define(e,"$pkg",{value:t})},P.prototype.set=function(e,t,r){var i=this.model.getPropertyDescriptor(e,t),n=i&&i.name;void 0===r?i?delete e[n]:delete e.$attrs[t]:i?n in e?e[n]=r:b(e,i,r):e.$attrs[t]=r},P.prototype.get=function(e,t){var r=this.model.getPropertyDescriptor(e,t);if(!r)return e.$attrs[t];var i=r.name;return!e[i]&&r.isMany&&b(e,r,[]),e[i]},P.prototype.define=function(e,t,r){if(!r.writable){var i=r.value;delete(r=f({},r,{get:function(){return i}})).value}Object.defineProperty(e,t,r)},P.prototype.defineDescriptor=function(e,t){this.define(e,"$descriptor",{value:t})},P.prototype.defineModel=function(e,t){this.define(e,"$model",{value:t})},w.prototype.create=function(e,t){var r=this.getType(e);if(!r)throw new Error("unknown type <"+e+">");return new r(t)},w.prototype.getType=function(e){var r,i=this.typeCache,n=(r=e,"[object String]"===t.call(r)?e:e.ns.name),o=i[n];return o||(e=this.registry.getEffectiveDescriptor(n),o=i[n]=this.factory.createType(e)),o},w.prototype.createAny=function(e,r,i){var o=h(e),p={$type:e,$instanceOf:function(e){return e===this.$type}},s={name:e,isGeneric:!0,ns:{prefix:o.prefix,localName:o.localName,uri:r}};return this.properties.defineDescriptor(p,s),this.properties.defineModel(p,this),this.properties.define(p,"$parent",{enumerable:!1,writable:!0}),this.properties.define(p,"$instanceOf",{enumerable:!1,writable:!0}),n(i,function(e,r){var i;i=e,"[object Object]"===t.call(i)&&void 0!==e.value?p[e.name]=e.value:p[r]=e}),p},w.prototype.getPackage=function(e){return this.registry.getPackage(e)},w.prototype.getPackages=function(){return this.registry.getPackages()},w.prototype.getElementDescriptor=function(e){return e.$descriptor},w.prototype.hasType=function(e,t){return void 0===t&&(t=e,e=this),t in e.$model.getElementDescriptor(e).allTypesByName},w.prototype.getPropertyDescriptor=function(e,t){return this.getElementDescriptor(e).propertiesByName[t]},w.prototype.getTypeDescriptor=function(e){return this.registry.typeMap[e]},e.Moddle=w,e.coerceType=function(e,t){var r=d[e];return r?r(t):t},e.isBuiltInType=l,e.isSimpleType=function(e){return!!d[e]},e.parseNameNS=h,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "moddle", | ||
"version": "5.0.2", | ||
"version": "5.0.3", | ||
"description": "A library for importing meta-model based file formats into JS", | ||
@@ -12,2 +12,3 @@ "scripts": { | ||
"build": "rollup -c", | ||
"prepare": "npm run build", | ||
"test:build": "mocha --reporter=spec --recursive test/distro", | ||
@@ -14,0 +15,0 @@ "prepublishOnly": "run-s distro" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83185
2316
1