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