srvx 0.1.1 → 0.1.3

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.
@@ -20,31 +20,28 @@ declare const NodeRequestProxy: {
20
20
  referrerPolicy: ReferrerPolicy;
21
21
  headers: xHeaders;
22
22
  bodyUsed: boolean;
23
- xNode: {
24
- req: NodeHttp__default.IncomingMessage;
25
- res: NodeHttp__default.ServerResponse;
26
- } | undefined;
27
- "__#3@#url": URL;
28
- "__#3@#abortSignal"?: AbortController;
29
- "__#3@#hasBody": boolean | undefined;
30
- "__#3@#rawBody"?: Promise<Uint8Array>;
31
- "__#3@#blobBody"?: Promise<Blob>;
32
- "__#3@#formDataBody"?: Promise<FormData>;
33
- "__#3@#jsonBody"?: Promise<any>;
34
- "__#3@#textBody"?: Promise<string>;
35
- "__#3@#bodyStream"?: undefined | ReadableStream<Uint8Array>;
23
+ _url: URL;
24
+ "__#448@#abortSignal"?: AbortController;
25
+ "__#448@#hasBody": boolean | undefined;
26
+ "__#448@#bodyBytes"?: Promise<Uint8Array>;
27
+ "__#448@#blobBody"?: Promise<Blob>;
28
+ "__#448@#formDataBody"?: Promise<FormData>;
29
+ "__#448@#jsonBody"?: Promise<any>;
30
+ "__#448@#textBody"?: Promise<string>;
31
+ "__#448@#bodyStream"?: undefined | ReadableStream<Uint8Array>;
36
32
  readonly xRemoteAddress: string | undefined;
37
33
  clone(): xRequest;
38
34
  readonly url: string;
39
35
  readonly method: string;
40
36
  readonly signal: AbortSignal;
41
37
  readonly _hasBody: boolean;
42
- readonly body: ReadableStream<Uint8Array> | null;
38
+ readonly body: ReadableStream<Uint8Array<ArrayBufferLike>> | null;
39
+ bytes(): Promise<Uint8Array>;
43
40
  arrayBuffer(): Promise<ArrayBuffer>;
44
41
  blob(): Promise<Blob>;
45
42
  formData(): Promise<FormData>;
46
- json(): Promise<any>;
47
43
  text(): Promise<string>;
44
+ json(): Promise<any>;
48
45
  [kNodeReq]: NodeHttp__default.IncomingMessage;
49
46
  readonly [Symbol.toStringTag]: string;
50
47
  [kNodeInspect](): {
@@ -58,8 +55,8 @@ declare const NodeRequestProxy: {
58
55
  type NodeFastResponse = InstanceType<typeof NodeFastResponse>;
59
56
  declare const NodeFastResponse: {
60
57
  new (body?: BodyInit | null, init?: ResponseInit): {
61
- "__#4@#body"?: BodyInit | null;
62
- "__#4@#init"?: ResponseInit;
58
+ "__#449@#body"?: BodyInit | null;
59
+ "__#449@#init"?: ResponseInit;
63
60
  /**
64
61
  * Prepare Node.js response object
65
62
  */
@@ -67,14 +64,14 @@ declare const NodeFastResponse: {
67
64
  status: number;
68
65
  statusText: string;
69
66
  headers: NodeHttp__default.OutgoingHttpHeader[];
70
- body: string | Uint8Array | ReadableStream<Uint8Array> | Buffer | DataView | null | undefined;
67
+ body: string | Uint8Array<ArrayBufferLike> | ReadableStream<Uint8Array<ArrayBufferLike>> | Buffer<ArrayBufferLike> | DataView<ArrayBufferLike> | null | undefined;
71
68
  };
72
69
  /** Lazy initialized response instance */
73
- "__#4@#responseObj"?: Response;
70
+ "__#449@#responseObj"?: Response;
74
71
  /** Lazy initialized headers instance */
75
- "__#4@#headersObj"?: Headers;
72
+ "__#449@#headersObj"?: Headers;
76
73
  clone(): Response;
77
- readonly "__#4@#response": Response;
74
+ readonly "__#449@#response": Response;
78
75
  readonly headers: Headers;
79
76
  readonly ok: boolean;
80
77
  readonly redirected: boolean;
@@ -82,11 +79,12 @@ declare const NodeFastResponse: {
82
79
  readonly statusText: string;
83
80
  readonly type: ResponseType;
84
81
  readonly url: string;
85
- "__#4@#fastBody"<T extends object>(as: new (...args: any[]) => T): T | null | false;
82
+ "__#449@#fastBody"<T extends object>(as: new (...args: any[]) => T): T | null | false;
86
83
  readonly body: ReadableStream<Uint8Array> | null;
87
84
  readonly bodyUsed: boolean;
88
85
  arrayBuffer(): Promise<ArrayBuffer>;
89
86
  blob(): Promise<Blob>;
87
+ bytes(): Promise<Uint8Array>;
90
88
  formData(): Promise<FormData>;
91
89
  text(): Promise<string>;
92
90
  json(): Promise<any>;
@@ -20,31 +20,28 @@ declare const NodeRequestProxy: {
20
20
  referrerPolicy: ReferrerPolicy;
21
21
  headers: xHeaders;
22
22
  bodyUsed: boolean;
23
- xNode: {
24
- req: NodeHttp__default.IncomingMessage;
25
- res: NodeHttp__default.ServerResponse;
26
- } | undefined;
27
- "__#3@#url": URL;
28
- "__#3@#abortSignal"?: AbortController;
29
- "__#3@#hasBody": boolean | undefined;
30
- "__#3@#rawBody"?: Promise<Uint8Array>;
31
- "__#3@#blobBody"?: Promise<Blob>;
32
- "__#3@#formDataBody"?: Promise<FormData>;
33
- "__#3@#jsonBody"?: Promise<any>;
34
- "__#3@#textBody"?: Promise<string>;
35
- "__#3@#bodyStream"?: undefined | ReadableStream<Uint8Array>;
23
+ _url: URL;
24
+ "__#448@#abortSignal"?: AbortController;
25
+ "__#448@#hasBody": boolean | undefined;
26
+ "__#448@#bodyBytes"?: Promise<Uint8Array>;
27
+ "__#448@#blobBody"?: Promise<Blob>;
28
+ "__#448@#formDataBody"?: Promise<FormData>;
29
+ "__#448@#jsonBody"?: Promise<any>;
30
+ "__#448@#textBody"?: Promise<string>;
31
+ "__#448@#bodyStream"?: undefined | ReadableStream<Uint8Array>;
36
32
  readonly xRemoteAddress: string | undefined;
37
33
  clone(): xRequest;
38
34
  readonly url: string;
39
35
  readonly method: string;
40
36
  readonly signal: AbortSignal;
41
37
  readonly _hasBody: boolean;
42
- readonly body: ReadableStream<Uint8Array> | null;
38
+ readonly body: ReadableStream<Uint8Array<ArrayBufferLike>> | null;
39
+ bytes(): Promise<Uint8Array>;
43
40
  arrayBuffer(): Promise<ArrayBuffer>;
44
41
  blob(): Promise<Blob>;
45
42
  formData(): Promise<FormData>;
46
- json(): Promise<any>;
47
43
  text(): Promise<string>;
44
+ json(): Promise<any>;
48
45
  [kNodeReq]: NodeHttp__default.IncomingMessage;
49
46
  readonly [Symbol.toStringTag]: string;
50
47
  [kNodeInspect](): {
@@ -58,8 +55,8 @@ declare const NodeRequestProxy: {
58
55
  type NodeFastResponse = InstanceType<typeof NodeFastResponse>;
59
56
  declare const NodeFastResponse: {
60
57
  new (body?: BodyInit | null, init?: ResponseInit): {
61
- "__#4@#body"?: BodyInit | null;
62
- "__#4@#init"?: ResponseInit;
58
+ "__#449@#body"?: BodyInit | null;
59
+ "__#449@#init"?: ResponseInit;
63
60
  /**
64
61
  * Prepare Node.js response object
65
62
  */
@@ -67,14 +64,14 @@ declare const NodeFastResponse: {
67
64
  status: number;
68
65
  statusText: string;
69
66
  headers: NodeHttp__default.OutgoingHttpHeader[];
70
- body: string | Uint8Array | ReadableStream<Uint8Array> | Buffer | DataView | null | undefined;
67
+ body: string | Uint8Array<ArrayBufferLike> | ReadableStream<Uint8Array<ArrayBufferLike>> | Buffer<ArrayBufferLike> | DataView<ArrayBufferLike> | null | undefined;
71
68
  };
72
69
  /** Lazy initialized response instance */
73
- "__#4@#responseObj"?: Response;
70
+ "__#449@#responseObj"?: Response;
74
71
  /** Lazy initialized headers instance */
75
- "__#4@#headersObj"?: Headers;
72
+ "__#449@#headersObj"?: Headers;
76
73
  clone(): Response;
77
- readonly "__#4@#response": Response;
74
+ readonly "__#449@#response": Response;
78
75
  readonly headers: Headers;
79
76
  readonly ok: boolean;
80
77
  readonly redirected: boolean;
@@ -82,11 +79,12 @@ declare const NodeFastResponse: {
82
79
  readonly statusText: string;
83
80
  readonly type: ResponseType;
84
81
  readonly url: string;
85
- "__#4@#fastBody"<T extends object>(as: new (...args: any[]) => T): T | null | false;
82
+ "__#449@#fastBody"<T extends object>(as: new (...args: any[]) => T): T | null | false;
86
83
  readonly body: ReadableStream<Uint8Array> | null;
87
84
  readonly bodyUsed: boolean;
88
85
  arrayBuffer(): Promise<ArrayBuffer>;
89
86
  blob(): Promise<Blob>;
87
+ bytes(): Promise<Uint8Array>;
90
88
  formData(): Promise<FormData>;
91
89
  text(): Promise<string>;
92
90
  json(): Promise<any>;
@@ -1,4 +1,4 @@
1
- export { a as NodeReqHeadersProxy, N as NodeRequestProxy, b as NodeResHeadersProxy, s as sendNodeResponse } from '../shared/srvx.109e963a.mjs';
1
+ export { a as NodeReqHeadersProxy, N as NodeRequestProxy, b as NodeResHeadersProxy, s as sendNodeResponse } from '../shared/srvx.1e3bbf3a.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.109e963a.mjs';
3
+ import { N as NodeRequestProxy, s as sendNodeResponse } from './shared/srvx.1e3bbf3a.mjs';
4
4
  import 'cookie-es';
5
5
 
6
6
  function serve(options) {
@@ -337,13 +337,12 @@ const NodeRequestProxy = /* @__PURE__ */ (() => class NodeRequestProxy2 {
337
337
  this.referrerPolicy = "";
338
338
  this.bodyUsed = false;
339
339
  this[kNodeReq] = nodeReq;
340
- this.#url = new NodeReqURLProxy(nodeReq);
340
+ this._url = new NodeReqURLProxy(nodeReq);
341
341
  this.headers = new NodeReqHeadersProxy(nodeReq);
342
342
  }
343
- #url;
344
343
  #abortSignal;
345
344
  #hasBody;
346
- #rawBody;
345
+ #bodyBytes;
347
346
  #blobBody;
348
347
  #formDataBody;
349
348
  #jsonBody;
@@ -356,7 +355,7 @@ const NodeRequestProxy = /* @__PURE__ */ (() => class NodeRequestProxy2 {
356
355
  return new NodeRequestProxy2(this[kNodeReq]);
357
356
  }
358
357
  get url() {
359
- return this.#url.href;
358
+ return this._url.href;
360
359
  }
361
360
  get method() {
362
361
  return this[kNodeReq].method || "GET";
@@ -386,7 +385,7 @@ const NodeRequestProxy = /* @__PURE__ */ (() => class NodeRequestProxy2 {
386
385
  return true;
387
386
  }
388
387
  get body() {
389
- if (!this.#hasBody) {
388
+ if (!this._hasBody) {
390
389
  return null;
391
390
  }
392
391
  if (!this.#bodyStream) {
@@ -408,17 +407,25 @@ const NodeRequestProxy = /* @__PURE__ */ (() => class NodeRequestProxy2 {
408
407
  }
409
408
  return this.#bodyStream;
410
409
  }
411
- arrayBuffer() {
412
- if (!this.#rawBody) {
410
+ bytes() {
411
+ if (!this.#bodyBytes) {
413
412
  const _bodyStream = this.body;
414
- return _bodyStream ? _readStream(_bodyStream).then((buff) => buff.buffer) : Promise.resolve(new ArrayBuffer(0));
413
+ this.#bodyBytes = _bodyStream ? _readStream(_bodyStream) : Promise.resolve(new Uint8Array());
415
414
  }
416
- return this.#rawBody.then((buff) => buff.buffer);
415
+ return this.#bodyBytes;
416
+ }
417
+ arrayBuffer() {
418
+ return this.bytes().then((buff) => {
419
+ return buff.buffer.slice(
420
+ buff.byteOffset,
421
+ buff.byteOffset + buff.byteLength
422
+ );
423
+ });
417
424
  }
418
425
  blob() {
419
426
  if (!this.#blobBody) {
420
- this.#blobBody = this.arrayBuffer().then((buff) => {
421
- return new Blob([buff], {
427
+ this.#blobBody = this.bytes().then((bytes) => {
428
+ return new Blob([bytes], {
422
429
  type: this[kNodeReq].headers["content-type"]
423
430
  });
424
431
  });
@@ -433,6 +440,14 @@ const NodeRequestProxy = /* @__PURE__ */ (() => class NodeRequestProxy2 {
433
440
  }
434
441
  return this.#formDataBody;
435
442
  }
443
+ text() {
444
+ if (!this.#textBody) {
445
+ this.#textBody = this.bytes().then((bytes) => {
446
+ return new TextDecoder().decode(bytes);
447
+ });
448
+ }
449
+ return this.#textBody;
450
+ }
436
451
  json() {
437
452
  if (!this.#jsonBody) {
438
453
  this.#jsonBody = this.text().then((txt) => {
@@ -441,14 +456,6 @@ const NodeRequestProxy = /* @__PURE__ */ (() => class NodeRequestProxy2 {
441
456
  }
442
457
  return this.#jsonBody;
443
458
  }
444
- text() {
445
- if (!this.#textBody) {
446
- this.#textBody = this.arrayBuffer().then((buff) => {
447
- return new TextDecoder().decode(buff);
448
- });
449
- }
450
- return this.#textBody;
451
- }
452
459
  get [(Symbol.toStringTag)]() {
453
460
  return "Request";
454
461
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "srvx",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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",
@@ -41,24 +41,24 @@
41
41
  "cookie-es": "^1.2.2"
42
42
  },
43
43
  "devDependencies": {
44
- "@hono/node-server": "^1.13.2",
45
- "@mjackson/node-fetch-server": "^0.1.0",
46
- "@types/bun": "^1.1.11",
44
+ "@hono/node-server": "^1.13.7",
45
+ "@mjackson/node-fetch-server": "^0.4.1",
46
+ "@types/bun": "^1.1.14",
47
47
  "@types/deno": "^2.0.0",
48
- "@types/node": "^22.7.5",
49
- "@vitest/coverage-v8": "^2.1.3",
48
+ "@types/node": "^22.10.1",
49
+ "@vitest/coverage-v8": "^2.1.8",
50
50
  "automd": "^0.3.12",
51
51
  "changelogen": "^0.5.7",
52
- "eslint": "^9.12.0",
53
- "eslint-config-unjs": "^0.4.1",
54
- "execa": "^9.4.0",
52
+ "eslint": "^9.16.0",
53
+ "eslint-config-unjs": "^0.4.2",
54
+ "execa": "^9.5.1",
55
55
  "get-port-please": "^3.1.2",
56
- "jiti": "^2.3.3",
57
- "prettier": "^3.3.3",
58
- "srvx": "^0.0.0",
59
- "typescript": "^5.6.3",
56
+ "jiti": "^2.4.1",
57
+ "prettier": "^3.4.1",
58
+ "srvx": "^0.1.1",
59
+ "typescript": "^5.7.2",
60
60
  "unbuild": "^2.0.0",
61
- "vitest": "^2.1.3"
61
+ "vitest": "^2.1.8"
62
62
  },
63
- "packageManager": "pnpm@9.12.1"
63
+ "packageManager": "pnpm@9.14.4"
64
64
  }