Skip to content

Releases: paf31/purescript-foreign-generic

v11.0.0

18 Mar 20:00
3cddc5f
Compare
Choose a tag to compare

v10.0.0

22 May 16:22
46f0999
Compare
Choose a tag to compare
  • Add Decode and Encode instances for Record

Breaking Changes

  • Decode_ and Encode_ were renamed to DecodeWithOptions and EncodeWithOptions.
  • The module structure was changed to simplify things and to make it possible to add instances which would have been orphans.

v9.0.0

15 Mar 17:14
Compare
Choose a tag to compare

Update dependencies (@pbrant)

v8.1.0

27 Feb 20:05
Compare
Choose a tag to compare

Add Encode and Decode instances to Identity (@arthurxavierx)

v8.0.0

30 Jan 01:36
Compare
Choose a tag to compare

Breaking Changes

Encode Nothing as null rather than undefined

(@hdgarrood)

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

24 Apr 02:23
5152882
Compare
Choose a tag to compare
  • Instances for Unit and Void
  • Remove NullOrUndefined, use Maybe instead for simplicity.

v5.0.1

16 Feb 18:39
Compare
Choose a tag to compare

Fix constructorTagTransform (@abaco)

v5.0.0

06 Aug 19:07
Compare
Choose a tag to compare

Add fieldTransform to Options, which allows the labels in a record to be modified for the purposes of (de)serialization (@jacereda)

v4.3.0

27 Jul 04:05
Compare
Choose a tag to compare

Instances for StrMap (@jacereda)

v4.2.0

06 Jul 23:13
Compare
Choose a tag to compare
  • Add generic support for encoding and decoding "enum" types (sum types with no data constructor arguments) (@justinwoo)
  • Update dependencies (@justinwoo)