# dumb-durable-object

> This is a package to make it easier to do rpc with your durable object by adding ways of typing and calling endpoints

Latest version **0.0.34** (published 2023-04-18) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install dumb-durable-object
pnpm add dumb-durable-object
yarn add dumb-durable-object
bun add dumb-durable-object
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.34 |
| Published | 2023-04-18 |
| First published | 2023-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18.13.0 |
| Dependencies | 0 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jacob Torrång |
| Maintainers | mewhhaha |
| Keywords | Durable Object, Utility, Cloudflare |

## Links

- npm: https://www.npmjs.com/package/dumb-durable-object
- Repository: https://github.com/mewhhaha/dumb
- Homepage: https://github.com/mewhhaha/dumb#readme
- Issues: https://github.com/mewhhaha/dumb/issues
- npm.io page: https://npm.io/package/dumb-durable-object

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 0.0.34 (latest) — 2023-04-18
- 0.0.33 — 2023-04-18
- 0.0.32 — 2023-04-17
- 0.0.31 — 2023-04-17
- 0.0.30 — 2023-04-17
- 0.0.29 — 2023-04-17
- 0.0.28 — 2023-04-16
- 0.0.27 — 2023-04-14
- 0.0.26 — 2023-04-14
- 0.0.25 — 2023-04-14
- 0.0.24 — 2023-04-14
- 0.0.23 — 2023-04-14
- 0.0.22 — 2023-04-11
- 0.0.21 — 2023-04-10
- 0.0.20 — 2023-04-10
- … 19 more at https://npm.io/package/dumb-durable-object/versions

## README

# Dumb Durable Object

This is a small package to ease the friction when communicating with a `Durable Object` binding. This package is under development and if you want to use it in any stable capacity I suggest you copy over the code and maintain it yourself. If you do any good improvements it'd be greatly appreciated if you can contribute back. There will likely be a lot of breaking packages when this package updates as it is in its infancy.

## Usage

This is a simple example using the library.

### Simple response

```ts
// In your worker most likely
class DurableObjectExample extends CallableDurableObject {
  @callable // Decorator that ensures the type signature required for it to be callable
  helloWorld(name: string) {
    return ok(200, `Hello world, ${name}!`);
  }
}

// In whoever is calling the worker, for example a pages function
type Env = {
  DO_EXAMPLE: DurableObjectNamespaceIs<DurableObjectExample>;
};

export async function onRequest({
  request,
  env,
}: {
  request: Request;
  env: Env;
}) {
  const id = "MY_DO_ID"; // Could also be a DurableObjectId
  const c = client(env.DO_EXAMPLE, id);
  const response = await c.helloWorld("MY NAME"); // Absence of error makes the json() function always the successful one

  const value = await response.json()

  return new Response(value, { status: 200 });
}
```

### Error response

```ts
// In your worker most likely
class DurableObjectExample extends CallableDurableObject {
  @callable // Decorator that ensures the type signature required for it to be callable
  helloWorld(name: string) {
    if (name === "") {
      return error(422, { message: "Your name was empty!" });
    }
    return ok(200, `Hello world, ${name}!`);
  }
}

// In whoever is calling the worker, for example a pages function
type Env = {
  DO_EXAMPLE: DurableObjectNamespaceIs<DurableObjectExample>;
};

export async function onRequest({
  request,
  env,
}: {
  request: Request;
  env: Env;
}) {
  const id = "MY_DO_ID"; // Could also be a DurableObjectId
  const c = client(env.DO_EXAMPLE, id);
  const response = await c.helloWorld("MY NAME");

  // Since it might return an error we have to disambiguate
  if (!response.ok) {
    const err = await response.json();
    // value is of type { message: string }
    return new Response(err.message, { status: response.status }); // Notice we get the error value here
  }

  const value = await response.json()
  // value is of type string
  return new Response(value, { status: response.status }); // Notice we get the successful value here
}
```

---
_Source: https://npm.io/package/dumb-durable-object · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
