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