srvx 0.1.0 → 0.1.2
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.md +1 -1
- package/dist/node-utils/index.d.mts +19 -17
- package/dist/node-utils/index.d.ts +19 -17
- package/dist/node-utils/index.mjs +11 -1
- package/dist/node.mjs +1 -1
- package/dist/shared/{srvx.cb35ffcb.mjs → srvx.2143ff37.mjs} +14 -1
- package/package.json +15 -18
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Universal Server API based on web platform standards. Works with [Deno](https://
|
|
|
11
11
|
|
|
12
12
|
- ✅ Seamless runtime integration with identical usage ([handler](https://srvx.unjs.io/guide/handler) and
|
|
13
13
|
- ✅ Zero overhead [Deno](https://deno.com/) and [Bun](https://bun.sh/) support
|
|
14
|
-
- ✅ [Node.js compatibility](https://srvx.unjs.io/guide/node) with ~native perf and [fast response]https://srvx.unjs.io/guide/node#fast-response) support
|
|
14
|
+
- ✅ [Node.js compatibility](https://srvx.unjs.io/guide/node) with ~native perf and [fast response](https://srvx.unjs.io/guide/node#fast-response) support
|
|
15
15
|
|
|
16
16
|
## Quick start
|
|
17
17
|
|
|
@@ -24,23 +24,24 @@ declare const NodeRequestProxy: {
|
|
|
24
24
|
req: NodeHttp__default.IncomingMessage;
|
|
25
25
|
res: NodeHttp__default.ServerResponse;
|
|
26
26
|
} | undefined;
|
|
27
|
-
"__#
|
|
28
|
-
"__#
|
|
29
|
-
"__#
|
|
30
|
-
"__#
|
|
31
|
-
"__#
|
|
32
|
-
"__#
|
|
33
|
-
"__#
|
|
34
|
-
"__#
|
|
35
|
-
"__#
|
|
27
|
+
"__#448@#url": URL;
|
|
28
|
+
"__#448@#abortSignal"?: AbortController;
|
|
29
|
+
"__#448@#hasBody": boolean | undefined;
|
|
30
|
+
"__#448@#rawBody"?: Promise<Uint8Array>;
|
|
31
|
+
"__#448@#blobBody"?: Promise<Blob>;
|
|
32
|
+
"__#448@#formDataBody"?: Promise<FormData>;
|
|
33
|
+
"__#448@#jsonBody"?: Promise<any>;
|
|
34
|
+
"__#448@#textBody"?: Promise<string>;
|
|
35
|
+
"__#448@#bodyStream"?: undefined | ReadableStream<Uint8Array>;
|
|
36
36
|
readonly xRemoteAddress: string | undefined;
|
|
37
37
|
clone(): xRequest;
|
|
38
38
|
readonly url: string;
|
|
39
39
|
readonly method: string;
|
|
40
40
|
readonly signal: AbortSignal;
|
|
41
41
|
readonly _hasBody: boolean;
|
|
42
|
-
readonly body: ReadableStream<Uint8Array
|
|
42
|
+
readonly body: ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
|
43
43
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
44
|
+
bytes(): Promise<Uint8Array>;
|
|
44
45
|
blob(): Promise<Blob>;
|
|
45
46
|
formData(): Promise<FormData>;
|
|
46
47
|
json(): Promise<any>;
|
|
@@ -58,8 +59,8 @@ declare const NodeRequestProxy: {
|
|
|
58
59
|
type NodeFastResponse = InstanceType<typeof NodeFastResponse>;
|
|
59
60
|
declare const NodeFastResponse: {
|
|
60
61
|
new (body?: BodyInit | null, init?: ResponseInit): {
|
|
61
|
-
"__#
|
|
62
|
-
"__#
|
|
62
|
+
"__#449@#body"?: BodyInit | null;
|
|
63
|
+
"__#449@#init"?: ResponseInit;
|
|
63
64
|
/**
|
|
64
65
|
* Prepare Node.js response object
|
|
65
66
|
*/
|
|
@@ -67,14 +68,14 @@ declare const NodeFastResponse: {
|
|
|
67
68
|
status: number;
|
|
68
69
|
statusText: string;
|
|
69
70
|
headers: NodeHttp__default.OutgoingHttpHeader[];
|
|
70
|
-
body: string |
|
|
71
|
+
body: string | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | ReadableStream<Uint8Array<ArrayBufferLike>> | DataView<ArrayBufferLike> | null | undefined;
|
|
71
72
|
};
|
|
72
73
|
/** Lazy initialized response instance */
|
|
73
|
-
"__#
|
|
74
|
+
"__#449@#responseObj"?: Response;
|
|
74
75
|
/** Lazy initialized headers instance */
|
|
75
|
-
"__#
|
|
76
|
+
"__#449@#headersObj"?: Headers;
|
|
76
77
|
clone(): Response;
|
|
77
|
-
readonly "__#
|
|
78
|
+
readonly "__#449@#response": Response;
|
|
78
79
|
readonly headers: Headers;
|
|
79
80
|
readonly ok: boolean;
|
|
80
81
|
readonly redirected: boolean;
|
|
@@ -82,11 +83,12 @@ declare const NodeFastResponse: {
|
|
|
82
83
|
readonly statusText: string;
|
|
83
84
|
readonly type: ResponseType;
|
|
84
85
|
readonly url: string;
|
|
85
|
-
"__#
|
|
86
|
+
"__#449@#fastBody"<T extends object>(as: new (...args: any[]) => T): T | null | false;
|
|
86
87
|
readonly body: ReadableStream<Uint8Array> | null;
|
|
87
88
|
readonly bodyUsed: boolean;
|
|
88
89
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
89
90
|
blob(): Promise<Blob>;
|
|
91
|
+
bytes(): Promise<Uint8Array>;
|
|
90
92
|
formData(): Promise<FormData>;
|
|
91
93
|
text(): Promise<string>;
|
|
92
94
|
json(): Promise<any>;
|
|
@@ -24,23 +24,24 @@ declare const NodeRequestProxy: {
|
|
|
24
24
|
req: NodeHttp__default.IncomingMessage;
|
|
25
25
|
res: NodeHttp__default.ServerResponse;
|
|
26
26
|
} | undefined;
|
|
27
|
-
"__#
|
|
28
|
-
"__#
|
|
29
|
-
"__#
|
|
30
|
-
"__#
|
|
31
|
-
"__#
|
|
32
|
-
"__#
|
|
33
|
-
"__#
|
|
34
|
-
"__#
|
|
35
|
-
"__#
|
|
27
|
+
"__#448@#url": URL;
|
|
28
|
+
"__#448@#abortSignal"?: AbortController;
|
|
29
|
+
"__#448@#hasBody": boolean | undefined;
|
|
30
|
+
"__#448@#rawBody"?: Promise<Uint8Array>;
|
|
31
|
+
"__#448@#blobBody"?: Promise<Blob>;
|
|
32
|
+
"__#448@#formDataBody"?: Promise<FormData>;
|
|
33
|
+
"__#448@#jsonBody"?: Promise<any>;
|
|
34
|
+
"__#448@#textBody"?: Promise<string>;
|
|
35
|
+
"__#448@#bodyStream"?: undefined | ReadableStream<Uint8Array>;
|
|
36
36
|
readonly xRemoteAddress: string | undefined;
|
|
37
37
|
clone(): xRequest;
|
|
38
38
|
readonly url: string;
|
|
39
39
|
readonly method: string;
|
|
40
40
|
readonly signal: AbortSignal;
|
|
41
41
|
readonly _hasBody: boolean;
|
|
42
|
-
readonly body: ReadableStream<Uint8Array
|
|
42
|
+
readonly body: ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
|
43
43
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
44
|
+
bytes(): Promise<Uint8Array>;
|
|
44
45
|
blob(): Promise<Blob>;
|
|
45
46
|
formData(): Promise<FormData>;
|
|
46
47
|
json(): Promise<any>;
|
|
@@ -58,8 +59,8 @@ declare const NodeRequestProxy: {
|
|
|
58
59
|
type NodeFastResponse = InstanceType<typeof NodeFastResponse>;
|
|
59
60
|
declare const NodeFastResponse: {
|
|
60
61
|
new (body?: BodyInit | null, init?: ResponseInit): {
|
|
61
|
-
"__#
|
|
62
|
-
"__#
|
|
62
|
+
"__#449@#body"?: BodyInit | null;
|
|
63
|
+
"__#449@#init"?: ResponseInit;
|
|
63
64
|
/**
|
|
64
65
|
* Prepare Node.js response object
|
|
65
66
|
*/
|
|
@@ -67,14 +68,14 @@ declare const NodeFastResponse: {
|
|
|
67
68
|
status: number;
|
|
68
69
|
statusText: string;
|
|
69
70
|
headers: NodeHttp__default.OutgoingHttpHeader[];
|
|
70
|
-
body: string |
|
|
71
|
+
body: string | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | ReadableStream<Uint8Array<ArrayBufferLike>> | DataView<ArrayBufferLike> | null | undefined;
|
|
71
72
|
};
|
|
72
73
|
/** Lazy initialized response instance */
|
|
73
|
-
"__#
|
|
74
|
+
"__#449@#responseObj"?: Response;
|
|
74
75
|
/** Lazy initialized headers instance */
|
|
75
|
-
"__#
|
|
76
|
+
"__#449@#headersObj"?: Headers;
|
|
76
77
|
clone(): Response;
|
|
77
|
-
readonly "__#
|
|
78
|
+
readonly "__#449@#response": Response;
|
|
78
79
|
readonly headers: Headers;
|
|
79
80
|
readonly ok: boolean;
|
|
80
81
|
readonly redirected: boolean;
|
|
@@ -82,11 +83,12 @@ declare const NodeFastResponse: {
|
|
|
82
83
|
readonly statusText: string;
|
|
83
84
|
readonly type: ResponseType;
|
|
84
85
|
readonly url: string;
|
|
85
|
-
"__#
|
|
86
|
+
"__#449@#fastBody"<T extends object>(as: new (...args: any[]) => T): T | null | false;
|
|
86
87
|
readonly body: ReadableStream<Uint8Array> | null;
|
|
87
88
|
readonly bodyUsed: boolean;
|
|
88
89
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
89
90
|
blob(): Promise<Blob>;
|
|
91
|
+
bytes(): Promise<Uint8Array>;
|
|
90
92
|
formData(): Promise<FormData>;
|
|
91
93
|
text(): Promise<string>;
|
|
92
94
|
json(): Promise<any>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as NodeReqHeadersProxy, N as NodeRequestProxy, b as NodeResHeadersProxy, s as sendNodeResponse } from '../shared/srvx.
|
|
1
|
+
export { a as NodeReqHeadersProxy, N as NodeRequestProxy, b as NodeResHeadersProxy, s as sendNodeResponse } from '../shared/srvx.2143ff37.mjs';
|
|
2
2
|
import { splitSetCookieString } from 'cookie-es';
|
|
3
3
|
|
|
4
4
|
const NodeFastResponse = /* @__PURE__ */ (() => (
|
|
@@ -184,6 +184,16 @@ const NodeFastResponse = /* @__PURE__ */ (() => (
|
|
|
184
184
|
}
|
|
185
185
|
return this.#response.blob();
|
|
186
186
|
}
|
|
187
|
+
bytes() {
|
|
188
|
+
if (this.#responseObj) {
|
|
189
|
+
return this.#responseObj.bytes();
|
|
190
|
+
}
|
|
191
|
+
const fastBody = this.#fastBody(Uint8Array);
|
|
192
|
+
if (fastBody !== false) {
|
|
193
|
+
return Promise.resolve(fastBody || new Uint8Array());
|
|
194
|
+
}
|
|
195
|
+
return this.#response.bytes();
|
|
196
|
+
}
|
|
187
197
|
formData() {
|
|
188
198
|
if (this.#responseObj) {
|
|
189
199
|
return this.#responseObj.formData();
|
package/dist/node.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import NodeHttp from 'node:http';
|
|
2
2
|
import { S as Server, r as resolvePort } from './shared/srvx.4f681732.mjs';
|
|
3
|
-
import { N as NodeRequestProxy, s as sendNodeResponse } from './shared/srvx.
|
|
3
|
+
import { N as NodeRequestProxy, s as sendNodeResponse } from './shared/srvx.2143ff37.mjs';
|
|
4
4
|
import 'cookie-es';
|
|
5
5
|
|
|
6
6
|
function serve(options) {
|
|
@@ -415,6 +415,13 @@ const NodeRequestProxy = /* @__PURE__ */ (() => class NodeRequestProxy2 {
|
|
|
415
415
|
}
|
|
416
416
|
return this.#rawBody.then((buff) => buff.buffer);
|
|
417
417
|
}
|
|
418
|
+
bytes() {
|
|
419
|
+
if (!this.#rawBody) {
|
|
420
|
+
const _bodyStream = this.body;
|
|
421
|
+
return _bodyStream ? _readStream(_bodyStream) : Promise.resolve(new Uint8Array());
|
|
422
|
+
}
|
|
423
|
+
return this.#rawBody;
|
|
424
|
+
}
|
|
418
425
|
blob() {
|
|
419
426
|
if (!this.#blobBody) {
|
|
420
427
|
this.#blobBody = this.arrayBuffer().then((buff) => {
|
|
@@ -480,7 +487,13 @@ async function sendNodeResponse(nodeRes, webRes) {
|
|
|
480
487
|
if (webRes.xNodeResponse) {
|
|
481
488
|
const res = webRes.xNodeResponse();
|
|
482
489
|
nodeRes.writeHead(res.status, res.statusText, res.headers);
|
|
483
|
-
|
|
490
|
+
if (res.body instanceof ReadableStream) {
|
|
491
|
+
return streamBody(res.body, nodeRes).finally(
|
|
492
|
+
() => endNodeResponse(nodeRes)
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
nodeRes.write(res.body);
|
|
496
|
+
return endNodeResponse(nodeRes);
|
|
484
497
|
}
|
|
485
498
|
const headerEntries = [];
|
|
486
499
|
for (const [key, value] of webRes.headers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "srvx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Universal Server API based on web platform standards. Works seamlessly with Deno, Bun and Node.js.",
|
|
5
5
|
"repository": "unjs/srvx",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,9 +33,6 @@
|
|
|
33
33
|
"lint": "eslint . && prettier -c .",
|
|
34
34
|
"lint:fix": "automd && eslint . --fix && prettier -w .",
|
|
35
35
|
"prepack": "pnpm build",
|
|
36
|
-
"play:bun": "bun run ./playground/index.ts",
|
|
37
|
-
"play:deno": "deno run --unstable-byonm -A ./playground/index.ts",
|
|
38
|
-
"play:node": "node --import jiti/register ./playground/index.ts",
|
|
39
36
|
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
|
40
37
|
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
|
41
38
|
"test:types": "tsc --noEmit --skipLibCheck"
|
|
@@ -44,24 +41,24 @@
|
|
|
44
41
|
"cookie-es": "^1.2.2"
|
|
45
42
|
},
|
|
46
43
|
"devDependencies": {
|
|
47
|
-
"@hono/node-server": "^1.13.
|
|
48
|
-
"@mjackson/node-fetch-server": "^0.1
|
|
49
|
-
"@types/bun": "^1.1.
|
|
44
|
+
"@hono/node-server": "^1.13.7",
|
|
45
|
+
"@mjackson/node-fetch-server": "^0.4.1",
|
|
46
|
+
"@types/bun": "^1.1.14",
|
|
50
47
|
"@types/deno": "^2.0.0",
|
|
51
|
-
"@types/node": "^22.
|
|
52
|
-
"@vitest/coverage-v8": "^2.1.
|
|
48
|
+
"@types/node": "^22.10.1",
|
|
49
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
53
50
|
"automd": "^0.3.12",
|
|
54
51
|
"changelogen": "^0.5.7",
|
|
55
|
-
"eslint": "^9.
|
|
56
|
-
"eslint-config-unjs": "^0.4.
|
|
57
|
-
"execa": "^9.
|
|
52
|
+
"eslint": "^9.16.0",
|
|
53
|
+
"eslint-config-unjs": "^0.4.2",
|
|
54
|
+
"execa": "^9.5.1",
|
|
58
55
|
"get-port-please": "^3.1.2",
|
|
59
|
-
"jiti": "^2.
|
|
60
|
-
"prettier": "^3.
|
|
61
|
-
"srvx": "^0.
|
|
62
|
-
"typescript": "^5.
|
|
56
|
+
"jiti": "^2.4.1",
|
|
57
|
+
"prettier": "^3.4.1",
|
|
58
|
+
"srvx": "^0.1.1",
|
|
59
|
+
"typescript": "^5.7.2",
|
|
63
60
|
"unbuild": "^2.0.0",
|
|
64
|
-
"vitest": "^2.1.
|
|
61
|
+
"vitest": "^2.1.8"
|
|
65
62
|
},
|
|
66
|
-
"packageManager": "pnpm@9.
|
|
63
|
+
"packageManager": "pnpm@9.14.4"
|
|
67
64
|
}
|