Skip to content

Commit 03c4c4f

Browse files
committed
docs: rewrite
1 parent 1d0d7eb commit 03c4c4f

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# Elysia remote DTS
1+
# Elysia Remote DTS
22

3-
A plugin that provide `.d.ts` types remotely for Eden Treaty to consume.
3+
A plugin that provides remote `.d.ts` types for Eden Treaty to consume.
44

55
[![NPM Version](https://img.shields.io/npm/v/elysia-remote-dts)](https://www.npmjs.com/package/elysia-remote-dts)
66
[![NPM Downloads](https://img.shields.io/npm/dw/elysia-remote-dts)](https://www.npmjs.com/package/elysia-remote-dts)
77
[![NPM License](https://img.shields.io/npm/l/elysia-remote-dts)](https://www.npmjs.com/package/elysia-remote-dts)
88

9-
Imagine in this scenario, you deploy an Elysia server remotely somewhere. And you also want to provide the benefit of end-to-end type safety by using [Eden Treaty](https://elysiajs.com/eden/overview#eden-treaty-recommended). But external developer may not have a direct access to source code to pull `typeof app` types out from your server maybe because.
9+
## Problem
1010

11-
- Your server is closed-source.
12-
- Frontend locate somewhere else that make types inaccessible.
11+
Imagine this scenario: You've deployed an Elysia server remotely and want to provide end-to-end type safety using [Eden Treaty](https://elysiajs.com/eden/overview#eden-treaty-recommended). However, external developers don't have direct access to your server's source code to extract the `typeof app` types because:
1312

14-
This plugin will attempt to expose types remotely, and provide remote type to Eden Treaty to consume somehow.
13+
- Your server is closed-source
14+
- The frontend is located elsewhere, making types inaccessible
15+
16+
This plugin solves this problem by exposing types remotely and providing them to Eden Treaty for consumption.
1517

1618
> [!NOTE]
17-
> Part of the code that responsible for runtime type-generation is copied from project [rolldown-plugin-dts](https://github.com/sxzz/rolldown-plugin-dts), what difference is this `generateDts` utility is completely dependent, and decoupled from rolldown lifecycle. Full credit should go to them, I just port some functionality that hoped to be cool stuff on Elysia ecosystem.
19+
> The code responsible for runtime type-generation is adapted from [rolldown-plugin-dts](https://github.com/sxzz/rolldown-plugin-dts). The difference is that our `generateDts` utility is completely independent and decoupled from the rolldown lifecycle. Full credit goes to the original developers - we've simply ported some functionality to enhance the Elysia ecosystem.
1820
19-
## Install
21+
## Installation
2022

2123
```
2224
bun add elysia-remote-dts
@@ -30,23 +32,25 @@ import { dts } from 'elysia-remote-dts'
3032

3133
const app = new Elysia().use(dts('./src/index.ts')).listen(3000)
3234

33-
// Be sure to export type for plugin to consume as well.
35+
// Be sure to export the type for the plugin to consume
3436
export type App = typeof app;
3537
```
3638

37-
Then types should be available at `/server.d.ts`.
39+
Types will then be available at `/server.d.ts`.
3840

39-
Due to limitations with [Triple-Slash Directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html), types cannot be directly consumed from a remote URL ([tracking issue](https://github.com/microsoft/TypeScript/issues/28985)). For frontend projects, you'll need to first download the type declaration file from this path before using it with Eden.
41+
Due to limitations with [Triple-Slash Directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html), types cannot be directly consumed from a remote URL ([tracking issue](https://github.com/microsoft/TypeScript/issues/28985)). For frontend projects, you'll need to first download the type declaration file before using it with Eden:
4042

4143
```
4244
curl -o server.ts https://<remote-url>/server.d.ts
4345
```
4446

47+
Then use it in your frontend code:
48+
4549
```ts
4650
import { treaty } from '@elysiajs/eden'
4751
import type { App } from './server'
4852

49-
// frontend project should already have both elysia, and @elysiajs/eden installed
53+
// Your frontend project should already have both elysia and @elysiajs/eden installed
5054
export const app = treaty<App>('https://<remote-url>')
5155
```
5256

@@ -61,7 +65,7 @@ dts(entryPoint, options)
6165
| Option | Type | Default | Description |
6266
|--------|------|---------|-------------|
6367
| `cwd` | `string` | Current directory | The directory where the plugin will look for the `tsconfig.json` file. |
64-
| `dtsInput` | `boolean` | `false` | When entries are `.d.ts` files (instead of `.ts` files), this option should be set to `true`. If enabled, the plugin will skip generating a `.d.ts` file for the entry point. |
68+
| `dtsInput` | `boolean` | `false` | Set to `true` when entries are `.d.ts` files (instead of `.ts` files). When enabled, the plugin will skip generating a `.d.ts` file for the entry point. |
6569
| `tsconfig` | `string \| boolean` | `"tsconfig.json"` | The path to the `tsconfig.json` file. When set to `false`, any `tsconfig.json` file will be ignored. |
6670
| `compilerOptions` | `object` | `{}` | The `compilerOptions` for the TypeScript compiler. See [TypeScript compiler options](https://www.typescriptlang.org/docs/handbook/compiler-options.html). |
6771
| `resolve` | `boolean \| (string \| RegExp)[]` | `false` | Resolve external types used in `.d.ts` files from `node_modules`. Can be a boolean or an array of strings/RegExp patterns. |
@@ -87,6 +91,8 @@ export type App = typeof app;
8791

8892
## Known Limitations
8993

90-
1. Sometimes emitting types can be `null`, this happens only in some runtime environment (So far, Distroless). I would recommended `oven/bun`, or `oven/bun:alpine` as base image.
91-
2. Be sure that `typescript` package is available when running. It's no longer `devDependencies`.
92-
3. For all elysia instances, and chaining controller. It's recomended to chain your routes instead of calling `controller.<METHOD>` after each new line since it's will not considered into type compliation by typescript. ([example](https://github.com/rayriffy/dts-chaining-repro/commit/fb4702ddc11a3973bf51eac753c18c1d606eae4b))
94+
1. Type emission may occasionally return `null` in certain runtime environments (particularly in Distroless). We recommend using `oven/bun` or `oven/bun:alpine` as your base image.
95+
96+
2. The `typescript` package must be available at runtime, not just as a development dependency.
97+
98+
3. For all Elysia instances and controller chaining, it's recommended to chain your routes rather than calling `controller.<METHOD>` on separate lines, as the latter approach won't be properly included in type compilation by TypeScript. ([example](https://github.com/rayriffy/dts-chaining-repro/commit/fb4702ddc11a3973bf51eac753c18c1d606eae4b))

0 commit comments

Comments
 (0)