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