packages feed

servant-js 0.9.1 → 0.9.2

raw patch · 5 files changed

+31/−21 lines, 5 files

Files

CHANGELOG.md view
@@ -1,3 +1,11 @@+0.9.2+-----++* Fix code generation for query flag+  ([#11](https://github.com/haskell-servant/servant-js/issues/11))+* Improve error handling in vanilla backend+  ([#9](https://github.com/haskell-servant/servant-js/pull/9))+ 0.9.1 ----- 
servant-js.cabal view
@@ -1,5 +1,5 @@ name:                servant-js-version:             0.9.1+version:             0.9.2 synopsis:            Automatically derive javascript functions to query servant webservices. description:   Automatically derive javascript functions to query servant webservices.@@ -66,11 +66,11 @@     buildable: False    build-depends:    base             >= 4.7 && < 5-                  , aeson            >= 0.7  && < 1.1+                  , aeson            >= 0.7  && < 1.2                   , filepath         >= 1                   , lens             >= 4-                  , servant          == 0.9.*-                  , servant-server   == 0.9.*+                  , servant+                  , servant-server                   , servant-js                   , stm                   , transformers
src/Servant/JS/Internal.hs view
@@ -183,7 +183,7 @@            <> "=' + encodeURIComponent("            <> name            <> if notTheEnd then ") + '" else ")"-    Flag   -> name <> "="+    Flag   -> name <> "'"     List   -> name            <> "[]=' + encodeURIComponent("            <> name
src/Servant/JS/Vanilla.hs view
@@ -29,28 +29,28 @@ -- | js codegen using XmlHttpRequest generateVanillaJSWith :: CommonGeneratorOptions -> AjaxReq -> Text generateVanillaJSWith opts req = "\n" <>-    fname <> " = function(" <> argsStr <> ")\n"- <> "{\n"+    fname <> " = function(" <> argsStr <> ") {\n"  <> "  var xhr = new XMLHttpRequest();\n"  <> "  xhr.open('" <> decodeUtf8 method <> "', " <> url <> ", true);\n"  <>    reqheaders- <> "  xhr.setRequestHeader(\"Accept\",\"application/json\");\n"- <> (if isJust (req ^. reqBody) then "  xhr.setRequestHeader(\"Content-Type\",\"application/json\");\n" else "")- <> "  xhr.onreadystatechange = function (e) {\n"- <> "    if (xhr.readyState == 4) {\n"- <> "      if (xhr.status == 204 || xhr.status == 205) {\n"- <> "        onSuccess();\n"- <> "      } else if (xhr.status >= 200 && xhr.status < 300) {\n"- <> "        var value = JSON.parse(xhr.responseText);\n"- <> "        onSuccess(value);\n"+ <> "  xhr.setRequestHeader('Accept', 'application/json');\n"+ <> (if isJust (req ^. reqBody) then "  xhr.setRequestHeader('Content-Type', 'application/json');\n" else "")+ <> "  xhr.onreadystatechange = function () {\n"+ <> "    var res = null;\n"+ <> "    if (xhr.readyState === 4) {\n"+ <> "      if (xhr.status === 204 || xhr.status === 205) {\n"+ <> "        " <> onSuccess <> "();\n"+ <> "      } else if (xhr.status >= 200 && xhr.status < 300 && xhr.responseType === 'json') {\n"+ <> "        try { res = JSON.parse(xhr.responseText); } catch (e) { " <> onError <> "(e); }\n"+ <> "        if (res) " <> onSuccess <> "(res);\n"  <> "      } else {\n"- <> "        var value = JSON.parse(xhr.responseText);\n"- <> "        onError(value);\n"+ <> "        try { res = JSON.parse(xhr.responseText); } catch (e) { " <> onError <> "(e); }\n"+ <> "        if (res) " <> onError <> "(res);\n"  <> "      }\n"  <> "    }\n"- <> "  }\n"+ <> "  };\n"  <> "  xhr.send(" <> dataBody <> ");\n"- <> "}\n"+ <> "};\n"    where argsStr = T.intercalate ", " args         args = captures@@ -79,7 +79,7 @@          dataBody =           if isJust (req ^. reqBody)-            then "JSON.stringify(body)\n"+            then "JSON.stringify(body)"             else "null"  
test/Servant/JSSpec.hs view
@@ -26,6 +26,7 @@  import           Servant.API.Internal.Test.ComprehensiveAPI import           Servant.API.ContentTypes+import           Servant.API.QueryParam import           Servant.JS import           Servant.JS.Internal import qualified Servant.JS.Angular           as NG@@ -42,6 +43,7 @@ -- * specs  type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] Text :> Post '[JSON] Bool+          :<|> "params" :> QueryParam "foo" Text :> QueryFlag "flag" :> Get '[JSON] Bool           :<|> "has.extension" :> Get '[FormUrlEncoded,JSON] Bool  type TopLevelRawAPI = "something" :> Get '[JSON] Int