datatype-expansion
Advanced tools
Comparing version 0.3.8 to 0.4.0
@@ -1,2 +0,2 @@ | ||
var expansion=function(e){"use strict";function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var r=require("lodash"),u=require("./util").isOpaqueType;function p(t,n,i,o){if("string"==typeof t)try{JSON.parse(t),t={type:"json",content:t}}catch(e){}if("string"==typeof t){if(/^\(.+\)$/.test(t)&&(t=t.match(/^\((.+)\)$/)[1]),u(t)||"object"===t||"array"===t)return{type:t};if(t.endsWith("?")&&u(t.replace("?","")))return s({type:"union",anyOf:[{type:t.replace("?","")},{type:"nil"}]},n,i,o);if(t.endsWith("[]"))return{type:"array",items:p(t.match(/^(.+)\[]$/)[1],n,i,o)};if(/^[^|\s]+(?:\|[^|\s]+)+$/.test(t.replace(/\s+/g,"")))return s({anyOf:t.split("|").map(function(e){return e.trim()}),type:"union"},n,i,o);if(t in n){if(t in i)return{type:"$recur"};i=Object.assign(function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}({},t,!0),i);var e=n[t];return o.trackOriginalType&&"object"!==a(e)&&(e={type:e}),e=p(e,n,i,o),o.trackOriginalType&&(e.originalType=t),e}throw new Error("could not resolve: "+t)}if("object"!==a(t))throw new Error("form can only be a string or an object");if(t=r.cloneDeep(t),Array.isArray(t)&&(t={type:t}),t.type=t.type||t.properties&&"object"||t.items&&"array"||o.topLevel||"any","string"==typeof t.type){if("array"===t.type)return y(t,n,i,o);if("object"===t.type)return f(t,n,i,o);if("union"===t.type)return s(t,n,i,o);t.type in n?(t=c(t,n,i,o)).type=p(t.type,n,i,o):t=Object.assign(t,p(t.type,n,i,o))}else Array.isArray(t.type)?(t=c(t,n,i,o)).type=t.type.map(function(e){return p(e,n,i,o)}):"object"===a(t.type)?(t=c(t,n,i,o)).type=p(t.type,n,i,o):t=Object.assign(t,p(t.type,n,i,o));return null!=t.facets&&r.each(t.facets,function(e,r){t.facets[r]=p(e,n,i,o)}),t}function c(e,r,t,n){return void 0!==e.properties&&(e=f(e,r,t,n)),void 0!==e.anyOf&&(e=s(e,r,t,n)),void 0!==e.items&&(e=y(e,r,t,n)),e}function y(e,r,t,n){return e.items=p(e.items||"any",r,t,n),e}function f(e,r,t,n){var i=e.properties;for(var o in i)if(Object.prototype.hasOwnProperty.call(i,o)){var a=p(i[o]||"any",r,t,n);o.endsWith("?")&&(delete i[o],o=o.slice(0,-1),a.required=!1),void 0===a.required&&(a.required=!0),i[o]=a}return void 0===e.additionalProperties&&(e.additionalProperties=!0),e}function s(e,r,t,n){return e.anyOf=e.anyOf.map(function(e){return p(e,r,t,n)}),e}module.exports.expandedForm=function(r,t,n){var i={};"object"===a(n)&&(n=(i=n).callback);var o={};for(var e in t)if(t[e]===r){o[e]=!0;break}if(null==n)return p(r,t,o,i);setTimeout(function(){var e;try{e=p(r,t,o,i)}catch(e){return void n(e,null)}n(null,e)},0)};var t=Object.freeze({}),l=require("lodash"),d=require("./minType"),m=require("./util").consistencyCheck,b=require("./util").isOpaqueType;function v(p,r){var e=(p=l.cloneDeep(p)).type;if(b(e))return m(p);if("array"===e)return p.items=v(p.items||{type:"any"},r),m(p);if("object"===e){var t=p.properties,c=[l.cloneDeep(p)];if(c[0].properties={},l.each(t,function(e,o){var a=v(e,r);if("union"===a.type&&!1!==r.hoistUnions){var u=[];a.anyOf.forEach(function(e){"boolean"==typeof p.required&&(e.required=a.required);for(var r=0,t=c;r<t.length;r++){var n=t[r];n=l.cloneDeep(n);var i=Object.assign({},a,e);delete i.anyOf,n.properties[o]=i,u.push(n)}}),c=u}else c=c.map(function(e){return e.properties[o]=a,e})}),1===c.length)return m(c[0]);if(1<c.length)return p.type="union",delete p.properties,delete p.additionalProperties,p.anyOf=c,m(p)}else{if("union"===e)return p.anyOf=p.anyOf.map(function(e){return v("type"in e?e:{type:e},r)}),m(p);if("object"===a(e)){var n=function r(e){if(void 0!==e.properties)return"object";if(void 0!==e.items)return"array";if("string"==typeof e.type)return e.type;if("object"===a(e.type)){if(!Array.isArray(e.type))return r(e.type);var t=e.type.map(function(e){try{return r(e)}catch(e){return null}}).filter(function(e){return null!==e})[0];if(void 0!==t)return t}throw new Error("Cannot find top level class for node, not in expanded form")}(p),i=l.cloneDeep(p);switch(i.type=n){case"object":i.properties=i.properties||{};break;case"array":i.items=i.items||{type:"any"};break;case"union":i.anyOf=i.anyOf||[]}if(Array.isArray(e))return i=l.cloneDeep(e).map(function(e){return v(e,r)}).reduce(function(e,r){return d(r,e)},v(i,r));var o=v(e,r);return d(o,v(i,r))}}return p}module.exports.canonicalForm=function(r,t){var n={};if("object"===a(t)&&(t=(n=t).callback),null==t)return v(r,n);setTimeout(function(){var e;try{e=v(r,n)}catch(e){return void t(e,null)}t(null,e)},0)};var n=Object.freeze({}),i={expandedForm:t.expandedForm,canonicalForm:n.canonicalForm},o=i.expandedForm,O=i.canonicalForm;return e.canonicalForm=O,e.default=i,e.expandedForm=o,e}({}); | ||
var expansion=function(e){"use strict";function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function u(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function y(e){if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,r){if(e){if("string"==typeof e)return u(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?u(e,r):void 0}}(e))){var r=0,t=function(){};return{s:t,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:t}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var n,o,i=!0,a=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){a=!0,o=e},f:function(){try{i||null==n.return||n.return()}finally{if(a)throw o}}}}var c=require("lodash"),p=require("./util").isOpaqueType;function l(t,n,o,i){if("string"==typeof t)try{JSON.parse(t),t={type:"json",content:t}}catch(e){}if("string"==typeof t){if(/^\(.+\)$/.test(t)&&(t=t.match(/^\((.+)\)$/)[1]),p(t)||"object"===t||"array"===t)return{type:t};if(t.endsWith("?")&&p(t.replace("?","")))return b({type:"union",anyOf:[{type:t.replace("?","")},{type:"nil"}]},n,o,i);if(t.endsWith("[]"))return{type:"array",items:l(t.match(/^(.+)\[]$/)[1],n,o,i)};if(/^[^|\s]+(?:\|[^|\s]+)+$/.test(t.replace(/\s+/g,"")))return b({anyOf:t.split("|").map(function(e){return e.trim()}),type:"union"},n,o,i);if(t in n){if(t in o)return{type:"$recur"};o=Object.assign((u=!0,(a=t)in(r={})?Object.defineProperty(r,a,{value:u,enumerable:!0,configurable:!0,writable:!0}):r[a]=u,r),o);var e=n[t];return i.trackOriginalType&&"object"!==f(e)&&(e={type:e}),e=l(e,n,o,i),i.trackOriginalType&&(e.originalType=t),e}throw new Error("could not resolve: "+t)}if("object"!==f(t))throw new Error("form can only be a string or an object");var r,a,u;if(t=c.cloneDeep(t),Array.isArray(t)&&(t={type:t}),t.type=t.type||t.properties&&"object"||t.items&&"array"||i.topLevel||"any","string"==typeof t.type){if("array"===t.type)return d(t,n,o,i);if("object"===t.type)return m(t,n,o,i);if("union"===t.type)return b(t,n,o,i);t.type in n?(t=s(t,n,o,i)).type=l(t.type,n,o,i):t=Object.assign(t,l(t.type,n,o,i))}else Array.isArray(t.type)?(t=s(t,n,o,i)).type=t.type.map(function(e){return l(e,n,o,i)}):"object"===f(t.type)?(t=s(t,n,o,i)).type=l(t.type,n,o,i):t=Object.assign(t,l(t.type,n,o,i));return null!=t.facets&&c.each(t.facets,function(e,r){t.facets[r]=l(e,n,o,i)}),t}function s(e,r,t,n){return void 0!==e.properties&&(e=m(e,r,t,n)),void 0!==e.anyOf&&(e=b(e,r,t,n)),void 0!==e.items&&(e=d(e,r,t,n)),e}function d(e,r,t,n){return e.items=l(e.items||"any",r,t,n),e}function m(e,r,t,n){var o=e.properties;for(var i in o)if(Object.prototype.hasOwnProperty.call(o,i)){var a=l(o[i]||"any",r,t,n);i.endsWith("?")&&(delete o[i],i=i.slice(0,-1),a.required=!1),void 0===a.required&&(a.required=!0),o[i]=a}return void 0===e.additionalProperties&&(e.additionalProperties=!0),e}function b(e,r,t,n){return e.anyOf=e.anyOf.map(function(e){return l(e,r,t,n)}),e}module.exports.expandedForm=function(r,t,n){var o={};"object"===f(n)&&(n=(o=n).callback);var i={};for(var e in t)if(t[e]===r){i[e]=!0;break}if(null==n)return l(r,t,i,o);setTimeout(function(){var e;try{e=l(r,t,i,o)}catch(e){return void n(e,null)}n(null,e)},0)};var r=Object.freeze({__proto__:null}),v=require("lodash"),a=require("./minType"),h=require("./util").consistencyCheck,O=require("./util").isOpaqueType;function j(c,r){var e=(c=v.cloneDeep(c)).type;if(O(e))return h(c);if("array"===e)return c.items=j(c.items||{type:"any"},r),h(c);if("object"===e){var t=c.properties,p=[v.cloneDeep(c)];if(p[0].properties={},v.each(t,function(e,i){var a=j(e,r);if("union"===a.type&&!1!==r.hoistUnions){var u=[];a.anyOf.forEach(function(e){"boolean"==typeof c.required&&(e.required=a.required);var r,t=y(p);try{for(t.s();!(r=t.n()).done;){var n=r.value;n=v.cloneDeep(n);var o=Object.assign({},a,e);delete o.anyOf,n.properties[i]=o,u.push(n)}}catch(e){t.e(e)}finally{t.f()}}),p=u}else p=p.map(function(e){return e.properties[i]=a,e})}),1===p.length)return h(p[0]);if(1<p.length)return c.type="union",delete c.properties,delete c.additionalProperties,c.anyOf=p,h(c)}else{if("union"===e)return c.anyOf=c.anyOf.map(function(e){return j("type"in e?e:{type:e},r)}),h(c);if("object"===f(e)){var n=function r(e){if(void 0!==e.properties)return"object";if(void 0!==e.items)return"array";if("string"==typeof e.type)return e.type;if("object"===f(e.type)){if(!Array.isArray(e.type))return r(e.type);var t=e.type.map(function(e){try{return r(e)}catch(e){return null}}).filter(function(e){return null!==e})[0];if(void 0!==t)return t}throw new Error("Cannot find top level class for node, not in expanded form")}(c),o=v.cloneDeep(c);switch(o.type=n){case"object":o.properties=o.properties||{};break;case"array":o.items=o.items||{type:"any"};break;case"union":o.anyOf=o.anyOf||[]}if(Array.isArray(e))return o=v.cloneDeep(e).map(function(e){return j(e,r)}).reduce(function(e,r){return a(r,e)},j(o,r));var i=j(e,r);return a(i,j(o,r))}}return c}module.exports.canonicalForm=function(r,t){var n={};if("object"===f(t)&&(t=(n=t).callback),null==t)return j(r,n);setTimeout(function(){var e;try{e=j(r,n)}catch(e){return void t(e,null)}t(null,e)},0)};var t=Object.freeze({__proto__:null}),n={expandedForm:r.expandedForm,canonicalForm:t.canonicalForm},o=n.expandedForm,i=n.canonicalForm;return e.canonicalForm=i,e.default=n,e.expandedForm=o,e}({}); | ||
//# sourceMappingURL=datatype-expansion.js.map |
{ | ||
"name": "datatype-expansion", | ||
"version": "0.3.8", | ||
"version": "0.4.0", | ||
"description": "Utility tool to expand a given RAML type and create a canonical form", | ||
@@ -34,17 +34,17 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.4.5", | ||
"@babel/preset-env": "^7.4.5", | ||
"@babel/core": "^7.7.5", | ||
"@babel/preset-env": "^7.7.6", | ||
"babel-plugin-lodash": "^3.3.4", | ||
"chai": "^4.1.1", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^6.1.4", | ||
"mkdirp": "^1.0.4", | ||
"mocha": "^7.1.2", | ||
"npm-run-all": "^4.1.5", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.12.3", | ||
"nyc": "^15.0.1", | ||
"rimraf": "^3.0.0", | ||
"rollup": "^2.7.3", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-commonjs": "^10.0.1", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.0.1", | ||
"rollup-plugin-uglify": "^6.0.2", | ||
"standard": "^13.1.0", | ||
"nyc": "^14.1.1" | ||
"rollup-plugin-uglify": "^6.0.4", | ||
"standard": "^14.3.1" | ||
}, | ||
@@ -51,0 +51,0 @@ "dependencies": { |
@@ -1,1 +0,1 @@ | ||
{"processes":{"59761df5-5aef-434a-8122-afdb4f924c00":{"parent":null,"children":[]},"ab7303c9-e0d3-460e-a2bd-4ba74e5d038e":{"parent":null,"children":[]}},"files":{"/Users/jstoikovitch/Code/datatype-expansion/src/index.js":["59761df5-5aef-434a-8122-afdb4f924c00","ab7303c9-e0d3-460e-a2bd-4ba74e5d038e"],"/Users/jstoikovitch/Code/datatype-expansion/src/expanded.js":["59761df5-5aef-434a-8122-afdb4f924c00","ab7303c9-e0d3-460e-a2bd-4ba74e5d038e"],"/Users/jstoikovitch/Code/datatype-expansion/src/util.js":["59761df5-5aef-434a-8122-afdb4f924c00","ab7303c9-e0d3-460e-a2bd-4ba74e5d038e"],"/Users/jstoikovitch/Code/datatype-expansion/src/canonical.js":["59761df5-5aef-434a-8122-afdb4f924c00","ab7303c9-e0d3-460e-a2bd-4ba74e5d038e"],"/Users/jstoikovitch/Code/datatype-expansion/src/minType.js":["59761df5-5aef-434a-8122-afdb4f924c00","ab7303c9-e0d3-460e-a2bd-4ba74e5d038e"]},"externalIds":{}} | ||
{"processes":{"38190aed-1a5b-4bae-a5db-ca5077e488f8":{"parent":null,"children":[]},"e0f4b407-a7f6-4b3f-bfe2-1b31e9145f35":{"parent":null,"children":[]}},"files":{"/home/travis/build/raml-org/datatype-expansion/src/canonical.js":["38190aed-1a5b-4bae-a5db-ca5077e488f8","e0f4b407-a7f6-4b3f-bfe2-1b31e9145f35"],"/home/travis/build/raml-org/datatype-expansion/src/expanded.js":["38190aed-1a5b-4bae-a5db-ca5077e488f8","e0f4b407-a7f6-4b3f-bfe2-1b31e9145f35"],"/home/travis/build/raml-org/datatype-expansion/src/index.js":["38190aed-1a5b-4bae-a5db-ca5077e488f8","e0f4b407-a7f6-4b3f-bfe2-1b31e9145f35"],"/home/travis/build/raml-org/datatype-expansion/src/minType.js":["38190aed-1a5b-4bae-a5db-ca5077e488f8","e0f4b407-a7f6-4b3f-bfe2-1b31e9145f35"],"/home/travis/build/raml-org/datatype-expansion/src/util.js":["38190aed-1a5b-4bae-a5db-ca5077e488f8","e0f4b407-a7f6-4b3f-bfe2-1b31e9145f35"]},"externalIds":{}} |
@@ -27,3 +27,3 @@ 'use strict' | ||
try { | ||
const expForm = expandedForm(types['error'], types) | ||
const expForm = expandedForm(types.error, types) | ||
canonicalForm(expForm) | ||
@@ -35,3 +35,3 @@ expect.fail() | ||
it('callback errors should work', function () { | ||
expandedForm(types['error'], types, function (err, expForm) { | ||
expandedForm(types.error, types, function (err, expForm) { | ||
err = null | ||
@@ -38,0 +38,0 @@ canonicalForm(expForm, function (err) { |
Sorry, the diff of this file is not supported yet
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
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
326694
4992