More deprecations have been added to prepare for v2.0, as well as some new functions to ease the pain of those deprecations.
map2...map5have been deprecated and will be replaced by the upcomingand+tuple2...tuple5andtupleAtLeast2...tupleAtLeast5have 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.Makeis deprecated
arrayAtallows decoding only specific positions of arrays, which is useful for building your own tuplesnullis a new decoder that only succeeds if it encounters a JSONnullvaluedictJson,arrayJson,listJsonwere 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.
hushis a new function that takes aDecode.AsResult.OfParseErrordecoder and converts it into aJs.Json.t => option('a)decoder (effectively "hushing" the error). This should make the transition away fromDecode.AsOptioneasier.literalBool,literalTrue, andliteralFalsejoin the otherliteral*decoders that first decode, then further validate the outputintUnionworks likestringUnionand should make the transition away fromvariantFromInteasier
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.OfStringNelwill be removed in an upcoming release. The errors are less useful thanOfParseError, and there's a cost to maintaining multiple decoder typesDecode.AsOptionwill also be removed. Again, there's a maintenance burden in keeping it, and if you really wantoption, it's easy enough to convert theresultreturn into anoption.Decode.Make(for making your own custom output types) will eventually be removed as we focus onParseErrorvariantFromJsonandvariantFromStringwill be removed in favor of new, simpler, more consistent tools for decoding variants (see the newliteralfunctions below)- The
Decode.Pipelinemodule is now deprecated. See the docs for alternatives and a teaser about upcoming changes that will make this experience way better stringMapwill be removed as we try to limit how much we depend on Belt-specific features. You can use thedictdecoder instead and convert theJs.Dictto 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
stringUnionfunction 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-bastetwas bumped to2.0andreludewas 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
publicflag 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-abstractpeer-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
Decodeand prevent direct access to theDecode_*modules via Bucklescript'spublicflag
okJsonis a decoder that always passes and preserves the input JSON
- All error-related types now live in
Decode.ParseError. Specifically, this means thatDecodeBase.failureis 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
pipefunction itself is now public
- More tests around string and int decoding
- Bump dependencies
optionFieldvalues 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
intandfloatfunctions have been removed. You should be usingintFromNumberandfloatFromNumberinstead to avoid shadowing issues tuple(which previously contructed atuplefrom a JSON object) is nowtupleFromFields- Base
failuretype now includes anExpectedTuple(int)constructor, whereintis the expected size. This is only a breaking change if you're manually matching on values of the basefailuretype.
- 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)
reludeandbs-abstractare 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.fallbackdoesn't assume you want to work withfields, but you can useDecode.(fallback(field("x", string), "default"))if you want the old behaviorDecode.Pipeline.fallbackhas the same new behavior, but it providesfallbackFieldto achieve the old behaviorDecode.ParseError.maphas been removed (it wasn't used internally or documented)- The
Decode.ParseErrorvariant type now includes aTriedMultipleconstructor. This is only a breaking change if you are matching directly on values of this type.
Decode.AsResult.OfStringNelactually collects multiple errors now
Decode.altallows combining decode functions and picking the first successDecode.AsResult.OfStringNelnow includes all of the samemap,flatMap, etc functions for decodersDecode.ParseErroris aliased asDecode.AsResult.OfParseError.ParseErrorso parse errors can be accessed from an aliased decode module
- Reorganize tests so that
Decode_AsOptiontests 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.keywas changed tostringin interface files for better editor suggestions
- Bump Relude dependency to the latest version
- Add continuous integration and coverage reporting
Decode.oneOfnow takes a single decoder, followed by a list of decoders instead of requiring you to construct aNonEmptyList(#28)Decode.okhas been removed; if you want to construct a decoder that always succeeds (ignoring the JSON input), useDecode.pureinstead- Decoders that produce
NonEmptyLists of errors now useRelude.NonEmpty.Listinstead of the implementation frombs-nonemptydue to more active maintenance and a broader collection of helper functions Decode.ResultUtilsis 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 withoptionandresulttypes. (#33)
- Decode functions now have
map,apply,map2...map5, andflatMapfunctions, meaning you can transform decoders before actually running them. (#23) Decode.NonEmptyListis exposed for all decode modules that return aNonEmptyListof errors. This means you can do basic operations with the errors without bringing in an additional library (#24)Decode.Pipelinealiases most of the base decoders (e.g.string,intFromNumber, etc), so locally-openingDecode.Pipelineshould 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
floatandintare nowfloatFromNumberandintFromNumberto avoid compiler warnings related to shadowingPervasives.float
Decode.datedecodes numbers or ISO-8601 strings intoJs.Date.tDecode.oneOfattempts multiple decodersDecode.dictdecodes an object into aJs.Dict.tDecode.variantFromJson(andvariantFromString,variantFromInt) decode JSON values directly into Reason variantsDecode.Pipeline.atnow bringsatfunctionality into the pipeline, to allow digging into nested JSON objects
- The
docs/folder has more content - The website is unpublished but mostly finished
Decode.intnow works correctly with0
Decode.AsResult.OfStringNelnow provides a consistentResultUtilmodule that matches...OfParseError
*.reifiles now exist to help with editor suggestions
- Rename
decode*functions (e.g.decodeStringis nowstring) - Flip arguments to
Pipeline.runso it can be piped with|>(thanks @gavacho)
Decode.booleanwas 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
Decodetop-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.