language js

private pattern js_module_reference() {
  or {
    JsImport(),
    JsImportCallExpression()
  }
}

private pattern app_server_protocol_connection_source() { r"^[\"'](?:\.\./)+connection(?:/.*)?[\"']$" }

private pattern root_app_server_connection_source() {
  or {
    r"^[\"'](?:\.\./)+app-server/connection(?:/.*)?[\"']$",
    r"^[\"']src/app-server/connection(?:/.*)?[\"']$"
  }
}

private pattern app_server_connection_boundary_source() {
  or {
    app_server_protocol_connection_source(),
    root_app_server_connection_source()
  }
}

js_module_reference() as $stmt where {
  $stmt <: contains `$source` where { $source <: app_server_connection_boundary_source() },
  register_diagnostic(span=$stmt, message="Do not import app-server connection internals from this module. Keep connection usage at app-server adapters.", severity="error")
}
