Skip to content

Commit

Permalink
result 0.6: First deprecations and renames
Browse files Browse the repository at this point in the history
- Renamed `unwrapErrors` to `unwrapErrs`, `unwrapAndThrowErrors` to
  `throwErrs`, and `unwrapResults` to `unwrapOks`. Despite the
  suggestion inherent in the name, an `Err` is not _necessarily_ an
  error, and they not related to the `Error` exception class. The old
  names are deprecated and will be removed for 1.0.

  The implementation for the old and new names is identical (they are
  documented alias constants).

- Improved the typings of `unwrapErrs` and `unwrapOks` so that it is
  clear that both the input and output arrays may contain heterogeneous
  types. This involved the use of some explicit `any` typing, but
  testing in the Typescript playground suggests that the internal
  utility types `InferErr` and `InferOk` cause Typescript to properly
  resolve disparate types.

- Ensured that `new Result()` throws an exception; the only way to
  instantiate a `Result` is through `Ok` or `Err`, which construct
  internal (non-exported) `OkResult` and `ErrResult` classes.

  - Unbound methods from `Result.prototype` throw better exceptions when
    rebound.

- Deprecated `Result#isOkAnd` and `Result#isErrAnd` in favour of
  `Result#isOk` and `Result#isErr` with an optional predicate.

- Deprecated `Result#mapOrElse` in favour of `Result#mapOr` where the
  provided default can either be a value or a function that returns
  a value.

- Deprecated `Result#unwrapOrElse` in favour of `Result#unwrapOr` where
  the provided default can either be a value or a function that returns
  a value.

- Improved documentation.

- Fixed GitHub pages deploy: This has been adapted from the "Jekyll"
  workflow that GitHub proposes.
  • Loading branch information
halostatue committed Mar 8, 2024
1 parent a1c77a2 commit bc33dc3
Show file tree
Hide file tree
Showing 9 changed files with 800 additions and 316 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# all files
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 90

[*.{md,.markdown}]
trim_trailing_whitespace = false
max_line_length = 78

[node_modules/**]
ignore = true
41 changes: 30 additions & 11 deletions .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ on:
branches:
- main

workflow_dispatch:

concurrency:
group: pages
cancel-in-progress: false

jobs:
deploy_pages:
concurrency: ci-pages-${{ github.ref }}
build:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v4
- uses: actions/configure-pages@v4

- uses: pnpm/action-setup@v3
with:
Expand All @@ -26,12 +29,28 @@ jobs:
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- run: pnpm install --frozen-lockfile
- run: |
pnpm install --frozen-lockfile
pnpm build:docs
touch docs/.nojekyll
- run: pnpm build:docs
- uses: actions/upload-pages-artifact@v3
with:
path: docs

- run: touch docs/.nojekyll
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

- uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
folder: docs
needs: build
runs-on: ubuntu-latest

permissions:
contents: read
pages: write
id-token: write

steps:
- uses: actions/deploy-pages@v4
id: deployment
38 changes: 38 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
# @kineticcafe/result

## 0.6.0 / 2024-03-05

- Renamed `unwrapErrors` to `unwrapErrs`, `unwrapAndThrowErrors` to `throwErrs`,
and `unwrapResults` to `unwrapOks`. Despite the suggestion inherent in the
name, an `Err` is not _necessarily_ an error, and they not related to the
`Error` exception class. The old names are deprecated and will be removed for
1.0.

The implementation for the old and new names is identical (they are documented
alias constants).

- Improved the typings of `unwrapErrs` and `unwrapOks` so that it is clear that
both the input and output arrays may contain heterogeneous types. This
involved the use of some explicit `any` typing, but testing in the Typescript
playground suggests that the internal utility types `InferErr` and `InferOk`
cause Typescript to properly resolve disparate types.

- Ensured that `new Result()` throws an exception; the only way to instantiate
a `Result` is through `Ok` or `Err`, which construct internal (non-exported)
`OkResult` and `ErrResult` classes.

- Unbound methods from `Result.prototype` throw better exceptions when
rebound.

- Deprecated `Result#isOkAnd` and `Result#isErrAnd` in favour of `Result#isOk`
and `Result#isErr` with an optional predicate.

- Deprecated `Result#mapOrElse` in favour of `Result#mapOr` where the provided
default can either be a value or a function that returns a value.

- Deprecated `Result#unwrapOrElse` in favour of `Result#unwrapOr` where the
provided default can either be a value or a function that returns a value.

- Improved documentation.

- Fixed GitHub pages deploy: This has been adapted from the "Jekyll" workflow
that GitHub proposes.

## 0.5.0 / 2024-02-27

- Initial release. The APIs are heavily based on the Rust interface, but it does
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@

## Description

@kineticcafe/result is another Typescript implementation of the Rust `Result`
type.
@kineticcafe/result is another [`Result` type][wiki] implementation for
Typescript, loosely based on Rust's [std::result][] type.

`Result` types contain a value or possible error and should be used to return
different types for success and failure without using exceptions for normal flow
control. As the values in `Result`s are not directly accessible, there is
explicit error handling at the point of use, through matching (`Result#match`),
transformation (`Result#andThen`, `Result#orElse`), unwrapping (`Result#unwrap`,
`Result#unwrapErr`), mapping (`Result#map`, `Result#mapErr`), or propagation
(returning the result to callers).

The @kineticcafe/result library additionally offers some utilities for dealing
with arrays of `Result` types.

## Synopsis

```javascript
import { Ok, Err } from '@kineticcafe/result'

Ok(3) // A successful result
Err('error') // An error
Err('error') // A likely error
```

## Installation
Expand All @@ -23,7 +34,7 @@ Err('error') // An error
`package.json`.

```sh
npm add @kineticcafe/result@^0.5
npm add @kineticcafe/result@^0.6
```

## Semantic Versioning
Expand All @@ -48,3 +59,5 @@ details.
[open source projects]: https://github.com/KineticCafe
[semantic versioning]: http://semver.org/
[licence.md]: https://github.com/KineticCafe/result/blob/main/Licence.md
[std::result]: https://doc.rust-lang.org/std/result/index.html
[wiki]: https://en.wikipedia.org/wiki/Result_type
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kineticcafe/result",
"type": "module",
"version": "0.5.0",
"version": "0.6.0",
"description": "A Result type loosely based on Rust Result",
"author": "Kinetic Commerce & contributors",
"homepage": "https://github.com/KineticCafe/result#readme",
Expand All @@ -28,7 +28,7 @@
}
},
"scripts": {
"build": "pkgroll",
"build": "tsc --noEmit && pkgroll",
"build:all": "pnpm run build && pnpm run build:docs",
"build:docs": "typedoc",
"build:watch": "concurrently 'pkgroll --watch' 'typedoc --watch --preserveWatchOutput'",
Expand All @@ -51,6 +51,7 @@
"@tsconfig/recommended": "^1.0.3",
"@types/node": "^20.11.20",
"@vitest/coverage-v8": "^1.3.1",
"concurrently": "^8.2.2",
"pkgroll": "^2.0.1",
"publint": "^0.2.7",
"tsx": "^4.7.1",
Expand Down
Loading

0 comments on commit bc33dc3

Please sign in to comment.