More deprecations have been added to prepare for v2.0, as well as some new functions to ease the pain of those deprecations.
map2
...map5
have been deprecated and will be replaced by the upcomingand+
tuple2
...tuple5
andtupleAtLeast2
...tupleAtLeast5
have been deprecated for the same reason, and they can be recreated usingarrayAt
(see below)ParseError.ResultOf
(and related modules) is deprecated for the same reasonDecode.Make
is deprecated
arrayAt
allows decoding only specific positions of arrays, which is useful for building your own tuplesnull
is a new decoder that only succeeds if it encounters a JSONnull
valuedictJson
,arrayJson
,listJson
were added to allow decoding outer structures while preserving inner JSON
This release adds helpers to ease the transition away from the deprecated features in the 1.0 release. Barring any bugs that require fixing, this is the last planned release in the 1.x series.
- Some deprecations mentioned in the previous release notes weren't actually deprecated in the code. Those will now trigger compiler warnings.
hush
is a new function that takes aDecode.AsResult.OfParseError
decoder and converts it into aJs.Json.t => option('a)
decoder (effectively "hushing" the error). This should make the transition away fromDecode.AsOption
easier.literalBool
,literalTrue
, andliteralFalse
join the otherliteral*
decoders that first decode, then further validate the outputintUnion
works likestringUnion
and should make the transition away fromvariantFromInt
easier
Version 1.0 is here! Very little has changed since 0.11.2; mostly this release indicates the stability (or lack of maintenance, depending on how you look at it) over the last several years. The 1.x releases will be the last to support BuckleScript as we turn our attention to Melange.
There are no breaking changes in this release, but there are a handful of deprecations. We should end up with decent alternatives to all of the features that will eventually be removed, but if any of this concerns you, please let me know!
Decode.AsResult.OfStringNel
will be removed in an upcoming release. The errors are less useful thanOfParseError
, and there's a cost to maintaining multiple decoder typesDecode.AsOption
will also be removed. Again, there's a maintenance burden in keeping it, and if you really wantoption
, it's easy enough to convert theresult
return into anoption
.Decode.Make
(for making your own custom output types) will eventually be removed as we focus onParseError
variantFromJson
andvariantFromString
will be removed in favor of new, simpler, more consistent tools for decoding variants (see the newliteral
functions below)- The
Decode.Pipeline
module is now deprecated. See the docs for alternatives and a teaser about upcoming changes that will make this experience way better stringMap
will be removed as we try to limit how much we depend on Belt-specific features. You can use thedict
decoder instead and convert theJs.Dict
to aBelt.String.Map
.
- Functions have been added to decode literal values e.g.
literalString
,literalInt
, andliteralFloat
. These functions first decode to the expected type, then ensure the value exactly matches the provided value. This is useful for decoding unions of string literals (e.g."dev" | "prod"
) - Decoding sting unions is such a common need that we've provided a
stringUnion
function to make it even simpler
- The documentation site got a handful of updates to explain the deprecations
- The guide on decoding variants was almost completely rewritten and might be particularly helpful
bs-bastet
was bumped to2.0
andrelude
was bumped to0.66.1
. As peer dependencies, this change is the most likely to impact your existing projects, but hopefully the update isn't too bad
- Compiled output files will no longer have a
/./
in the middle of the path, which causes issues with some bundlers/dev setups (thanks @hamza0867 for finding and fixing this!)
- Revert the
public
flag in thebsconfig.json
. There are apparently some strange quirks that cause aliased modules not to compile in downstream projects, so I got rid of it. You still shouldn't need to accessDecode_*
modules directly (instead useDecode.AsWhatever
) but those modules won't be hidden from you.
- The
bs-abstract
peer-dependency is nowbs-bastet
, and the required Relude version is 0.59+. See the Relude release notes and the Bastet migration guide for details. - Alias everything in
Decode
and prevent direct access to theDecode_*
modules via Bucklescript'spublic
flag
okJson
is a decoder that always passes and preserves the input JSON
- All error-related types now live in
Decode.ParseError
. Specifically, this means thatDecodeBase.failure
is nowDecode.ParseError.base
, which is important if you're extending the base errors to create your own custom errors.
- README explains peer dependencies better
- Nested array decoding is demonstrated in the tests
- Haskell-style object decoding operates on the decoders, not the result
- Bump dependencies and allow compilation with Bucklescript 7.1
- Internally, use structural typing for typeclasses rather than named modules
- Decode into a Belt Map (with string keys)
- Allow easy access to tuple helpers from Pipeline
pipe
function itself is now public
- More tests around string and int decoding
- Bump dependencies
optionField
values that are present but fail to decode will now report the field in theParseError
- CI will now show failures correctly if tests don't pass
- Long-deprecated
int
andfloat
functions have been removed. You should be usingintFromNumber
andfloatFromNumber
instead to avoid shadowing issues tuple
(which previously contructed atuple
from a JSON object) is nowtupleFromFields
- Base
failure
type now includes anExpectedTuple(int)
constructor, whereint
is the expected size. This is only a breaking change if you're manually matching on values of the basefailure
type.
- JSON arrays can now be decoded directly into tuples using
tuple2
...tuple5
(which will fail if the JSON array is larger than expected) ortupleAtLeast2
...tupleAtLeast5
(which will tolerate longer arrays)
relude
andbs-abstract
are now peerDependencies. This means you'll need to add these dependencies to your ownpackage.json
, and you're much less likely to end up with duplicate versions of these packages.
Decode.array
(and its friendlist
) had a regression where they could fail in some browsers when given large amounts of data, but stack safety has been restored
- Fix links in
package.json
Decode.fallback
doesn't assume you want to work withfield
s, but you can useDecode.(fallback(field("x", string), "default"))
if you want the old behaviorDecode.Pipeline.fallback
has the same new behavior, but it providesfallbackField
to achieve the old behaviorDecode.ParseError.map
has been removed (it wasn't used internally or documented)- The
Decode.ParseError
variant type now includes aTriedMultiple
constructor. This is only a breaking change if you are matching directly on values of this type.
Decode.AsResult.OfStringNel
actually collects multiple errors now
Decode.alt
allows combining decode functions and picking the first successDecode.AsResult.OfStringNel
now includes all of the samemap
,flatMap
, etc functions for decodersDecode.ParseError
is aliased asDecode.AsResult.OfParseError.ParseError
so parse errors can be accessed from an aliased decode module
- Reorganize tests so that
Decode_AsOption
tests decoders pass-vs-fail,Decode_AsResult_*
tests failure reporting - Test coverage has increased to 100%
- Internally, many functions were re-written to use
map
,flatMap
,alt
, etc on the decoders themselves, rather than running the decoders and transforming the output Js.Dict.key
was changed tostring
in interface files for better editor suggestions
- Bump Relude dependency to the latest version
- Add continuous integration and coverage reporting
Decode.oneOf
now takes a single decoder, followed by a list of decoders instead of requiring you to construct aNonEmptyList
(#28)Decode.ok
has been removed; if you want to construct a decoder that always succeeds (ignoring the JSON input), useDecode.pure
instead- Decoders that produce
NonEmptyList
s of errors now useRelude.NonEmpty.List
instead of the implementation frombs-nonempty
due to more active maintenance and a broader collection of helper functions Decode.ResultUtils
is no longer part of the public interface. Decode functions themselves are more easily composable (see "New stuff" below), so there's less need to transform the output after decoding. Plus better libraries exist if you want to work withoption
andresult
types. (#33)
- Decode functions now have
map
,apply
,map2
...map5
, andflatMap
functions, meaning you can transform decoders before actually running them. (#23) Decode.NonEmptyList
is exposed for all decode modules that return aNonEmptyList
of errors. This means you can do basic operations with the errors without bringing in an additional library (#24)Decode.Pipeline
aliases most of the base decoders (e.g.string
,intFromNumber
, etc), so locally-openingDecode.Pipeline
should get you everything you need (#27)
- Internal use of infix functions has been greatly reduced to improve code clarity
- Tests have fewer global opens and fewer aliased functions
float
andint
are nowfloatFromNumber
andintFromNumber
to avoid compiler warnings related to shadowingPervasives.float
Decode.date
decodes numbers or ISO-8601 strings intoJs.Date.t
Decode.oneOf
attempts multiple decodersDecode.dict
decodes an object into aJs.Dict.t
Decode.variantFromJson
(andvariantFromString
,variantFromInt
) decode JSON values directly into Reason variantsDecode.Pipeline.at
now bringsat
functionality into the pipeline, to allow digging into nested JSON objects
- The
docs/
folder has more content - The website is unpublished but mostly finished
Decode.int
now works correctly with0
Decode.AsResult.OfStringNel
now provides a consistentResultUtil
module that matches...OfParseError
*.rei
files now exist to help with editor suggestions
- Rename
decode*
functions (e.g.decodeString
is nowstring
) - Flip arguments to
Pipeline.run
so it can be piped with|>
(thanks @gavacho)
Decode.boolean
was missing but now exists (thinks @johnhaley81)
- Basic failure type is now a polymorphic variant so it's easier to extend with custom validations
- Many submodules were renamed and reorganized
Decode
top-level modules provides a convenient way to access everything
- Some basic examples now exist
Initial release includes basic decode functions and the choice of decoding into an option
or a Belt.Result.t
with recursively structured errors.