@faapi/faapi 6.10.0 → 6.11.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/dist/cli/index.js +59 -33
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +60 -33
- package/dist/index.js.map +1 -1
- package/dist/testing.js +42 -20
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/testing.js
CHANGED
|
@@ -271,20 +271,32 @@ function formatEntry(entry) {
|
|
|
271
271
|
|
|
272
272
|
// src/logger/logger.ts
|
|
273
273
|
var LEVEL_RANK = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
274
|
-
var
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
274
|
+
var LOGGING_STATE_KEY = /* @__PURE__ */ Symbol.for("faapi.logger.state");
|
|
275
|
+
function createDefaultLoggingState() {
|
|
276
|
+
return {
|
|
277
|
+
level: null,
|
|
278
|
+
consoleLevel: null,
|
|
279
|
+
sink: null,
|
|
280
|
+
fileSink: null,
|
|
281
|
+
stdout: true,
|
|
282
|
+
accessLog: true,
|
|
283
|
+
disabled: false
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function getLoggingState() {
|
|
287
|
+
const g = globalThis;
|
|
288
|
+
let state2 = g[LOGGING_STATE_KEY];
|
|
289
|
+
if (!state2) {
|
|
290
|
+
state2 = createDefaultLoggingState();
|
|
291
|
+
g[LOGGING_STATE_KEY] = state2;
|
|
292
|
+
}
|
|
293
|
+
return state2;
|
|
294
|
+
}
|
|
283
295
|
function pipelineThreshold() {
|
|
284
|
-
return
|
|
296
|
+
return getLoggingState().level ?? void 0;
|
|
285
297
|
}
|
|
286
298
|
function consoleThreshold() {
|
|
287
|
-
return
|
|
299
|
+
return getLoggingState().consoleLevel ?? "info";
|
|
288
300
|
}
|
|
289
301
|
function belowThreshold(level, threshold) {
|
|
290
302
|
return threshold !== void 0 && LEVEL_RANK[level] < LEVEL_RANK[threshold];
|
|
@@ -301,15 +313,16 @@ function consoleDispatch(entry) {
|
|
|
301
313
|
console[CONSOLE_METHOD[entry.level]](formatEntry(entry));
|
|
302
314
|
}
|
|
303
315
|
function globalDispatch(entry) {
|
|
304
|
-
|
|
316
|
+
const state2 = getLoggingState();
|
|
317
|
+
if (state2.disabled) return;
|
|
305
318
|
const pipeThreshold = pipelineThreshold();
|
|
306
|
-
if (
|
|
307
|
-
if (!belowThreshold(entry.level, pipeThreshold))
|
|
319
|
+
if (state2.sink) {
|
|
320
|
+
if (!belowThreshold(entry.level, pipeThreshold)) state2.sink(entry);
|
|
308
321
|
return;
|
|
309
322
|
}
|
|
310
|
-
if (
|
|
311
|
-
if (!belowThreshold(entry.level, pipeThreshold))
|
|
312
|
-
if (
|
|
323
|
+
if (state2.fileSink) {
|
|
324
|
+
if (!belowThreshold(entry.level, pipeThreshold)) state2.fileSink.write(entry);
|
|
325
|
+
if (state2.stdout) consoleDispatch(entry);
|
|
313
326
|
return;
|
|
314
327
|
}
|
|
315
328
|
consoleDispatch(entry);
|
|
@@ -318,7 +331,8 @@ function writeLogEntry(entry) {
|
|
|
318
331
|
globalDispatch(entry);
|
|
319
332
|
}
|
|
320
333
|
function isAccessLogEnabled() {
|
|
321
|
-
|
|
334
|
+
const state2 = getLoggingState();
|
|
335
|
+
return !state2.disabled && state2.accessLog;
|
|
322
336
|
}
|
|
323
337
|
function createLogger(scope, options) {
|
|
324
338
|
const baseScope = scope;
|
|
@@ -1022,6 +1036,9 @@ async function injectParamsAsync(handler, ctx, body, injectors) {
|
|
|
1022
1036
|
function wrapResult(result, ctx) {
|
|
1023
1037
|
return wrapOkResult(result, ctx.config);
|
|
1024
1038
|
}
|
|
1039
|
+
function stashHandlerResult(ctx, result) {
|
|
1040
|
+
ctx.__faapiHandlerResult = result;
|
|
1041
|
+
}
|
|
1025
1042
|
function mergeMeta(response, meta) {
|
|
1026
1043
|
const hasMeta = meta.status !== void 0 || Object.keys(meta.headers).length > 0 || meta.setCookies.length > 0;
|
|
1027
1044
|
if (!hasMeta) return response;
|
|
@@ -1090,7 +1107,9 @@ async function invokeHandler(handler, ctx, body, middlewares, injectors) {
|
|
|
1090
1107
|
const result = await injectParamsAsync(handler, ctx, body, injectors);
|
|
1091
1108
|
const sseResponse = pickSseAndAutoClose();
|
|
1092
1109
|
if (sseResponse) return sseResponse;
|
|
1093
|
-
|
|
1110
|
+
const response = await toResponse(wrapResult(result, ctx), meta);
|
|
1111
|
+
if (!(result instanceof Response)) stashHandlerResult(ctx, result);
|
|
1112
|
+
return response;
|
|
1094
1113
|
} catch (err) {
|
|
1095
1114
|
autoCloseSseOnError();
|
|
1096
1115
|
throw err;
|
|
@@ -1101,7 +1120,9 @@ async function invokeHandler(handler, ctx, body, middlewares, injectors) {
|
|
|
1101
1120
|
const result = await injectParamsAsync(handler, ctx, body, injectors);
|
|
1102
1121
|
const sseResponse = pickSseAndAutoClose();
|
|
1103
1122
|
if (sseResponse) return sseResponse;
|
|
1104
|
-
|
|
1123
|
+
const response = await toResponse(wrapResult(result, ctx), meta);
|
|
1124
|
+
if (!(result instanceof Response)) stashHandlerResult(ctx, result);
|
|
1125
|
+
return response;
|
|
1105
1126
|
} catch (err) {
|
|
1106
1127
|
autoCloseSseOnError();
|
|
1107
1128
|
throw err;
|
|
@@ -4774,6 +4795,7 @@ async function handleRequest(routes, rootDir, dist, req, res, outerMiddlewares,
|
|
|
4774
4795
|
globalInjectors
|
|
4775
4796
|
});
|
|
4776
4797
|
const response = outerMiddlewares.length > 0 ? await compose(outerMiddlewares, ctx, routePipeline) : await routePipeline();
|
|
4798
|
+
res.__faapiHandlerResult = ctx.__faapiHandlerResult;
|
|
4777
4799
|
await sendSuccessResponse(response, res);
|
|
4778
4800
|
} catch (err) {
|
|
4779
4801
|
if (res.destroyed || res.writableEnded) return;
|