{"version":3,"file":"unsupported.cjs","names":["ruleToString"],"sources":["../../src/compat/unsupported.ts"],"sourcesContent":["/**\n * The error a codec raises when the target agent cannot enforce a restrictive rule or setting.\n *\n * A codec that drops or loosens a `deny` or `ask` rule, or a default mode, lets a policy look enforced when it is not, so it refuses instead. The error names every rule and setting it refused and why, so the caller can fix the policy or choose a different target.\n */\n\nimport { ruleToString } from \"../evaluate.ts\";\nimport type { Rule } from \"../schema.ts\";\n\n/** One rule a codec refused to convert, with the reason the target cannot enforce it. */\nexport interface UnsupportedRule {\n  readonly rule: Rule;\n  readonly reason: string;\n}\n\n/** One policy-wide setting, such as the default mode, a codec refused to convert, with the reason. */\nexport interface UnsupportedSetting {\n  /** The canonical key, such as `defaultMode`. */\n  readonly setting: string;\n  /** The value the target has no equivalent for. */\n  readonly value: string;\n  readonly reason: string;\n}\n\nexport class UnsupportedCapabilityError extends Error {\n  /** The agent whose native format could not represent the policy. */\n  readonly agent: string;\n  /** Every refused rule, in the order the codec met them. */\n  readonly unsupported: readonly UnsupportedRule[];\n  /** Every refused policy-wide setting. */\n  readonly settings: readonly UnsupportedSetting[];\n\n  constructor(\n    agent: string,\n    unsupported: readonly UnsupportedRule[],\n    settings: readonly UnsupportedSetting[] = [],\n  ) {\n    const lines = [\n      ...settings.map((s) => `  ${s.setting}: ${s.value}: ${s.reason}`),\n      ...unsupported.map(\n        (u) => `  ${ruleToString(u.rule)} [${u.rule.tier}]: ${u.reason}`,\n      ),\n    ];\n    const counts = [\n      { count: unsupported.length, noun: \"rule(s)\" },\n      { count: settings.length, noun: \"setting(s)\" },\n    ]\n      .filter(({ count }) => count > 0)\n      .map(({ count, noun }) => `${String(count)} ${noun}`);\n    super(\n      `${agent} cannot enforce ${counts.join(\" and \")} in this policy, and converting them would weaken it:\\n${lines.join(\"\\n\")}`,\n    );\n    this.name = \"UnsupportedCapabilityError\";\n    this.agent = agent;\n    this.unsupported = unsupported;\n    this.settings = settings;\n  }\n}\n"],"mappings":";;;;;;;;;AAwBA,IAAa,6BAAb,cAAgD,MAAM;;CAEpD,AAAS;;CAET,AAAS;;CAET,AAAS;CAET,YACE,OACA,aACA,WAA0C,CAAC,GAC3C;EACA,MAAM,QAAQ,CACZ,GAAG,SAAS,KAAK,MAAM,KAAK,EAAE,QAAQ,IAAI,EAAE,MAAM,IAAI,EAAE,QAAQ,GAChE,GAAG,YAAY,KACZ,MAAM,KAAKA,8BAAa,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,KAAK,KAAK,EAAE,QAC1D,CACF;EACA,MAAM,SAAS,CACb;GAAE,OAAO,YAAY;GAAQ,MAAM;EAAU,GAC7C;GAAE,OAAO,SAAS;GAAQ,MAAM;EAAa,CAC/C,CAAC,CACE,QAAQ,EAAE,YAAY,QAAQ,CAAC,CAAC,CAChC,KAAK,EAAE,OAAO,WAAW,GAAG,OAAO,KAAK,EAAE,GAAG,MAAM;EACtD,MACE,GAAG,MAAM,kBAAkB,OAAO,KAAK,OAAO,EAAE,yDAAyD,MAAM,KAAK,IAAI,GAC1H;EACA,KAAK,OAAO;EACZ,KAAK,QAAQ;EACb,KAAK,cAAc;EACnB,KAAK,WAAW;CAClB;AACF"}