@pegasusheavy/nestjs-platform-deno 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +330 -0
- package/dist/index.cjs +1708 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +786 -0
- package/dist/index.d.ts +786 -0
- package/dist/index.js +1673 -0
- package/dist/index.js.map +1 -0
- package/package.json +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pegasus Heavy Industries LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
# @pegasus-heavy/nestjs-platform-deno
|
|
2
|
+
|
|
3
|
+
A NestJS HTTP adapter for the Deno runtime, similar to `@nestjs/platform-express` and `@nestjs/platform-fastify`.
|
|
4
|
+
|
|
5
|
+
This adapter allows you to run your NestJS applications directly on Deno's native HTTP server (`Deno.serve`) without requiring Express, Fastify, or any other Node.js HTTP framework.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 🦕 Native Deno HTTP server support via `Deno.serve`
|
|
10
|
+
- 🚀 Full NestJS compatibility
|
|
11
|
+
- 📦 Zero external HTTP framework dependencies
|
|
12
|
+
- 🔒 Built-in CORS support
|
|
13
|
+
- 📁 Static file serving
|
|
14
|
+
- 🔄 Middleware support
|
|
15
|
+
- 💪 TypeScript first
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Using Deno
|
|
21
|
+
deno add jsr:@pegasus-heavy/nestjs-platform-deno npm:@nestjs/common npm:@nestjs/core
|
|
22
|
+
|
|
23
|
+
# Using npm/pnpm (for Node.js + Deno interop)
|
|
24
|
+
pnpm add @pegasus-heavy/nestjs-platform-deno @nestjs/common @nestjs/core
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic Usage
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { NestFactory } from '@nestjs/core';
|
|
33
|
+
import { DenoAdapter } from '@pegasus-heavy/nestjs-platform-deno';
|
|
34
|
+
import { AppModule } from './app.module.ts';
|
|
35
|
+
|
|
36
|
+
async function bootstrap() {
|
|
37
|
+
const app = await NestFactory.create(AppModule, new DenoAdapter());
|
|
38
|
+
await app.listen(3000);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
bootstrap();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### With CORS
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { NestFactory } from '@nestjs/core';
|
|
48
|
+
import { DenoAdapter } from '@pegasus-heavy/nestjs-platform-deno';
|
|
49
|
+
import { AppModule } from './app.module.ts';
|
|
50
|
+
|
|
51
|
+
async function bootstrap() {
|
|
52
|
+
const app = await NestFactory.create(AppModule, new DenoAdapter());
|
|
53
|
+
|
|
54
|
+
app.enableCors({
|
|
55
|
+
origin: ['http://localhost:3000', 'https://myapp.com'],
|
|
56
|
+
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
|
57
|
+
credentials: true,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
await app.listen(3000);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
bootstrap();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Serving Static Assets
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { NestFactory } from '@nestjs/core';
|
|
70
|
+
import { DenoAdapter } from '@pegasus-heavy/nestjs-platform-deno';
|
|
71
|
+
import { AppModule } from './app.module.ts';
|
|
72
|
+
|
|
73
|
+
async function bootstrap() {
|
|
74
|
+
const app = await NestFactory.create(AppModule, new DenoAdapter());
|
|
75
|
+
|
|
76
|
+
const adapter = app.getHttpAdapter() as DenoAdapter;
|
|
77
|
+
adapter.useStaticAssets('./public', {
|
|
78
|
+
prefix: '/static',
|
|
79
|
+
maxAge: 3600,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
await app.listen(3000);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
bootstrap();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Custom Error Handler
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { NestFactory } from '@nestjs/core';
|
|
92
|
+
import { DenoAdapter } from '@pegasus-heavy/nestjs-platform-deno';
|
|
93
|
+
import { AppModule } from './app.module.ts';
|
|
94
|
+
|
|
95
|
+
async function bootstrap() {
|
|
96
|
+
const app = await NestFactory.create(AppModule, new DenoAdapter());
|
|
97
|
+
|
|
98
|
+
const adapter = app.getHttpAdapter() as DenoAdapter;
|
|
99
|
+
adapter.setErrorHandler((error, req, res) => {
|
|
100
|
+
console.error('Error:', error);
|
|
101
|
+
res.status(500).json({
|
|
102
|
+
statusCode: 500,
|
|
103
|
+
message: 'Something went wrong',
|
|
104
|
+
timestamp: new Date().toISOString(),
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
await app.listen(3000);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
bootstrap();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Using Express Middleware
|
|
115
|
+
|
|
116
|
+
The Deno adapter provides full compatibility with Express middleware, allowing you to use the vast ecosystem of existing Express middleware packages.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { NestFactory } from '@nestjs/core';
|
|
120
|
+
import { DenoAdapter } from '@pegasus-heavy/nestjs-platform-deno';
|
|
121
|
+
import { AppModule } from './app.module.ts';
|
|
122
|
+
import helmet from 'helmet';
|
|
123
|
+
import compression from 'compression';
|
|
124
|
+
import morgan from 'morgan';
|
|
125
|
+
|
|
126
|
+
async function bootstrap() {
|
|
127
|
+
const adapter = new DenoAdapter();
|
|
128
|
+
|
|
129
|
+
// Use Express middleware directly
|
|
130
|
+
adapter.useExpressMiddleware(helmet());
|
|
131
|
+
adapter.useExpressMiddleware(compression());
|
|
132
|
+
adapter.useExpressMiddleware(morgan('combined'));
|
|
133
|
+
|
|
134
|
+
// Apply middleware to specific paths
|
|
135
|
+
adapter.useExpressMiddleware('/api', someApiMiddleware());
|
|
136
|
+
|
|
137
|
+
const app = await NestFactory.create(AppModule, adapter);
|
|
138
|
+
await app.listen(3000);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
bootstrap();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Using Express-style App Object
|
|
145
|
+
|
|
146
|
+
For middleware that requires an Express app instance (like `express-session`), you can use `getExpressApp()`:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { NestFactory } from '@nestjs/core';
|
|
150
|
+
import { DenoAdapter } from '@pegasus-heavy/nestjs-platform-deno';
|
|
151
|
+
import { AppModule } from './app.module.ts';
|
|
152
|
+
import session from 'express-session';
|
|
153
|
+
import cookieParser from 'cookie-parser';
|
|
154
|
+
|
|
155
|
+
async function bootstrap() {
|
|
156
|
+
const adapter = new DenoAdapter();
|
|
157
|
+
|
|
158
|
+
// Get an Express-like app interface
|
|
159
|
+
const expressApp = adapter.getExpressApp();
|
|
160
|
+
|
|
161
|
+
// Use with middleware that needs app.use()
|
|
162
|
+
expressApp.use(cookieParser());
|
|
163
|
+
expressApp.use(session({
|
|
164
|
+
secret: 'my-secret',
|
|
165
|
+
resave: false,
|
|
166
|
+
saveUninitialized: false,
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
const app = await NestFactory.create(AppModule, adapter);
|
|
170
|
+
await app.listen(3000);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
bootstrap();
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Using Fastify Middleware/Hooks
|
|
177
|
+
|
|
178
|
+
The Deno adapter also supports Fastify-style hooks and plugins:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { NestFactory } from '@nestjs/core';
|
|
182
|
+
import { DenoAdapter } from '@pegasus-heavy/nestjs-platform-deno';
|
|
183
|
+
import { AppModule } from './app.module.ts';
|
|
184
|
+
|
|
185
|
+
async function bootstrap() {
|
|
186
|
+
const adapter = new DenoAdapter();
|
|
187
|
+
|
|
188
|
+
// Use Fastify hooks directly
|
|
189
|
+
adapter.useFastifyHook('onRequest', async (request, reply) => {
|
|
190
|
+
console.log('Request:', request.method, request.url);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
adapter.useFastifyHook('preHandler', (request, reply, done) => {
|
|
194
|
+
// Validate something
|
|
195
|
+
done();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const app = await NestFactory.create(AppModule, adapter);
|
|
199
|
+
await app.listen(3000);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
bootstrap();
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Using Fastify Plugins
|
|
206
|
+
|
|
207
|
+
For Fastify plugins that require a Fastify instance:
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { NestFactory } from '@nestjs/core';
|
|
211
|
+
import { DenoAdapter } from '@pegasus-heavy/nestjs-platform-deno';
|
|
212
|
+
import { AppModule } from './app.module.ts';
|
|
213
|
+
import fastifyCors from '@fastify/cors';
|
|
214
|
+
import fastifyHelmet from '@fastify/helmet';
|
|
215
|
+
|
|
216
|
+
async function bootstrap() {
|
|
217
|
+
const adapter = new DenoAdapter();
|
|
218
|
+
|
|
219
|
+
// Register Fastify plugins
|
|
220
|
+
await adapter.registerFastifyPlugin(fastifyCors, { origin: '*' });
|
|
221
|
+
await adapter.registerFastifyPlugin(fastifyHelmet);
|
|
222
|
+
|
|
223
|
+
// Or use the Fastify instance directly
|
|
224
|
+
const fastify = adapter.getFastifyInstance();
|
|
225
|
+
|
|
226
|
+
fastify.addHook('onRequest', async (request, reply) => {
|
|
227
|
+
request.startTime = Date.now();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
fastify.decorateRequest('user', null);
|
|
231
|
+
|
|
232
|
+
const app = await NestFactory.create(AppModule, adapter);
|
|
233
|
+
await app.listen(3000);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
bootstrap();
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## API Reference
|
|
240
|
+
|
|
241
|
+
### DenoAdapter
|
|
242
|
+
|
|
243
|
+
The main adapter class that extends NestJS's `AbstractHttpAdapter`.
|
|
244
|
+
|
|
245
|
+
#### Constructor
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
new DenoAdapter(instance?: unknown)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
#### Static Methods
|
|
252
|
+
|
|
253
|
+
- `DenoAdapter.create(options?: NestApplicationOptions): DenoAdapter` - Factory method to create a new adapter instance
|
|
254
|
+
|
|
255
|
+
#### Instance Methods
|
|
256
|
+
|
|
257
|
+
- `listen(port: number, callback?: () => void): Promise<void>` - Start the server
|
|
258
|
+
- `listen(port: number, hostname: string, callback?: () => void): Promise<void>` - Start the server on a specific hostname
|
|
259
|
+
- `close(): Promise<void>` - Gracefully shutdown the server
|
|
260
|
+
- `enableCors(options?: DenoCorsOptions): void` - Enable CORS
|
|
261
|
+
- `useStaticAssets(path: string, options?: DenoStaticAssetsOptions): void` - Serve static files
|
|
262
|
+
- `useExpressMiddleware(middleware: ExpressMiddleware): void` - Use Express middleware
|
|
263
|
+
- `useExpressMiddleware(path: string, middleware: ExpressMiddleware): void` - Use Express middleware for a path
|
|
264
|
+
- `getExpressApp(): ExpressLikeApp` - Get an Express-compatible app object for middleware
|
|
265
|
+
- `useFastifyHook(name: FastifyHookName, hook: FastifyHook): void` - Use a Fastify hook
|
|
266
|
+
- `registerFastifyPlugin(plugin, opts?): Promise<void>` - Register a Fastify plugin
|
|
267
|
+
- `getFastifyInstance(): FastifyLikeInstance` - Get a Fastify-compatible instance
|
|
268
|
+
- `setErrorHandler(handler: Function): void` - Set custom error handler
|
|
269
|
+
- `setNotFoundHandler(handler: Function): void` - Set custom 404 handler
|
|
270
|
+
- `getHttpServer(): DenoHttpServer | undefined` - Get the underlying Deno server
|
|
271
|
+
- `getType(): string` - Returns `'deno'`
|
|
272
|
+
|
|
273
|
+
### DenoCorsOptions
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
interface DenoCorsOptions {
|
|
277
|
+
origin?: string | string[] | boolean | ((origin: string) => boolean | string);
|
|
278
|
+
methods?: string | string[];
|
|
279
|
+
allowedHeaders?: string | string[];
|
|
280
|
+
exposedHeaders?: string | string[];
|
|
281
|
+
credentials?: boolean;
|
|
282
|
+
maxAge?: number;
|
|
283
|
+
preflightContinue?: boolean;
|
|
284
|
+
optionsSuccessStatus?: number;
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### DenoStaticAssetsOptions
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
interface DenoStaticAssetsOptions {
|
|
292
|
+
prefix?: string;
|
|
293
|
+
index?: string | boolean;
|
|
294
|
+
redirect?: boolean;
|
|
295
|
+
maxAge?: number;
|
|
296
|
+
immutable?: boolean;
|
|
297
|
+
dotfiles?: 'allow' | 'deny' | 'ignore';
|
|
298
|
+
etag?: boolean;
|
|
299
|
+
lastModified?: boolean;
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Requirements
|
|
304
|
+
|
|
305
|
+
- Deno 1.40+ (for `Deno.serve` API)
|
|
306
|
+
- NestJS 10.0.0+ or 11.0.0+
|
|
307
|
+
|
|
308
|
+
## Compatibility
|
|
309
|
+
|
|
310
|
+
This adapter is designed to be a drop-in replacement for the Express or Fastify adapters. Most NestJS features work out of the box:
|
|
311
|
+
|
|
312
|
+
- ✅ Controllers and routing
|
|
313
|
+
- ✅ Dependency injection
|
|
314
|
+
- ✅ Middleware (native + Express + Fastify)
|
|
315
|
+
- ✅ Express middleware compatibility (helmet, compression, morgan, etc.)
|
|
316
|
+
- ✅ Fastify hooks and plugins (@fastify/cors, @fastify/helmet, etc.)
|
|
317
|
+
- ✅ Guards
|
|
318
|
+
- ✅ Interceptors
|
|
319
|
+
- ✅ Pipes
|
|
320
|
+
- ✅ Exception filters
|
|
321
|
+
- ✅ CORS
|
|
322
|
+
- ✅ Static file serving
|
|
323
|
+
- ✅ Cookie handling
|
|
324
|
+
- ✅ Request/Reply decorators (Fastify-style)
|
|
325
|
+
- ⚠️ View engines (not implemented in base adapter)
|
|
326
|
+
- ⚠️ WebSockets (requires separate adapter)
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
MIT © Pegasus Heavy Industries LLC
|