Skip to content

Commit

Permalink
Add changelog, contributing, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
mlms13 committed May 25, 2019
1 parent 6ef6785 commit 9a4b191
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.re linguist-language=Reason
22 changes: 22 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# keep the tests and docs out of npm
test
/docs
/website
CONTRIBUTING.md
CHANGELOG.md

# ...plus all of the stuff from gitignore
node_modules
*/log
.vscode

# generated
/lib/bs
*.bs.js
/dist
.merlin
.bsb.lock
/coverage

# os files
.DS_Store
116 changes: 116 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
## Unreleased

The following changes are currently in the `master` branch but have not been published in a tagged release yet.

### :rotating_light: Breaking

- `Decode.ParseError.map` has been removed (it wasn't used internally or documented)

### :bug: Bug fixes

- `...AsResult.OfStringNel` actually collects multiple errors now

### :sparkles: New features

- `Decode.alt` allows combining decode functions and picking the first success
- `...AsResult.OfStringNel` now includes all of the same `map`, `flatMap`, etc functions for decoders

### :heavy_check_mark: Code quality

- Reorganize tests so that `...AsOption` tests decoders pass-vs-fail, `...AsResult` tests failure reporting
- Test coverage has increased to 100%
- Internally, many functions were re-written to use `map`, `flatMap`, `alt`, etc on the functions themselves, rather than running the decoders and transforming the output
- `Js.Dict.key` was changed to `string` in interface files for better editor suggestions

## 0.5.1 (May 22, 2019)

### :heavy_check_mark: Code quality

- Bump Relude dependency to the latest version
- Add continuous integration and coverage reporting

## 0.5.0 (May 13, 2019)

### :rotating_light: Breaking

- `Decode.oneOf` now takes a single decoder, followed by a list of decoders instead of requiring you to construct a `NonEmptyList` (#28)
- `Decode.ok` has been removed; if you want to construct a decoder that always succeeds (ignoring the JSON input), use `Decode.pure` instead
- Decoders that produce `NonEmptyList`s of errors now use `Relude.NonEmpty.List` instead of the implementation from `bs-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](https://github.com/reazen/relude) exist if you want to work with `option` and `result` types. (#33)

### :sparkles: New features

- Decode functions now have `map`, `apply`, `map2`...`map5`, and `flatMap` functions, meaning you can transform decoders before actually running them. (#23)
- `Decode.NonEmptyList` is exposed for all decode modules that return a `NonEmptyList` 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-opening `Decode.Pipeline` should get you everything you need (#27)

### :heavy_check_mark: Code quality

- Internal use of infix functions has been greatly reduced to improve code clarity
- Tests have fewer global opens and fewer aliased functions

## 0.4.0 (Jan 24, 2019)

### :rotating_light: Breaking

- `float` and `int` are now `floatFromNumber` and `intFromNumber` to avoid compiler warnings related to shadowing `Pervasives.float`

### :sparkles: New features

- `Decode.date` decodes numbers or ISO-8601 strings into `Js.Date.t`
- `Decode.oneOf` attempts multiple decoders
- `Decode.dict` decodes an object into a `Js.Dict.t`
- `Decode.variantFromJson` (and `variantFromString`, `variantFromInt`) decode JSON values directly into Reason variants
- `Decode.Pipeline.at` now brings `at` functionality into the pipeline, to allow digging into nested JSON objects

### :memo: Documentation

- The `docs/` folder has more content
- The website is unpublished but mostly finished

## 0.3.3 (Oct 12, 2018)

### :bug: Bug fixes

- `Decode.int` now works correctly with `0`

## 0.3.1 (Oct 12, 2018)

### :sparkles: New features

- `Decode.AsResult.OfStringNel` now provides a consistent `ResultUtil` module that matches `...OfParseError`

### :heavy_check_mark: Code quality

- `*.rei` files now exist to help with editor suggestions


## 0.3.0 (Oct 10, 2018)

### :rotating_light: Breaking

- Rename `decode*` functions (e.g. `decodeString` is now `string`)
- Flip arguments to `Pipeline.run` so it can be piped with `|>` (thanks @gavacho)

### :sparkles: New features

- `Decode.boolean` was missing but now exists (thinks @johnhaley81)

## 0.2.0 (Sep 28, 2018)

### :rotating_light: Breaking

- Basic failure type is now a polymorphic variant so it's easier to extend with custom validations
- Many submodules were renamed and reorganized

### :sparkles: New features

- `Decode` top-level modules provides a convenient way to access everything

### :memo: Documentation

- Some basic examples now exist

## 0.1.0 (Sep 24, 2018)

Initial release includes basic decode functions and the choice of decoding into an `option` or a `Belt.Result.t` with recursively structured errors.
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
### Getting Started

1. Fork [this repo on Github](https://github.com/mlms13/bs-decode) and clone it locally
2. `npm install` to grab dependencies
3. `npm run cleanbuild && npm run test` to build and run tests
4. Make your changes (and add appropriate tests)
5. [Open a pull request](https://help.github.com/en/articles/about-pull-requests) with your changes

### Code style and conventions

We use [Relude](https://github.com/reazen/relude/) as our standard library, so try to avoid using `Belt` or `Pervasives` when working with lists, options, etc.

To make the code easier to understand for other new contributors, we've tried to minimize our use of infix functions. Using `>>` for forward composition is fine, though.

Also, please make sure that your code has been formatted with [`refmt`](https://reasonml.github.io/docs/en/editor-plugins).

### Project structure

- `DecodeBase.re` is where all of the decoders are defined
- `Decode_As*.re` modules construct `DecodeBase` with everything it needs to produce decoders for a specific output type (e.g. `option`, `result`)
- `Decode_ParseError.re` defines the structured errors and helper functions to work with `Belt.Result.t` values of that error type

### Tests

`bs-decode` currently has 100% test coverage, and we hope to keep it that way. :) Running `npm run test` (or `jest --coverage`) will run your tests and give you a coverage report. You can see the detailed report in `./coverage/lcov-report/index.html`, which will help you track down any uncovered functions or branches.

### Documentation

The documentation website is currently generated with [Docusaurus](https://docusaurus.io/). For more information on contributing to, running, and publishing the website, see [the README in the website folder](https://github.com/mlms13/bs-decode/blob/master/website/README.md).

Separately from the website, we maintain `*.rei` interface files that provide type hints and doc comments to editors. When adding new functionality, make sure you update the appropriate interface files with type signatures and comments.
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Decode JSON values into structured ReasonML and OCaml types. Inspired by Elm's [
The following is available to give you an idea of how the library works, but [the complete documentation](https://mlms13.github.io/bs-decode/docs/simple-example) will probably be more useful if you want to write your own decoders.

```reason
/* imagine you have a `user` type and `make` function to construct one */
// imagine you have a `user` type and `make` function to construct one
type user = {
name: string,
age: int,
Expand All @@ -42,7 +42,7 @@ let make = (name, age, isAdmin, lastLogin) =>
/**
* Given a JSON value that looks like:
* { "name": "Michael", "age": 32, "isAdmin": true }
* { "name": "Michael", "age": 32, "roles": ["admin"] }
*
* you can write a function to convert this JSON into a value of type `user`
*/
Expand All @@ -53,27 +53,18 @@ let decode = json =>
succeed(make)
|> field("name", string)
|> field("age", intFromNumber)
|> field("isAdmin", boolean)
|> field("roles", map(List.contains("admin"), list(string)))
|> optionalField("lastLogin", date)
|> run(json)
);
let myUser = decode(json); /* Belt.Result.Ok({...}) */
let myUser = decode(json); /* Ok({ name: "Michael", ...}) */
```

## Contributing

1. Fork and clone this repository
2. `npm install`
3. Add features and tests
4. `npm run test`

A note on project structure:

- `DecodeBase.re` is where most of the actual functionality lives
- `Decode_As*.re` define the actual implementations, but those are minimal
- `Decode_ParseError.re` defines the error type useful for Results, as well as a collection of helpers to work with Results of that kind.
All contributions are welcome! This obviously includes code changes and documentation improvements ([see CONTRIBUTING](https://github.com/mlms13/bs-decode/blob/master/CONTRIBUTING.md)), but we also appreciate any feedback you want to provide (in the form of [Github issues](https://github.com/mlms13/bs-decode/issues)) about concepts that are confusing or poorly explained in [the docs](https://mlms13.github.io/bs-decode/docs/what-and-why).

## License

Released under the MIT license. See `LICENSE`.
Released under the [MIT license](https://github.com/mlms13/bs-decode/blob/master/LICENSE).
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"build": "bsb -make-world",
"clean": "bsb -clean-world",
"cleanbuild": "npm run clean && npm run build",
"test": "npm run clean && npm run build && jest --coverage",
"watch": "bsb -make-world -w",
"test": "jest --coverage",
"coverage": "jest --coverage --coverageReporters=text-lcov | coveralls"
},
"homepage": "https://mlms13.github.io/bs-decode/docs",
Expand Down

0 comments on commit 9a4b191

Please sign in to comment.