@tsed/platform-fastify 8.5.0-beta.1

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.
Files changed (31) hide show
  1. package/.swcrc +21 -0
  2. package/lib/esm/components/PlatformFastify.js +283 -0
  3. package/lib/esm/components/PlatformFastify.js.map +1 -0
  4. package/lib/esm/index.js +9 -0
  5. package/lib/esm/index.js.map +1 -0
  6. package/lib/esm/interfaces/PlatformFastifySettings.js +2 -0
  7. package/lib/esm/interfaces/PlatformFastifySettings.js.map +1 -0
  8. package/lib/esm/interfaces/interfaces.js +2 -0
  9. package/lib/esm/interfaces/interfaces.js.map +1 -0
  10. package/lib/esm/services/PlatformFastifyRequest.js +34 -0
  11. package/lib/esm/services/PlatformFastifyRequest.js.map +1 -0
  12. package/lib/esm/services/PlatformFastifyResponse.js +76 -0
  13. package/lib/esm/services/PlatformFastifyResponse.js.map +1 -0
  14. package/lib/types/components/PlatformFastify.d.ts +63 -0
  15. package/lib/types/index.d.ts +8 -0
  16. package/lib/types/interfaces/PlatformFastifySettings.d.ts +4 -0
  17. package/lib/types/interfaces/interfaces.d.ts +22 -0
  18. package/lib/types/services/PlatformFastifyRequest.d.ts +41 -0
  19. package/lib/types/services/PlatformFastifyResponse.d.ts +56 -0
  20. package/package.json +118 -0
  21. package/readme.md +67 -0
  22. package/src/components/PlatformFastify.spec.ts +34 -0
  23. package/src/components/PlatformFastify.ts +361 -0
  24. package/src/index.ts +8 -0
  25. package/src/interfaces/PlatformFastifySettings.ts +5 -0
  26. package/src/interfaces/interfaces.ts +26 -0
  27. package/src/services/PlatformFastifyRequest.spec.ts +54 -0
  28. package/src/services/PlatformFastifyRequest.ts +61 -0
  29. package/src/services/PlatformFastifyResponse.spec.ts +114 -0
  30. package/src/services/PlatformFastifyResponse.ts +100 -0
  31. package/vitest.config.mts +21 -0
package/.swcrc ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "sourceMaps": false,
3
+ "jsc": {
4
+ "parser": {
5
+ "syntax": "typescript",
6
+ "decorators": true,
7
+ "dynamicImport": true
8
+ },
9
+ "target": "es2022",
10
+ "externalHelpers": true,
11
+ "keepClassNames": true,
12
+ "transform": {
13
+ "useDefineForClassFields": false,
14
+ "legacyDecorator": true,
15
+ "decoratorMetadata": true
16
+ }
17
+ },
18
+ "module": {
19
+ "type": "es6"
20
+ }
21
+ }
@@ -0,0 +1,283 @@
1
+ import * as Http from "node:http";
2
+ import * as Https from "node:https";
3
+ import fastifyMiddie from "@fastify/middie";
4
+ import fastifyStatics from "@fastify/static";
5
+ import { isFunction, isString } from "@tsed/core";
6
+ import { constant, inject, logger, runInContext } from "@tsed/di";
7
+ import { NotFound } from "@tsed/exceptions";
8
+ import { PlatformExceptions } from "@tsed/platform-exceptions";
9
+ import { adapter, createContext, createServer, Platform, PlatformAdapter, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/platform-http";
10
+ import { PlatformHandlerType } from "@tsed/platform-router";
11
+ import Fastify from "fastify";
12
+ import { PlatformFastifyRequest } from "../services/PlatformFastifyRequest.js";
13
+ import { PlatformFastifyResponse } from "../services/PlatformFastifyResponse.js";
14
+ export class PlatformFastify extends PlatformAdapter {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.NAME = "fastify";
18
+ this.providers = [
19
+ {
20
+ token: PlatformHandler
21
+ },
22
+ { token: PlatformApplication },
23
+ { token: Platform },
24
+ {
25
+ token: PlatformResponse,
26
+ useClass: PlatformFastifyResponse
27
+ },
28
+ {
29
+ token: PlatformRequest,
30
+ useClass: PlatformFastifyRequest
31
+ }
32
+ ];
33
+ this.staticsDecorated = false;
34
+ }
35
+ /**
36
+ * Create new serverless application. In this mode, the component scan are disabled.
37
+ * @param module
38
+ * @param settings
39
+ */
40
+ static create(module, settings = {}) {
41
+ return PlatformBuilder.create(module, {
42
+ ...settings,
43
+ adapter: PlatformFastify
44
+ });
45
+ }
46
+ /**
47
+ * Bootstrap a server application
48
+ * @param module
49
+ * @param settings
50
+ */
51
+ static bootstrap(module, settings = {}) {
52
+ return PlatformBuilder.bootstrap(module, {
53
+ ...settings,
54
+ adapter: PlatformFastify
55
+ });
56
+ }
57
+ mapLayers(layers) {
58
+ const { app } = this;
59
+ const rawApp = app.getApp();
60
+ layers.forEach((layer) => {
61
+ switch (layer.method) {
62
+ case "use":
63
+ if (rawApp.use) {
64
+ rawApp.use(...layer.getArgs());
65
+ }
66
+ return;
67
+ case "statics":
68
+ this.statics(layer.path, layer.opts);
69
+ // rawApp.register();
70
+ return;
71
+ }
72
+ try {
73
+ rawApp.route({
74
+ method: layer.method.toUpperCase(),
75
+ url: layer.path,
76
+ handler: this.compose(layer),
77
+ config: {
78
+ rawBody: layer.handlers.some((handler) => handler.opts?.paramsTypes?.RAW_BODY)
79
+ }
80
+ });
81
+ }
82
+ catch (er) {
83
+ logger().warn({
84
+ error_name: er.code,
85
+ error_message: er.message
86
+ });
87
+ }
88
+ });
89
+ }
90
+ mapHandler(handler, metadata) {
91
+ if (metadata.isRawMiddleware()) {
92
+ return handler;
93
+ }
94
+ switch (metadata.type) {
95
+ case PlatformHandlerType.MIDDLEWARE:
96
+ return (request, _, done) => {
97
+ const { $ctx } = request;
98
+ $ctx.next = done;
99
+ return runInContext($ctx, () => handler($ctx));
100
+ };
101
+ default:
102
+ return async (request, _, done) => {
103
+ const { $ctx } = request;
104
+ $ctx.next = done;
105
+ await runInContext($ctx, () => handler($ctx));
106
+ if (metadata.type === PlatformHandlerType.CTX_FN) {
107
+ done();
108
+ }
109
+ };
110
+ }
111
+ }
112
+ async useContext() {
113
+ const { app } = this;
114
+ const invoke = createContext();
115
+ const rawApp = app.getApp();
116
+ rawApp.addHook("onRequest", async (request, reply) => {
117
+ const $ctx = invoke({
118
+ request: request,
119
+ response: reply
120
+ });
121
+ $ctx.request.getReq().$ctx = $ctx;
122
+ await $ctx.start();
123
+ });
124
+ rawApp.addHook("onResponse", async (request, reply) => {
125
+ const { $ctx } = request;
126
+ $ctx.request.getReq().$ctx = undefined;
127
+ await $ctx.finish();
128
+ });
129
+ await rawApp.register(fastifyMiddie, {
130
+ hook: "onRequest"
131
+ });
132
+ const plugins = await this.resolvePlugins();
133
+ for (const plugin of plugins) {
134
+ // console.log("register", (plugin.use as any)[Symbol.for("plugin-meta")].name, plugin.options)
135
+ await rawApp.register(plugin.use, plugin.options);
136
+ }
137
+ }
138
+ createApp() {
139
+ const { app, ...props } = constant("fastify") || {};
140
+ const httpPort = constant("httpPort");
141
+ const httpOptions = constant("httpOptions");
142
+ const httpsPort = constant("httpsPort");
143
+ const httpsOptions = constant("httpsOptions");
144
+ const opts = {
145
+ ...props,
146
+ ignoreTrailingSlash: true,
147
+ http: httpPort !== false
148
+ ? {
149
+ ...httpOptions
150
+ }
151
+ : null,
152
+ https: httpsPort !== false
153
+ ? {
154
+ ...httpsOptions
155
+ }
156
+ : null
157
+ };
158
+ const instance = app || Fastify(opts);
159
+ instance.decorateRequest("$ctx", null);
160
+ instance.decorateReply("locals", null);
161
+ return {
162
+ app: instance,
163
+ callback: () => {
164
+ return async (request, response) => {
165
+ await instance.ready();
166
+ instance.server.emit("request", request, response);
167
+ };
168
+ }
169
+ };
170
+ }
171
+ afterLoadRoutes() {
172
+ const rawApp = this.app.getApp();
173
+ rawApp.setErrorHandler((error, request, reply) => {
174
+ const { $ctx } = request;
175
+ $ctx.error = $ctx.error || error;
176
+ return inject(PlatformExceptions)?.catch(error, $ctx);
177
+ });
178
+ rawApp.setNotFoundHandler((request, reply) => {
179
+ const { $ctx } = request;
180
+ return inject(PlatformExceptions)?.catch(new NotFound(`Resource "${request.originalUrl}" not found`), $ctx);
181
+ });
182
+ return Promise.resolve();
183
+ }
184
+ getServers() {
185
+ const httpsPort = constant("httpsPort");
186
+ const httpPort = constant("httpPort");
187
+ const listen = (hostinfo) => this.app.getApp().listen({
188
+ host: hostinfo.address,
189
+ port: hostinfo.port
190
+ });
191
+ const server = () => this.app.getApp().server;
192
+ return [
193
+ createServer({
194
+ port: httpsPort,
195
+ type: "https",
196
+ token: Https.Server,
197
+ server,
198
+ listen
199
+ }),
200
+ createServer({
201
+ port: httpPort,
202
+ type: "http",
203
+ token: Http.Server,
204
+ server,
205
+ listen
206
+ })
207
+ ];
208
+ }
209
+ bodyParser(type, opts) {
210
+ return null;
211
+ }
212
+ multipart(options) {
213
+ logger().warn({
214
+ event: "PLATFORM_UNSUPPORTED_FEATURE",
215
+ message: "Multipart method is not implemented yet",
216
+ options
217
+ });
218
+ return null;
219
+ }
220
+ statics(endpoint, options) {
221
+ this.app.getApp().register(fastifyStatics, {
222
+ root: options.root,
223
+ prefix: endpoint,
224
+ decorateReply: !this.staticsDecorated
225
+ });
226
+ this.staticsDecorated = true;
227
+ return null;
228
+ }
229
+ compose(layer) {
230
+ return (req, reply) => {
231
+ return runInContext(req.$ctx, async () => {
232
+ const $ctx = req.$ctx;
233
+ $ctx.next = null;
234
+ for (const metadata of layer.handlers) {
235
+ try {
236
+ if (!req.$ctx.isDone()) {
237
+ if (($ctx.error && metadata.type === PlatformHandlerType.ERR_MIDDLEWARE) ||
238
+ (!$ctx.error && metadata.type !== PlatformHandlerType.ERR_MIDDLEWARE)) {
239
+ await metadata.compiledHandler($ctx);
240
+ }
241
+ }
242
+ }
243
+ catch (er) {
244
+ $ctx.error = er;
245
+ }
246
+ }
247
+ if (req.$ctx.error) {
248
+ // TODO maybe we can use platform exception here?
249
+ throw req.$ctx.error;
250
+ }
251
+ });
252
+ };
253
+ }
254
+ async resolvePlugins() {
255
+ let plugins = constant("plugins", []);
256
+ const env = constant("env");
257
+ const promises = plugins.map(async (plugin) => {
258
+ if (isFunction(plugin)) {
259
+ return {
260
+ env,
261
+ use: plugin
262
+ };
263
+ }
264
+ if (isString(plugin)) {
265
+ plugin = { env, use: plugin };
266
+ }
267
+ let { use } = plugin;
268
+ if (isString(use)) {
269
+ const mod = await import(use);
270
+ use = mod.default || mod;
271
+ }
272
+ return {
273
+ env,
274
+ ...plugin,
275
+ use
276
+ };
277
+ });
278
+ plugins = await Promise.all(promises);
279
+ return plugins.filter((middleware) => middleware.use).filter((middleware) => middleware.env === env);
280
+ }
281
+ }
282
+ adapter(PlatformFastify);
283
+ //# sourceMappingURL=PlatformFastify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformFastify.js","sourceRoot":"","sources":["../../../src/components/PlatformFastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAW,UAAU,EAAE,QAAQ,EAA+B,MAAM,YAAY,CAAC;AACxF,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAC,MAAM,UAAU,CAAC;AAChE,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,OAAO,EACP,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,eAAe,EAEf,eAAe,EACf,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAA0B,mBAAmB,EAAgB,MAAM,uBAAuB,CAAC;AAClG,OAAO,OAAwD,MAAM,SAAS,CAAC;AAI/E,OAAO,EAAC,sBAAsB,EAAC,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAC,uBAAuB,EAAC,MAAM,wCAAwC,CAAC;AAU/E,MAAM,OAAO,eAAgB,SAAQ,eAAgC;IAArE;;QACW,SAAI,GAAG,SAAS,CAAC;QAEjB,cAAS,GAAG;YACnB;gBACE,KAAK,EAAE,eAAe;aACvB;YACD,EAAC,KAAK,EAAE,mBAAmB,EAAC;YAC5B,EAAC,KAAK,EAAE,QAAQ,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,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEtC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;IACvG,CAAC;CACF;AAED,OAAO,CAAC,eAAe,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./components/PlatformFastify.js";
5
+ export * from "./interfaces/interfaces.js";
6
+ export * from "./interfaces/PlatformFastifySettings.js";
7
+ export * from "./services/PlatformFastifyRequest.js";
8
+ export * from "./services/PlatformFastifyResponse.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PlatformFastifySettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformFastifySettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformFastifySettings.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from "./PlatformFastifySettings.js";
2
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAKA,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,34 @@
1
+ import "@fastify/accepts";
2
+ import { PlatformRequest } from "@tsed/platform-http";
3
+ /**
4
+ * @platform
5
+ * @fastify
6
+ */
7
+ export class PlatformFastifyRequest extends PlatformRequest {
8
+ get host() {
9
+ return this.raw.hostname;
10
+ }
11
+ get secure() {
12
+ return this.protocol === "https";
13
+ }
14
+ /**
15
+ * Returns the HTTP request header specified by field. The match is case-insensitive.
16
+ *
17
+ * ```typescript
18
+ * request.get('Content-Type') // => "text/plain"
19
+ * ```
20
+ *
21
+ * @param name
22
+ */
23
+ get(name) {
24
+ return this.raw.raw.headers[name.toLowerCase()];
25
+ }
26
+ getReq() {
27
+ return this.raw.raw;
28
+ }
29
+ accepts(mime) {
30
+ const accepts = this.raw.accepts().type([].concat(mime));
31
+ return (accepts ? accepts : false);
32
+ }
33
+ }
34
+ //# sourceMappingURL=PlatformFastifyRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformFastifyRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformFastifyRequest.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAI1B,OAAO,EAAuB,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAqB1E;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,eAA+B;IACzE,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,QAAQ,KAAK,OAAO,CAAC;IACnC,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,OAAO,CAAC,IAAwB;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAW,CAAC,CAAC,CAAC;QAEhE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAQ,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,76 @@
1
+ import { PlatformResponse } from "@tsed/platform-http";
2
+ import contentDisposition from "content-disposition";
3
+ /**
4
+ * @platform
5
+ * @fastify
6
+ */
7
+ export class PlatformFastifyResponse extends PlatformResponse {
8
+ constructor($ctx) {
9
+ super($ctx);
10
+ this.$ctx = $ctx;
11
+ this.raw.locals = {};
12
+ }
13
+ // set raw(raw: FastifyReply) {
14
+ // this.$ctx.event.response = raw;
15
+ // }
16
+ /**
17
+ * Return the Node.js response object
18
+ */
19
+ getRes() {
20
+ return this.raw.raw;
21
+ }
22
+ /**
23
+ * Sets the HTTP status for the response.
24
+ *
25
+ * @param status
26
+ */
27
+ status(status) {
28
+ this.raw.code(status);
29
+ return this;
30
+ }
31
+ /**
32
+ * Set `Content-Type` response header with `type` through `mime.lookup()`
33
+ * when it does not contain "/", or set the Content-Type to `type` otherwise.
34
+ *
35
+ * Examples:
36
+ *
37
+ * res.type('.html');
38
+ * res.type('html');
39
+ * res.type('json');
40
+ * res.type('application/json');
41
+ * res.type('png');
42
+ */
43
+ contentType(contentType) {
44
+ this.raw.type(contentType);
45
+ return this;
46
+ }
47
+ /**
48
+ * Returns the HTTP response header specified by field. The match is case-insensitive.
49
+ *
50
+ * ```typescript
51
+ * response.get('Content-Type') // => "text/plain"
52
+ * ```
53
+ *
54
+ * @param name
55
+ */
56
+ get(name) {
57
+ return this.raw.getHeader(name);
58
+ }
59
+ attachment(filename) {
60
+ this.setHeader("Content-Disposition", contentDisposition(filename));
61
+ return this;
62
+ }
63
+ setHeader(key, item) {
64
+ this.raw.header(key, this.formatHeader(key, item));
65
+ return this;
66
+ }
67
+ stream(data) {
68
+ this.raw.send(data);
69
+ return this;
70
+ }
71
+ json(data) {
72
+ this.raw.send(data);
73
+ return this;
74
+ }
75
+ }
76
+ //# sourceMappingURL=PlatformFastifyResponse.js.map
@@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nD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,IAAS;QACd,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,IAAS;QACZ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,63 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import * as Http from "node:http";
3
+ import { IncomingMessage, ServerResponse } from "node:http";
4
+ import { Type } from "@tsed/core";
5
+ import { Platform, PlatformAdapter, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformMulterSettings, PlatformRequest, PlatformResponse, PlatformStaticsOptions } from "@tsed/platform-http";
6
+ import { PlatformHandlerMetadata, PlatformLayer } from "@tsed/platform-router";
7
+ import Fastify, { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
8
+ import type { PlatformFastifyPluginLoadingOptions } from "../interfaces/interfaces.js";
9
+ import { PlatformFastifyRequest } from "../services/PlatformFastifyRequest.js";
10
+ import { PlatformFastifyResponse } from "../services/PlatformFastifyResponse.js";
11
+ declare global {
12
+ namespace TsED {
13
+ interface Application extends FastifyInstance {
14
+ }
15
+ }
16
+ namespace TsED { }
17
+ }
18
+ export declare class PlatformFastify extends PlatformAdapter<FastifyInstance> {
19
+ readonly NAME = "fastify";
20
+ readonly providers: ({
21
+ token: typeof PlatformHandler;
22
+ useClass?: undefined;
23
+ } | {
24
+ token: typeof PlatformApplication;
25
+ useClass?: undefined;
26
+ } | {
27
+ token: typeof Platform;
28
+ useClass?: undefined;
29
+ } | {
30
+ token: typeof PlatformResponse;
31
+ useClass: typeof PlatformFastifyResponse;
32
+ } | {
33
+ token: typeof PlatformRequest;
34
+ useClass: typeof PlatformFastifyRequest;
35
+ })[];
36
+ private staticsDecorated;
37
+ /**
38
+ * Create new serverless application. In this mode, the component scan are disabled.
39
+ * @param module
40
+ * @param settings
41
+ */
42
+ static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<TsED.Application>;
43
+ /**
44
+ * Bootstrap a server application
45
+ * @param module
46
+ * @param settings
47
+ */
48
+ static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<TsED.Application>>;
49
+ mapLayers(layers: PlatformLayer[]): void;
50
+ mapHandler(handler: (...args: any[]) => any, metadata: PlatformHandlerMetadata): (...args: any[]) => any;
51
+ useContext(): Promise<void>;
52
+ createApp(): {
53
+ app: Fastify.FastifyInstance<Fastify.RawServerDefault, Http.IncomingMessage, Http.ServerResponse<Http.IncomingMessage>, Fastify.FastifyBaseLogger, Fastify.FastifyTypeProviderDefault>;
54
+ callback: () => (request: IncomingMessage, response: ServerResponse) => Promise<void>;
55
+ };
56
+ afterLoadRoutes(): Promise<void>;
57
+ getServers(): any[];
58
+ bodyParser(type: string, opts: Record<string, any> | undefined): any;
59
+ multipart(options: PlatformMulterSettings): any;
60
+ statics(endpoint: string, options: PlatformStaticsOptions): any;
61
+ protected compose(layer: PlatformLayer): (req: FastifyRequest, reply: FastifyReply) => Promise<Promise<void>>;
62
+ protected resolvePlugins(): Promise<PlatformFastifyPluginLoadingOptions[]>;
63
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./components/PlatformFastify.js";
5
+ export * from "./interfaces/interfaces.js";
6
+ export * from "./interfaces/PlatformFastifySettings.js";
7
+ export * from "./services/PlatformFastifyRequest.js";
8
+ export * from "./services/PlatformFastifyResponse.js";
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ export interface PlatformFastifySettings {
3
+ app?: FastifyInstance;
4
+ }
@@ -0,0 +1,22 @@
1
+ import type { Env } from "@tsed/core";
2
+ import type { FastifyPluginOptions, FastifyRegisterOptions } from "fastify";
3
+ import type { PlatformFastifySettings } from "./PlatformFastifySettings.js";
4
+ export * from "./PlatformFastifySettings.js";
5
+ export type PlatformFastifyPluginTypes = ((opts?: any) => any) | /*Type<any> |*/ string;
6
+ export type PlatformFastifyPluginLoadingOptions = {
7
+ env?: Env;
8
+ use: PlatformFastifyPluginTypes;
9
+ options?: FastifyRegisterOptions<FastifyPluginOptions>;
10
+ };
11
+ export type PlatformFastifyPluginSettings = PlatformFastifyPluginTypes | PlatformFastifyPluginLoadingOptions | any;
12
+ declare global {
13
+ namespace TsED {
14
+ interface Configuration {
15
+ /**
16
+ * Configuration related to Fastify platform application.
17
+ */
18
+ fastify: PlatformFastifySettings;
19
+ plugins: PlatformFastifyPluginSettings[];
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,41 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import "@fastify/accepts";
3
+ import type { IncomingMessage } from "node:http";
4
+ import { type PlatformContext, PlatformRequest } from "@tsed/platform-http";
5
+ import type { FastifyRequest } from "fastify";
6
+ declare module "fastify" {
7
+ interface FastifyRequest {
8
+ $ctx: PlatformContext;
9
+ }
10
+ }
11
+ declare module "http" {
12
+ interface IncomingMessage {
13
+ $ctx: PlatformContext;
14
+ }
15
+ }
16
+ declare global {
17
+ namespace TsED {
18
+ interface Request extends FastifyRequest {
19
+ }
20
+ }
21
+ }
22
+ /**
23
+ * @platform
24
+ * @fastify
25
+ */
26
+ export declare class PlatformFastifyRequest extends PlatformRequest<FastifyRequest> {
27
+ get host(): string;
28
+ get secure(): boolean;
29
+ /**
30
+ * Returns the HTTP request header specified by field. The match is case-insensitive.
31
+ *
32
+ * ```typescript
33
+ * request.get('Content-Type') // => "text/plain"
34
+ * ```
35
+ *
36
+ * @param name
37
+ */
38
+ get(name: string): string | string[] | undefined;
39
+ getReq(): IncomingMessage;
40
+ accepts(mime?: string | string[]): any;
41
+ }
@@ -0,0 +1,56 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { ServerResponse } from "node:http";
3
+ import { type PlatformContext, PlatformResponse } from "@tsed/platform-http";
4
+ import type { FastifyReply } from "fastify";
5
+ declare global {
6
+ namespace TsED {
7
+ interface Response extends FastifyReply {
8
+ locals: Record<string, unknown>;
9
+ }
10
+ }
11
+ }
12
+ /**
13
+ * @platform
14
+ * @fastify
15
+ */
16
+ export declare class PlatformFastifyResponse extends PlatformResponse<TsED.Response> {
17
+ readonly $ctx: PlatformContext;
18
+ constructor($ctx: PlatformContext);
19
+ /**
20
+ * Return the Node.js response object
21
+ */
22
+ getRes(): ServerResponse;
23
+ /**
24
+ * Sets the HTTP status for the response.
25
+ *
26
+ * @param status
27
+ */
28
+ status(status: number): this;
29
+ /**
30
+ * Set `Content-Type` response header with `type` through `mime.lookup()`
31
+ * when it does not contain "/", or set the Content-Type to `type` otherwise.
32
+ *
33
+ * Examples:
34
+ *
35
+ * res.type('.html');
36
+ * res.type('html');
37
+ * res.type('json');
38
+ * res.type('application/json');
39
+ * res.type('png');
40
+ */
41
+ contentType(contentType: string): this;
42
+ /**
43
+ * Returns the HTTP response header specified by field. The match is case-insensitive.
44
+ *
45
+ * ```typescript
46
+ * response.get('Content-Type') // => "text/plain"
47
+ * ```
48
+ *
49
+ * @param name
50
+ */
51
+ get(name: string): string | number | string[] | undefined;
52
+ attachment(filename: string): this;
53
+ setHeader(key: string, item: any): this;
54
+ stream(data: any): this;
55
+ json(data: any): this;
56
+ }