@inversifyjs/http-fastify 4.3.0 → 4.5.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/CHANGELOG.md +16 -0
- package/lib/cjs/adapter/InversifyFastifyHttpAdapter.d.ts +9 -6
- package/lib/cjs/adapter/InversifyFastifyHttpAdapter.d.ts.map +1 -1
- package/lib/cjs/adapter/InversifyFastifyHttpAdapter.js +33 -73
- package/lib/cjs/adapter/InversifyFastifyHttpAdapter.js.map +1 -1
- package/lib/cjs/models/FastifyMiddleware.d.ts +2 -2
- package/lib/cjs/models/FastifyMiddleware.d.ts.map +1 -1
- package/lib/esm/index.d.ts +10 -7
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @inversifyjs/http-fastify
|
|
2
2
|
|
|
3
|
+
## 4.5.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @inversifyjs/http-core@4.5.0
|
|
9
|
+
|
|
10
|
+
## 4.4.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
Fixed fastify next function to be `() => void`
|
|
15
|
+
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @inversifyjs/http-core@4.4.0
|
|
18
|
+
|
|
3
19
|
## 4.3.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { HttpStatusCode, InversifyHttpAdapter, RouterParams } from '@inversifyjs/http-core';
|
|
3
|
-
import { FastifyInstance, FastifyReply, FastifyRequest
|
|
3
|
+
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
4
4
|
import { Container } from 'inversify';
|
|
5
5
|
import { FastifyHttpAdapterOptions } from '../models/FastifyHttpAdapterOptions';
|
|
6
|
-
export declare class InversifyFastifyHttpAdapter extends InversifyHttpAdapter<FastifyRequest, FastifyReply,
|
|
6
|
+
export declare class InversifyFastifyHttpAdapter extends InversifyHttpAdapter<FastifyRequest, FastifyReply, () => void, void, FastifyHttpAdapterOptions> {
|
|
7
7
|
#private;
|
|
8
8
|
constructor(container: Container, httpAdapterOptions?: FastifyHttpAdapterOptions, customApp?: FastifyInstance);
|
|
9
9
|
build(): Promise<FastifyInstance>;
|
|
10
10
|
protected _getBody(request: FastifyRequest, _response: FastifyReply, parameterName?: string): unknown;
|
|
11
|
-
protected _getParams(request: FastifyRequest,
|
|
12
|
-
protected
|
|
13
|
-
protected
|
|
11
|
+
protected _getParams(request: FastifyRequest): Record<string, string>;
|
|
12
|
+
protected _getParams(request: FastifyRequest, parameterName: string): string | undefined;
|
|
13
|
+
protected _getQuery(request: FastifyRequest): Record<string, unknown>;
|
|
14
|
+
protected _getQuery(request: FastifyRequest, parameterName: string): unknown;
|
|
15
|
+
protected _getHeaders(request: FastifyRequest): Record<string, string | string[] | undefined>;
|
|
16
|
+
protected _getHeaders(request: FastifyRequest, parameterName: string): string | string[] | undefined;
|
|
14
17
|
protected _getCookies(request: FastifyRequest, _response: FastifyReply, parameterName?: string): unknown;
|
|
15
18
|
protected _replyText(_request: FastifyRequest, response: FastifyReply, value: string): void;
|
|
16
19
|
protected _replyJson(_request: FastifyRequest, response: FastifyReply, value?: object): void;
|
|
17
20
|
protected _replyStream(_request: FastifyRequest, response: FastifyReply, value: Readable): Promise<void>;
|
|
18
21
|
protected _setStatus(_request: FastifyRequest, response: FastifyReply, statusCode: HttpStatusCode): void;
|
|
19
22
|
protected _setHeader(_request: FastifyRequest, response: FastifyReply, key: string, value: string): void;
|
|
20
|
-
protected _buildRouter(routerParams: RouterParams<FastifyRequest, FastifyReply,
|
|
23
|
+
protected _buildRouter(routerParams: RouterParams<FastifyRequest, FastifyReply, () => void, void>): void;
|
|
21
24
|
}
|
|
22
25
|
//# sourceMappingURL=InversifyFastifyHttpAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InversifyFastifyHttpAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapter/InversifyFastifyHttpAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC,OAAO,
|
|
1
|
+
{"version":3,"file":"InversifyFastifyHttpAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapter/InversifyFastifyHttpAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC,OAAO,EAGL,cAAc,EACd,oBAAoB,EAIpB,YAAY,EACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,eAAe,EAEf,YAAY,EACZ,cAAc,EAEf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAEhF,qBAAa,2BAA4B,SAAQ,oBAAoB,CACnE,cAAc,EACd,YAAY,EACZ,MAAM,IAAI,EACV,IAAI,EACJ,yBAAyB,CAC1B;;gBAIG,SAAS,EAAE,SAAS,EACpB,kBAAkB,CAAC,EAAE,yBAAyB,EAC9C,SAAS,CAAC,EAAE,eAAe;IAgBhB,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC;IAM9C,SAAS,CAAC,QAAQ,CAChB,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,YAAY,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO;IAQV,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACrE,SAAS,CAAC,UAAU,CAClB,OAAO,EAAE,cAAc,EACvB,aAAa,EAAE,MAAM,GACpB,MAAM,GAAG,SAAS;IASrB,SAAS,CAA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
@@ -66,24 +66,20 @@ class InversifyFastifyHttpAdapter extends http_core_1.InversifyHttpAdapter {
|
|
|
66
66
|
response.header(key, value);
|
|
67
67
|
}
|
|
68
68
|
_buildRouter(routerParams) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
done();
|
|
85
|
-
};
|
|
86
|
-
this.#app.register(router, { prefix: routerParams.path });
|
|
69
|
+
for (const routeParams of routerParams.routeParamsList) {
|
|
70
|
+
const orderedHandlers = [
|
|
71
|
+
...routeParams.preHandlerMiddlewareList,
|
|
72
|
+
...routeParams.guardList,
|
|
73
|
+
routeParams.handler,
|
|
74
|
+
...routeParams.postHandlerMiddlewareList,
|
|
75
|
+
];
|
|
76
|
+
const normalizedPath = (0, http_core_1.buildNormalizedPath)(`${routerParams.path}${routeParams.path}`);
|
|
77
|
+
const handleMiddlewares = (0, http_core_1.handleMiddlewareList)(orderedHandlers);
|
|
78
|
+
const fastifyHandler = async (request, reply) => {
|
|
79
|
+
await handleMiddlewares(request, reply);
|
|
80
|
+
};
|
|
81
|
+
this.#getAppRouteHandler(routeParams.requestMethodType)(normalizedPath, fastifyHandler);
|
|
82
|
+
}
|
|
87
83
|
}
|
|
88
84
|
#buildDefaultFastifyApp(customApp) {
|
|
89
85
|
const app = customApp ?? (0, fastify_1.fastify)();
|
|
@@ -103,61 +99,25 @@ class InversifyFastifyHttpAdapter extends http_core_1.InversifyHttpAdapter {
|
|
|
103
99
|
}
|
|
104
100
|
return app;
|
|
105
101
|
}
|
|
106
|
-
#
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return middlewareList.map((middleware) => this.#buildFastifyOnResponseAsyncMiddleware(middleware));
|
|
126
|
-
}
|
|
127
|
-
#buildFastifyPreHandlerAsyncMiddleware(middleware) {
|
|
128
|
-
return async (request, reply) => {
|
|
129
|
-
await new Promise((resolve, reject) => {
|
|
130
|
-
const done = (err) => {
|
|
131
|
-
if (err !== undefined) {
|
|
132
|
-
reject(err);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
resolve();
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
middleware(request, reply, done);
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
#buildFastifyOnResponseAsyncMiddleware(middleware) {
|
|
143
|
-
return async (request, reply) => {
|
|
144
|
-
await new Promise((resolve, reject) => {
|
|
145
|
-
const done = (err) => {
|
|
146
|
-
if (err !== undefined) {
|
|
147
|
-
reject(err);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
resolve();
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
middleware(request, reply, done);
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
#convertRequestMethodType(requestMethodType) {
|
|
158
|
-
return requestMethodType === http_core_1.RequestMethodType.All
|
|
159
|
-
? Object.values(http_core_1.RequestMethodType).filter((method) => method !== http_core_1.RequestMethodType.All)
|
|
160
|
-
: requestMethodType;
|
|
102
|
+
#getAppRouteHandler(requestMethodType) {
|
|
103
|
+
switch (requestMethodType) {
|
|
104
|
+
case http_core_1.RequestMethodType.All:
|
|
105
|
+
return this.#app.all.bind(this.#app);
|
|
106
|
+
case http_core_1.RequestMethodType.Delete:
|
|
107
|
+
return this.#app.delete.bind(this.#app);
|
|
108
|
+
case http_core_1.RequestMethodType.Get:
|
|
109
|
+
return this.#app.get.bind(this.#app);
|
|
110
|
+
case http_core_1.RequestMethodType.Head:
|
|
111
|
+
return this.#app.head.bind(this.#app);
|
|
112
|
+
case http_core_1.RequestMethodType.Options:
|
|
113
|
+
return this.#app.options.bind(this.#app);
|
|
114
|
+
case http_core_1.RequestMethodType.Patch:
|
|
115
|
+
return this.#app.patch.bind(this.#app);
|
|
116
|
+
case http_core_1.RequestMethodType.Post:
|
|
117
|
+
return this.#app.post.bind(this.#app);
|
|
118
|
+
case http_core_1.RequestMethodType.Put:
|
|
119
|
+
return this.#app.put.bind(this.#app);
|
|
120
|
+
}
|
|
161
121
|
}
|
|
162
122
|
#getMultipartRequestBody(request, parameterName) {
|
|
163
123
|
if (request.isMultipart()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InversifyFastifyHttpAdapter.js","sourceRoot":"","sources":["../../../src/adapter/InversifyFastifyHttpAdapter.ts"],"names":[],"mappings":";;;;AAEA,qEAA+D;AAC/D,yEAAgD;AAChD,2EAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"InversifyFastifyHttpAdapter.js","sourceRoot":"","sources":["../../../src/adapter/InversifyFastifyHttpAdapter.ts"],"names":[],"mappings":";;;;AAEA,qEAA+D;AAC/D,yEAAgD;AAChD,2EAAkD;AAClD,sDASgC;AAChC,qCAOiB;AAKjB,MAAa,2BAA4B,SAAQ,gCAMhD;IACU,IAAI,CAAkB;IAE/B,YACE,SAAoB,EACpB,kBAA8C,EAC9C,SAA2B;QAE3B,KAAK,CACH,SAAS,EACT;YACE,MAAM,EAAE,IAAI;YACZ,UAAU,EAAE,KAAK;YACjB,iBAAiB,EAAE,KAAK;YACxB,oBAAoB,EAAE,KAAK;SAC5B,EACD,kBAAkB,EAClB,CAAC,sCAA0B,CAAC,IAAI,CAAC,CAClC,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,MAAM,IAAI,CAA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AO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3C,KAAK,6BAAiB,CAAC,KAAK;gBAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzC,KAAK,6BAAiB,CAAC,IAAI;gBACzB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACxC,KAAK,6BAAiB,CAAC,GAAG;gBACxB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,wBAAwB,CACtB,OAAuB,EACvB,aAAiC;QAEjC,IAAI,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;YAC1B,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;gBAChC,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;YACzB,CAAC;YAED,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,eAAe,CACb,OAAuB,EACvB,aAAiC;QAEjC,OAAO,aAAa,KAAK,SAAS;YAChC,CAAC,CAAC,OAAO,CAAC,IAAI;YACd,CAAC,CAAE,OAAO,CAAC,IAAgC,CAAC,aAAa,CAAC,CAAC;IAC/D,CAAC;CACF;AAjQD,kEAiQC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Middleware } from '@inversifyjs/http-core';
|
|
2
|
-
import { FastifyReply, FastifyRequest
|
|
3
|
-
export type FastifyMiddleware = Middleware<FastifyRequest, FastifyReply,
|
|
2
|
+
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
3
|
+
export type FastifyMiddleware = Middleware<FastifyRequest, FastifyReply, () => void, void>;
|
|
4
4
|
//# sourceMappingURL=FastifyMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FastifyMiddleware.d.ts","sourceRoot":"","sources":["../../../src/models/FastifyMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"FastifyMiddleware.d.ts","sourceRoot":"","sources":["../../../src/models/FastifyMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG,UAAU,CACxC,cAAc,EACd,YAAY,EACZ,MAAM,IAAI,EACV,IAAI,CACL,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { HttpAdapterOptions, InversifyHttpAdapter, HttpStatusCode, RouterParams, ErrorFilter, Guard, Interceptor, Middleware } from '@inversifyjs/http-core';
|
|
3
|
-
import { FastifyRequest, FastifyReply,
|
|
3
|
+
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
|
|
4
4
|
import { Container } from 'inversify';
|
|
5
5
|
import { FastifyMultipartAttachFieldsToBodyOptions, FastifyMultipartOptions } from '@fastify/multipart';
|
|
6
6
|
|
|
@@ -10,21 +10,24 @@ interface FastifyHttpAdapterOptions extends HttpAdapterOptions {
|
|
|
10
10
|
useMultipartFormData?: boolean | FastifyMultipartAttachFieldsToBodyOptions | FastifyMultipartOptions;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
declare class InversifyFastifyHttpAdapter extends InversifyHttpAdapter<FastifyRequest, FastifyReply,
|
|
13
|
+
declare class InversifyFastifyHttpAdapter extends InversifyHttpAdapter<FastifyRequest, FastifyReply, () => void, void, FastifyHttpAdapterOptions> {
|
|
14
14
|
#private;
|
|
15
15
|
constructor(container: Container, httpAdapterOptions?: FastifyHttpAdapterOptions, customApp?: FastifyInstance);
|
|
16
16
|
build(): Promise<FastifyInstance>;
|
|
17
17
|
protected _getBody(request: FastifyRequest, _response: FastifyReply, parameterName?: string): unknown;
|
|
18
|
-
protected _getParams(request: FastifyRequest,
|
|
19
|
-
protected
|
|
20
|
-
protected
|
|
18
|
+
protected _getParams(request: FastifyRequest): Record<string, string>;
|
|
19
|
+
protected _getParams(request: FastifyRequest, parameterName: string): string | undefined;
|
|
20
|
+
protected _getQuery(request: FastifyRequest): Record<string, unknown>;
|
|
21
|
+
protected _getQuery(request: FastifyRequest, parameterName: string): unknown;
|
|
22
|
+
protected _getHeaders(request: FastifyRequest): Record<string, string | string[] | undefined>;
|
|
23
|
+
protected _getHeaders(request: FastifyRequest, parameterName: string): string | string[] | undefined;
|
|
21
24
|
protected _getCookies(request: FastifyRequest, _response: FastifyReply, parameterName?: string): unknown;
|
|
22
25
|
protected _replyText(_request: FastifyRequest, response: FastifyReply, value: string): void;
|
|
23
26
|
protected _replyJson(_request: FastifyRequest, response: FastifyReply, value?: object): void;
|
|
24
27
|
protected _replyStream(_request: FastifyRequest, response: FastifyReply, value: Readable): Promise<void>;
|
|
25
28
|
protected _setStatus(_request: FastifyRequest, response: FastifyReply, statusCode: HttpStatusCode): void;
|
|
26
29
|
protected _setHeader(_request: FastifyRequest, response: FastifyReply, key: string, value: string): void;
|
|
27
|
-
protected _buildRouter(routerParams: RouterParams<FastifyRequest, FastifyReply,
|
|
30
|
+
protected _buildRouter(routerParams: RouterParams<FastifyRequest, FastifyReply, () => void, void>): void;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
type FastifyErrorFilter<TError = unknown> = ErrorFilter<TError, FastifyRequest, FastifyReply, void>;
|
|
@@ -33,7 +36,7 @@ type FastifyGuard = Guard<FastifyRequest>;
|
|
|
33
36
|
|
|
34
37
|
type FastifyInterceptor = Interceptor<FastifyRequest, FastifyReply>;
|
|
35
38
|
|
|
36
|
-
type FastifyMiddleware = Middleware<FastifyRequest, FastifyReply,
|
|
39
|
+
type FastifyMiddleware = Middleware<FastifyRequest, FastifyReply, () => void, void>;
|
|
37
40
|
|
|
38
41
|
export { InversifyFastifyHttpAdapter };
|
|
39
42
|
export type { FastifyErrorFilter, FastifyGuard, FastifyHttpAdapterOptions, FastifyInterceptor, FastifyMiddleware };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import t from"@fastify/cookie";import e from"@fastify/formbody";import r from"@fastify/multipart";import{InversifyHttpAdapter as s,RequestMethodParameterType as a,buildNormalizedPath as i,handleMiddlewareList as p,RequestMethodType as o}from"@inversifyjs/http-core";import{fastify as d}from"fastify";class u extends s{#t;constructor(t,e,r){super(t,{logger:!0,useCookies:!1,useFormUrlEncoded:!1,useMultipartFormData:!1},e,[a.Body]),this.#t=this.#e(r)}async build(){return await this._buildServer(),this.#t}_getBody(t,e,r){return!1!==this.httpAdapterOptions.useMultipartFormData?this.#r(t,r):this.#s(t,r)}_getParams(t,e){return void 0===e?t.params:t.params[e]}_getQuery(t,e){return void 0===e?t.query:t.query[e]}_getHeaders(t,e){return void 0===e?t.headers:t.headers[e]}_getCookies(t,e,r){return void 0===r?t.cookies:t.cookies[r]}_replyText(t,e,r){e.send(r)}_replyJson(t,e,r){e.send(r)}async _replyStream(t,e,r){await e.send(r)}_setStatus(t,e,r){e.status(r)}_setHeader(t,e,r,s){e.header(r,s)}_buildRouter(t){for(const e of t.routeParamsList){const r=[...e.preHandlerMiddlewareList,...e.guardList,e.handler,...e.postHandlerMiddlewareList],s=i(`${t.path}${e.path}`),a=p(r),o=async(t,e)=>{await a(t,e)};this.#a(e.requestMethodType)(s,o)}}#e(s){const a=s??d();return this.httpAdapterOptions.useCookies&&a.register(t),this.httpAdapterOptions.useFormUrlEncoded&&a.register(e),!1!==this.httpAdapterOptions.useMultipartFormData&&(!0===this.httpAdapterOptions.useMultipartFormData?a.register(r):a.register(r,this.httpAdapterOptions.useMultipartFormData)),a}#a(t){switch(t){case o.All:return this.#t.all.bind(this.#t);case o.Delete:return this.#t.delete.bind(this.#t);case o.Get:return this.#t.get.bind(this.#t);case o.Head:return this.#t.head.bind(this.#t);case o.Options:return this.#t.options.bind(this.#t);case o.Patch:return this.#t.patch.bind(this.#t);case o.Post:return this.#t.post.bind(this.#t);case o.Put:return this.#t.put.bind(this.#t)}}#r(t,e){if(t.isMultipart()){if(void 0===e)return t.parts();throw new Error("Cannot get multipart form data body with a specific parameter name.")}return this.#s(t,e)}#s(t,e){return void 0===e?t.body:t.body[e]}}export{u as InversifyFastifyHttpAdapter};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/adapter/InversifyFastifyHttpAdapter.ts"],"sourcesContent":[null],"names":["InversifyFastifyHttpAdapter","InversifyHttpAdapter","app","constructor","container","httpAdapterOptions","customApp","super","logger","useCookies","useFormUrlEncoded","useMultipartFormData","RequestMethodParameterType","Body","this","buildDefaultFastifyApp","build","_buildServer","_getBody","request","_response","parameterName","getMultipartRequestBody","getRequestBody","_getParams","undefined","params","_getQuery","query","_getHeaders","headers","_getCookies","cookies","_replyText","_request","response","value","send","_replyJson","_replyStream","_setStatus","statusCode","status","_setHeader","key","header","_buildRouter","routerParams","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/adapter/InversifyFastifyHttpAdapter.ts"],"sourcesContent":[null],"names":["InversifyFastifyHttpAdapter","InversifyHttpAdapter","app","constructor","container","httpAdapterOptions","customApp","super","logger","useCookies","useFormUrlEncoded","useMultipartFormData","RequestMethodParameterType","Body","this","buildDefaultFastifyApp","build","_buildServer","_getBody","request","_response","parameterName","getMultipartRequestBody","getRequestBody","_getParams","undefined","params","_getQuery","query","_getHeaders","headers","_getCookies","cookies","_replyText","_request","response","value","send","_replyJson","_replyStream","_setStatus","statusCode","status","_setHeader","key","header","_buildRouter","routerParams","routeParams","routeParamsList","orderedHandlers","preHandlerMiddlewareList","guardList","handler","postHandlerMiddlewareList","normalizedPath","buildNormalizedPath","path","handleMiddlewares","handleMiddlewareList","fastifyHandler","async","reply","getAppRouteHandler","requestMethodType","fastify","register","cookie","fastifyFormbody","fastifyMultipart","RequestMethodType","All","all","bind","Delete","delete","Get","get","Head","head","Options","options","Patch","patch","Post","post","Put","put","isMultipart","parts","Error","body"],"mappings":"4SA2BM,MAAOA,UAAoCC,EAOtCC,GAET,WAAAC,CACEC,EACAC,EACAC,GAEAC,MACEH,EACA,CACEI,QAAQ,EACRC,YAAY,EACZC,mBAAmB,EACnBC,sBAAsB,GAExBN,EACA,CAACO,EAA2BC,OAE9BC,MAAKZ,EAAOY,MAAKC,EAAwBT,EAC3C,CAEO,WAAMU,GAGX,aAFMF,KAAKG,eAEJH,MAAKZ,CACd,CAEU,QAAAgB,CACRC,EACAC,EACAC,GAEA,OAAqD,IAAjDP,KAAKT,mBAAmBM,qBACnBG,MAAKQ,EAAyBH,EAASE,GAEvCP,MAAKS,EAAgBJ,EAASE,EAEzC,CAOU,UAAAG,CACRL,EACAE,GAEA,YAAyBI,IAAlBJ,EACFF,EAAQO,OACRP,EAAQO,OAAkCL,EACjD,CAGU,SAAAM,CACRR,EACAE,GAEA,YAAyBI,IAAlBJ,EACHF,EAAQS,MACPT,EAAQS,MAAkCP,EACjD,CASU,WAAAQ,CACRV,EACAE,GAMA,YAAyBI,IAAlBJ,EACHF,EAAQW,QACRX,EAAQW,QAAQT,EACtB,CAEU,WAAAU,CACRZ,EACAC,EACAC,GAEA,YAAyBI,IAAlBJ,EACHF,EAAQa,QACRb,EAAQa,QAAQX,EACtB,CAEU,UAAAY,CACRC,EACAC,EACAC,GAEAD,EAASE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E,KAAKN,KAAK3D,MAAKZ,GAClC,KAAKoE,EAAkBU,QACrB,OAAOlE,MAAKZ,EAAK+E,QAAQR,KAAK3D,MAAKZ,GACrC,KAAKoE,EAAkBY,MACrB,OAAOpE,MAAKZ,EAAKiF,MAAMV,KAAK3D,MAAKZ,GACnC,KAAKoE,EAAkBc,KACrB,OAAOtE,MAAKZ,EAAKmF,KAAKZ,KAAK3D,MAAKZ,GAClC,KAAKoE,EAAkBgB,IACrB,OAAOxE,MAAKZ,EAAKqF,IAAId,KAAK3D,MAAKZ,GAErC,CAEA,EAAAoB,CACEH,EACAE,GAEA,GAAIF,EAAQqE,cAAe,CACzB,QAAsB/D,IAAlBJ,EACF,OAAOF,EAAQsE,QAGjB,MAAM,IAAIC,MACR,sEAEJ,CACE,OAAO5E,MAAKS,EAAgBJ,EAASE,EAEzC,CAEA,EAAAE,CACEJ,EACAE,GAEA,YAAyBI,IAAlBJ,EACHF,EAAQwE,KACPxE,EAAQwE,KAAiCtE,EAChD"}
|
package/package.json
CHANGED
|
@@ -8,22 +8,22 @@
|
|
|
8
8
|
"@fastify/cookie": "11.0.2",
|
|
9
9
|
"@fastify/formbody": "8.0.2",
|
|
10
10
|
"@fastify/multipart": "9.3.0",
|
|
11
|
-
"@inversifyjs/http-core": "4.
|
|
11
|
+
"@inversifyjs/http-core": "4.5.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@stryker-mutator/core": "9.3.0",
|
|
15
15
|
"@stryker-mutator/typescript-checker": "9.3.0",
|
|
16
16
|
"@stryker-mutator/vitest-runner": "9.3.0",
|
|
17
|
-
"@types/node": "24.10.
|
|
18
|
-
"@vitest/coverage-v8": "4.0.
|
|
17
|
+
"@types/node": "24.10.1",
|
|
18
|
+
"@vitest/coverage-v8": "4.0.10",
|
|
19
19
|
"eslint": "9.39.1",
|
|
20
20
|
"prettier": "3.6.2",
|
|
21
|
-
"rimraf": "6.1.
|
|
22
|
-
"rollup": "4.53.
|
|
21
|
+
"rimraf": "6.1.2",
|
|
22
|
+
"rollup": "4.53.3",
|
|
23
23
|
"ts-loader": "9.5.4",
|
|
24
24
|
"tslib": "2.8.1",
|
|
25
25
|
"typescript": "5.9.3",
|
|
26
|
-
"vitest": "4.0.
|
|
26
|
+
"vitest": "4.0.10"
|
|
27
27
|
},
|
|
28
28
|
"devEngines": {
|
|
29
29
|
"node": "^24.10.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"name": "@inversifyjs/http-fastify",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"fastify": "^5.6.
|
|
54
|
+
"fastify": "^5.6.2",
|
|
55
55
|
"inversify": "^7.10.4"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"type": "git",
|
|
62
62
|
"url": "git+https://github.com/inversify/monorepo.git"
|
|
63
63
|
},
|
|
64
|
-
"version": "4.
|
|
64
|
+
"version": "4.5.0",
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "pnpm run build:cjs && pnpm run build:esm",
|
|
67
67
|
"build:cjs": "tsc --build tsconfig.cjs.json && pnpm exec foundation-ts-package-cjs ./lib/cjs",
|