Skip to content

Tags: paf31/purescript-foreign-generic

Tags

v11.0.0

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Merge pull request #61 from fsoikin/purescript-0.14

Migrate to PureScript 0.14

v10.0.0

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Add Decode/Encode instances for Record, simplify module structure (#53)

* Add Decode/Encode instances for Record

* Docs

* Simplify the module structure

* Update README

* Better backwards-compatibility

v9.0.0

Update dependencies (#51)

v8.1.0

Add Encode and Decode instances to Identity (#50)

v8.0.0

Encode Nothing as null rather than undefined (#49)

Previously, the Encode (Maybe a) instance was mapping Nothing to
undefined, which meant that Nothing fields in records would disappear
when stringifying:

    -- old behaviour
    newtype Foo = Foo { x :: Maybe Int }
    derive instance genericFoo :: Generic Foo _

    foo = Foo { x: Nothing }
    log (encodeJSON foo)
    -- {"tag":"Foo","contents":{}}

This commit changes the behaviour of the Encode (Maybe a) instance so
that Nothing is mapped to null rather than undefined. This means that
Nothing fields are present in the JSON, with a value of null:

    -- new behaviour
    log (encodeJSON foo)
    -- {"tag":"Foo","contents":{"x":null}}

Note that we remain lenient about decoding records with Maybe fields:
a field may be present and have a value of null, or it may be absent;
in both cases, the field is decoded as Nothing.

This change brings foreign-generic more into line with Aeson, as by
default Aeson will also encode Nothing fields as present with a value of
null (in fact, this is configurable in Aeson: there is a configuration
option `omitNothingFields` which, when turned on, means that
Nothing-valued fields will be omitted during JSON encoding.)

Maybe values which ended up inside arrays in the encoded JSON are
unaffected by this change; previously they were mapped to `null` anyway.

Maybe values at the top level of the encoded JSON, however, are
affected. In fact, encoding Maybe values at the top level could
previously lead to runtime errors:

    -- previously
    > encodeJSON (Nothing :: Maybe Int)
    ./purescript-foreign-generic/.psci_modules/node_modules/Data.Show/foreign.js:30
      var l = s.length;
                ^

    TypeError: Cannot read property 'length' of undefined

    -- now
    > encodeJSON (Nothing :: Maybe Int)
    "null"

v6.0.0

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Add Unit instances (#43)

* Add Unit instances

* Void instances, docs

* Add Maybe instances

v5.0.1

Fix bug constructorTagTransform (#41)

* Add failing test for constructorTagTransform

* Fix bug with some constructoTagTransform functions

v5.0.0

Add fieldTransform to Options (#32)

* Add fieldTransform to Options

* Add comment about fieldTransform

v4.3.0

Encode/Decode instances for StrMap (#28)

* Encode/Decode instances for StrMap

* Use readStrMap

* Remove redundant checks