Coder Social home page Coder Social logo

purescript-argonaut-generic's People

Contributors

carstenkoenig avatar dependabot[bot] avatar frigoeu avatar garyb avatar jordanmartinez avatar justinwoo avatar kl0tl avatar liamgoodacre avatar matoruru avatar paluh avatar purefunctor avatar rightfold avatar srghma avatar th-awake avatar thomashoneyman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

purescript-argonaut-generic's Issues

unwrapSingleArguments should create an object and not a mix of object and array

Environment

  • PureScript [version] 0.13.8
  • purescript-argonaut-generic [version] 0.6.0

Current behavior

data NodeContent
  = NodeContentStart
  | NodeContentEnd { returnValue :: String }

encoding :: Encoding
encoding = defaultEncoding { tagKey = "tag", unwrapSingleArguments = true, valuesKey = "values" }

instance encodeJsonNodeContent :: EncodeJson NodeContent where
  encodeJson = genericEncodeJsonWith encoding

instance decodeJsonNodeContent :: DecodeJson NodeContent where
  decodeJson = genericDecodeJsonWith encoding

If there is an argument unwrapSingleArguments makes values and object, instead of an array objects.
If there is no argument, values will be an empty array.

Expected behavior

I'd expect an empty object if there are no arguments (for consistency).

toJsonString NodeContentStart 
-- Actual: "{\"values\":[],\"tag\":\"NodeContentStart\"}"
-- Expected: "{\"values\":{}\,\"tag\":\"NodeContentStart\"}"

Code

genericEncodeJson not respecting `EncodeJson` instances of fields

I hope the example clarifies:

data Foo = Foo Bar
data Bar = Bar

derive instance genericFoo :: Generic Foo
derive instance genericBar :: Generic Bar

instance encodeJsonFoo :: EncodeJson Foo where
  encodeJson = genericEncodeJson Argonaut.options

instance encodeJsonBar :: EncodeJson Bar where
  encodeJson _ = fromString "yippie"

main :: forall e. Eff (console :: CONSOLE | e) Unit
main = Console.log $ Json.stringify $ encodeJson $ Foo Bar

-- I expected "yippie" to show up in the output

I've also created a repro repo: https://github.com/felixSchl/repro-encodejson

Library doesn't have sufficient module documentation

Is your change request related to a problem? Please describe.
As described in the documentation section of the Library Guidelines, Contributors libraries are expected to have mostly complete module documentation, preferably uploaded to Pursuit.

This library currently doesn't have sufficient module documentation -- many publicly-exported types and functions don't have any documentation comments.

Describe the solution you'd like
The library needs to have documentation comments on the majority (and preferably all) public types and functions. Once updated, we should tag a release and upload new module documentation to Pursuit so that folks can use it.

Additional context
See the Governance repository for more information about requirements in the Contributors organization.

Misleading installation instructions

Is your change request related to a problem? Please describe.
The README suggests that this package can be installed with spago install argonaut but argonaut-generic is not a dependency of argonaut so this isn’t actually possible.

Describe the solution you'd like
We should either remove the instruction or add argonaut-generic to the dependencies of argonaut.

Drop the Rep suffix from modules names?

We renamed the Data.Generic.Rep.* modules to Data.*.Generic when porting generics-rep to prelude in purescript/purescript-prelude#235, so we should probably rename Data.Argonaut.Decode.Generic.Rep to Data.Argonaut.Decode.Generic, Data.Argonaut.Encode.Generic.Rep to Data.Argonaut.Encode.Generic and Data.Argonaut.Types.Generic.Rep to Data.Argonaut.Types.Generic when dropping generics-rep and updating the prelude dependency to its latest version.

Library has inadequate documentation in the docs directory

Is your change request related to a problem? Please describe.
As described in the documentation section of the Library Guidelines, Contributors libraries are expected to have some documentation in the docs directory -- specifically, a changelog and at least a short tutorial that expands on the quick start in the README.

This library currently doesn't have an up to date changelog or any extra documentation in the docs directory.

Describe the solution you'd like
The changelog needs to be updated for at least the most recent release (we can then start curating it going forward). In addition, we need a short tutorial and at least some explanation of how to tailor these generic instances to your needs.

The argonaut-codecs docs directory has a good example of expanded documentation for a Contributor library. But it would even be useful to add something considerably smaller and shorter to this library.

Additional context
See the Governance repository for more information about requirements in the Contributors organization.

small optimization for encode

Could the following two lines of code be switched around ?

$ FO.insert e.tagKey (fromString (reflectSymbol (Proxy :: Proxy name)))
$ FO.insert e.valuesKey values

Reason being that right now values come first in the encoded json and tag later. But for decoding it can potentially be faster to first get the tag to get of the type (FP) or class (OO) that the values have to be deserialized into.

Also for debugging it's nicer to see tag first and (potentially long) value string after that.

PureScript 0.12

starting with v0.12 purescript-generics will no longer be supported by the compiler/deriving but purescript-generics-rep still is.

The later removed support for rows/records though and it seems RowToList is the way to go.

We need a way to deal with this in order for this lib to keep being usable after people switch to 0.12 or higher

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.