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