class AllEntityPolicies {
  constructor(policies) {
    this.policies = policies;
  }
  async enforce(entity) {
    let result = entity;
    for (const policy of this.policies) {
      const output = await policy.enforce(result);
      if (!output) {
        throw new Error(
          `Policy ${policy.constructor.name} did not return a result`
        );
      }
      result = output;
    }
    return result;
  }
}
class AnyEntityPolicy {
  constructor(policies) {
    this.policies = policies;
  }
  async enforce(entity) {
    for (const policy of this.policies) {
      const output = await policy.enforce(entity);
      if (output) {
        return output;
      }
    }
    throw new Error(`The entity did not match any known policy`);
  }
}
const EntityPolicies = {
  allOf(policies) {
    return new AllEntityPolicies(policies);
  },
  oneOf(policies) {
    return new AnyEntityPolicy(policies);
  }
};

export { EntityPolicies };
//# sourceMappingURL=EntityPolicies.esm.js.map
