|
1 | | -# quick-npm |
| 1 | +# Elysia remote DTS |
2 | 2 |
|
3 | | -Quick start template to rapidly develop NPM packages with speed, and automations. |
| 3 | +A plugin that provide `.d.ts` types remotely for Eden Treaty to consume. |
| 4 | + |
| 5 | +[](https://www.npmjs.com/package/elysia-remote-dts) |
| 6 | +[](https://www.npmjs.com/package/elysia-remote-dts) |
| 7 | +[](https://www.npmjs.com/package/elysia-remote-dts) |
| 8 | + |
| 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. |
| 10 | + |
| 11 | +- Your server is closed-source. |
| 12 | +- Frontend locate somewhere else that make types inaccessible. |
| 13 | + |
| 14 | +This plugin will attempt to expose types remotely, and provide remote type to Eden Treaty to consume somehow. |
| 15 | + |
| 16 | +> [!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. |
4 | 18 |
|
5 | 19 | ## Install |
6 | 20 |
|
7 | | -```bash |
8 | | -bun add @rayriffy/quick-npm |
| 21 | +``` |
| 22 | +bun add elysia-remote-dts |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +```ts |
| 28 | +import { Elysia } from 'elysia' |
| 29 | +import { dts } from 'elysia-remote-dts' |
| 30 | + |
| 31 | +const app = new Elysia().use(dts('./src/index.ts')).listen(3000) |
| 32 | + |
| 33 | +// Be sure to export type for plugin to consume as well. |
| 34 | +export type App = typeof app; |
| 35 | +``` |
| 36 | + |
| 37 | +Then types should be available at `/server.d.ts`. |
| 38 | + |
| 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. |
| 40 | + |
| 41 | +``` |
| 42 | +curl -o server.ts https://<remote-url>/server.d.ts |
| 43 | +``` |
| 44 | + |
| 45 | +```ts |
| 46 | +import { treaty } from '@elysiajs/eden' |
| 47 | +import type { App } from './server' |
| 48 | + |
| 49 | +// frontend project should already have both elysia, and @elysiajs/eden installed |
| 50 | +export const app = treaty<App>('https://<remote-url>') |
9 | 51 | ``` |
10 | 52 |
|
11 | | -## Setting up |
| 53 | +## Configuration |
12 | 54 |
|
13 | | -1. Allow GitHub Actions to create pull request |
14 | | -2. Generate NPM authotization token into `NPM_TOKEN` secret |
| 55 | +To be documented |
15 | 56 |
|
16 | | -## Publishing |
| 57 | +## Known Limitations |
17 | 58 |
|
18 | | -This repository has been configured to automatically publish NPM packages by [Changesets](https://github.com/changesets/changesets). Run `bun changeset` command to publishing your changes before commit. |
| 59 | +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. |
| 60 | +2. Be sure that `typescript` package is available when running. It's no longer `devDependencies`. |
0 commit comments