You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
10
10
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:
13
12
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.
15
17
16
18
> [!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.
18
20
19
-
## Install
21
+
## Installation
20
22
21
23
```
22
24
bun add elysia-remote-dts
@@ -30,23 +32,25 @@ import { dts } from 'elysia-remote-dts'
// Be sure to export type for plugin to consume as well.
35
+
// Be sure to export the type for the plugin to consume
34
36
exporttypeApp=typeofapp;
35
37
```
36
38
37
-
Then types should be available at `/server.d.ts`.
39
+
Types will then be available at `/server.d.ts`.
38
40
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:
|`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. |
65
69
|`tsconfig`|`string \| boolean`|`"tsconfig.json"`| The path to the `tsconfig.json` file. When set to `false`, any `tsconfig.json` file will be ignored. |
66
70
|`compilerOptions`|`object`|`{}`| The `compilerOptions` for the TypeScript compiler. See [TypeScript compiler options](https://www.typescriptlang.org/docs/handbook/compiler-options.html). |
67
71
|`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;
87
91
88
92
## Known Limitations
89
93
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