var{defineProperty:J,getOwnPropertyNames:T,getOwnPropertyDescriptor:W}=Object,X=Object.prototype.hasOwnProperty;function Y(j){return this[j]}var $=(j)=>{var z=(L??=new WeakMap).get(j),B;if(z)return z;if(z=J({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var D of T(j))if(!X.call(z,D))J(z,D,{get:Y.bind(j,D),enumerable:!(B=W(j,D))||B.enumerable})}return L.set(j,z),z},L;var Z=(j)=>j;function _(j,z){this[j]=Z.bind(null,z)}var A=(j,z)=>{for(var B in z)J(j,B,{get:z[B],enumerable:!0,configurable:!0,set:_.bind(z,B)})};var U=(j,z)=>()=>(j&&(z=j(j=0)),z);class G extends Error{capabilityKey;requiredVersion;constructor(j,z){let B=z?`.v${z}`:"";super(`Missing required capability: ${j}${B}`);this.name="CapabilityMissingError",this.capabilityKey=j,this.requiredVersion=z}}class H{capabilities;capabilityVersions;constructor(j){let z=new Set,B=new Map;for(let D of j)z.add(D.key),B.set(D.key,D.version);this.capabilities=z,this.capabilityVersions=B}hasCapability(j,z){if(!this.capabilities.has(j))return!1;if(z!=null)return this.capabilityVersions.get(j)===z;return!0}requireCapability(j,z){if(!this.hasCapability(j,z))throw new G(j,z)}hasAllCapabilities(j){return j.every((z)=>this.capabilities.has(z))}hasAnyCapability(j){return j.some((z)=>this.capabilities.has(z))}getMatchingCapabilities(j){if(!j.includes("*"))return this.capabilities.has(j)?[j]:[];let z=j.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*"),B=new RegExp(`^${z}$`);return[...this.capabilities].filter((D)=>B.test(D))}}function O(j){return new H(j)}function S(){return new H([])}function K(j){return new H(j)}function N(j,z){if(!z.capability)return{allowed:!0};let{key:B,version:D}=z.capability;if(j.hasCapability(B,D))return{allowed:!0};return{allowed:!1,missingCapability:{key:B,version:D},reason:`Operation "${z.meta.key}" requires capability "${B}.v${D}"`}}function V(j,z){let B=N(j,z);if(!B.allowed&&B.missingCapability)throw new G(B.missingCapability.key,B.missingCapability.version)}function Q(j,z){if(!z.capability)return{allowed:!0};let{key:B,version:D}=z.capability;if(j.hasCapability(B,D))return{allowed:!0};return{allowed:!1,missingCapability:{key:B,version:D},reason:`Event "${z.meta.key}" requires capability "${B}.v${D}"`}}function f(j,z){let B=Q(j,z);if(!B.allowed&&B.missingCapability)throw new G(B.missingCapability.key,B.missingCapability.version)}function R(j,z){if(!z.capability)return{allowed:!0};let{key:B,version:D}=z.capability;if(j.hasCapability(B,D))return{allowed:!0};return{allowed:!1,missingCapability:{key:B,version:D},reason:`Presentation "${z.meta.key}" requires capability "${B}.v${D}"`}}function q(j,z){let B=R(j,z);if(!B.allowed&&B.missingCapability)throw new G(B.missingCapability.key,B.missingCapability.version)}function E(j,z){return z.filter((B)=>N(j,B).allowed)}function F(j,z){return z.filter((B)=>Q(j,B).allowed)}function M(j,z){return z.filter((B)=>R(j,B).allowed)}export{M as filterPresentationsByCapability,E as filterOperationsByCapability,F as filterEventsByCapability,R as checkCapabilityForPresentation,N as checkCapabilityForOperation,Q as checkCapabilityForEvent,q as assertCapabilityForPresentation,V as assertCapabilityForOperation,f as assertCapabilityForEvent};
