@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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,786 @@
|
|
|
1
|
+
import { AbstractHttpAdapter } from '@nestjs/core';
|
|
2
|
+
import { RequestMethod, INestApplication } from '@nestjs/common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for configuring the Deno HTTP server
|
|
6
|
+
*/
|
|
7
|
+
interface DenoHttpOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The port to listen on
|
|
10
|
+
*/
|
|
11
|
+
port?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The hostname to bind to
|
|
14
|
+
*/
|
|
15
|
+
hostname?: string;
|
|
16
|
+
/**
|
|
17
|
+
* TLS certificate configuration
|
|
18
|
+
*/
|
|
19
|
+
cert?: string;
|
|
20
|
+
/**
|
|
21
|
+
* TLS key configuration
|
|
22
|
+
*/
|
|
23
|
+
key?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Handler for when the server starts listening
|
|
26
|
+
*/
|
|
27
|
+
onListen?: (params: {
|
|
28
|
+
hostname: string;
|
|
29
|
+
port: number;
|
|
30
|
+
}) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Signal for aborting the server
|
|
33
|
+
*/
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
/**
|
|
36
|
+
* Enable HTTP/2
|
|
37
|
+
*/
|
|
38
|
+
alpnProtocols?: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents a Deno HTTP server instance
|
|
42
|
+
*/
|
|
43
|
+
interface DenoHttpServer {
|
|
44
|
+
/**
|
|
45
|
+
* The port the server is listening on
|
|
46
|
+
*/
|
|
47
|
+
port: number;
|
|
48
|
+
/**
|
|
49
|
+
* The hostname the server is bound to
|
|
50
|
+
*/
|
|
51
|
+
hostname: string;
|
|
52
|
+
/**
|
|
53
|
+
* Promise that resolves when the server finishes
|
|
54
|
+
*/
|
|
55
|
+
finished: Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Reference to the underlying Deno server
|
|
58
|
+
*/
|
|
59
|
+
ref(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Unreference the server
|
|
62
|
+
*/
|
|
63
|
+
unref(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Shutdown the server gracefully
|
|
66
|
+
*/
|
|
67
|
+
shutdown(): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* CORS options for the Deno adapter
|
|
71
|
+
*/
|
|
72
|
+
interface DenoCorsOptions {
|
|
73
|
+
origin?: string | string[] | boolean | ((origin: string) => boolean | string);
|
|
74
|
+
methods?: string | string[];
|
|
75
|
+
allowedHeaders?: string | string[];
|
|
76
|
+
exposedHeaders?: string | string[];
|
|
77
|
+
credentials?: boolean;
|
|
78
|
+
maxAge?: number;
|
|
79
|
+
preflightContinue?: boolean;
|
|
80
|
+
optionsSuccessStatus?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Static assets options
|
|
84
|
+
*/
|
|
85
|
+
interface DenoStaticAssetsOptions {
|
|
86
|
+
prefix?: string;
|
|
87
|
+
index?: string | boolean;
|
|
88
|
+
redirect?: boolean;
|
|
89
|
+
maxAge?: number;
|
|
90
|
+
immutable?: boolean;
|
|
91
|
+
dotfiles?: 'allow' | 'deny' | 'ignore';
|
|
92
|
+
etag?: boolean;
|
|
93
|
+
lastModified?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Body parser options
|
|
97
|
+
*/
|
|
98
|
+
interface DenoBodyParserOptions {
|
|
99
|
+
limit?: number | string;
|
|
100
|
+
type?: string | string[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Express-compatible Request interface
|
|
105
|
+
* Provides a compatibility layer for Express middleware
|
|
106
|
+
*/
|
|
107
|
+
interface ExpressCompatRequest {
|
|
108
|
+
method: string;
|
|
109
|
+
url: string;
|
|
110
|
+
originalUrl: string;
|
|
111
|
+
baseUrl: string;
|
|
112
|
+
path: string;
|
|
113
|
+
hostname: string;
|
|
114
|
+
ip: string | undefined;
|
|
115
|
+
protocol: string;
|
|
116
|
+
secure: boolean;
|
|
117
|
+
headers: Record<string, string | string[] | undefined>;
|
|
118
|
+
params: Record<string, string>;
|
|
119
|
+
query: Record<string, string>;
|
|
120
|
+
body: unknown;
|
|
121
|
+
get(name: string): string | undefined;
|
|
122
|
+
header(name: string): string | undefined;
|
|
123
|
+
is(type: string | string[]): string | false | null;
|
|
124
|
+
accepts(...types: string[]): string | false;
|
|
125
|
+
acceptsEncodings(...encodings: string[]): string | false;
|
|
126
|
+
acceptsCharsets(...charsets: string[]): string | false;
|
|
127
|
+
acceptsLanguages(...langs: string[]): string | false;
|
|
128
|
+
raw: Request;
|
|
129
|
+
cookies?: Record<string, string>;
|
|
130
|
+
signedCookies?: Record<string, string>;
|
|
131
|
+
fresh?: boolean;
|
|
132
|
+
stale?: boolean;
|
|
133
|
+
xhr?: boolean;
|
|
134
|
+
subdomains?: string[];
|
|
135
|
+
[key: string]: unknown;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Express-compatible Response interface
|
|
139
|
+
* Provides a compatibility layer for Express middleware
|
|
140
|
+
*/
|
|
141
|
+
interface ExpressCompatResponse {
|
|
142
|
+
statusCode: number;
|
|
143
|
+
statusMessage: string;
|
|
144
|
+
headersSent: boolean;
|
|
145
|
+
status(code: number): this;
|
|
146
|
+
sendStatus(code: number): this;
|
|
147
|
+
set(field: string, value: string | string[]): this;
|
|
148
|
+
set(field: Record<string, string | string[]>): this;
|
|
149
|
+
header(field: string, value?: string | string[]): this | string | undefined;
|
|
150
|
+
get(field: string): string | undefined;
|
|
151
|
+
append(field: string, value: string | string[]): this;
|
|
152
|
+
send(body?: unknown): this;
|
|
153
|
+
json(body?: unknown): this;
|
|
154
|
+
jsonp(body?: unknown): this;
|
|
155
|
+
end(data?: unknown, encoding?: string): this;
|
|
156
|
+
redirect(url: string): void;
|
|
157
|
+
redirect(status: number, url: string): void;
|
|
158
|
+
type(type: string): this;
|
|
159
|
+
contentType(type: string): this;
|
|
160
|
+
cookie(name: string, value: string, options?: CookieOptions): this;
|
|
161
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
162
|
+
location(url: string): this;
|
|
163
|
+
links(links: Record<string, string>): this;
|
|
164
|
+
vary(field: string): this;
|
|
165
|
+
format(obj: Record<string, () => void>): this;
|
|
166
|
+
[key: string]: unknown;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Cookie options interface
|
|
170
|
+
*/
|
|
171
|
+
interface CookieOptions {
|
|
172
|
+
domain?: string;
|
|
173
|
+
encode?: (value: string) => string;
|
|
174
|
+
expires?: Date;
|
|
175
|
+
httpOnly?: boolean;
|
|
176
|
+
maxAge?: number;
|
|
177
|
+
path?: string;
|
|
178
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
179
|
+
secure?: boolean;
|
|
180
|
+
signed?: boolean;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Express NextFunction type
|
|
184
|
+
*/
|
|
185
|
+
type ExpressNextFunction = (err?: unknown) => void;
|
|
186
|
+
/**
|
|
187
|
+
* Express middleware function signature
|
|
188
|
+
*/
|
|
189
|
+
type ExpressMiddleware = (req: ExpressCompatRequest, res: ExpressCompatResponse, next: ExpressNextFunction) => void | Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Express error-handling middleware function signature
|
|
192
|
+
*/
|
|
193
|
+
type ExpressErrorMiddleware = (err: unknown, req: ExpressCompatRequest, res: ExpressCompatResponse, next: ExpressNextFunction) => void | Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Create an Express-compatible request wrapper from a DenoRequest
|
|
196
|
+
*/
|
|
197
|
+
declare function createExpressRequest(denoReq: DenoRequest): ExpressCompatRequest;
|
|
198
|
+
/**
|
|
199
|
+
* Create an Express-compatible response wrapper from a DenoResponse
|
|
200
|
+
*/
|
|
201
|
+
declare function createExpressResponse(denoRes: DenoResponse): ExpressCompatResponse;
|
|
202
|
+
/**
|
|
203
|
+
* Wrap an Express middleware to work with the Deno adapter
|
|
204
|
+
*/
|
|
205
|
+
declare function wrapExpressMiddleware(middleware: ExpressMiddleware | ExpressErrorMiddleware): (req: DenoRequest, res: DenoResponse, next: () => Promise<void>) => Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Create an Express-like app object for middleware that expects app.use()
|
|
208
|
+
*/
|
|
209
|
+
interface ExpressLikeApp {
|
|
210
|
+
use: (...args: unknown[]) => void;
|
|
211
|
+
get: (path: string, ...handlers: ExpressMiddleware[]) => void;
|
|
212
|
+
post: (path: string, ...handlers: ExpressMiddleware[]) => void;
|
|
213
|
+
put: (path: string, ...handlers: ExpressMiddleware[]) => void;
|
|
214
|
+
delete: (path: string, ...handlers: ExpressMiddleware[]) => void;
|
|
215
|
+
patch: (path: string, ...handlers: ExpressMiddleware[]) => void;
|
|
216
|
+
options: (path: string, ...handlers: ExpressMiddleware[]) => void;
|
|
217
|
+
head: (path: string, ...handlers: ExpressMiddleware[]) => void;
|
|
218
|
+
all: (path: string, ...handlers: ExpressMiddleware[]) => void;
|
|
219
|
+
locals: Record<string, unknown>;
|
|
220
|
+
settings: Record<string, unknown>;
|
|
221
|
+
set: (key: string, value: unknown) => void;
|
|
222
|
+
enable: (key: string) => void;
|
|
223
|
+
disable: (key: string) => void;
|
|
224
|
+
enabled: (key: string) => boolean;
|
|
225
|
+
disabled: (key: string) => boolean;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Fastify-compatible Request interface
|
|
230
|
+
* Provides a compatibility layer for Fastify middleware and hooks
|
|
231
|
+
*/
|
|
232
|
+
interface FastifyCompatRequest {
|
|
233
|
+
id: string;
|
|
234
|
+
params: Record<string, string>;
|
|
235
|
+
query: Record<string, string>;
|
|
236
|
+
body: unknown;
|
|
237
|
+
headers: Record<string, string | string[] | undefined>;
|
|
238
|
+
raw: Request;
|
|
239
|
+
url: string;
|
|
240
|
+
originalUrl: string;
|
|
241
|
+
method: string;
|
|
242
|
+
hostname: string;
|
|
243
|
+
ip: string | undefined;
|
|
244
|
+
protocol: 'http' | 'https';
|
|
245
|
+
routerPath?: string;
|
|
246
|
+
routerMethod?: string;
|
|
247
|
+
validationError?: Error;
|
|
248
|
+
[key: string]: unknown;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Fastify-compatible Reply interface
|
|
252
|
+
* Provides a compatibility layer for Fastify middleware and hooks
|
|
253
|
+
*/
|
|
254
|
+
interface FastifyCompatReply {
|
|
255
|
+
statusCode: number;
|
|
256
|
+
sent: boolean;
|
|
257
|
+
code(statusCode: number): this;
|
|
258
|
+
status(statusCode: number): this;
|
|
259
|
+
header(key: string, value: string | number | boolean): this;
|
|
260
|
+
headers(headers: Record<string, string | number | boolean>): this;
|
|
261
|
+
getHeader(key: string): string | undefined;
|
|
262
|
+
getHeaders(): Record<string, string | undefined>;
|
|
263
|
+
removeHeader(key: string): this;
|
|
264
|
+
hasHeader(key: string): boolean;
|
|
265
|
+
send(payload?: unknown): this;
|
|
266
|
+
serialize(payload: unknown): string;
|
|
267
|
+
serializer(fn: (payload: unknown) => string): this;
|
|
268
|
+
type(contentType: string): this;
|
|
269
|
+
redirect(url: string): this;
|
|
270
|
+
redirect(statusCode: number, url: string): this;
|
|
271
|
+
callNotFound(): void;
|
|
272
|
+
getResponseTime(): number;
|
|
273
|
+
raw: DenoResponse;
|
|
274
|
+
[key: string]: unknown;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Fastify hook types
|
|
278
|
+
*/
|
|
279
|
+
type FastifyHookName = 'onRequest' | 'preParsing' | 'preValidation' | 'preHandler' | 'preSerialization' | 'onSend' | 'onResponse' | 'onError' | 'onTimeout' | 'onReady' | 'onClose';
|
|
280
|
+
/**
|
|
281
|
+
* Fastify done callback
|
|
282
|
+
*/
|
|
283
|
+
type FastifyDoneCallback = (err?: Error) => void;
|
|
284
|
+
/**
|
|
285
|
+
* Fastify hook function (callback style)
|
|
286
|
+
*/
|
|
287
|
+
type FastifyHookCallback = (request: FastifyCompatRequest, reply: FastifyCompatReply, done: FastifyDoneCallback) => void;
|
|
288
|
+
/**
|
|
289
|
+
* Fastify hook function (async style)
|
|
290
|
+
*/
|
|
291
|
+
type FastifyHookAsync = (request: FastifyCompatRequest, reply: FastifyCompatReply) => Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Fastify hook function (either style)
|
|
294
|
+
*/
|
|
295
|
+
type FastifyHook = FastifyHookCallback | FastifyHookAsync;
|
|
296
|
+
/**
|
|
297
|
+
* Fastify onError hook
|
|
298
|
+
*/
|
|
299
|
+
type FastifyErrorHook = (request: FastifyCompatRequest, reply: FastifyCompatReply, error: Error, done: FastifyDoneCallback) => void;
|
|
300
|
+
/**
|
|
301
|
+
* Fastify onSend hook with payload
|
|
302
|
+
*/
|
|
303
|
+
type FastifyOnSendHook = (request: FastifyCompatRequest, reply: FastifyCompatReply, payload: unknown, done: (err?: Error, payload?: unknown) => void) => void;
|
|
304
|
+
/**
|
|
305
|
+
* Fastify plugin function
|
|
306
|
+
*/
|
|
307
|
+
type FastifyPlugin<Options = Record<string, unknown>> = (instance: FastifyLikeInstance, opts: Options, done: FastifyDoneCallback) => void;
|
|
308
|
+
/**
|
|
309
|
+
* Fastify async plugin function
|
|
310
|
+
*/
|
|
311
|
+
type FastifyPluginAsync<Options = Record<string, unknown>> = (instance: FastifyLikeInstance, opts: Options) => Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* Fastify route handler
|
|
314
|
+
*/
|
|
315
|
+
type FastifyRouteHandler = (request: FastifyCompatRequest, reply: FastifyCompatReply) => unknown | Promise<unknown>;
|
|
316
|
+
/**
|
|
317
|
+
* Fastify route options
|
|
318
|
+
*/
|
|
319
|
+
interface FastifyRouteOptions {
|
|
320
|
+
method: string | string[];
|
|
321
|
+
url: string;
|
|
322
|
+
handler: FastifyRouteHandler;
|
|
323
|
+
schema?: unknown;
|
|
324
|
+
preValidation?: FastifyHook | FastifyHook[];
|
|
325
|
+
preHandler?: FastifyHook | FastifyHook[];
|
|
326
|
+
preSerialization?: FastifyOnSendHook | FastifyOnSendHook[];
|
|
327
|
+
onRequest?: FastifyHook | FastifyHook[];
|
|
328
|
+
onResponse?: FastifyHook | FastifyHook[];
|
|
329
|
+
onSend?: FastifyOnSendHook | FastifyOnSendHook[];
|
|
330
|
+
onError?: FastifyErrorHook | FastifyErrorHook[];
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Fastify-like instance interface
|
|
334
|
+
*/
|
|
335
|
+
interface FastifyLikeInstance {
|
|
336
|
+
decorate(name: string, value: unknown): this;
|
|
337
|
+
decorateRequest(name: string, value: unknown): this;
|
|
338
|
+
decorateReply(name: string, value: unknown): this;
|
|
339
|
+
hasDecorator(name: string): boolean;
|
|
340
|
+
hasRequestDecorator(name: string): boolean;
|
|
341
|
+
hasReplyDecorator(name: string): boolean;
|
|
342
|
+
addHook(name: 'onRequest', hook: FastifyHook): this;
|
|
343
|
+
addHook(name: 'preParsing', hook: FastifyHook): this;
|
|
344
|
+
addHook(name: 'preValidation', hook: FastifyHook): this;
|
|
345
|
+
addHook(name: 'preHandler', hook: FastifyHook): this;
|
|
346
|
+
addHook(name: 'preSerialization', hook: FastifyOnSendHook): this;
|
|
347
|
+
addHook(name: 'onSend', hook: FastifyOnSendHook): this;
|
|
348
|
+
addHook(name: 'onResponse', hook: FastifyHook): this;
|
|
349
|
+
addHook(name: 'onError', hook: FastifyErrorHook): this;
|
|
350
|
+
addHook(name: FastifyHookName, hook: FastifyHook | FastifyErrorHook | FastifyOnSendHook): this;
|
|
351
|
+
register<Options = Record<string, unknown>>(plugin: FastifyPlugin<Options> | FastifyPluginAsync<Options>, opts?: Options): this;
|
|
352
|
+
route(opts: FastifyRouteOptions): this;
|
|
353
|
+
get(path: string, handler: FastifyRouteHandler): this;
|
|
354
|
+
get(path: string, opts: Partial<FastifyRouteOptions>, handler: FastifyRouteHandler): this;
|
|
355
|
+
post(path: string, handler: FastifyRouteHandler): this;
|
|
356
|
+
post(path: string, opts: Partial<FastifyRouteOptions>, handler: FastifyRouteHandler): this;
|
|
357
|
+
put(path: string, handler: FastifyRouteHandler): this;
|
|
358
|
+
put(path: string, opts: Partial<FastifyRouteOptions>, handler: FastifyRouteHandler): this;
|
|
359
|
+
delete(path: string, handler: FastifyRouteHandler): this;
|
|
360
|
+
delete(path: string, opts: Partial<FastifyRouteOptions>, handler: FastifyRouteHandler): this;
|
|
361
|
+
patch(path: string, handler: FastifyRouteHandler): this;
|
|
362
|
+
patch(path: string, opts: Partial<FastifyRouteOptions>, handler: FastifyRouteHandler): this;
|
|
363
|
+
options(path: string, handler: FastifyRouteHandler): this;
|
|
364
|
+
options(path: string, opts: Partial<FastifyRouteOptions>, handler: FastifyRouteHandler): this;
|
|
365
|
+
head(path: string, handler: FastifyRouteHandler): this;
|
|
366
|
+
head(path: string, opts: Partial<FastifyRouteOptions>, handler: FastifyRouteHandler): this;
|
|
367
|
+
all(path: string, handler: FastifyRouteHandler): this;
|
|
368
|
+
all(path: string, opts: Partial<FastifyRouteOptions>, handler: FastifyRouteHandler): this;
|
|
369
|
+
log: FastifyLogger;
|
|
370
|
+
prefix: string;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Fastify logger interface
|
|
374
|
+
*/
|
|
375
|
+
interface FastifyLogger {
|
|
376
|
+
info(msg: string, ...args: unknown[]): void;
|
|
377
|
+
error(msg: string, ...args: unknown[]): void;
|
|
378
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
379
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
380
|
+
trace(msg: string, ...args: unknown[]): void;
|
|
381
|
+
fatal(msg: string, ...args: unknown[]): void;
|
|
382
|
+
child(bindings: Record<string, unknown>): FastifyLogger;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Create a Fastify-compatible request from a DenoRequest
|
|
386
|
+
*/
|
|
387
|
+
declare function createFastifyRequest(denoReq: DenoRequest): FastifyCompatRequest;
|
|
388
|
+
/**
|
|
389
|
+
* Create a Fastify-compatible reply from a DenoResponse
|
|
390
|
+
*/
|
|
391
|
+
declare function createFastifyReply(denoRes: DenoResponse): FastifyCompatReply;
|
|
392
|
+
/**
|
|
393
|
+
* Wrap a Fastify hook to work with the Deno adapter middleware system
|
|
394
|
+
*/
|
|
395
|
+
declare function wrapFastifyHook(hook: FastifyHook): (req: DenoRequest, res: DenoResponse, next: () => Promise<void>) => Promise<void>;
|
|
396
|
+
/**
|
|
397
|
+
* Wrap a Fastify plugin for use with the Deno adapter
|
|
398
|
+
* This allows using Fastify plugins that add hooks or decorators
|
|
399
|
+
*/
|
|
400
|
+
declare function wrapFastifyPlugin<Options = Record<string, unknown>>(plugin: FastifyPlugin<Options> | FastifyPluginAsync<Options>, instance: FastifyLikeInstance, opts?: Options): Promise<void>;
|
|
401
|
+
/**
|
|
402
|
+
* Create a simple logger that matches Fastify's logger interface
|
|
403
|
+
*/
|
|
404
|
+
declare function createFastifyLogger(): FastifyLogger;
|
|
405
|
+
|
|
406
|
+
type RequestHandler = (req: DenoRequest, res: DenoResponse) => Promise<void> | void;
|
|
407
|
+
/**
|
|
408
|
+
* Extended Request object for Deno adapter
|
|
409
|
+
*/
|
|
410
|
+
interface DenoRequest {
|
|
411
|
+
readonly raw: Request;
|
|
412
|
+
readonly url: string;
|
|
413
|
+
readonly method: string;
|
|
414
|
+
readonly headers: Headers;
|
|
415
|
+
params: Record<string, string>;
|
|
416
|
+
readonly query: Record<string, string>;
|
|
417
|
+
body?: unknown;
|
|
418
|
+
ip?: string;
|
|
419
|
+
hostname?: string;
|
|
420
|
+
protocol?: string;
|
|
421
|
+
secure?: boolean;
|
|
422
|
+
originalUrl?: string;
|
|
423
|
+
baseUrl?: string;
|
|
424
|
+
path?: string;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Extended Response object for Deno adapter
|
|
428
|
+
*/
|
|
429
|
+
interface DenoResponse {
|
|
430
|
+
statusCode: number;
|
|
431
|
+
headers: Headers;
|
|
432
|
+
body?: BodyInit | null;
|
|
433
|
+
headersSent: boolean;
|
|
434
|
+
status(code: number): this;
|
|
435
|
+
setHeader(name: string, value: string): this;
|
|
436
|
+
getHeader(name: string): string | null;
|
|
437
|
+
removeHeader(name: string): this;
|
|
438
|
+
send(body?: BodyInit | object | null): void;
|
|
439
|
+
json(body: unknown): void;
|
|
440
|
+
redirect(url: string, statusCode?: number): void;
|
|
441
|
+
end(body?: BodyInit | null): void;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* DenoAdapter - NestJS HTTP adapter for Deno runtime
|
|
445
|
+
*
|
|
446
|
+
* This adapter allows NestJS applications to run on Deno's native HTTP server
|
|
447
|
+
* (Deno.serve) without requiring Express, Fastify, or other Node.js frameworks.
|
|
448
|
+
*/
|
|
449
|
+
declare class DenoAdapter extends AbstractHttpAdapter<DenoHttpServer | undefined, DenoRequest, DenoResponse> {
|
|
450
|
+
private readonly routes;
|
|
451
|
+
private readonly middlewares;
|
|
452
|
+
private server;
|
|
453
|
+
private abortController;
|
|
454
|
+
private corsOptions;
|
|
455
|
+
private errorHandler;
|
|
456
|
+
private notFoundHandler;
|
|
457
|
+
private staticAssetsPath;
|
|
458
|
+
private staticAssetsOptions;
|
|
459
|
+
constructor(instance?: unknown);
|
|
460
|
+
/**
|
|
461
|
+
* Create a new DenoAdapter instance
|
|
462
|
+
*/
|
|
463
|
+
static create(): DenoAdapter;
|
|
464
|
+
/**
|
|
465
|
+
* Start listening on the specified port
|
|
466
|
+
*/
|
|
467
|
+
listen(port: string | number, callback?: () => void): Promise<void>;
|
|
468
|
+
listen(port: string | number, hostname: string, callback?: () => void): Promise<void>;
|
|
469
|
+
/**
|
|
470
|
+
* Handle incoming HTTP requests
|
|
471
|
+
*/
|
|
472
|
+
private handleRequest;
|
|
473
|
+
/**
|
|
474
|
+
* Create a DenoRequest object from a native Request
|
|
475
|
+
*/
|
|
476
|
+
private createRequest;
|
|
477
|
+
/**
|
|
478
|
+
* Create a DenoResponse object
|
|
479
|
+
*/
|
|
480
|
+
private createResponse;
|
|
481
|
+
/**
|
|
482
|
+
* Build a Response object from DenoResponse
|
|
483
|
+
*/
|
|
484
|
+
private buildResponse;
|
|
485
|
+
/**
|
|
486
|
+
* Run all matching middlewares
|
|
487
|
+
*/
|
|
488
|
+
private runMiddlewares;
|
|
489
|
+
/**
|
|
490
|
+
* Find a matching route
|
|
491
|
+
*/
|
|
492
|
+
private findRoute;
|
|
493
|
+
/**
|
|
494
|
+
* Extract route parameters from path
|
|
495
|
+
*/
|
|
496
|
+
private extractParams;
|
|
497
|
+
/**
|
|
498
|
+
* Convert a path pattern to a RegExp
|
|
499
|
+
*/
|
|
500
|
+
private pathToRegex;
|
|
501
|
+
/**
|
|
502
|
+
* Extract parameter keys from path pattern
|
|
503
|
+
*/
|
|
504
|
+
private extractKeys;
|
|
505
|
+
/**
|
|
506
|
+
* Register a route handler
|
|
507
|
+
*/
|
|
508
|
+
private registerRoute;
|
|
509
|
+
get(handler: RequestHandler): void;
|
|
510
|
+
get(path: string, handler: RequestHandler): void;
|
|
511
|
+
post(handler: RequestHandler): void;
|
|
512
|
+
post(path: string, handler: RequestHandler): void;
|
|
513
|
+
put(handler: RequestHandler): void;
|
|
514
|
+
put(path: string, handler: RequestHandler): void;
|
|
515
|
+
delete(handler: RequestHandler): void;
|
|
516
|
+
delete(path: string, handler: RequestHandler): void;
|
|
517
|
+
patch(handler: RequestHandler): void;
|
|
518
|
+
patch(path: string, handler: RequestHandler): void;
|
|
519
|
+
options(handler: RequestHandler): void;
|
|
520
|
+
options(path: string, handler: RequestHandler): void;
|
|
521
|
+
head(handler: RequestHandler): void;
|
|
522
|
+
head(path: string, handler: RequestHandler): void;
|
|
523
|
+
all(handler: RequestHandler): void;
|
|
524
|
+
all(path: string, handler: RequestHandler): void;
|
|
525
|
+
/**
|
|
526
|
+
* Add middleware
|
|
527
|
+
*/
|
|
528
|
+
use(handler: (req: DenoRequest, res: DenoResponse, next: () => Promise<void>) => Promise<void> | void): void;
|
|
529
|
+
use(path: string, handler: (req: DenoRequest, res: DenoResponse, next: () => Promise<void>) => Promise<void> | void): void;
|
|
530
|
+
/**
|
|
531
|
+
* Use Express middleware with the Deno adapter
|
|
532
|
+
*
|
|
533
|
+
* This method wraps Express middleware to be compatible with the Deno adapter,
|
|
534
|
+
* allowing you to use existing Express middleware packages.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* import helmet from 'helmet';
|
|
539
|
+
* import compression from 'compression';
|
|
540
|
+
*
|
|
541
|
+
* const adapter = new DenoAdapter();
|
|
542
|
+
* adapter.useExpressMiddleware(helmet());
|
|
543
|
+
* adapter.useExpressMiddleware('/api', compression());
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
useExpressMiddleware(middleware: ExpressMiddleware | ExpressErrorMiddleware): void;
|
|
547
|
+
useExpressMiddleware(path: string, middleware: ExpressMiddleware | ExpressErrorMiddleware): void;
|
|
548
|
+
/**
|
|
549
|
+
* Create an Express-like app instance for middleware that requires app.use()
|
|
550
|
+
*
|
|
551
|
+
* Some Express middleware (like express-session) require an Express app instance.
|
|
552
|
+
* This creates a compatible shim that routes middleware through the Deno adapter.
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```typescript
|
|
556
|
+
* import session from 'express-session';
|
|
557
|
+
*
|
|
558
|
+
* const adapter = new DenoAdapter();
|
|
559
|
+
* const expressApp = adapter.getExpressApp();
|
|
560
|
+
*
|
|
561
|
+
* expressApp.use(session({ secret: 'keyboard cat' }));
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
getExpressApp(): ExpressLikeApp;
|
|
565
|
+
/**
|
|
566
|
+
* Use Fastify middleware/hooks with the Deno adapter
|
|
567
|
+
*
|
|
568
|
+
* This method wraps Fastify hooks to be compatible with the Deno adapter,
|
|
569
|
+
* allowing you to use Fastify-style middleware.
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```typescript
|
|
573
|
+
* const adapter = new DenoAdapter();
|
|
574
|
+
*
|
|
575
|
+
* // Use a Fastify hook
|
|
576
|
+
* adapter.useFastifyHook('onRequest', async (request, reply) => {
|
|
577
|
+
* console.log('Request received:', request.url);
|
|
578
|
+
* });
|
|
579
|
+
*
|
|
580
|
+
* // Use with callback style
|
|
581
|
+
* adapter.useFastifyHook('preHandler', (request, reply, done) => {
|
|
582
|
+
* // Do something
|
|
583
|
+
* done();
|
|
584
|
+
* });
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
useFastifyHook(_name: FastifyHookName, hook: FastifyHook): void;
|
|
588
|
+
/**
|
|
589
|
+
* Register a Fastify plugin with the Deno adapter
|
|
590
|
+
*
|
|
591
|
+
* This allows using Fastify plugins that add hooks, decorators, or routes.
|
|
592
|
+
*
|
|
593
|
+
* @example
|
|
594
|
+
* ```typescript
|
|
595
|
+
* import fastifyCors from '@fastify/cors';
|
|
596
|
+
* import fastifyHelmet from '@fastify/helmet';
|
|
597
|
+
*
|
|
598
|
+
* const adapter = new DenoAdapter();
|
|
599
|
+
* const fastify = adapter.getFastifyInstance();
|
|
600
|
+
*
|
|
601
|
+
* // Register plugins
|
|
602
|
+
* await adapter.registerFastifyPlugin(fastifyCors, { origin: '*' });
|
|
603
|
+
* await adapter.registerFastifyPlugin(fastifyHelmet);
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
registerFastifyPlugin<Options = Record<string, unknown>>(plugin: FastifyPlugin<Options> | FastifyPluginAsync<Options>, opts?: Options): Promise<void>;
|
|
607
|
+
/**
|
|
608
|
+
* Get a Fastify-like instance for plugins that require it
|
|
609
|
+
*
|
|
610
|
+
* This creates a Fastify-compatible interface that routes hooks and routes
|
|
611
|
+
* through the Deno adapter.
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* const adapter = new DenoAdapter();
|
|
616
|
+
* const fastify = adapter.getFastifyInstance();
|
|
617
|
+
*
|
|
618
|
+
* // Add hooks
|
|
619
|
+
* fastify.addHook('onRequest', async (request, reply) => {
|
|
620
|
+
* console.log('Request:', request.method, request.url);
|
|
621
|
+
* });
|
|
622
|
+
*
|
|
623
|
+
* // Add decorators
|
|
624
|
+
* fastify.decorateRequest('user', null);
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
getFastifyInstance(): FastifyLikeInstance;
|
|
628
|
+
/**
|
|
629
|
+
* Get the underlying HTTP server
|
|
630
|
+
*/
|
|
631
|
+
getHttpServer(): DenoHttpServer | undefined;
|
|
632
|
+
/**
|
|
633
|
+
* Set the HTTP server instance
|
|
634
|
+
*/
|
|
635
|
+
setHttpServer(server: DenoHttpServer): void;
|
|
636
|
+
/**
|
|
637
|
+
* Close the server
|
|
638
|
+
*/
|
|
639
|
+
close(): Promise<void>;
|
|
640
|
+
/**
|
|
641
|
+
* Set error handler
|
|
642
|
+
*/
|
|
643
|
+
setErrorHandler(handler: (error: Error, req: DenoRequest, res: DenoResponse) => void): void;
|
|
644
|
+
/**
|
|
645
|
+
* Set 404 handler
|
|
646
|
+
*/
|
|
647
|
+
setNotFoundHandler(handler: (req: DenoRequest, res: DenoResponse) => void): void;
|
|
648
|
+
/**
|
|
649
|
+
* Enable CORS
|
|
650
|
+
*/
|
|
651
|
+
enableCors(options?: DenoCorsOptions): void;
|
|
652
|
+
/**
|
|
653
|
+
* Handle CORS preflight requests
|
|
654
|
+
*/
|
|
655
|
+
private handleCors;
|
|
656
|
+
/**
|
|
657
|
+
* Apply CORS headers to response
|
|
658
|
+
*/
|
|
659
|
+
private applyCorsHeaders;
|
|
660
|
+
/**
|
|
661
|
+
* Use static assets
|
|
662
|
+
*/
|
|
663
|
+
useStaticAssets(path: string, options?: DenoStaticAssetsOptions): void;
|
|
664
|
+
/**
|
|
665
|
+
* Serve static asset
|
|
666
|
+
*/
|
|
667
|
+
private serveStaticAsset;
|
|
668
|
+
/**
|
|
669
|
+
* Set view engine (not implemented for base adapter)
|
|
670
|
+
*/
|
|
671
|
+
setViewEngine(_engine: string): void;
|
|
672
|
+
/**
|
|
673
|
+
* Render view (not implemented for base adapter)
|
|
674
|
+
*/
|
|
675
|
+
render(_response: DenoResponse, _view: string, _options: object): void;
|
|
676
|
+
/**
|
|
677
|
+
* Get request hostname
|
|
678
|
+
*/
|
|
679
|
+
getRequestHostname(request: DenoRequest): string;
|
|
680
|
+
/**
|
|
681
|
+
* Get request method
|
|
682
|
+
*/
|
|
683
|
+
getRequestMethod(request: DenoRequest): string;
|
|
684
|
+
/**
|
|
685
|
+
* Get request URL
|
|
686
|
+
*/
|
|
687
|
+
getRequestUrl(request: DenoRequest): string;
|
|
688
|
+
/**
|
|
689
|
+
* Send a reply
|
|
690
|
+
*/
|
|
691
|
+
reply(response: DenoResponse, body: unknown, statusCode?: number): void;
|
|
692
|
+
/**
|
|
693
|
+
* Set response status
|
|
694
|
+
*/
|
|
695
|
+
status(response: DenoResponse, statusCode: number): void;
|
|
696
|
+
/**
|
|
697
|
+
* Redirect response
|
|
698
|
+
*/
|
|
699
|
+
redirect(response: DenoResponse, statusCode: number, url: string): void;
|
|
700
|
+
/**
|
|
701
|
+
* Set response header
|
|
702
|
+
*/
|
|
703
|
+
setHeader(response: DenoResponse, name: string, value: string): void;
|
|
704
|
+
/**
|
|
705
|
+
* Get response header
|
|
706
|
+
*/
|
|
707
|
+
getHeader(response: DenoResponse, name: string): string | null;
|
|
708
|
+
/**
|
|
709
|
+
* Append value to header
|
|
710
|
+
*/
|
|
711
|
+
appendHeader(response: DenoResponse, name: string, value: string): void;
|
|
712
|
+
/**
|
|
713
|
+
* End response
|
|
714
|
+
*/
|
|
715
|
+
end(response: DenoResponse, message?: string): void;
|
|
716
|
+
/**
|
|
717
|
+
* Check if headers have been sent
|
|
718
|
+
*/
|
|
719
|
+
isHeadersSent(response: DenoResponse): boolean;
|
|
720
|
+
/**
|
|
721
|
+
* Register body parser middleware
|
|
722
|
+
*/
|
|
723
|
+
registerParserMiddleware(): void;
|
|
724
|
+
/**
|
|
725
|
+
* Create middleware factory
|
|
726
|
+
*/
|
|
727
|
+
createMiddlewareFactory(_requestMethod: RequestMethod): (path: string, callback: Function) => void;
|
|
728
|
+
/**
|
|
729
|
+
* Initialize the adapter
|
|
730
|
+
*/
|
|
731
|
+
initHttpServer(): void;
|
|
732
|
+
/**
|
|
733
|
+
* Get the adapter type
|
|
734
|
+
*/
|
|
735
|
+
getType(): string;
|
|
736
|
+
/**
|
|
737
|
+
* Apply version filter
|
|
738
|
+
*/
|
|
739
|
+
applyVersionFilter(handler: Function, _version: unknown, _versioningOptions: unknown): (req: DenoRequest, res: DenoResponse, next: () => void) => Function;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Interface for a NestJS application running on the Deno adapter
|
|
744
|
+
*/
|
|
745
|
+
interface NestDenoApplication extends INestApplication {
|
|
746
|
+
/**
|
|
747
|
+
* Get the underlying Deno HTTP server
|
|
748
|
+
*/
|
|
749
|
+
getHttpServer(): DenoHttpServer | undefined;
|
|
750
|
+
/**
|
|
751
|
+
* Enable CORS for the application
|
|
752
|
+
* @param options CORS configuration options
|
|
753
|
+
*/
|
|
754
|
+
enableCors(options?: DenoCorsOptions): this;
|
|
755
|
+
/**
|
|
756
|
+
* Serve static assets from a directory
|
|
757
|
+
* @param path Path to the static assets directory
|
|
758
|
+
* @param options Static assets options
|
|
759
|
+
*/
|
|
760
|
+
useStaticAssets(path: string, options?: DenoStaticAssetsOptions): this;
|
|
761
|
+
/**
|
|
762
|
+
* Set a custom error handler
|
|
763
|
+
* @param handler Error handler function
|
|
764
|
+
*/
|
|
765
|
+
setErrorHandler(handler: (error: Error, req: DenoRequest, res: DenoResponse) => void): this;
|
|
766
|
+
/**
|
|
767
|
+
* Set a custom 404 handler
|
|
768
|
+
* @param handler Not found handler function
|
|
769
|
+
*/
|
|
770
|
+
setNotFoundHandler(handler: (req: DenoRequest, res: DenoResponse) => void): this;
|
|
771
|
+
/**
|
|
772
|
+
* Start listening for connections
|
|
773
|
+
* @param port Port number to listen on
|
|
774
|
+
* @param callback Callback when server starts
|
|
775
|
+
*/
|
|
776
|
+
listen(port: number | string, callback?: () => void): Promise<void>;
|
|
777
|
+
/**
|
|
778
|
+
* Start listening for connections
|
|
779
|
+
* @param port Port number to listen on
|
|
780
|
+
* @param hostname Hostname to bind to
|
|
781
|
+
* @param callback Callback when server starts
|
|
782
|
+
*/
|
|
783
|
+
listen(port: number | string, hostname: string, callback?: () => void): Promise<void>;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
export { type CookieOptions, DenoAdapter, type DenoBodyParserOptions, type DenoCorsOptions, type DenoHttpOptions, type DenoHttpServer, type DenoRequest, type DenoResponse, type DenoStaticAssetsOptions, type ExpressCompatRequest, type ExpressCompatResponse, type ExpressErrorMiddleware, type ExpressLikeApp, type ExpressMiddleware, type ExpressNextFunction, type FastifyCompatReply, type FastifyCompatRequest, type FastifyDoneCallback, type FastifyErrorHook, type FastifyHook, type FastifyHookAsync, type FastifyHookCallback, type FastifyHookName, type FastifyLikeInstance, type FastifyLogger, type FastifyOnSendHook, type FastifyPlugin, type FastifyPluginAsync, type FastifyRouteHandler, type FastifyRouteOptions, type NestDenoApplication, createExpressRequest, createExpressResponse, createFastifyLogger, createFastifyReply, createFastifyRequest, wrapExpressMiddleware, wrapFastifyHook, wrapFastifyPlugin };
|