@fluojs/runtime 1.0.0-beta.7 → 1.0.0-beta.8
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.
|
@@ -16,7 +16,8 @@ export interface DeferredFrameworkRequestShellOptions<RawRequest> {
|
|
|
16
16
|
query?: QueryRecord;
|
|
17
17
|
queryFactory?: () => QueryRecord;
|
|
18
18
|
raw: RawRequest;
|
|
19
|
-
|
|
19
|
+
requestId?: string;
|
|
20
|
+
signal: AbortSignal | (() => AbortSignal);
|
|
20
21
|
url: string;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
@@ -55,7 +56,7 @@ export declare function createDeferredFrameworkRequest(request: IncomingMessage,
|
|
|
55
56
|
* @param options - Raw request, metadata factories, and deferred body materialization hooks.
|
|
56
57
|
* @returns A framework request with lazy headers, cookies, query values, and optional body materialization.
|
|
57
58
|
*/
|
|
58
|
-
export declare function createDeferredFrameworkRequestShell<RawRequest>({ cookieHeader, headers, headersFactory, materializeBody, method, path, query, queryFactory, raw, signal, url, }: DeferredFrameworkRequestShellOptions<RawRequest>): FrameworkRequest;
|
|
59
|
+
export declare function createDeferredFrameworkRequestShell<RawRequest>({ cookieHeader, headers, headersFactory, materializeBody, method, path, query, queryFactory, raw, requestId, signal, url, }: DeferredFrameworkRequestShellOptions<RawRequest>): FrameworkRequest;
|
|
59
60
|
/**
|
|
60
61
|
* Materializes a deferred Node framework request body exactly once.
|
|
61
62
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-node-request.d.ts","sourceRoot":"","sources":["../../src/node/internal-node-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,cAAc,EACf,MAAM,WAAW,CAAC;AAInB,OAAO,EAEL,wBAAwB,EACxB,KAAK,gBAAgB,EACtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AA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AG,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAW1G;AAUD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsBrG;AAoDD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAuB/F;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAQ5E"}
|
|
@@ -94,6 +94,7 @@ export function createDeferredFrameworkRequest(request, signal, multipartOptions
|
|
|
94
94
|
path: urlParts.path,
|
|
95
95
|
queryFactory: () => parseQueryParamsFromSearch(urlParts.search),
|
|
96
96
|
raw: request,
|
|
97
|
+
requestId: resolvePrimaryRequestIdFromHeaders(headers),
|
|
97
98
|
signal,
|
|
98
99
|
url: urlParts.path + urlParts.search
|
|
99
100
|
});
|
|
@@ -116,12 +117,15 @@ export function createDeferredFrameworkRequestShell({
|
|
|
116
117
|
query,
|
|
117
118
|
queryFactory,
|
|
118
119
|
raw,
|
|
120
|
+
requestId,
|
|
119
121
|
signal,
|
|
120
122
|
url
|
|
121
123
|
}) {
|
|
124
|
+
const hasQuerySnapshot = query !== undefined;
|
|
125
|
+
const hasLazySignal = typeof signal === 'function';
|
|
122
126
|
const resolveHeaders = headersFactory ? createMemoizedValue(headersFactory) : () => headers ?? {};
|
|
123
127
|
const resolveCookies = createMemoizedValue(() => parseCookieHeader(cookieHeader ?? resolveHeaders().cookie));
|
|
124
|
-
const resolveQuery = createMemoizedValue(() =>
|
|
128
|
+
const resolveQuery = hasQuerySnapshot ? undefined : createMemoizedValue(() => queryFactory?.() ?? {});
|
|
125
129
|
const frameworkRequest = {
|
|
126
130
|
get cookies() {
|
|
127
131
|
return resolveCookies();
|
|
@@ -132,13 +136,32 @@ export function createDeferredFrameworkRequestShell({
|
|
|
132
136
|
method: method ?? 'GET',
|
|
133
137
|
params: {},
|
|
134
138
|
path,
|
|
135
|
-
|
|
136
|
-
return resolveQuery();
|
|
137
|
-
},
|
|
139
|
+
requestId,
|
|
138
140
|
raw,
|
|
139
|
-
signal,
|
|
140
141
|
url
|
|
141
142
|
};
|
|
143
|
+
if (hasLazySignal) {
|
|
144
|
+
Object.defineProperty(frameworkRequest, 'signal', {
|
|
145
|
+
configurable: true,
|
|
146
|
+
enumerable: true,
|
|
147
|
+
get() {
|
|
148
|
+
return signal();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
frameworkRequest.signal = signal;
|
|
153
|
+
}
|
|
154
|
+
if (hasQuerySnapshot) {
|
|
155
|
+
frameworkRequest.query = query;
|
|
156
|
+
} else {
|
|
157
|
+
Object.defineProperty(frameworkRequest, 'query', {
|
|
158
|
+
configurable: true,
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get() {
|
|
161
|
+
return resolveQuery();
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
142
165
|
if (materializeBody) {
|
|
143
166
|
frameworkRequest.materializeBody = materializeBody;
|
|
144
167
|
}
|
|
@@ -232,6 +255,10 @@ export function resolveRequestIdFromHeaders(headers) {
|
|
|
232
255
|
const requestId = headers['x-request-id'] ?? headers['x-correlation-id'];
|
|
233
256
|
return Array.isArray(requestId) ? requestId[0] : requestId;
|
|
234
257
|
}
|
|
258
|
+
function resolvePrimaryRequestIdFromHeaders(headers) {
|
|
259
|
+
const requestId = headers['x-request-id'];
|
|
260
|
+
return Array.isArray(requestId) ? requestId[0] : requestId;
|
|
261
|
+
}
|
|
235
262
|
|
|
236
263
|
/**
|
|
237
264
|
* Parses a raw URL search string into the framework query shape.
|
package/dist/web.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ declare module '@fluojs/http' {
|
|
|
11
11
|
* Configures Web request parsing, multipart handling, and raw body preservation.
|
|
12
12
|
*/
|
|
13
13
|
export interface CreateWebRequestResponseFactoryOptions {
|
|
14
|
+
consumeOriginalBody?: boolean;
|
|
14
15
|
maxBodySize?: number;
|
|
15
16
|
multipart?: MultipartOptions;
|
|
17
|
+
preferNativeJsonBodyReader?: boolean;
|
|
16
18
|
rawBody?: boolean;
|
|
17
19
|
}
|
|
18
20
|
/**
|
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAMtB,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,wCAAwC,CAAC;AAEhD,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,gBAAgB;QACxB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;QACvB,OAAO,CAAC,EAAE,UAAU,CAAC;KACtB;CACF;AAOD;;GAEG;AACH,MAAM,WAAW,sCAAsC;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,sCAAsC;IACvF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;OAIG;IACH,OAAO,CAAC,EAAE,sBAAsB,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,oBAAoB,CAAC,CAAC;IACzF,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM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AAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,UAAU,IAAI,QAAQ,CAAC;CACxB;AAED,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAgNhD;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,GAAE,sCAA2C,GACnD,sBAAsB,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,oBAAoB,CAAC,CA+BhF;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,UAAU,EACV,yBAAiG,EACjG,OAAO,EACP,OAAO,EACP,GAAG,OAAO,EACX,EAAE,yBAAyB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAU/C;AAED;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,EACnB,gBAAgB,CAAC,EAAE,gBAAgB,EACnC,WAAW,SAAwB,EACnC,eAAe,UAAQ,GACtB,OAAO,CAAC,gBAAgB,CAAC,CAW3B"}
|
package/dist/web.js
CHANGED
|
@@ -170,7 +170,7 @@ class MutableWebFrameworkResponse {
|
|
|
170
170
|
export function createWebRequestResponseFactory(options = {}) {
|
|
171
171
|
return {
|
|
172
172
|
async createRequest(request, signal) {
|
|
173
|
-
return createDeferredWebFrameworkRequest(request, signal, options.multipart, options.maxBodySize ?? DEFAULT_MAX_BODY_SIZE, options.rawBody ?? false);
|
|
173
|
+
return createDeferredWebFrameworkRequest(request, signal, options.multipart, options.maxBodySize ?? DEFAULT_MAX_BODY_SIZE, options.rawBody ?? false, options.preferNativeJsonBodyReader ?? false, options.consumeOriginalBody ?? false);
|
|
174
174
|
},
|
|
175
175
|
materializeRequest(request) {
|
|
176
176
|
return materializeWebFrameworkRequestBody(request);
|
|
@@ -241,7 +241,7 @@ export async function createWebFrameworkRequest(request, signal, multipartOption
|
|
|
241
241
|
* @param preserveRawBody - Whether materialization should retain raw request body bytes.
|
|
242
242
|
* @returns The framework request shell with metadata snapshotted and body materialization deferred.
|
|
243
243
|
*/
|
|
244
|
-
function createDeferredWebFrameworkRequest(request, signal, multipartOptions, maxBodySize = DEFAULT_MAX_BODY_SIZE, preserveRawBody = false) {
|
|
244
|
+
function createDeferredWebFrameworkRequest(request, signal, multipartOptions, maxBodySize = DEFAULT_MAX_BODY_SIZE, preserveRawBody = false, preferNativeJsonBodyReader = false, consumeOriginalBody = false) {
|
|
245
245
|
const url = new URL(request.url);
|
|
246
246
|
const requestHeaders = new Headers(request.headers);
|
|
247
247
|
const method = request.method;
|
|
@@ -250,15 +250,11 @@ function createDeferredWebFrameworkRequest(request, signal, multipartOptions, ma
|
|
|
250
250
|
const query = createMemoizedValue(() => parseQueryString(url.search));
|
|
251
251
|
const contentType = requestHeaders.get('content-type') ?? undefined;
|
|
252
252
|
const isMultipart = typeof contentType === 'string' && contentType.includes('multipart/form-data');
|
|
253
|
-
const
|
|
253
|
+
const hasRequestBody = request.body !== null;
|
|
254
|
+
const materializeBody = hasRequestBody ? createMemoizedAsyncValue(async () => {
|
|
254
255
|
if (isMultipart) {
|
|
255
256
|
const materializedRequest = request.clone();
|
|
256
|
-
const result = await parseMultipart({
|
|
257
|
-
body: materializedRequest.body,
|
|
258
|
-
headers: requestHeaders,
|
|
259
|
-
method,
|
|
260
|
-
url: request.url
|
|
261
|
-
}, {
|
|
257
|
+
const result = await parseMultipart(createRequestWithSnapshotMetadata(materializedRequest, request.url, method, requestHeaders), {
|
|
262
258
|
...multipartOptions,
|
|
263
259
|
maxTotalSize: multipartOptions?.maxTotalSize ?? maxBodySize
|
|
264
260
|
});
|
|
@@ -271,12 +267,13 @@ function createDeferredWebFrameworkRequest(request, signal, multipartOptions, ma
|
|
|
271
267
|
frameworkRequest.body = undefined;
|
|
272
268
|
return;
|
|
273
269
|
}
|
|
274
|
-
const
|
|
270
|
+
const requestToRead = consumeOriginalBody ? request : request.clone();
|
|
271
|
+
const bodyResult = await readWebRequestBody(requestToRead, contentType, maxBodySize, preserveRawBody, preferNativeJsonBodyReader);
|
|
275
272
|
frameworkRequest.body = bodyResult.body;
|
|
276
273
|
if (bodyResult.rawBody) {
|
|
277
274
|
frameworkRequest.rawBody = bodyResult.rawBody;
|
|
278
275
|
}
|
|
279
|
-
});
|
|
276
|
+
}) : undefined;
|
|
280
277
|
const frameworkRequest = {
|
|
281
278
|
get cookies() {
|
|
282
279
|
return cookies();
|
|
@@ -291,13 +288,28 @@ function createDeferredWebFrameworkRequest(request, signal, multipartOptions, ma
|
|
|
291
288
|
return query();
|
|
292
289
|
},
|
|
293
290
|
raw: request,
|
|
291
|
+
requestId: requestHeaders.get('x-request-id') ?? undefined,
|
|
294
292
|
signal,
|
|
295
293
|
url: url.pathname + url.search,
|
|
296
294
|
materializeBody
|
|
297
295
|
};
|
|
296
|
+
if (!hasRequestBody) {
|
|
297
|
+
frameworkRequest.body = undefined;
|
|
298
|
+
}
|
|
298
299
|
const nativeRouteHandoff = consumeRawRequestNativeRouteHandoff(request);
|
|
299
300
|
return nativeRouteHandoff ? attachFrameworkRequestNativeRouteHandoff(frameworkRequest, nativeRouteHandoff) : frameworkRequest;
|
|
300
301
|
}
|
|
302
|
+
function createRequestWithSnapshotMetadata(request, url, method, headers) {
|
|
303
|
+
const init = {
|
|
304
|
+
headers: new Headers(headers),
|
|
305
|
+
method
|
|
306
|
+
};
|
|
307
|
+
if (request.body) {
|
|
308
|
+
init.body = request.body;
|
|
309
|
+
init.duplex = 'half';
|
|
310
|
+
}
|
|
311
|
+
return new Request(url, init);
|
|
312
|
+
}
|
|
301
313
|
function validateWebRequestContentLength(request, maxBodySize) {
|
|
302
314
|
const contentLength = request.headers.get('content-length');
|
|
303
315
|
if (contentLength === null) {
|
|
@@ -410,14 +422,23 @@ function parseCookieHeader(cookieHeader) {
|
|
|
410
422
|
return [pair.slice(0, index).trim(), decodeCookieValue(pair.slice(index + 1).trim())];
|
|
411
423
|
}));
|
|
412
424
|
}
|
|
413
|
-
async function readWebRequestBody(request, contentType, maxBodySize = DEFAULT_MAX_BODY_SIZE, preserveRawBody = false) {
|
|
425
|
+
async function readWebRequestBody(request, contentType, maxBodySize = DEFAULT_MAX_BODY_SIZE, preserveRawBody = false, preferNativeJsonBodyReader = false) {
|
|
414
426
|
validateWebRequestContentLength(request, maxBodySize);
|
|
415
427
|
if (!request.body) {
|
|
416
428
|
return {
|
|
417
429
|
body: undefined
|
|
418
430
|
};
|
|
419
431
|
}
|
|
420
|
-
|
|
432
|
+
if (!preserveRawBody && isJsonContentType(contentType) && (preferNativeJsonBodyReader || isContentLengthWithinLimit(request, maxBodySize))) {
|
|
433
|
+
const rawBody = new Uint8Array(await request.arrayBuffer());
|
|
434
|
+
if (rawBody.byteLength > maxBodySize) {
|
|
435
|
+
throw new PayloadTooLargeException(REQUEST_BODY_LIMIT_MESSAGE);
|
|
436
|
+
}
|
|
437
|
+
return parseWebRequestRawBody(rawBody, contentType, preserveRawBody);
|
|
438
|
+
}
|
|
439
|
+
return parseWebRequestRawBody(await readByteLimitedStream(request.body, maxBodySize), contentType, preserveRawBody);
|
|
440
|
+
}
|
|
441
|
+
function parseWebRequestRawBody(rawBody, contentType, preserveRawBody) {
|
|
421
442
|
if (rawBody.byteLength === 0) {
|
|
422
443
|
return {
|
|
423
444
|
body: undefined
|
|
@@ -430,7 +451,7 @@ async function readWebRequestBody(request, contentType, maxBodySize = DEFAULT_MA
|
|
|
430
451
|
rawBody: preserveRawBody ? rawBody : undefined
|
|
431
452
|
};
|
|
432
453
|
}
|
|
433
|
-
if (
|
|
454
|
+
if (isJsonContentType(contentType)) {
|
|
434
455
|
try {
|
|
435
456
|
return {
|
|
436
457
|
body: JSON.parse(bodyText),
|
|
@@ -445,6 +466,14 @@ async function readWebRequestBody(request, contentType, maxBodySize = DEFAULT_MA
|
|
|
445
466
|
rawBody: preserveRawBody ? rawBody : undefined
|
|
446
467
|
};
|
|
447
468
|
}
|
|
469
|
+
function isContentLengthWithinLimit(request, maxBodySize) {
|
|
470
|
+
const contentLength = request.headers.get('content-length');
|
|
471
|
+
if (contentLength === null) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
const parsedContentLength = Number(contentLength);
|
|
475
|
+
return Number.isFinite(parsedContentLength) && parsedContentLength > 0 && parsedContentLength <= maxBodySize;
|
|
476
|
+
}
|
|
448
477
|
async function readByteLimitedStream(stream, maxBodySize) {
|
|
449
478
|
const reader = stream.getReader();
|
|
450
479
|
const chunks = [];
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"module-graph",
|
|
10
10
|
"orchestration"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.0-beta.
|
|
12
|
+
"version": "1.0.0-beta.8",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@fluojs/config": "^1.0.0-beta.3",
|
|
71
71
|
"@fluojs/core": "^1.0.0-beta.2",
|
|
72
72
|
"@fluojs/di": "^1.0.0-beta.5",
|
|
73
|
-
"@fluojs/http": "^1.0.0-beta.
|
|
73
|
+
"@fluojs/http": "^1.0.0-beta.6"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"vitest": "^3.2.4",
|