Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

api-smart-diff

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-smart-diff - npm Package Compare versions

Comparing version 0.4.6 to 0.5.0

4

browser/api-smart-diff.min.js

@@ -1,2 +0,2 @@

/*! api-smart-diff@0.4.6 */
var ApiSmartDiff=function(r){var n={};function a(e){if(n[e])return n[e].exports;var t=n[e]={i:e,l:!1,exports:{}};return r[e].call(t.exports,t,t.exports,a),t.l=!0,t.exports}return a.m=r,a.c=n,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)a.d(r,n,function(e){return t[e]}.bind(null,n));return r},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(I,e,t){"use strict";t.r(e),t.d(e,"messageTraitsRules",function(){return W}),t.d(e,"messageRules",function(){return X}),t.d(e,"asyncApi2Rules",function(){return Z}),t.d(e,"openapi3Rules",function(){return ee}),t.d(e,"jsonSchemaRules",function(){return P}),t.d(e,"contentMediaTypeRules",function(){return te}),t.d(e,"serviceNodeRules",function(){return ae}),t.d(e,"DIFF_META_KEY",function(){return q}),t.d(e,"DiffAction",function(){return d}),t.d(e,"ClassifierType",function(){return r}),t.d(e,"breaking",function(){return n}),t.d(e,"nonBreaking",function(){return a}),t.d(e,"unclassified",function(){return s}),t.d(e,"annotation",function(){return i}),t.d(e,"allNonBreaking",function(){return o}),t.d(e,"allBreaking",function(){return c}),t.d(e,"onlyAddBreaking",function(){return f}),t.d(e,"addNonBreaking",function(){return u}),t.d(e,"allUnclassified",function(){return l}),t.d(e,"allAnnotation",function(){return p}),t.d(e,"PathPointer",function(){return B}),t.d(e,"breakingIf",function(){return h}),t.d(e,"breakingIfAfterTrue",function(){return m}),t.d(e,"added",function(){return j}),t.d(e,"removed",function(){return k}),t.d(e,"replaced",function(){return V}),t.d(e,"renamed",function(){return F}),t.d(e,"unchanged",function(){return y}),t.d(e,"isEmptyObject",function(){return b}),t.d(e,"typeOf",function(){return v}),t.d(e,"parsePath",function(){return K}),t.d(e,"buildPath",function(){return U}),t.d(e,"getPathRules",function(){return N}),t.d(e,"getPathMatchFunc",function(){return z}),t.d(e,"findExternalRefs",function(){return L}),t.d(e,"matchRule",function(){return O}),t.d(e,"objArray",function(){return M}),t.d(e,"resolveRef",function(){return R}),t.d(e,"getValueByPath",function(){return J}),t.d(e,"setValueByPath",function(){return Y}),t.d(e,"mergeValues",function(){return A}),t.d(e,"ApiCompare",function(){return $}),t.d(e,"JsonCompare",function(){return se}),t.d(e,"apiDiff",function(){return ce}),t.d(e,"apiMerge",function(){return fe}),t.d(e,"apiDiffTree",function(){return ue});var d,r;function g(e,t){var r={};for(a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,a=Object.getOwnPropertySymbols(e);n<a.length;n++)t.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(r[a[n]]=e[a[n]]);return r}const q="$diff",{breaking:n,nonBreaking:a,unclassified:s,annotation:i}=((t=d=d||{}).add="add",t.remove="remove",t.replace="replace",t.rename="rename",t.test="test",(e=r=r||{}).breaking="breaking",e.nonBreaking="non-breaking",e.annotation="annotation",e.unclassified="unclassified",r),o=[a,a,a],c=[n,n,n],f=[n,a,a],u=[a,n,n],l=[s,s,s],p=[i,i,i];class B{constructor(e,t){this.key=e,this.parent=t,this.items=[],void 0===e?this.escapedKey="":(this.escapedKey="string"==typeof e?e.replace(new RegExp("~1","g"),"/"):String(e),this.items=t?[...t.items,e]:[e])}get ref(){return this.parent?this.parent.ref+"/"+this.escapedKey:this.escapedKey}[Symbol.iterator](){let e=0;return{next:()=>({done:!(e<this.items.length),value:this.items[e++]})}}childPath(e){return new B(e,this)}}const h=e=>e?n:a,m=({after:e})=>h(e),j=(e,t)=>({path:e.items,after:t,action:d.add}),k=(e,t)=>({path:e.items,before:t,action:d.remove}),V=(e,t,r)=>({path:e.items,before:t,after:r,action:d.replace}),F=(e,t,r)=>({path:e.items,before:t,after:r,action:d.rename}),y=(e,t)=>({path:e.items,before:t,action:d.test}),b=e=>{for(const t in e)return!1;return!0},v=e=>Array.isArray(e)?"array":null==e?"null":typeof e,K=e=>{var[,...e]=e.split("/").map(e=>e.replace(new RegExp("~1","g"),"/"));return e},U=e=>"/"+e.map(e=>String(e).replace(new RegExp("/","g"),"~1")).join("/"),N=(e,t,r)=>{let n=e,a=r;for(var s of[...t]){if(a=void 0!==s&&void 0!==a?a[s]:void 0,n.hasOwnProperty("/"+s)&&"number"!=typeof s||(s="*"),!n.hasOwnProperty("/"+s))return;{const i=n["/"+s];if(Array.isArray(i))return i;n="function"==typeof i?i(a):i}}return n},z=(e,t,r)=>{e=N(e,t.items,r);return e&&!Array.isArray(e)?e["#"]:void 0},L=e=>{if("object"!=typeof e)return[];let t=new Set;if("array"===v(e))for(const n of e)"object"==typeof n&&(t=new Set([...t,...L(n)]));else for(const a of Object.keys(e)){var r;"$ref"===a?([r]=e[a].split("#"),r&&t.add(r)):"object"==typeof e[a]&&(t=new Set([...t,...L(e[a])]))}return[...t]},O=(e,t)=>(e["#"]=t,e),M=(r,e)=>O(e,({before:e,after:t})=>t.value[r]===e.value[r]),R=(e,t,r)=>{const n=e["$ref"],a=g(e,["$ref"]);if(n){var[s,i]=n.split("#");if(s&&!r.has(s))return e;r=J(s?r.get(s):t,K(i));return b(a)?r:A(r,a)}return e},J=(e,t)=>{let r=e;for(const n of t)if(void 0===(r="array"===v(r)?r[+n]:r[n]))break;return r},Y=(e,t,r,n=0)=>{var a;n>=t.length||("object"!=typeof e[a=t[n]]&&(e[a]={}),n===t.length-1?e[a]=r:Y(e[a],t,r,n+1))},A=(e,t)=>{if(Array.isArray(e))return Array.isArray(t)?e.push(...t):e;if("object"!=typeof e||"object"!=typeof t)return t;for(const r of Reflect.ownKeys(t))e[r]=A(e[r],t[r]);return e},x=[n,a,({before:e,after:t})=>h(t<e)],w=[n,a,({before:e,after:t})=>h(e<t)],G=[m,a,m],S=[m,a,m],H=[n,a,({before:e,after:t})=>h(!!(e%t))],Q=({after:e,up:t})=>{return void 0!==(null==(t=null==(t=null==(t=t(2).after)?void 0:t.properties)?void 0:t[e])?void 0:t.default)?a:n},P=(e=l)=>({"/":e,"/title":p,"/multipleOf":H,"/maximum":x,"/exclusiveMaximum":G,"/minimum":w,"/exclusiveMinimum":G,"/maxLength":x,"/minLength":w,"/pattern":[n,a,n],"/maxItems":x,"/minItems":w,"/uniqueItems":S,"/maxProperties":x,"/minProperties":w,"/required":{"/":f,"/*":[Q,a,Q]},"/enum":{"/":[n,a,n],"/*":[a,n,n]},"/type":[n,a,n],"/not":{"/":[n,a,n],"/*":()=>P(c)},"/allOf":{"/":[n,a,n],"/*":()=>P(c)},"/oneOf":{"/":[n,a,n],"/*":()=>P(u)},"/anyOf":{"/":[n,a,n],"/*":()=>P(u)},"/items":()=>P(u),"/properties":{"/":[n,a,n],"/*":()=>P(u)},"/additionalProperties":()=>P([n,n,m]),"/description":p,"/format":[n,a,n],"/default":[a,n,n],"/nullable":S,"/discriminator":{"/":l,"/propertyName":l,"/mapping":l},"/readOnly":S,"/writeOnly":S,"/example":p,"/examples":p,"/externalDocs":p,"/deprecated":S,"/xml":{"/":l,"/name":l,"/namespace":l,"/prefix":l,"/attribute":l,"/wrapped":l}});var t={"/":u,"/location":u,"/description":p},e={"/summary":p,"/tags":p,"/externalDocs":p,"/bindings":l},_=Object.assign({"/":u,"/*":u,"/operationId":u,"/description":p},e);const W=Object.assign({"/":u,"/*":u,"/headers":l,"/correlationId":t,"/schemaFormat":c,"/contentType":u,"/name":o,"/title":o,"/examples":p},e),X=Object.assign({"/":c,"/headers":l,"/correlationId":t,"/schemaFormat":c,"/contentType":u,"/name":o,"/title":o,"/description":o,"/examples":p,"/traits":W,"/payload":P(c)},e);t=Object.assign({"/":u,"/operationId":u,"/description":p,"/traits":_,"/message":X},e),_={"/":u,"/version":u,"/termsOfService":u,"/license":{"/":u,"/name":c,"/url":f},"/title":p,"/description":p,"/contact":{"/":p,"/name":p,"/url":p,"/email":p}},e={"/":u,"/*":{"/":u,"/url":u,"/description":p,"/protocol":c,"/protocolVersion":c,"/variables":{"/":u,"/*":{"/":u,"/enum":{"/":u,"/*":u},"/default":c,"/description":p,"/examples":p}},"/security":{"/":c,"/*":c},"/bindings":l}},t={"/":u,"/description":o,"/bindings":l,"/subscribe":t,"/publish":t,"/parameters":{"/":c,"/*":{"/":u,"/description":o,"/schema":P(c),"/location":c}}};const Z={"/asyncapi":u,"/id":p,"/defaultContentType":c,"/info":_,"/servers":e,"/channels":{"/":u,"/*":t},"/components":o,"/tags":p,"/externalDocs":p};var _={"/":[a,n,n],"/*":{"/":[a,n,n],"/url":[a,n,n],"/description":p,"/variables":{"/":[a,n,n],"/*":{"/":[a,n,n],"/enum":{"/":[a,n,n],"/*":[a,n,n]},"/default":[n,n,n],"/description":p}}}},e={"/":[a,n,n],"/*":{"/":[a,n,n],"/name":[a,n,e=>{return"path"===(null==(e=e.up().before)?void 0:e.in)?a:n}],"/in":[a,n,n],"/schema":P(c),"/description":p,"/required":[n,a,m],"/deprecated":[n,a,m]}},t={"/":[a,n,n],"/*":{"/":[a,n,n],"/description":p,"/required":[n,a,m],"/deprecated":[n,a,m]}},T={"/":[a,a,a],"/*":{"/contentType":[a,n,n],"/headers":t,"/style":[a,n,n],"/explode":[a,n,n],"/allowReserved":[a,n,n]}},T=(T={"/":[a,n,n],"/*":{"/":[a,n,s],"/schema":P(c),"/example":p,"/examples":p,"/encoding":T}},O(T,({before:e,after:t})=>{const[r=""]=String(t.key).split(";"),[n=""]=String(e.key).split(";");var[t,e]=r.split("/"),[a,s]=n.split("/");return(t===a||"*"===t||"*"===a)&&(e===s||"*"===e||"*"===s)})),C={"/":[a,n,n],"/description":p,"/content":T,"/required":[n,a,e=>e.after?n:a]},T={"/":[a,n,n],"/*":{"/":[a,n,n],"/description":p,"/headers":t,"/content":T}},D={"/":[n,a,s],"/*":[n,a,s]},E={"/":[a,n,n],"/tags":p,"/summary":p,"/description":p,"/externalDocs":p,"/operationId":[a,n,n],"/parameters":e,"/requestBody":C,"/responses":T,"/deprecated":[n,a,m],"/security":D,"/servers":_};const ee={"/openapi":[a,n,n],"/info":{"/":[a,n,n],"/title":p,"/description":p,"/termsOfService":p,"/contact":p,"/licence":{"/":[a,n,n],"/name":[n,n,n],"/url":[n,a,a]},"/version":p},"/servers":_,"/paths":(E={"/":[a,n,n],"/*":{"/":[a,n,a],"/summary":p,"/description":p,"/*":E,"/servers":_,"/parameters":e}},O(E,({before:e,after:t})=>{return String(e.key).replace(new RegExp("{.*?}","g"),"*")===String(t.key).replace(new RegExp("{.*?}","g"),"*")})),"/components":{"/":[a,a,a],"/schemas":{"/":[a,n,n],"/*":P(u)},"/responses":{"/":[a,n,n],"/*":T},"/parameters":{"/":[a,n,n],"/*":e},"/examples":p,"/requestBodies":{"/":[a,n,n],"/*":C},"/headers":t,"/securitySchemes":{"/":[n,a,n],"/*":{"/":[n,a,n],"/type":[n,a,n],"/description":p,"/name":[n,a,n],"/in":[n,a,n],"/scheme":[n,a,n],"/bearerFormat":p,"/flows":[n,a,n],"/openIdConnectUrl":p}}},"/security":D,"/tags":p,"/externalDocs":p};_=e=>O(e,({before:{value:e},after:{value:t}})=>{var r;return t.type===e.type&&("model"===t.type?t.name===e.name:(null==(r=e.data.path)?void 0:r.replace(new RegExp("{.*?}","g"),"*"))===(null==(r=t.data.path)?void 0:r.replace(new RegExp("{.*?}","g"),"*"))&&e.data.method===t.data.method)});const te=e=>O(e,({before:e,after:t})=>{const[r=""]=String(t.value.mediaType).split(";"),[n=""]=String(e.value.mediaType).split(";");var[t,e]=r.split("/"),[a,s]=n.split("/");return(t===a||"*"===t||"*"===a)&&(e===s||"*"===e||"*"===s)});E={"/name":[a,n,n],"/style":l,"/description":p,"/examples":p,"/schema":P(c),"/explode":l,"/required":[n,a,m],"/deprecated":[n,a,m]},T={"/":[a,n,n],"/*":E},e=te({"/":u,"/*":{"/":[a,n,s],"/mediaType":[a,n,s],"/schema":P(c),"/examples":M("key",{"/":p,"/*":p}),"/encodings":[a,n,n]}}),C={"/path":M("name",T),"/query":M("name",{"/":[a,n,n],"/*":Object.assign(Object.assign({},E),{"/allowEmptyValue":[n,a,m],"/allowReserved":[n,a,m]})}),"/headers":M("name",T),"/cookie":M("name",T),"/body":{"/":[a,n,n],"/contents":e,"/required":[n,a,m],"/description":p}},t={"/":l,"/*":{"/name":[a,n,n],"/style":l,"/description":p,"/schema":P(c),"/explode":l,"/required":[n,a,m],"/deprecated":[n,a,m]}},D={"/":u,"/*":{"/":u,"/code":l,"/contents":e,"/headers":M("name",t),"/description":p}},E={"/":[a,n,n],"/url":[a,n,n],"/name":p,"/description":p,"/variables":[a,n,n]},T={"/":[n,a,s],"/*":[n,a,s]};const re={"/":[a,n,n],"/data":()=>P(u),"/*":p},ne={"/":[a,n,n],"/data":{"/id":p,"/iid":p,"/tags":p,"/summary":p,"/description":p,"/method":[a,n,n],"/path":[a,n,n],"/request":C,"/responses":M("code",D),"/servers":{"/":l,"/*":E},"/callbacks":_({"/callbackName":p,"/method":[a,n,n],"/path":[a,n,n],"/request":C,"/responses":M("code",D),"/deprecated":l,"/internal":l,"/extensions":l}),"/security":T,"/deprecated":[n,a,m],"/internal":l,"/extensions":l},"/*":p};e={"/id":p,"/iid":p,"/tags":p,"/summary":p,"/description":p,"/name":p,"/version":p,"/servers":{"/":[a,n,n],"/*":E},"/security":T,"/securitySchemes":M("name",{"/":u,"/*":{"/":[n,a,n],"/type":[n,a,n],"/description":p,"/name":[n,a,n],"/in":[n,a,n],"/scheme":[n,a,n],"/bearerFormat":p,"/flows":[n,a,n],"/openIdConnectUrl":p}}),"/termsOfService":p,"/contact":p,"/license":[n,n,n],"/logo":p};const ae={"/*":p,"/data":e,"/children":_({"/":[a,n,n],"/*":({type:e})=>"model"===e?re:ne}),"/components":{"/":[a,a,a],"/schemas":{"/":[a,n,n],"/*":P(u)}}};class se{constructor(e,t,r={}){this.before=e,this.after=t,this._merged={},this._formatMergeMeta=e=>Object.assign({action:e.action},e.action===d.replace||e.action===d.rename?{replaced:e.before}:{}),this.trimStrings=r.trimStrings,this.caseSensitive=r.caseSensitive,this.strictArrays=r.strictArrays,this.matchRules=r.matchRules||{},this.diffKey=r.metaKey||q,this.arrayMeta=r.arrayMeta,this.formatMergedMeta=r.formatMergedMeta||this._formatMergeMeta.bind(this)}get merged(){return this._merged.value}setMeta(e,t,r){void 0===e[this.diffKey]&&(e[this.diffKey]={}),e[this.diffKey][t]=r}checkMatch(e,t,r,n,a){const s=this.getMatchFunc(e);return!!s&&s({path:e.items,before:{key:n,value:t[n],parent:t,source:this.before},after:{key:a,value:r[a],parent:r,source:this.after}})}getMatchFunc(e){e=e.ref;return this.matchRules[e]}compare(){return this.compareAny(this.before,this.after).diffs}buildDiffTree(){return this.compareAny(this.before,this.after).diffTree}merge(){return this.compareAny(this.before,this.after),this._merged.value}normalizeString(e){return e=this.trimStrings?e.trim():e,e=this.caseSensitive?e:e.toLowerCase()}mergeResults(e,t,r=!1){const n={diffs:[],diffTree:{}};for(var a of Object.keys(e)){var s,i,{diffs:o,diff:c,diffTree:f,parentMeta:u}=e[a];c&&c.action!==d.test?(i=c["path"],s=g(c,["path"]),i=i[i.length-1],this.setMeta(n.diffTree,i,s),n.diffs.push(c),r&&!this.arrayMeta?(void 0===n.parentMeta&&(n.parentMeta={}),n.parentMeta[i]=this.formatMergedMeta(c)):c.action===d.rename?this.setMeta(t,c.after,this.formatMergedMeta(c)):this.setMeta(t,i,this.formatMergedMeta(c)),a):(o.length&&(n.diffTree[a]=f,n.diffs.push(...o)),u&&this.setMeta(t,r?+a:a,{array:u}))}return n}mergeValue({action:e,before:t,after:r}){return e===d.test||e===d.remove?t:r}compareResult(e){return e.action===d.test?{diffs:[],diff:e}:{diffs:[e],diff:e}}compareAny(e,t,r=new B,n=this._merged,a="value"){if(v(e)!==v(t))return n[a]=t,this.compareResult(V(r,e,t));switch(v(e)){case"object":return n[a]={},this.compareObjects(e,t,r,n[a]);case"array":return n[a]=[],this.compareArrays(e,t,r,n[a]);default:var s=("string"==typeof e?this.normalizeString(e)===this.normalizeString(t):e===t)?y(r,e):V(r,e,t);return n[a]=this.mergeValue(s),this.compareResult(s)}}compareObjects(t,r,n,e){const a={};if(b(t)&&b(r))return this.compareResult(y(n,t));var s=Object.keys(t);const i=new Set(Object.keys(r));for(const u of s){var o,c=[...i].find(e=>e===u||this.checkMatch(n,t,r,u,e));c&&c!==u&&(a[c]=this.compareResult(F(n,u,c))),void 0===c?(o=k(n.childPath(u),t[u]),e[u]=this.mergeValue(o),a[u]=this.compareResult(o)):(a[u]=this.compareAny(t[u],r[c],n.childPath(u),e,c),i.delete(c))}for(const d of i){var f=j(n.childPath(d),r[d]);e[d]=this.mergeValue(f),a[d]=this.compareResult(f)}return this.mergeResults(a,e)}compareArrays(t,r,n,e){if(0===t.length&&0===r.length)return this.compareResult(y(n,t));var a=this.getMatchFunc(n);if(!this.strictArrays&&!a)return this.compareEnums(t,r,n,e);const s={},i=new Set(r.keys());for(const u of t.keys()){var o,c=n.childPath(u),f=a?[...i].find(e=>this.checkMatch(n,t,r,u,e)):u;void 0===f||f>=r.length?(o=k(c,t[u]),e[u]=this.mergeValue(o),s[u]=this.compareResult(o)):(i.delete(f),s[u]=this.compareAny(t[u],r[f],c,e,u))}let u=t.length;for(const l of i){var d=j(n.childPath(u),r[l]);e[u]=this.mergeValue(d),s[u++]=this.compareResult(d)}return this.mergeResults(s,e,!0)}compareEnums(t,r,n,a){const s={},e=[],i=[],o=new Set,c=new Set;for(const g of t.keys()){let e=[];for(const b of r.keys())if(!o.has(b)){var f={},u=this.compareAny(t[g],r[b],n.childPath(g),f);if(!u.diffs.length){o.add(b),c.add(g),e={value:f.value,res:u};break}e[b]={value:f.value,res:u,diffs:typeof t[g]==typeof r[b]?u.diffs.length:-1}}i.push(e)}for(const g of t.keys()){const v=i[g];if(Array.isArray(v)){const O=[...Array(r.length).keys()].filter(e=>{return 0<=((null==(e=v[e])?void 0:e.diffs)||0)});var d,l=O.sort((e,t)=>{return((null==(e=v[e])?void 0:e.diffs)||0)-((null==(e=v[t])?void 0:e.diffs)||0)});for(const M of r.keys()){let e=l[M];if(!o.has(e)){for(const R of t.keys()){var p=i[R];if(Array.isArray(p)&&!c.has(R)&&p[e]<v[e]){e=-1;break}}if(0<=e){var{value:h,res:m}=v[e];a[g]=h,s[g]=m,c.add(g),o.add(e);break}}}c.has(g)||(d=k(n.childPath(g),t[g]),a[g]=this.mergeValue(d),s[g]=this.compareResult(d))}else e[g]=[],a[g]=v.value,s[g]=v.res}let g=t.length;for(var y of r.keys())o.has(y)||(y=j(n.childPath(g),r[y]),a[g]=this.mergeValue(y),s[g++]=this.compareResult(y));return this.mergeResults(s,a,!0)}}class ie{constructor(e,t){this._engine=e,this._path=t}get before(){return this._engine.resolvePath("before",this._path)}get after(){var e=this._engine.getRenamedPath(this._path);return this._engine.resolvePath("after",e)}get up(){return(e=1)=>new ie(this._engine,this._path.slice(0,-e))}get root(){return new ie(this._engine,[])}}const oe=Symbol("renamed");class $ extends se{constructor(e,t,r={}){super(e,t,r),this.before=e,this.after=t,this.beforeRefs=new Set,this.afterRefs=new Set,this.beforeCache=new Map,this.afterCache=new Map,this.compareCache=new Map,this.renamedPath={},this._formatMergeMeta=e=>Object.assign({type:e.type,action:e.action},e.action===d.replace||e.action===d.rename?{replaced:e.before}:{}),this.resolvePath=(e,t)=>{var r="before"===e?this.beforeCache:this.afterCache;let n=this[e];for(const s of t){var a=Array.isArray(n)?n[+s]:n[s];if(void 0===(n=void 0===a&&n.$ref?(n=R(n,this[e],r),Array.isArray(n)?n[+s]:n[s]):a))break}return n.$ref?R(n,this[e],r):n},this.rules="string"==typeof r.rules?this.getBaseRules(r.rules):r.rules||{},this.formatMergedMeta=r.formatMergedMeta||this._formatMergeMeta.bind(this),this.resolveUnchangedRefs=r.resolveUnchangedRefs||!1;var n=r.externalRefs||{};for(const a of Object.keys(n))this.beforeCache.set(a,n[a]),this.afterCache.set(a,n[a])}getMatchFunc(e){return z(this.rules,e,this.before)||super.getMatchFunc(e)}static apiDiff(e,t,r={}){return new $(e,t,r).compare()}static apiDiffTree(e,t,r={}){return new $(e,t,r).buildDiffTree()}static apiMerge(e,t,r={}){return new $(e,t,r).merge()}dereference(e,t,r){const n="#"+r.ref,[a,s]="before"===e?[this.beforeRefs,this.beforeCache]:[this.afterRefs,this.afterCache];r=()=>{t.$ref&&a.delete(t.$ref),a.delete(n)};return a.has(t.$ref)||"#"===t.$ref?[t,r]:(a.add(n),t.$ref&&a.add(t.$ref),[R(t,this[e],s),r])}getBaseRules(e){switch(e){case"OpenApi3":return ee;case"AsyncApi2":return Z;case"JsonSchema":return P()}}classifyDiff(e){const t=e;if("test"===e.action)return t;var r="rename"===e.action?[...e.path,"*",""]:[...e.path,""],r=N(this.rules,r,this.merged);const n=(Array.isArray(r)?r:l)["rename"===e.action?2:["add","remove","replace"].indexOf(e.action)];try{return t.type="function"==typeof n?n(new ie(this,e.path)):n,t}catch(e){return t.type=s,t}}getRenamedPath(t){const r=[...t];let n=this.renamedPath;for(let e=0;e<t.length;e++){var a=t[e];if(void 0===n[a])break;(n=n[a])[oe]&&(r[e]=n[oe])}return r}compareResult(e){return e.action===d.rename&&Y(this.renamedPath,[...e.path,e.before,oe],e.after),super.compareResult(this.classifyDiff(e))}compareObjects(e,t,r,n){var a=e["$ref"],s=g(e,["$ref"]),i=t["$ref"],o=g(t,["$ref"]),c=a?a===i?a:a+":"+i:"#"+r.ref;const f=this.compareCache.get(c);if(f&&(b(s)&&b(o)||!a&&!i)){if(!f.result.diffs.length&&!this.resolveUnchangedRefs)return super.compareObjects(e,t,r,n);A(n,f.merged);var u=f.result.diffs.map(e=>Object.assign(Object.assign({},e),{path:[...r,...e.path]}));return Object.assign(Object.assign({},f.result),{diffs:u})}const[d,l]=this.dereference("before",e,r),[p,h]=this.dereference("after",t,r);u=Array.isArray(n)?[]:{};let m=super.compareObjects(d,p,r,n);return a&&i&&b(s)&&b(o)&&(s=m.diffs.map(e=>Object.assign(Object.assign({},e),{path:e.path.slice(r.items.length)})),this.compareCache.set(c,{result:Object.assign(Object.assign({},m),{diffs:s}),merged:n})),h(),l(),!a||a!==i||m.diffs.length||this.resolveUnchangedRefs?A(n,u):(Array.isArray(n)?n.length=0:Object.keys(n).forEach(e=>delete n[e]),m=super.compareObjects(e,t,r,n)),m}}const ce=$.apiDiff,fe=$.apiMerge,ue=$.apiDiffTree}]);
/*! api-smart-diff@0.5.0 */
var ApiSmartDiff=function(r){var n={};function a(e){if(n[e])return n[e].exports;var t=n[e]={i:e,l:!1,exports:{}};return r[e].call(t.exports,t,t.exports,a),t.l=!0,t.exports}return a.m=r,a.c=n,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)a.d(r,n,function(e){return t[e]}.bind(null,n));return r},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(I,e,t){"use strict";t.r(e),t.d(e,"messageTraitsRules",function(){return W}),t.d(e,"messageRules",function(){return X}),t.d(e,"asyncApi2Rules",function(){return Z}),t.d(e,"openapi3Rules",function(){return ee}),t.d(e,"jsonSchemaRules",function(){return P}),t.d(e,"contentMediaTypeRules",function(){return te}),t.d(e,"serviceNodeRules",function(){return ae}),t.d(e,"DIFF_META_KEY",function(){return q}),t.d(e,"DiffAction",function(){return d}),t.d(e,"ClassifierType",function(){return r}),t.d(e,"breaking",function(){return n}),t.d(e,"nonBreaking",function(){return a}),t.d(e,"unclassified",function(){return i}),t.d(e,"annotation",function(){return s}),t.d(e,"allNonBreaking",function(){return o}),t.d(e,"allBreaking",function(){return c}),t.d(e,"onlyAddBreaking",function(){return f}),t.d(e,"addNonBreaking",function(){return u}),t.d(e,"allUnclassified",function(){return l}),t.d(e,"allAnnotation",function(){return p}),t.d(e,"PathPointer",function(){return V}),t.d(e,"breakingIf",function(){return h}),t.d(e,"breakingIfAfterTrue",function(){return m}),t.d(e,"added",function(){return j}),t.d(e,"removed",function(){return k}),t.d(e,"replaced",function(){return F}),t.d(e,"renamed",function(){return B}),t.d(e,"unchanged",function(){return g}),t.d(e,"isEmptyObject",function(){return b}),t.d(e,"typeOf",function(){return v}),t.d(e,"parsePath",function(){return K}),t.d(e,"buildPath",function(){return U}),t.d(e,"getPathRules",function(){return N}),t.d(e,"getPathMatchFunc",function(){return z}),t.d(e,"findExternalRefs",function(){return L}),t.d(e,"matchRule",function(){return O}),t.d(e,"objArray",function(){return M}),t.d(e,"resolveRef",function(){return R}),t.d(e,"getValueByPath",function(){return J}),t.d(e,"setValueByPath",function(){return Y}),t.d(e,"mergeValues",function(){return x}),t.d(e,"ApiCompare",function(){return $}),t.d(e,"JsonCompare",function(){return ie}),t.d(e,"apiDiff",function(){return ce}),t.d(e,"apiMerge",function(){return fe}),t.d(e,"apiDiffTree",function(){return ue});var d,r;function y(e,t){var r={};for(a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,a=Object.getOwnPropertySymbols(e);n<a.length;n++)t.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(r[a[n]]=e[a[n]]);return r}const q="$diff",{breaking:n,nonBreaking:a,unclassified:i,annotation:s}=((t=d=d||{}).add="add",t.remove="remove",t.replace="replace",t.rename="rename",t.test="test",(e=r=r||{}).breaking="breaking",e.nonBreaking="non-breaking",e.annotation="annotation",e.unclassified="unclassified",r),o=[a,a,a],c=[n,n,n],f=[n,a,a],u=[a,n,n],l=[i,i,i],p=[s,s,s];class V{constructor(e,t){this.key=e,this.parent=t,this.items=[],void 0===e?this.escapedKey="":(this.escapedKey="string"==typeof e?e.replace(new RegExp("~1","g"),"/"):String(e),this.items=t?[...t.items,e]:[e])}get ref(){return this.parent?this.parent.ref+"/"+this.escapedKey:this.escapedKey}[Symbol.iterator](){let e=0;return{next:()=>({done:!(e<this.items.length),value:this.items[e++]})}}childPath(e){return new V(e,this)}}const h=e=>e?n:a,m=({after:e})=>h(e),j=(e,t)=>({path:e.items,after:t,action:d.add}),k=(e,t)=>({path:e.items,before:t,action:d.remove}),F=(e,t,r)=>({path:e.items,before:t,after:r,action:d.replace}),B=(e,t,r)=>({path:e.items,before:t,after:r,action:d.rename}),g=(e,t)=>({path:e.items,before:t,action:d.test}),b=e=>{for(const t in e)return!1;return!0},v=e=>Array.isArray(e)?"array":null==e?"null":typeof e,K=e=>{var[,...e]=e.split("/").map(e=>e.replace(new RegExp("~1","g"),"/"));return e},U=e=>"/"+e.map(e=>String(e).replace(new RegExp("/","g"),"~1")).join("/"),N=(e,t,r)=>{let n=e,a=r;for(var i of[...t]){if(a=void 0!==i&&void 0!==a?a[i]:void 0,n.hasOwnProperty("/"+i)&&"number"!=typeof i||(i="*"),!n.hasOwnProperty("/"+i))return;{const s=n["/"+i];if(Array.isArray(s))return s;n="function"==typeof s?s(a):s}}return n},z=(e,t,r)=>{e=N(e,t.items,r);return e&&!Array.isArray(e)?e["#"]:void 0},L=e=>{if("object"!=typeof e)return[];let t=new Set;if("array"===v(e))for(const n of e)"object"==typeof n&&(t=new Set([...t,...L(n)]));else for(const a of Object.keys(e)){var r;"$ref"===a?([r]=e[a].split("#"),r&&t.add(r)):"object"==typeof e[a]&&(t=new Set([...t,...L(e[a])]))}return[...t]},O=(e,t)=>(e["#"]=t,e),M=(r,e)=>O(e,({before:e,after:t})=>t.value[r]===e.value[r]),R=(e,t,r)=>{const n=e["$ref"],a=y(e,["$ref"]);if(n){var[i,s]=n.split("#");if(i&&!r.has(i))return e;r=J(i?r.get(i):t,K(s));return b(a)?r:x(r,a)}return e},J=(e,t)=>{let r=e;for(const n of t)if(void 0===(r="array"===v(r)?r[+n]:r[n]))break;return r},Y=(e,t,r,n=0)=>{var a;n>=t.length||("object"!=typeof e[a=t[n]]&&(e[a]={}),n===t.length-1?e[a]=r:Y(e[a],t,r,n+1))},x=(e,t)=>{if(Array.isArray(e))return Array.isArray(t)?e.push(...t):e;if("object"!=typeof e||"object"!=typeof t)return t;for(const r of Reflect.ownKeys(t))e[r]=x(e[r],t[r]);return e},A=[n,a,({before:e,after:t})=>h(t<e)],w=[n,a,({before:e,after:t})=>h(e<t)],G=[m,a,m],S=[m,a,m],H=[n,a,({before:e,after:t})=>h(!!(e%t))],Q=({after:e,up:t})=>{return void 0!==(null==(t=null==(t=null==(t=t(2).after)?void 0:t.properties)?void 0:t[e])?void 0:t.default)?a:n},P=(e=l)=>({"/":e,"/title":p,"/multipleOf":H,"/maximum":A,"/exclusiveMaximum":G,"/minimum":w,"/exclusiveMinimum":G,"/maxLength":A,"/minLength":w,"/pattern":[n,a,n],"/maxItems":A,"/minItems":w,"/uniqueItems":S,"/maxProperties":A,"/minProperties":w,"/required":{"/":f,"/*":[Q,a,Q]},"/enum":{"/":[n,a,n],"/*":[a,n,n]},"/type":[n,a,n],"/not":{"/":[n,a,n],"/*":()=>P(c)},"/allOf":{"/":[n,a,n],"/*":()=>P(c)},"/oneOf":{"/":[n,a,n],"/*":()=>P(u)},"/anyOf":{"/":[n,a,n],"/*":()=>P(u)},"/items":()=>P(u),"/properties":{"/":[n,a,n],"/*":()=>P(u)},"/additionalProperties":()=>P([n,n,m]),"/description":p,"/format":[n,a,n],"/default":[a,n,n],"/nullable":S,"/discriminator":{"/":l,"/propertyName":l,"/mapping":l},"/readOnly":S,"/writeOnly":S,"/example":p,"/examples":p,"/externalDocs":p,"/deprecated":S,"/xml":{"/":l,"/name":l,"/namespace":l,"/prefix":l,"/attribute":l,"/wrapped":l}});var t={"/":u,"/location":u,"/description":p},e={"/summary":p,"/tags":p,"/externalDocs":p,"/bindings":l},_=Object.assign({"/":u,"/*":u,"/operationId":u,"/description":p},e);const W=Object.assign({"/":u,"/*":u,"/headers":l,"/correlationId":t,"/schemaFormat":c,"/contentType":u,"/name":o,"/title":o,"/examples":p},e),X=Object.assign({"/":c,"/headers":l,"/correlationId":t,"/schemaFormat":c,"/contentType":u,"/name":o,"/title":o,"/description":o,"/examples":p,"/traits":W,"/payload":P(c)},e);t=Object.assign({"/":u,"/operationId":u,"/description":p,"/traits":_,"/message":X},e),_={"/":u,"/version":u,"/termsOfService":u,"/license":{"/":u,"/name":c,"/url":f},"/title":p,"/description":p,"/contact":{"/":p,"/name":p,"/url":p,"/email":p}},e={"/":u,"/*":{"/":u,"/url":u,"/description":p,"/protocol":c,"/protocolVersion":c,"/variables":{"/":u,"/*":{"/":u,"/enum":{"/":u,"/*":u},"/default":c,"/description":p,"/examples":p}},"/security":{"/":c,"/*":c},"/bindings":l}},t={"/":u,"/description":o,"/bindings":l,"/subscribe":t,"/publish":t,"/parameters":{"/":c,"/*":{"/":u,"/description":o,"/schema":P(c),"/location":c}}};const Z={"/asyncapi":u,"/id":p,"/defaultContentType":c,"/info":_,"/servers":e,"/channels":{"/":u,"/*":t},"/components":o,"/tags":p,"/externalDocs":p};var _={"/":[a,n,n],"/*":{"/":[a,n,n],"/url":[a,n,n],"/description":p,"/variables":{"/":[a,n,n],"/*":{"/":[a,n,n],"/enum":{"/":[a,n,n],"/*":[a,n,n]},"/default":[n,n,n],"/description":p}}}},e={"/":[a,n,n],"/*":{"/":[a,n,n],"/name":[a,n,e=>{return"path"===(null==(e=e.up().before)?void 0:e.in)?a:n}],"/in":[a,n,n],"/schema":P(c),"/description":p,"/required":[n,a,m],"/deprecated":[n,a,m]}},t={"/":[a,n,n],"/*":{"/":[a,n,n],"/description":p,"/required":[n,a,m],"/deprecated":[n,a,m]}},T={"/":[a,a,a],"/*":{"/contentType":[a,n,n],"/headers":t,"/style":[a,n,n],"/explode":[a,n,n],"/allowReserved":[a,n,n]}},T=(T={"/":[a,n,n],"/*":{"/":[a,n,i],"/schema":P(c),"/example":p,"/examples":p,"/encoding":T}},O(T,({before:e,after:t})=>{const[r=""]=String(t.key).split(";"),[n=""]=String(e.key).split(";");var[t,e]=r.split("/"),[a,i]=n.split("/");return(t===a||"*"===t||"*"===a)&&(e===i||"*"===e||"*"===i)})),C={"/":[a,n,n],"/description":p,"/content":T,"/required":[n,a,e=>e.after?n:a]},T={"/":[a,n,n],"/*":{"/":[a,n,n],"/description":p,"/headers":t,"/content":T}},D={"/":[n,a,i],"/*":[n,a,i]},E={"/":[a,n,n],"/tags":p,"/summary":p,"/description":p,"/externalDocs":p,"/operationId":[a,n,n],"/parameters":e,"/requestBody":C,"/responses":T,"/deprecated":[n,a,m],"/security":D,"/servers":_};const ee={"/openapi":[a,n,n],"/info":{"/":[a,n,n],"/title":p,"/description":p,"/termsOfService":p,"/contact":p,"/licence":{"/":[a,n,n],"/name":[n,n,n],"/url":[n,a,a]},"/version":p},"/servers":_,"/paths":(E={"/":[a,n,n],"/*":{"/":[a,n,a],"/summary":p,"/description":p,"/*":E,"/servers":_,"/parameters":e}},O(E,({before:e,after:t})=>{return String(e.key).replace(new RegExp("{.*?}","g"),"*")===String(t.key).replace(new RegExp("{.*?}","g"),"*")})),"/components":{"/":[a,a,a],"/schemas":{"/":[a,n,n],"/*":P(u)},"/responses":{"/":[a,n,n],"/*":T},"/parameters":{"/":[a,n,n],"/*":e},"/examples":p,"/requestBodies":{"/":[a,n,n],"/*":C},"/headers":t,"/securitySchemes":{"/":[n,a,n],"/*":{"/":[n,a,n],"/type":[n,a,n],"/description":p,"/name":[n,a,n],"/in":[n,a,n],"/scheme":[n,a,n],"/bearerFormat":p,"/flows":[n,a,n],"/openIdConnectUrl":p}}},"/security":D,"/tags":p,"/externalDocs":p};_=e=>O(e,({before:{value:e},after:{value:t}})=>{var r;return t.type===e.type&&("model"===t.type?t.name===e.name:(null==(r=e.data.path)?void 0:r.replace(new RegExp("{.*?}","g"),"*"))===(null==(r=t.data.path)?void 0:r.replace(new RegExp("{.*?}","g"),"*"))&&e.data.method===t.data.method)});const te=e=>O(e,({before:e,after:t})=>{const[r=""]=String(t.value.mediaType).split(";"),[n=""]=String(e.value.mediaType).split(";");var[t,e]=r.split("/"),[a,i]=n.split("/");return(t===a||"*"===t||"*"===a)&&(e===i||"*"===e||"*"===i)});E={"/name":[a,n,n],"/style":l,"/description":p,"/examples":p,"/schema":P(c),"/explode":l,"/required":[n,a,m],"/deprecated":[n,a,m]},T={"/":[a,n,n],"/*":E},e=te({"/":u,"/*":{"/":[a,n,i],"/mediaType":[a,n,i],"/schema":P(c),"/examples":M("key",{"/":p,"/*":p}),"/encodings":[a,n,n]}}),C={"/path":M("name",T),"/query":M("name",{"/":[a,n,n],"/*":Object.assign(Object.assign({},E),{"/allowEmptyValue":[n,a,m],"/allowReserved":[n,a,m]})}),"/headers":M("name",T),"/cookie":M("name",T),"/body":{"/":[a,n,n],"/contents":e,"/required":[n,a,m],"/description":p}},t={"/":l,"/*":{"/name":[a,n,n],"/style":l,"/description":p,"/schema":P(c),"/explode":l,"/required":[n,a,m],"/deprecated":[n,a,m]}},D={"/":u,"/*":{"/":u,"/code":l,"/contents":e,"/headers":M("name",t),"/description":p}},E={"/":[a,n,n],"/url":[a,n,n],"/name":p,"/description":p,"/variables":[a,n,n]},T={"/":[n,a,i],"/*":[n,a,i]};const re={"/":[a,n,n],"/data":()=>P(u),"/*":p},ne={"/":[a,n,n],"/data":{"/id":p,"/iid":p,"/tags":p,"/summary":p,"/description":p,"/method":[a,n,n],"/path":[a,n,n],"/request":C,"/responses":M("code",D),"/servers":{"/":l,"/*":E},"/callbacks":_({"/callbackName":p,"/method":[a,n,n],"/path":[a,n,n],"/request":C,"/responses":M("code",D),"/deprecated":l,"/internal":l,"/extensions":l}),"/security":T,"/deprecated":[n,a,m],"/internal":l,"/extensions":l},"/*":p};e={"/id":p,"/iid":p,"/tags":p,"/summary":p,"/description":p,"/name":p,"/version":p,"/servers":{"/":[a,n,n],"/*":E},"/security":T,"/securitySchemes":M("name",{"/":u,"/*":{"/":[n,a,n],"/type":[n,a,n],"/description":p,"/name":[n,a,n],"/in":[n,a,n],"/scheme":[n,a,n],"/bearerFormat":p,"/flows":[n,a,n],"/openIdConnectUrl":p}}),"/termsOfService":p,"/contact":p,"/license":[n,n,n],"/logo":p};const ae={"/*":p,"/data":e,"/children":_({"/":[a,n,n],"/*":({type:e})=>"model"===e?re:ne}),"/components":{"/":[a,a,a],"/schemas":{"/":[a,n,n],"/*":P(u)}}};class ie{constructor(e,t,r={}){this.before=e,this.after=t,this._merged={},this._formatMergeMeta=e=>Object.assign({action:e.action},e.action===d.replace||e.action===d.rename?{replaced:e.before}:{}),this.trimStrings=r.trimStrings,this.caseSensitive=r.caseSensitive,this.strictArrays=r.strictArrays,this.matchRules=r.matchRules||{},this.diffKey=r.metaKey||q,this.arrayMeta=r.arrayMeta,this.formatMergedMeta=r.formatMergedMeta||this._formatMergeMeta.bind(this)}get merged(){return this._merged.value}setMeta(e,t,r){void 0===e[this.diffKey]&&(e[this.diffKey]={}),e[this.diffKey][t]=r}checkMatch(e,t,r,n,a){const i=this.getMatchFunc(e);return!!i&&i({path:e.items,before:{key:n,value:t[n],parent:t,source:this.before},after:{key:a,value:r[a],parent:r,source:this.after}})}getMatchFunc(e){e=e.ref;return this.matchRules[e]}compare(){return this.compareAny(this.before,this.after).diffs}buildDiffTree(){return this.compareAny(this.before,this.after).diffTree}merge(){return this.compareAny(this.before,this.after),this._merged.value}normalizeString(e){return e=this.trimStrings?e.trim():e,e=this.caseSensitive?e:e.toLowerCase()}mergeResults(e,t,r=!1){const n={diffs:[],diffTree:{}};for(var a of Object.keys(e)){var i,s,{diffs:o,diff:c,diffTree:f,parentMeta:u}=e[a];c&&c.action!==d.test?(s=c["path"],i=y(c,["path"]),s=s[s.length-1],this.setMeta(n.diffTree,s,i),n.diffs.push(c),r&&!this.arrayMeta?(void 0===n.parentMeta&&(n.parentMeta={}),n.parentMeta[s]=this.formatMergedMeta(c)):c.action===d.rename?this.setMeta(t,c.after,this.formatMergedMeta(c)):this.setMeta(t,s,this.formatMergedMeta(c)),a):(o.length&&(n.diffTree[a]=f,n.diffs.push(...o)),u&&this.setMeta(t,r?+a:a,{array:u}))}return n}mergeValue({action:e,before:t,after:r}){return e===d.test||e===d.remove?t:r}compareResult(e){return e.action===d.test?{diffs:[],diff:e}:{diffs:[e],diff:e}}compareAny(e,t,r=new V,n=this._merged,a="value"){if(v(e)!==v(t))return n[a]=t,this.compareResult(F(r,e,t));switch(v(e)){case"object":return n[a]={},this.compareObjects(e,t,r,n[a]);case"array":return n[a]=[],this.compareArrays(e,t,r,n[a]);default:var i=("string"==typeof e?this.normalizeString(e)===this.normalizeString(t):e===t)?g(r,e):F(r,e,t);return n[a]=this.mergeValue(i),this.compareResult(i)}}compareObjects(t,r,n,e){const a={};if(b(t)&&b(r))return this.compareResult(g(n,t));var i=Object.keys(t);const s=new Set(Object.keys(r));for(const u of i){var o,c=[...s].find(e=>e===u||this.checkMatch(n,t,r,u,e));c&&c!==u&&(a[c]=this.compareResult(B(n,u,c))),void 0===c?(o=k(n.childPath(u),t[u]),e[u]=this.mergeValue(o),a[u]=this.compareResult(o)):(a[u]=this.compareAny(t[u],r[c],n.childPath(u),e,c),s.delete(c))}for(const d of s){var f=j(n.childPath(d),r[d]);e[d]=this.mergeValue(f),a[d]=this.compareResult(f)}return this.mergeResults(a,e)}compareArrays(t,r,n,e){if(0===t.length&&0===r.length)return this.compareResult(g(n,t));var a=this.getMatchFunc(n);if(!this.strictArrays&&!a)return this.compareEnums(t,r,n,e);const i={},s=new Set(r.keys());for(const u of t.keys()){var o,c=n.childPath(u),f=a?[...s].find(e=>this.checkMatch(n,t,r,u,e)):u;void 0===f||f>=r.length?(o=k(c,t[u]),e[u]=this.mergeValue(o),i[u]=this.compareResult(o)):(s.delete(f),i[u]=this.compareAny(t[u],r[f],c,e,u))}let u=t.length;for(const l of s){var d=j(n.childPath(u),r[l]);e[u]=this.mergeValue(d),i[u++]=this.compareResult(d)}return this.mergeResults(i,e,!0)}compareEnums(t,r,n,a){const i={},e=[],s=[],o=new Set,c=new Set;for(const y of t.keys()){let e=[];for(const b of r.keys())if(!o.has(b)){var f={},u=this.compareAny(t[y],r[b],n.childPath(y),f);if(!u.diffs.length){o.add(b),c.add(y),e={value:f.value,res:u};break}e[b]={value:f.value,res:u,diffs:typeof t[y]==typeof r[b]?u.diffs.length:-1}}s.push(e)}for(const y of t.keys()){const v=s[y];if(Array.isArray(v)){const O=[...Array(r.length).keys()].filter(e=>{return 0<=((null==(e=v[e])?void 0:e.diffs)||0)});var d,l=O.sort((e,t)=>{return((null==(e=v[e])?void 0:e.diffs)||0)-((null==(e=v[t])?void 0:e.diffs)||0)});for(const M of r.keys()){let e=l[M];if(!o.has(e)){for(const R of t.keys()){var p=s[R];if(Array.isArray(p)&&!c.has(R)&&p[e]<v[e]){e=-1;break}}if(0<=e){var{value:h,res:m}=v[e];a[y]=h,i[y]=m,c.add(y),o.add(e);break}}}c.has(y)||(d=k(n.childPath(y),t[y]),a[y]=this.mergeValue(d),i[y]=this.compareResult(d))}else e[y]=[],a[y]=v.value,i[y]=v.res}let y=t.length;for(var g of r.keys())o.has(g)||(g=j(n.childPath(y),r[g]),a[y]=this.mergeValue(g),i[y++]=this.compareResult(g));return this.mergeResults(i,a,!0)}}class se{constructor(e,t){this._engine=e,this._path=t}get before(){return this._engine.resolvePath("before",this._path)}get after(){var e=this._engine.getRenamedPath(this._path);return this._engine.resolvePath("after",e)}get up(){return(e=1)=>new se(this._engine,this._path.slice(0,-e))}get root(){return new se(this._engine,[])}}const oe=Symbol("renamed");class $ extends ie{constructor(e,t,r={}){super(e,t,r),this.before=e,this.after=t,this.beforeRefs=new Set,this.afterRefs=new Set,this.beforeCache=new Map,this.afterCache=new Map,this.compareCache=new Map,this.renamedPath={},this._formatMergeMeta=e=>Object.assign({type:e.type,action:e.action},e.action===d.replace||e.action===d.rename?{replaced:e.before}:{}),this.resolvePath=(e,t)=>{var r="before"===e?this.beforeCache:this.afterCache;let n=this[e];for(const i of t){var a=Array.isArray(n)?n[+i]:n[i];if(void 0===(n=void 0===a&&n.$ref?(n=R(n,this[e],r),Array.isArray(n)?n[+i]:n[i]):a))break}return n.$ref?R(n,this[e],r):n},this.rules=r.rules||this.calcApiRules(e),this.formatMergedMeta=r.formatMergedMeta||this._formatMergeMeta.bind(this),this.resolveUnchangedRefs=r.resolveUnchangedRefs||!1;var n=r.externalRefs||{};for(const a of Object.keys(n))this.beforeCache.set(a,n[a]),this.afterCache.set(a,n[a])}getMatchFunc(e){return z(this.rules,e,this.before)||super.getMatchFunc(e)}static apiDiff(e,t,r={}){return new $(e,t,r).compare()}static apiDiffTree(e,t,r={}){return new $(e,t,r).buildDiffTree()}static apiMerge(e,t,r={}){return new $(e,t,r).merge()}dereference(e,t,r){const n="#"+r.ref,[a,i]="before"===e?[this.beforeRefs,this.beforeCache]:[this.afterRefs,this.afterCache];r=()=>{t.$ref&&a.delete(t.$ref),a.delete(n)};return a.has(t.$ref)||"#"===t.$ref?[t,r]:(a.add(n),t.$ref&&a.add(t.$ref),[R(t,this[e],i),r])}calcApiRules(e){return"object"==typeof e&&e?/3.+/.test((null==e?void 0:e.openapi)||"")?ee:/2.+/.test((null==e?void 0:e.asyncapi)||"")?Z:P():P()}classifyDiff(e){const t=e;if("test"===e.action)return t;var r="rename"===e.action?[...e.path,"*",""]:[...e.path,""],r=N(this.rules,r,this.merged);const n=(Array.isArray(r)?r:l)["rename"===e.action?2:["add","remove","replace"].indexOf(e.action)];try{return t.type="function"==typeof n?n(new se(this,e.path)):n,t}catch(e){return t.type=i,t}}getRenamedPath(t){const r=[...t];let n=this.renamedPath;for(let e=0;e<t.length;e++){var a=t[e];if(void 0===n[a])break;(n=n[a])[oe]&&(r[e]=n[oe])}return r}compareResult(e){return e.action===d.rename&&Y(this.renamedPath,[...e.path,e.before,oe],e.after),super.compareResult(this.classifyDiff(e))}compareObjects(e,t,r,n){var a=e["$ref"],i=y(e,["$ref"]),s=t["$ref"],o=y(t,["$ref"]),c=a?a===s?a:a+":"+s:"#"+r.ref;const f=this.compareCache.get(c);if(f&&(b(i)&&b(o)||!a&&!s)){if(!f.result.diffs.length&&!this.resolveUnchangedRefs)return super.compareObjects(e,t,r,n);x(n,f.merged);var u=f.result.diffs.map(e=>Object.assign(Object.assign({},e),{path:[...r,...e.path]}));return Object.assign(Object.assign({},f.result),{diffs:u})}const[d,l]=this.dereference("before",e,r),[p,h]=this.dereference("after",t,r);u=Array.isArray(n)?[]:{};let m=super.compareObjects(d,p,r,n);return a&&s&&b(i)&&b(o)&&(i=m.diffs.map(e=>Object.assign(Object.assign({},e),{path:e.path.slice(r.items.length)})),this.compareCache.set(c,{result:Object.assign(Object.assign({},m),{diffs:i}),merged:n})),h(),l(),!a||a!==s||m.diffs.length||this.resolveUnchangedRefs?x(n,u):(Array.isArray(n)?n.length=0:Object.keys(n).forEach(e=>delete n[e]),m=super.compareObjects(e,t,r,n)),m}}const ce=$.apiDiff,fe=$.apiMerge,ue=$.apiDiffTree}]);

@@ -25,3 +25,3 @@ import { Diff, ObjPath, Rules, ApiDiffOptions, JsonDiff, ApiMergedMeta, MatchFunc, CompareResult } from "./types";

dereference(source: "before" | "after", value: any, objPath: PathPointer): [any, () => void];
private getBaseRules;
private calcApiRules;
classifyDiff(diff: JsonDiff): Diff;

@@ -28,0 +28,0 @@ resolvePath: (source: "before" | "after", objPath: ObjPath) => any;

@@ -43,3 +43,3 @@ "use strict";

};
this.rules = typeof options.rules === "string" ? this.getBaseRules(options.rules) : options.rules || {};
this.rules = options.rules || this.calcApiRules(before);
this.formatMergedMeta = options.formatMergedMeta || this._formatMergeMeta.bind(this);

@@ -82,11 +82,11 @@ this.resolveUnchangedRefs = options.resolveUnchangedRefs || false;

}
getBaseRules(name) {
switch (name) {
case "OpenApi3":
return rules_1.openapi3Rules;
case "AsyncApi2":
return rules_1.asyncApi2Rules;
case "JsonSchema":
return (0, rules_1.jsonSchemaRules)();
calcApiRules(data) {
if (typeof data !== "object" || !data) {
return (0, rules_1.jsonSchemaRules)();
}
if (/3.+/.test((data === null || data === void 0 ? void 0 : data.openapi) || ""))
return rules_1.openapi3Rules;
if (/2.+/.test((data === null || data === void 0 ? void 0 : data.asyncapi) || ""))
return rules_1.asyncApi2Rules;
return (0, rules_1.jsonSchemaRules)();
}

@@ -93,0 +93,0 @@ classifyDiff(diff) {

@@ -47,3 +47,2 @@ export declare type ObjPath = Array<string | number>;

};
export declare type BaseRulesType = "OpenApi3" | "AsyncApi2" | "JsonSchema";
export declare type JsonCompareOptions<T extends JsonDiff = JsonDiff> = {

@@ -68,3 +67,3 @@ trimStrings?: boolean;

resolveUnchangedRefs?: boolean;
rules?: Rules | BaseRulesType;
rules?: Rules;
externalRefs?: {

@@ -71,0 +70,0 @@ [key: string]: any;

@@ -25,3 +25,3 @@ import { Diff, ObjPath, Rules, ApiDiffOptions, JsonDiff, ApiMergedMeta, MatchFunc, CompareResult } from "./types";

dereference(source: "before" | "after", value: any, objPath: PathPointer): [any, () => void];
private getBaseRules;
private calcApiRules;
classifyDiff(diff: JsonDiff): Diff;

@@ -28,0 +28,0 @@ resolvePath: (source: "before" | "after", objPath: ObjPath) => any;

@@ -40,3 +40,3 @@ import { __rest } from "tslib";

};
this.rules = typeof options.rules === "string" ? this.getBaseRules(options.rules) : options.rules || {};
this.rules = options.rules || this.calcApiRules(before);
this.formatMergedMeta = options.formatMergedMeta || this._formatMergeMeta.bind(this);

@@ -79,11 +79,11 @@ this.resolveUnchangedRefs = options.resolveUnchangedRefs || false;

}
getBaseRules(name) {
switch (name) {
case "OpenApi3":
return openapi3Rules;
case "AsyncApi2":
return asyncApi2Rules;
case "JsonSchema":
return jsonSchemaRules();
calcApiRules(data) {
if (typeof data !== "object" || !data) {
return jsonSchemaRules();
}
if (/3.+/.test((data === null || data === void 0 ? void 0 : data.openapi) || ""))
return openapi3Rules;
if (/2.+/.test((data === null || data === void 0 ? void 0 : data.asyncapi) || ""))
return asyncApi2Rules;
return jsonSchemaRules();
}

@@ -90,0 +90,0 @@ classifyDiff(diff) {

@@ -47,3 +47,2 @@ export declare type ObjPath = Array<string | number>;

};
export declare type BaseRulesType = "OpenApi3" | "AsyncApi2" | "JsonSchema";
export declare type JsonCompareOptions<T extends JsonDiff = JsonDiff> = {

@@ -68,3 +67,3 @@ trimStrings?: boolean;

resolveUnchangedRefs?: boolean;
rules?: Rules | BaseRulesType;
rules?: Rules;
externalRefs?: {

@@ -71,0 +70,0 @@ [key: string]: any;

{
"name": "api-smart-diff",
"version": "0.4.6",
"version": "0.5.0",
"description": "Generate the diff between two API specifications (OpenAPI, AsyncAPI, JsonSchema)",

@@ -5,0 +5,0 @@ "module": "dist/esm/index.js",

@@ -41,3 +41,3 @@ # api-smart-diff

const diffs = apiDiff(oldSpec, newSpec, { rules: "OpenApi3" })
const diffs = apiDiff(oldSpec, newSpec)
// {

@@ -51,3 +51,3 @@ // action: "add" | "remove" | "replace" | "rename",

const merged = apiMerge(oldSpec, newSpec, { rules: "OpenApi3" })
const merged = apiMerge(oldSpec, newSpec)

@@ -67,4 +67,4 @@ ```

<script>
var diffs = ApiSmartDiff.apiDiff(oldSpec, newSpec, { rules: "OpenApi3" })
var merged = ApiSmartDiff.apiMerge(oldSpec, newSpec, { rules: "OpenApi3" })
var diffs = ApiSmartDiff.apiDiff(oldSpec, newSpec)
var merged = ApiSmartDiff.apiMerge(oldSpec, newSpec)
</script>

@@ -78,6 +78,6 @@ ```

`apiDiff (before, after, options?: CompareOptions): Array<Diff>`
> Calculates the difference list between two objects and classify difference in accordinance with specified rules: OpenApi3, AsyncApi2, JsonSchema.
> Calculates the difference list between two objects and classify difference in accordinance with before document type: OpenApi3, AsyncApi2, JsonSchema.
`apiDiffTree (before, after, options?: CompareOptions): object`
> Calculates the difference tree between two objects and classify difference in accordinance with specified rules: OpenApi3, AsyncApi2, JsonSchema.
> Calculates the difference tree between two objects and classify difference in accordinance with before document type: OpenApi3, AsyncApi2, JsonSchema.

@@ -95,3 +95,3 @@ `apiMerge (before, after, options?: MergeOptions): object`

type CompareOptions = {
rules?: Rules | "OpenApi3" | "AsyncApi2" | "JsonSchema"
rules?: Rules
trimStrings?: boolean

@@ -104,3 +104,3 @@ caseSensitive?: boolean

#### *Arguments*
- `rules` - match and classification rules, custom or predefined.
- `rules` - custom match and classification rules
- `trimString` - ignore spaces in matching, default `false`

@@ -126,3 +126,3 @@ - `caseSensitive` - ignore case in matching, default `false`

```ts
const diffs = apiDiff(before, after, { rules: "OpenApi3" })
const diffs = apiDiff(before, after)
if (diffs.length) {

@@ -152,3 +152,3 @@ // do something with the changes

```ts
const diff = apiDiffTree(before, after, { rules: "OpenApi3" })
const diff = apiDiffTree(before, after)
// do something with the changes object

@@ -199,3 +199,3 @@ ```

const apiKey = Symbol("diff")
const merged = apiMerge(before, after, { rules: "OpenApi3", apiKey })
const merged = apiMerge(before, after, { apiKey })

@@ -202,0 +202,0 @@ // do something with merged object

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc