@fluojs/platform-fastify 1.0.0-beta.4 → 1.0.0-beta.5
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/README.ko.md +3 -3
- package/README.md +3 -3
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +65 -9
- package/package.json +5 -4
package/README.ko.md
CHANGED
|
@@ -126,11 +126,11 @@ await bootstrapFastifyApplication(AppModule, {
|
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
### 네이티브 라우트 등록과 안전한 폴백
|
|
129
|
-
fluo 라우트 메타데이터를 Fastify 경로로 그대로 옮길 수 있는 경우, 어댑터는 모든 요청을 단일 와일드카드 라우트로 보내는 대신 Fastify 네이티브 per-route 핸들러를 등록합니다.
|
|
129
|
+
fluo 라우트 메타데이터를 Fastify 경로로 그대로 옮길 수 있는 경우, 어댑터는 모든 요청을 단일 와일드카드 라우트로 보내는 대신 Fastify 네이티브 per-route 핸들러를 등록합니다. 의미 보존이 가능한 unversioned route에서는 Fastify가 미리 고른 descriptor와 params를 공유 fluo dispatcher에 전달하므로 duplicate route matching을 건너뛰면서도 middleware, guards, interceptors, observers, SSE, multipart, raw body, streaming, error handling 의미론은 그대로 유지됩니다.
|
|
130
130
|
|
|
131
|
-
여러 라우트가 같은 method와 정규화된 param shape를 공유하는 경우(예: `/:id` 와 `/:slug`),
|
|
131
|
+
여러 라우트가 같은 method와 정규화된 param shape를 공유하는 경우(예: `/:id` 와 `/:slug`), `@All(...)`을 사용하는 경우, non-URI versioning에 의존하는 경우, 또는 duplicate slash / trailing slash 변형으로 들어온 경우에는 어댑터가 해당 요청을 의도적으로 와일드카드 fallback 경로에 남겨 둡니다. 이렇게 해서 Fastify 등록 단계에서 부팅 실패가 나거나 fluo의 등록 순서 기반 매칭 의미론이 좁아지지 않도록 보장합니다. app middleware가 native handoff 이후 framework request의 method 또는 path를 rewrite하면 dispatcher는 stale handoff를 무시하고 rewrite된 요청을 다시 매칭합니다.
|
|
132
132
|
|
|
133
|
-
어댑터는 매칭되지 않은 경로와 이식성에 민감한 경우를 위해 와일드카드 fallback 라우트를 계속 유지하며, Fastify의 trailing slash / duplicate slash 정규화를 켜서 네이티브 선택 경로도 fluo의 문서화된 route path 계약과 맞추어 동작하도록 합니다.
|
|
133
|
+
어댑터는 매칭되지 않은 경로와 이식성에 민감한 경우를 위해 와일드카드 fallback 라우트를 계속 유지하며, Fastify의 trailing slash / duplicate slash 정규화를 켜서 네이티브 선택 경로도 fluo의 문서화된 route path 계약과 맞추어 동작하도록 합니다. CORS 처리는 Fastify 플러그인이 아니라 fluo의 공유 middleware 경로가 계속 소유하고, `OPTIONS` 같은 미지원 메서드는 fluo route가 명시적으로 소유하지 않는 한 fallback dispatcher 경로로 흐릅니다.
|
|
134
134
|
|
|
135
135
|
## 성능
|
|
136
136
|
|
package/README.md
CHANGED
|
@@ -126,11 +126,11 @@ await bootstrapFastifyApplication(AppModule, {
|
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
### Native Route Registration with Safe Fallback
|
|
129
|
-
When fluo route metadata can be translated directly, the adapter registers Fastify-native per-route handlers instead of sending every request through a single wildcard route.
|
|
129
|
+
When fluo route metadata can be translated directly, the adapter registers Fastify-native per-route handlers instead of sending every request through a single wildcard route. For semantically safe unversioned routes, those native handlers hand a pre-matched descriptor and params to the shared fluo dispatcher so duplicate route matching is skipped without changing framework-owned guards, interceptors, observers, SSE, multipart, raw body, streaming, or error handling.
|
|
130
130
|
|
|
131
|
-
When multiple routes share the same method and normalized param shape (for example `/:id` and `/:slug`), the adapter intentionally leaves
|
|
131
|
+
When multiple routes share the same method and normalized param shape (for example `/:id` and `/:slug`), use `@All(...)`, depend on non-URI versioning, or arrive through duplicate-slash / trailing-slash variants, the adapter intentionally leaves those requests on the wildcard fallback path so Fastify registration cannot boot-fail or narrow fluo's matching semantics. If app middleware rewrites the framework request method or path after a native handoff was attached, the dispatcher ignores that stale handoff and rematches the rewritten request.
|
|
132
132
|
|
|
133
|
-
The adapter keeps a wildcard fallback route for unmatched paths and portability-sensitive cases, and enables Fastify trailing-slash / duplicate-slash normalization so native selection stays aligned with fluo's documented route path contract.
|
|
133
|
+
The adapter keeps a wildcard fallback route for unmatched paths and portability-sensitive cases, and enables Fastify trailing-slash / duplicate-slash normalization so native selection stays aligned with fluo's documented route path contract. CORS handling remains owned by fluo's shared middleware path rather than Fastify plugins, and unsupported methods such as `OPTIONS` continue through the fallback dispatcher path unless a fluo route explicitly owns them.
|
|
134
134
|
|
|
135
135
|
## Performance
|
|
136
136
|
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,IAAI,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAOtE,OAAO,EAOL,KAAK,WAAW,EAChB,KAAK,UAAU,EAIf,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,IAAI,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAOtE,OAAO,EAOL,KAAK,WAAW,EAChB,KAAK,UAAU,EAIf,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;AAOtB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAC;AAczB,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,gBAAgB;QACxB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;QACvB,OAAO,CAAC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AAI,CAAC;IAM7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAyBd,wBAAwB;IAiBtC,OAAO,CAAC,oBAAoB;IAsB5B,OAAO,CAAC,6BAA6B;YAMvB,eAAe;YAkBf,aAAa;CAS5B;AA6GD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,qBAA0B,EACnC,gBAAgB,CAAC,EAAE,gBAAgB,GAClC,sBAAsB,CAYxB;AAED;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,kCAAkC,GAC1C,OAAO,CAAC,WAAW,CAAC,CAMtB;AAED;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,WAAW,CAAC,CAQtB;AA8SD;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAgBvE"}
|
package/dist/adapter.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Transform } from 'node:stream';
|
|
|
2
2
|
import multipart from '@fastify/multipart';
|
|
3
3
|
import fastify from 'fastify';
|
|
4
4
|
import { createServerBackedHttpAdapterRealtimeCapability, createErrorResponse, HttpException, InternalServerErrorException, PayloadTooLargeException } from '@fluojs/http';
|
|
5
|
+
import { attachFrameworkRequestNativeRouteHandoff, bindRawRequestNativeRouteHandoff, consumeRawRequestNativeRouteHandoff, isRoutePathNormalizationSensitive } from '@fluojs/http/internal';
|
|
5
6
|
import { createNodeShutdownSignalRegistration, defaultNodeShutdownSignals } from '@fluojs/runtime/node';
|
|
6
7
|
import { bootstrapHttpAdapterApplication, runHttpAdapterApplication } from '@fluojs/runtime/internal/http-adapter';
|
|
7
8
|
import { dispatchWithRequestResponseFactory } from '@fluojs/runtime/internal/request-response-factory';
|
|
@@ -16,7 +17,7 @@ import { dispatchWithRequestResponseFactory } from '@fluojs/runtime/internal/req
|
|
|
16
17
|
|
|
17
18
|
const DEFAULT_MAX_BODY_SIZE = 1 * 1024 * 1024;
|
|
18
19
|
const DEFAULT_SHUTDOWN_TIMEOUT_MS = 10_000;
|
|
19
|
-
const FASTIFY_NATIVE_ROUTE_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', '
|
|
20
|
+
const FASTIFY_NATIVE_ROUTE_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'];
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Bootstrap options for creating a Fastify-backed application without
|
|
@@ -102,6 +103,14 @@ export class FastifyHttpApplicationAdapter {
|
|
|
102
103
|
for (const route of createFastifyNativeRoutes(descriptors)) {
|
|
103
104
|
this.app.route({
|
|
104
105
|
handler: async (request, reply) => {
|
|
106
|
+
const requestPath = readRequestPathFromRawUrl(request.raw.url);
|
|
107
|
+
const params = normalizeNativeRouteParams(request.params);
|
|
108
|
+
if (!isRoutePathNormalizationSensitive(requestPath) && !hasNativeRouteParamSeparators(params)) {
|
|
109
|
+
bindRawRequestNativeRouteHandoff(request.raw, {
|
|
110
|
+
descriptor: route.descriptor,
|
|
111
|
+
params
|
|
112
|
+
});
|
|
113
|
+
}
|
|
105
114
|
await this.handleRequest(request, reply);
|
|
106
115
|
},
|
|
107
116
|
method: route.method,
|
|
@@ -167,29 +176,34 @@ function resolveDispatcherRouteDescriptors(dispatcher) {
|
|
|
167
176
|
function createFastifyNativeRoutes(descriptors) {
|
|
168
177
|
const candidates = new Map();
|
|
169
178
|
const shapePaths = new Map();
|
|
179
|
+
const versionSensitiveRouteKeys = collectVersionSensitiveRouteKeys(descriptors);
|
|
170
180
|
for (const descriptor of descriptors) {
|
|
171
|
-
|
|
172
|
-
if (descriptor.route.method === 'ALL') {
|
|
173
|
-
for (const method of FASTIFY_NATIVE_ROUTE_METHODS) {
|
|
174
|
-
registerFastifyNativeRouteCandidate(candidates, shapePaths, method, path);
|
|
175
|
-
}
|
|
181
|
+
if (!isFastifyNativeRouteDescriptor(descriptor) || versionSensitiveRouteKeys.has(`${descriptor.route.method}:${descriptor.route.path}`)) {
|
|
176
182
|
continue;
|
|
177
183
|
}
|
|
178
|
-
registerFastifyNativeRouteCandidate(candidates, shapePaths, descriptor
|
|
184
|
+
registerFastifyNativeRouteCandidate(candidates, shapePaths, descriptor);
|
|
179
185
|
}
|
|
180
186
|
return [...candidates.values()].filter(candidate => shapePaths.get(candidate.shapeKey)?.size === 1).map(({
|
|
187
|
+
descriptor,
|
|
181
188
|
method,
|
|
182
189
|
path
|
|
183
190
|
}) => ({
|
|
191
|
+
descriptor,
|
|
184
192
|
method,
|
|
185
193
|
path
|
|
186
194
|
}));
|
|
187
195
|
}
|
|
188
|
-
function
|
|
196
|
+
function isFastifyNativeRouteDescriptor(descriptor) {
|
|
197
|
+
return descriptor.route.method !== 'ALL' && FASTIFY_NATIVE_ROUTE_METHODS.includes(descriptor.route.method) && descriptor.route.version === undefined;
|
|
198
|
+
}
|
|
199
|
+
function registerFastifyNativeRouteCandidate(candidates, shapePaths, descriptor) {
|
|
200
|
+
const method = descriptor.route.method;
|
|
201
|
+
const path = descriptor.route.path;
|
|
189
202
|
const routeKey = `${method}:${path}`;
|
|
190
203
|
const shapeKey = `${method}:${canonicalizeFastifyRouteShape(path)}`;
|
|
191
204
|
if (!candidates.has(routeKey)) {
|
|
192
205
|
candidates.set(routeKey, {
|
|
206
|
+
descriptor,
|
|
193
207
|
method,
|
|
194
208
|
path,
|
|
195
209
|
shapeKey
|
|
@@ -278,6 +292,18 @@ function createFrameworkResponse(reply) {
|
|
|
278
292
|
this.committed = true;
|
|
279
293
|
await reply.send(serialized.payload);
|
|
280
294
|
},
|
|
295
|
+
async sendSimpleJson(body) {
|
|
296
|
+
if (reply.sent) {
|
|
297
|
+
this.committed = true;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const serialized = serializeResponseBody(body);
|
|
301
|
+
if (!reply.hasHeader('content-type') && serialized.defaultContentType) {
|
|
302
|
+
reply.header('content-type', serialized.defaultContentType);
|
|
303
|
+
}
|
|
304
|
+
this.committed = true;
|
|
305
|
+
await reply.send(serialized.payload);
|
|
306
|
+
},
|
|
281
307
|
setHeader(name, value) {
|
|
282
308
|
const lowerName = name.toLowerCase();
|
|
283
309
|
if (lowerName === 'set-cookie') {
|
|
@@ -392,7 +418,37 @@ async function createFrameworkRequest(request, signal, multipartOptions, maxBody
|
|
|
392
418
|
frameworkRequest.rawBody = rawBodyValue;
|
|
393
419
|
}
|
|
394
420
|
}
|
|
395
|
-
|
|
421
|
+
const nativeRouteHandoff = consumeRawRequestNativeRouteHandoff(request.raw);
|
|
422
|
+
return nativeRouteHandoff ? attachFrameworkRequestNativeRouteHandoff(frameworkRequest, nativeRouteHandoff) : frameworkRequest;
|
|
423
|
+
}
|
|
424
|
+
function normalizeNativeRouteParams(params) {
|
|
425
|
+
if (typeof params !== 'object' || params === null) {
|
|
426
|
+
return {};
|
|
427
|
+
}
|
|
428
|
+
return Object.fromEntries(Object.entries(params).flatMap(([key, value]) => typeof value === 'string' ? [[key, value]] : value === undefined ? [] : [[key, String(value)]]));
|
|
429
|
+
}
|
|
430
|
+
function hasNativeRouteParamSeparators(params) {
|
|
431
|
+
return Object.values(params).some(value => value.includes('/'));
|
|
432
|
+
}
|
|
433
|
+
function collectVersionSensitiveRouteKeys(descriptors) {
|
|
434
|
+
const grouped = new Map();
|
|
435
|
+
for (const descriptor of descriptors) {
|
|
436
|
+
if (!FASTIFY_NATIVE_ROUTE_METHODS.includes(descriptor.route.method)) {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
const routeKey = `${descriptor.route.method}:${descriptor.route.path}`;
|
|
440
|
+
const current = grouped.get(routeKey) ?? {
|
|
441
|
+
count: 0,
|
|
442
|
+
hasVersioned: false
|
|
443
|
+
};
|
|
444
|
+
current.count += 1;
|
|
445
|
+
current.hasVersioned ||= descriptor.route.version !== undefined;
|
|
446
|
+
grouped.set(routeKey, current);
|
|
447
|
+
}
|
|
448
|
+
return new Set([...grouped.entries()].filter(([, current]) => current.count > 1 || current.hasVersioned).map(([routeKey]) => routeKey));
|
|
449
|
+
}
|
|
450
|
+
function readRequestPathFromRawUrl(rawUrl) {
|
|
451
|
+
return new URL(rawUrl ?? '/', 'http://localhost').pathname;
|
|
396
452
|
}
|
|
397
453
|
async function parseMultipartRequest(request, options = {}) {
|
|
398
454
|
const fields = {};
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"platform",
|
|
9
9
|
"server"
|
|
10
10
|
],
|
|
11
|
-
"version": "1.0.0-beta.
|
|
11
|
+
"version": "1.0.0-beta.5",
|
|
12
12
|
"private": false,
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
@@ -38,11 +38,12 @@
|
|
|
38
38
|
"@fastify/multipart": "^9.2.1",
|
|
39
39
|
"fastify": "^5.8.5",
|
|
40
40
|
"fastify-raw-body": "^5.0.0",
|
|
41
|
-
"@fluojs/http": "^1.0.0-beta.
|
|
42
|
-
"@fluojs/runtime": "^1.0.0-beta.
|
|
41
|
+
"@fluojs/http": "^1.0.0-beta.4",
|
|
42
|
+
"@fluojs/runtime": "^1.0.0-beta.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"vitest": "^3.2.4"
|
|
45
|
+
"vitest": "^3.2.4",
|
|
46
|
+
"@fluojs/di": "^1.0.0-beta.5"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"prebuild": "node ../../tooling/scripts/clean-dist.mjs",
|