// @bun
var{defineProperty:l,getOwnPropertyNames:f,getOwnPropertyDescriptor:t}=Object,D=Object.prototype.hasOwnProperty;function K(a){return this[a]}var Q=(a)=>{var i=(x??=new WeakMap).get(a),o;if(i)return i;if(i=l({},"__esModule",{value:!0}),a&&typeof a==="object"||typeof a==="function"){for(var n of f(a))if(!D.call(i,n))l(i,n,{get:K.bind(a,n),enumerable:!(o=t(a,n))||o.enumerable})}return x.set(a,i),i},x;var h=(a)=>a;function E(a,i){this[a]=h.bind(null,i)}var $=(a,i)=>{for(var o in i)l(a,o,{get:i[o],enumerable:!0,configurable:!0,set:E.bind(i,o)})};var b=(a,i)=>()=>(a&&(i=a(a=0)),i);var j={};$(j,{groupByToArray:()=>A,groupByMultiple:()=>H,groupBy:()=>V,getUniqueTags:()=>S,getUniqueOwners:()=>J,getUniqueDomains:()=>P,filterBy:()=>p,GroupingStrategies:()=>s});function p(a,i){return a.filter((o)=>{if(i.tags?.length){if(!i.tags.some((u)=>o.meta.tags?.includes(u)))return!1}if(i.owners?.length){if(!i.owners.some((u)=>o.meta.owners?.includes(u)))return!1}if(i.stability?.length){if(!i.stability.includes(o.meta.stability??"stable"))return!1}if(i.domain){if(s.byDomain(o)!==i.domain)return!1}if(i.keyPattern){let n=o.meta.key??o.meta.key??"",u=i.keyPattern.replace(/\*/g,".*").replace(/\?/g,".");if(!new RegExp(`^${u}$`,"i").test(n))return!1}return!0})}function V(a,i){let o=new Map;for(let n of a){let u=i(n),z=o.get(u);if(z)z.push(n);else o.set(u,[n])}return o}function A(a,i){let o=V(a,i);return Array.from(o.entries()).map(([n,u])=>({key:n,items:u}))}function H(a,i){let o=new Map;for(let n of a){let u=i(n);for(let z of u){let c=o.get(z);if(c)c.push(n);else o.set(z,[n])}}return o}function S(a){let i=new Set;for(let o of a)for(let n of o.meta.tags??[])i.add(n);return Array.from(i).sort()}function J(a){let i=new Set;for(let o of a)for(let n of o.meta.owners??[])i.add(n);return Array.from(i).sort()}function P(a){let i=new Set;for(let o of a)i.add(s.byDomain(o));return Array.from(i).sort()}var s;var R=b(()=>{s={byTag:(a)=>a.meta.tags?.[0]??"untagged",byAllTags:(a)=>a.meta.tags?.length?a.meta.tags:["untagged"],byOwner:(a)=>a.meta.owners?.[0]??"unowned",byDomain:(a)=>{return(a.meta.key??a.meta.key??"").split(".")[0]??"default"},byStability:(a)=>a.meta.stability??"stable",byUrlPath:(a)=>(i)=>{if(!i.path)return"root";return i.path.split("/").filter(Boolean).slice(0,a).join("/")||"root"}}});R();import{compareVersions as G}from"compare-versions";var I=(a)=>`${a.meta.key}.v${a.meta.version}`;class C{contractType;items=new Map;constructor(a,i){this.contractType=a;if(i)i.forEach((o)=>this.register(o))}register(a){let i=I(a);if(this.items.has(i))throw Error(`Duplicate contract \`${this.contractType}\` ${i}`);return this.items.set(i,a),this}count(){return this.items.size}list(){return[...this.items.values()]}get(a,i){if(i!=null)return this.items.get(`${a}.v${i}`);let o;for(let[n,u]of this.items.entries()){if(!n.startsWith(`${a}.v`))continue;if(!o||G(u.meta.version,o.meta.version)>0)o=u}return o}has(a,i){return!!this.get(a,i)}filter(a){return p(this.list(),a)}listByTag(a){return this.list().filter((i)=>i.meta.tags?.includes(a))}listByOwner(a){return this.list().filter((i)=>i.meta.owners?.includes(a))}groupBy(a){return V(this.list(),a)}getUniqueTags(){return S(this.list())}}function L(a){return`${a.meta.key}.v${a.meta.version}`}class M extends C{constructor(a){super("visualization",a)}}function N(a){return a}export{L as visualizationKey,N as defineVisualization,M as VisualizationRegistry};
