@whatwg-node/server 0.10.0 → 0.10.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.
- package/cjs/createServerAdapter.js +8 -6
- package/cjs/index.js +1 -1
- package/esm/createServerAdapter.js +8 -6
- package/esm/index.js +1 -1
- package/package.json +2 -2
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
- package/typings/plugins/types.d.cts +3 -3
- package/typings/plugins/types.d.ts +3 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createServerAdapter = createServerAdapter;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const instrumentation_1 = require("@envelop/instrumentation");
|
|
6
6
|
const disposablestack_1 = require("@whatwg-node/disposablestack");
|
|
7
7
|
const DefaultFetchAPI = tslib_1.__importStar(require("@whatwg-node/fetch"));
|
|
8
8
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
@@ -28,7 +28,7 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
|
28
28
|
: serverAdapterBaseObject.handle;
|
|
29
29
|
const onRequestHooks = [];
|
|
30
30
|
const onResponseHooks = [];
|
|
31
|
-
let
|
|
31
|
+
let instrumentation;
|
|
32
32
|
const waitUntilPromises = new Set();
|
|
33
33
|
let _disposableStack;
|
|
34
34
|
function ensureDisposableStack() {
|
|
@@ -64,8 +64,10 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
|
64
64
|
}
|
|
65
65
|
if (options?.plugins != null) {
|
|
66
66
|
for (const plugin of options.plugins) {
|
|
67
|
-
if (plugin.
|
|
68
|
-
|
|
67
|
+
if (plugin.instrumentation) {
|
|
68
|
+
instrumentation = instrumentation
|
|
69
|
+
? (0, instrumentation_1.chain)(instrumentation, plugin.instrumentation)
|
|
70
|
+
: plugin.instrumentation;
|
|
69
71
|
}
|
|
70
72
|
if (plugin.onRequest) {
|
|
71
73
|
onRequestHooks.push(plugin.onRequest);
|
|
@@ -141,10 +143,10 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
|
141
143
|
})), handleEarlyResponse);
|
|
142
144
|
}
|
|
143
145
|
: givenHandleRequest;
|
|
144
|
-
if (
|
|
146
|
+
if (instrumentation?.request) {
|
|
145
147
|
const originalRequestHandler = handleRequest;
|
|
146
148
|
handleRequest = (request, initialContext) => {
|
|
147
|
-
return (0,
|
|
149
|
+
return (0, instrumentation_1.getInstrumented)({ request }).asyncFn(instrumentation.request, originalRequestHandler)(request, initialContext);
|
|
148
150
|
};
|
|
149
151
|
}
|
|
150
152
|
// TODO: Remove this on the next major version
|
package/cjs/index.js
CHANGED
|
@@ -14,4 +14,4 @@ var fetch_1 = require("@whatwg-node/fetch");
|
|
|
14
14
|
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return fetch_1.Response; } });
|
|
15
15
|
var disposablestack_1 = require("@whatwg-node/disposablestack");
|
|
16
16
|
Object.defineProperty(exports, "DisposableSymbols", { enumerable: true, get: function () { return disposablestack_1.DisposableSymbols; } });
|
|
17
|
-
tslib_1.__exportStar(require("@envelop/
|
|
17
|
+
tslib_1.__exportStar(require("@envelop/instrumentation"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chain, getInstrumented } from '@envelop/
|
|
1
|
+
import { chain, getInstrumented } from '@envelop/instrumentation';
|
|
2
2
|
import { AsyncDisposableStack, DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
3
3
|
import * as DefaultFetchAPI from '@whatwg-node/fetch';
|
|
4
4
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
|
@@ -24,7 +24,7 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
|
24
24
|
: serverAdapterBaseObject.handle;
|
|
25
25
|
const onRequestHooks = [];
|
|
26
26
|
const onResponseHooks = [];
|
|
27
|
-
let
|
|
27
|
+
let instrumentation;
|
|
28
28
|
const waitUntilPromises = new Set();
|
|
29
29
|
let _disposableStack;
|
|
30
30
|
function ensureDisposableStack() {
|
|
@@ -60,8 +60,10 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
|
60
60
|
}
|
|
61
61
|
if (options?.plugins != null) {
|
|
62
62
|
for (const plugin of options.plugins) {
|
|
63
|
-
if (plugin.
|
|
64
|
-
|
|
63
|
+
if (plugin.instrumentation) {
|
|
64
|
+
instrumentation = instrumentation
|
|
65
|
+
? chain(instrumentation, plugin.instrumentation)
|
|
66
|
+
: plugin.instrumentation;
|
|
65
67
|
}
|
|
66
68
|
if (plugin.onRequest) {
|
|
67
69
|
onRequestHooks.push(plugin.onRequest);
|
|
@@ -137,10 +139,10 @@ function createServerAdapter(serverAdapterBaseObject, options) {
|
|
|
137
139
|
})), handleEarlyResponse);
|
|
138
140
|
}
|
|
139
141
|
: givenHandleRequest;
|
|
140
|
-
if (
|
|
142
|
+
if (instrumentation?.request) {
|
|
141
143
|
const originalRequestHandler = handleRequest;
|
|
142
144
|
handleRequest = (request, initialContext) => {
|
|
143
|
-
return getInstrumented({ request }).asyncFn(
|
|
145
|
+
return getInstrumented({ request }).asyncFn(instrumentation.request, originalRequestHandler)(request, initialContext);
|
|
144
146
|
};
|
|
145
147
|
}
|
|
146
148
|
// TODO: Remove this on the next major version
|
package/esm/index.js
CHANGED
|
@@ -8,4 +8,4 @@ export * from './plugins/useContentEncoding.js';
|
|
|
8
8
|
export * from './uwebsockets.js';
|
|
9
9
|
export { Response } from '@whatwg-node/fetch';
|
|
10
10
|
export { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
11
|
-
export * from '@envelop/
|
|
11
|
+
export * from '@envelop/instrumentation';
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whatwg-node/server",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Fetch API compliant HTTP Server adapter",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@envelop/
|
|
7
|
+
"@envelop/instrumentation": "^1.0.0",
|
|
8
8
|
"@whatwg-node/disposablestack": "^0.0.6",
|
|
9
9
|
"@whatwg-node/fetch": "^0.10.5",
|
|
10
10
|
"@whatwg-node/promise-helpers": "^1.2.3",
|
package/typings/index.d.cts
CHANGED
|
@@ -8,4 +8,4 @@ export * from './plugins/useContentEncoding.cjs';
|
|
|
8
8
|
export * from './uwebsockets.cjs';
|
|
9
9
|
export { Response } from '@whatwg-node/fetch';
|
|
10
10
|
export { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
11
|
-
export * from '@envelop/
|
|
11
|
+
export * from '@envelop/instrumentation';
|
package/typings/index.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export * from './plugins/useContentEncoding.js';
|
|
|
8
8
|
export * from './uwebsockets.js';
|
|
9
9
|
export { Response } from '@whatwg-node/fetch';
|
|
10
10
|
export { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
11
|
-
export * from '@envelop/
|
|
11
|
+
export * from '@envelop/instrumentation';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FetchAPI, ServerAdapterRequestHandler, type ServerAdapterInitialContext } from '../types.cjs';
|
|
2
2
|
export interface ServerAdapterPlugin<TServerContext = {}> {
|
|
3
3
|
/**
|
|
4
|
-
* A tracer
|
|
4
|
+
* A tracer instance. It can be used to wrap the entire request handling pipeline (including the
|
|
5
5
|
* plugin hooks). It is mostly used for observability (monitoring, tracing, etc...).
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
instrumentation?: Instrumentation;
|
|
8
8
|
/**
|
|
9
9
|
* This hook is invoked for ANY incoming HTTP request. Here you can manipulate the request,
|
|
10
10
|
* create a short circuit before the request handler takes it over.
|
|
@@ -43,7 +43,7 @@ export interface ServerAdapterPlugin<TServerContext = {}> {
|
|
|
43
43
|
*/
|
|
44
44
|
onDispose?: () => PromiseLike<void> | void;
|
|
45
45
|
}
|
|
46
|
-
export type
|
|
46
|
+
export type Instrumentation = {
|
|
47
47
|
/**
|
|
48
48
|
* Run code befor, after or around the handling of each request.
|
|
49
49
|
* This instrument can't modify result or paramters of the request handling.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FetchAPI, ServerAdapterRequestHandler, type ServerAdapterInitialContext } from '../types.js';
|
|
2
2
|
export interface ServerAdapterPlugin<TServerContext = {}> {
|
|
3
3
|
/**
|
|
4
|
-
* A tracer
|
|
4
|
+
* A tracer instance. It can be used to wrap the entire request handling pipeline (including the
|
|
5
5
|
* plugin hooks). It is mostly used for observability (monitoring, tracing, etc...).
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
instrumentation?: Instrumentation;
|
|
8
8
|
/**
|
|
9
9
|
* This hook is invoked for ANY incoming HTTP request. Here you can manipulate the request,
|
|
10
10
|
* create a short circuit before the request handler takes it over.
|
|
@@ -43,7 +43,7 @@ export interface ServerAdapterPlugin<TServerContext = {}> {
|
|
|
43
43
|
*/
|
|
44
44
|
onDispose?: () => PromiseLike<void> | void;
|
|
45
45
|
}
|
|
46
|
-
export type
|
|
46
|
+
export type Instrumentation = {
|
|
47
47
|
/**
|
|
48
48
|
* Run code befor, after or around the handling of each request.
|
|
49
49
|
* This instrument can't modify result or paramters of the request handling.
|