Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deno #26

Merged
merged 6 commits into from
Oct 31, 2024
Merged

deno #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
pull_request:
types: [opened, reopened, synchronize]
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
name: Test

steps:
- name: Checkout repo
uses: actions/checkout@v3

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Run tests
run: deno task test

lint:
runs-on: ubuntu-latest
name: Lint

steps:
- name: Checkout repo
uses: actions/checkout@v3

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- run: deno fmt --check
- run: deno lint
92 changes: 0 additions & 92 deletions .github/workflows/pr-checks.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.DS_Store
npm/
node_modules/
coverage/
.turbo
dist/
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

18 changes: 0 additions & 18 deletions .prettierrc

This file was deleted.

19 changes: 0 additions & 19 deletions .vscode/all.code-workspace

This file was deleted.

7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"deno.enable": true,
"editor.defaultFormatter": "denoland.vscode-deno",
"[ignore]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
}
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ TypeScript implementation of the `Result` type from `Rust` with a full-fledged
interface to work with async primitives.

> Also check out
> [eslint-plugin-resulto](https://github.com/adjsky/resulto/tree/master/packages/eslint-plugin-resulto).
> This ESLint plugin ensures that your Results are used to prevent leaving
> Err variants unhandled.
> [eslint-plugin-resulto](https://github.com/adjsky/resulto/tree/master/eslint-plugin).
> This ESLint plugin ensures that your Results are used to prevent leaving Err
> variants unhandled.

## Installation

Expand All @@ -16,13 +16,13 @@ npm install resulto

## API documentation

https://adjsky.github.io/resulto/
https://jsr.io/@resulto/core/doc

## History

Exceptions are dangerous. Most of the time you do not know some function you
use could throw, you forget to wrap this function in a `try/catch` block and
deploy your broken application to production.
Exceptions are dangerous. Most of the time you do not know some function you use
could throw, you forget to wrap this function in a `try/catch` block and deploy
your broken application to production.

Exceptions are ugly. Wraping each function call that may throw in a `try/catch`
block for regular control flow lead to convoluted and smelly code.
Expand Down
25 changes: 13 additions & 12 deletions packages/resulto/README.md → core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ npm install resulto

## API documentation

1. [Result](https://adjsky.github.io/resulto/types/Result.html)
2. [AsyncResult](https://adjsky.github.io/resulto/types/AsyncResult.html)
3. [ok](https://adjsky.github.io/resulto/functions/ok-1.html)
4. [okAsync](https://adjsky.github.io/resulto/functions/okAsync.html)
5. [err](https://adjsky.github.io/resulto/functions/err-1.html)
6. [errAsync](https://adjsky.github.io/resulto/functions/errAsync.html)
7. [fromPromise](https://adjsky.github.io/resulto/functions/fromPromise.html)
8. [fromSafePromise](https://adjsky.github.io/resulto/functions/fromSafePromise.html)
9. [fromThrowable](https://adjsky.github.io/resulto/functions/fromThrowable.html)
10. [combine](https://adjsky.github.io/resulto/functions/combine.html)
11. [combineAsync](https://adjsky.github.io/resulto/functions/combineAsync.html)
1. [Result](https://jsr.io/@resulto/core/doc/~/Result)
2. [AsyncResult](https://jsr.io/@resulto/core/doc/~/AsyncResult)
3. [ok](https://jsr.io/@resulto/core/doc/~/ok)
4. [okAsync](https://jsr.io/@resulto/core/doc/~/okAsync)
5. [err](https://jsr.io/@resulto/core/doc/~/err)
6. [errAsync](https://jsr.io/@resulto/core/doc/~/errAsync)
7. [fromPromise](https://jsr.io/@resulto/core/doc/~/fromPromise)
8. [fromSafePromise](https://jsr.io/@resulto/core/doc/~/fromSafePromise)
9. [fromThrowable](https://jsr.io/@resulto/core/doc/~/fromThrowable)
10. [combine](https://jsr.io/@resulto/core/doc/~/combine)
11. [combineAsync](https://jsr.io/@resulto/core/doc/~/combineAsync)

> 👉 Also check out [repository root](https://github.com/adjsky/resulto#readme) for more info.
> 👉 Also check out [repository root](https://github.com/adjsky/resulto#readme)
> for more info.
31 changes: 31 additions & 0 deletions core/build_npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { build, emptyDir } from "@deno/dnt";
import denoJson from "./deno.json" with { type: "json" };

await emptyDir("./npm");

await build({
entryPoints: ["./mod.ts"],
outDir: "./npm",
shims: {},
test: false,
package: {
name: "resulto",
version: denoJson.version,
description:
"TypeScript implementation of the Result type from Rust with async support",
author: "adjsky",
repository: {
"type": "git",
"url": "git+https://github.com/adjsky/resulto.git",
},
keywords: [
"result",
"rust",
],
license: "MIT",
},
postBuild() {
Deno.copyFileSync("../LICENSE", "npm/LICENSE");
Deno.copyFileSync("README.md", "npm/README.md");
},
});
40 changes: 40 additions & 0 deletions core/chain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @param {*} chainHead
* @returns {*}
*/
export function chain(chainHead) {
let currentPromise = Promise.resolve(chainHead);
let currentThis;

const proxy = new Proxy(function () {}, {
get(_, property) {
switch (property) {
case "then":
case "catch":
case "finally":
return (...args) => currentPromise[property](...args);
default:
currentPromise = currentPromise.then((resolvedObject) => {
currentThis = resolvedObject;

return resolvedObject?.[property];
});

return proxy;
}
},
apply(_, __, args) {
currentPromise = currentPromise.then((resolvedFunction) => {
if (typeof resolvedFunction != "function") {
throw new Error(`Trying to call ${resolvedFunction}`);
}

return Reflect.apply(resolvedFunction, currentThis, args);
});

return proxy;
},
});

return proxy;
}
7 changes: 7 additions & 0 deletions core/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@resulto/core",
"version": "1.4.0",
"exports": {
".": "./mod.ts"
}
}
23 changes: 23 additions & 0 deletions core/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export {
type AsyncResult,
combine,
combineAsync,
Err,
err,
errAsync,
type ErrFn,
type ErrPredicate,
type Fn,
fromPromise,
fromSafePromise,
fromThrowable,
Ok,
ok,
okAsync,
type Predicate,
type Result,
type ResultDeclarations,
ResultError,
type UnwrapErrs,
type UnwrapOks,
} from "./result.ts";
Loading
Loading