"""Declared editor capabilities and the payloads that carry them. The capabilities of a source belong to its module. A filter is offered only when that module implements it. """ from __future__ import annotations EDITORS = { "note": True, "markdown_file": False, } def capability_payload() -> dict: from app.sourceregistry import registered_sources return { "sources": [module.capabilities for module in registered_sources()], "modules": [ { "kind": module.kind, "label": module.label, "representation": module.representation, "config_fields": [item.public() for item in module.config_fields], } for module in registered_sources() ], "editors": EDITORS, "protection_profiles": { "legacy-plaintext": "cleartext", "managed-encrypted": "locked", "client-encrypted": "locked", }, } def with_capabilities(kind: str, connector_id: str, payload: dict) -> dict: from app.sourceregistry import require_source body = dict(payload) spec = require_source(kind).capabilities body["connector_id"] = connector_id body["capabilities"] = spec body["unsupported"] = [name for name, enabled in spec["search"].items() if not enabled] if spec["search"].get("continuation"): body["continuation"] = body.get("next_before") if body.get("next_before") is not None else body.get("next_page") else: body["continuation"] = None body["incomplete"] = bool(body.get("incomplete")) return body