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