srvx 0.2.2 → 0.2.4
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/adapters/node.mjs +224 -213
- package/dist/types.d.mts +1 -1
- package/package.json +4 -2
package/dist/adapters/node.mjs
CHANGED
|
@@ -88,103 +88,107 @@ const kNodeInspect = /* @__PURE__ */ Symbol.for(
|
|
|
88
88
|
"nodejs.util.inspect.custom"
|
|
89
89
|
);
|
|
90
90
|
|
|
91
|
-
const NodeReqHeadersProxy = /* @__PURE__ */ (() =>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
name
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
91
|
+
const NodeReqHeadersProxy = /* @__PURE__ */ (() => {
|
|
92
|
+
class NodeReqHeadersProxy2 {
|
|
93
|
+
constructor(req) {
|
|
94
|
+
this[kNodeReq] = req;
|
|
95
|
+
}
|
|
96
|
+
append(name, value) {
|
|
97
|
+
name = name.toLowerCase();
|
|
98
|
+
const _headers = this[kNodeReq].headers;
|
|
99
|
+
const _current = _headers[name];
|
|
100
|
+
if (_current) {
|
|
101
|
+
if (Array.isArray(_current)) {
|
|
102
|
+
_current.push(value);
|
|
103
|
+
} else {
|
|
104
|
+
_headers[name] = [_current, value];
|
|
105
|
+
}
|
|
102
106
|
} else {
|
|
103
|
-
_headers[name] =
|
|
107
|
+
_headers[name] = value;
|
|
104
108
|
}
|
|
105
|
-
} else {
|
|
106
|
-
_headers[name] = value;
|
|
107
109
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this[kNodeReq].headers[name] = void 0;
|
|
112
|
-
}
|
|
113
|
-
get(name) {
|
|
114
|
-
name = name.toLowerCase();
|
|
115
|
-
return _normalizeValue(this[kNodeReq].headers[name]);
|
|
116
|
-
}
|
|
117
|
-
getSetCookie() {
|
|
118
|
-
const setCookie = this[kNodeReq].headers["set-cookie"];
|
|
119
|
-
if (!setCookie || setCookie.length === 0) {
|
|
120
|
-
return [];
|
|
110
|
+
delete(name) {
|
|
111
|
+
name = name.toLowerCase();
|
|
112
|
+
this[kNodeReq].headers[name] = void 0;
|
|
121
113
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this[kNodeReq].headers[name] = value;
|
|
131
|
-
}
|
|
132
|
-
get count() {
|
|
133
|
-
throw new Error("Method not implemented.");
|
|
134
|
-
}
|
|
135
|
-
getAll(_name) {
|
|
136
|
-
throw new Error("Method not implemented.");
|
|
137
|
-
}
|
|
138
|
-
toJSON() {
|
|
139
|
-
const _headers = this[kNodeReq].headers;
|
|
140
|
-
const result = {};
|
|
141
|
-
for (const key in _headers) {
|
|
142
|
-
if (_headers[key]) {
|
|
143
|
-
result[key] = _normalizeValue(_headers[key]);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
forEach(cb, thisArg) {
|
|
149
|
-
const _headers = this[kNodeReq].headers;
|
|
150
|
-
for (const key in _headers) {
|
|
151
|
-
if (_headers[key]) {
|
|
152
|
-
cb.call(
|
|
153
|
-
thisArg,
|
|
154
|
-
_normalizeValue(_headers[key]),
|
|
155
|
-
key,
|
|
156
|
-
this
|
|
157
|
-
);
|
|
114
|
+
get(name) {
|
|
115
|
+
name = name.toLowerCase();
|
|
116
|
+
return _normalizeValue(this[kNodeReq].headers[name]);
|
|
117
|
+
}
|
|
118
|
+
getSetCookie() {
|
|
119
|
+
const setCookie = this[kNodeReq].headers["set-cookie"];
|
|
120
|
+
if (!setCookie || setCookie.length === 0) {
|
|
121
|
+
return [];
|
|
158
122
|
}
|
|
123
|
+
return splitSetCookieString(setCookie);
|
|
159
124
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
for (const key in _headers) {
|
|
164
|
-
yield [key, _normalizeValue(_headers[key])];
|
|
125
|
+
has(name) {
|
|
126
|
+
name = name.toLowerCase();
|
|
127
|
+
return !!this[kNodeReq].headers[name];
|
|
165
128
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
for (const key of keys) {
|
|
170
|
-
yield key;
|
|
129
|
+
set(name, value) {
|
|
130
|
+
name = name.toLowerCase();
|
|
131
|
+
this[kNodeReq].headers[name] = value;
|
|
171
132
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
133
|
+
get count() {
|
|
134
|
+
throw new Error("Method not implemented.");
|
|
135
|
+
}
|
|
136
|
+
getAll(_name) {
|
|
137
|
+
throw new Error("Method not implemented.");
|
|
138
|
+
}
|
|
139
|
+
toJSON() {
|
|
140
|
+
const _headers = this[kNodeReq].headers;
|
|
141
|
+
const result = {};
|
|
142
|
+
for (const key in _headers) {
|
|
143
|
+
if (_headers[key]) {
|
|
144
|
+
result[key] = _normalizeValue(_headers[key]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
forEach(cb, thisArg) {
|
|
150
|
+
const _headers = this[kNodeReq].headers;
|
|
151
|
+
for (const key in _headers) {
|
|
152
|
+
if (_headers[key]) {
|
|
153
|
+
cb.call(
|
|
154
|
+
thisArg,
|
|
155
|
+
_normalizeValue(_headers[key]),
|
|
156
|
+
key,
|
|
157
|
+
this
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
*entries() {
|
|
163
|
+
const _headers = this[kNodeReq].headers;
|
|
164
|
+
for (const key in _headers) {
|
|
165
|
+
yield [key, _normalizeValue(_headers[key])];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
*keys() {
|
|
169
|
+
const keys = Object.keys(this[kNodeReq].headers);
|
|
170
|
+
for (const key of keys) {
|
|
171
|
+
yield key;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
*values() {
|
|
175
|
+
const values = Object.values(this[kNodeReq].headers);
|
|
176
|
+
for (const value of values) {
|
|
177
|
+
yield _normalizeValue(value);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
[(Symbol.iterator)]() {
|
|
181
|
+
return this.entries()[Symbol.iterator]();
|
|
182
|
+
}
|
|
183
|
+
get [Symbol.toStringTag]() {
|
|
184
|
+
return "Headers";
|
|
185
|
+
}
|
|
186
|
+
[kNodeInspect]() {
|
|
187
|
+
return Object.fromEntries(this.entries());
|
|
177
188
|
}
|
|
178
189
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
get [Symbol.toStringTag]() {
|
|
183
|
-
return "Headers";
|
|
184
|
-
}
|
|
185
|
-
[kNodeInspect]() {
|
|
186
|
-
return Object.fromEntries(this.entries());
|
|
187
|
-
}
|
|
190
|
+
Object.setPrototypeOf(NodeReqHeadersProxy2.prototype, Headers.prototype);
|
|
191
|
+
return NodeReqHeadersProxy2;
|
|
188
192
|
})();
|
|
189
193
|
function _normalizeValue(value) {
|
|
190
194
|
if (Array.isArray(value)) {
|
|
@@ -350,148 +354,155 @@ function parseHost(host) {
|
|
|
350
354
|
return [s[0], String(Number.parseInt(s[1]) || "")];
|
|
351
355
|
}
|
|
352
356
|
|
|
353
|
-
const NodeRequestProxy = /* @__PURE__ */ (() =>
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
#abortSignal;
|
|
370
|
-
#hasBody;
|
|
371
|
-
#bodyBytes;
|
|
372
|
-
#blobBody;
|
|
373
|
-
#formDataBody;
|
|
374
|
-
#jsonBody;
|
|
375
|
-
#textBody;
|
|
376
|
-
#bodyStream;
|
|
377
|
-
get remoteAddress() {
|
|
378
|
-
return this[kNodeReq].socket?.remoteAddress;
|
|
379
|
-
}
|
|
380
|
-
clone() {
|
|
381
|
-
return new NodeRequestProxy2(this[kNodeReq]);
|
|
382
|
-
}
|
|
383
|
-
get url() {
|
|
384
|
-
return this._url.href;
|
|
385
|
-
}
|
|
386
|
-
get method() {
|
|
387
|
-
return this[kNodeReq].method || "GET";
|
|
388
|
-
}
|
|
389
|
-
get signal() {
|
|
390
|
-
if (!this.#abortSignal) {
|
|
391
|
-
this.#abortSignal = new AbortController();
|
|
357
|
+
const NodeRequestProxy = /* @__PURE__ */ (() => {
|
|
358
|
+
class NodeRequestProxy2 {
|
|
359
|
+
#url;
|
|
360
|
+
#headers;
|
|
361
|
+
#bodyUsed = false;
|
|
362
|
+
#abortSignal;
|
|
363
|
+
#hasBody;
|
|
364
|
+
#bodyBytes;
|
|
365
|
+
#blobBody;
|
|
366
|
+
#formDataBody;
|
|
367
|
+
#jsonBody;
|
|
368
|
+
#textBody;
|
|
369
|
+
#bodyStream;
|
|
370
|
+
constructor(nodeReq) {
|
|
371
|
+
this[kNodeReq] = nodeReq;
|
|
392
372
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return this.#
|
|
373
|
+
get headers() {
|
|
374
|
+
if (!this.#headers) {
|
|
375
|
+
this.#headers = new NodeReqHeadersProxy(this[kNodeReq]);
|
|
376
|
+
}
|
|
377
|
+
return this.#headers;
|
|
398
378
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
379
|
+
get remoteAddress() {
|
|
380
|
+
return this[kNodeReq].socket?.remoteAddress;
|
|
381
|
+
}
|
|
382
|
+
clone() {
|
|
383
|
+
return new NodeRequestProxy2(this[kNodeReq]);
|
|
384
|
+
}
|
|
385
|
+
get url() {
|
|
386
|
+
if (!this.#url) {
|
|
387
|
+
this.#url = new NodeReqURLProxy(this[kNodeReq]);
|
|
388
|
+
}
|
|
389
|
+
return this.#url.href;
|
|
390
|
+
}
|
|
391
|
+
get method() {
|
|
392
|
+
return this[kNodeReq].method || "GET";
|
|
403
393
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
394
|
+
get signal() {
|
|
395
|
+
if (!this.#abortSignal) {
|
|
396
|
+
this.#abortSignal = new AbortController();
|
|
397
|
+
}
|
|
398
|
+
return this.#abortSignal.signal;
|
|
399
|
+
}
|
|
400
|
+
get bodyUsed() {
|
|
401
|
+
return this.#bodyUsed;
|
|
402
|
+
}
|
|
403
|
+
get _hasBody() {
|
|
404
|
+
if (this.#hasBody !== void 0) {
|
|
405
|
+
return this.#hasBody;
|
|
406
|
+
}
|
|
407
|
+
const method = this[kNodeReq].method?.toUpperCase();
|
|
408
|
+
if (!method || !(method === "PATCH" || method === "POST" || method === "PUT" || method === "DELETE")) {
|
|
407
409
|
this.#hasBody = false;
|
|
408
410
|
return false;
|
|
409
411
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return null;
|
|
416
|
-
}
|
|
417
|
-
if (!this.#bodyStream) {
|
|
418
|
-
this.bodyUsed = true;
|
|
419
|
-
this.#bodyStream = new ReadableStream({
|
|
420
|
-
start: (controller) => {
|
|
421
|
-
this[kNodeReq].on("data", (chunk) => {
|
|
422
|
-
controller.enqueue(chunk);
|
|
423
|
-
}).once("error", (error) => {
|
|
424
|
-
controller.error(error);
|
|
425
|
-
this.#abortSignal?.abort();
|
|
426
|
-
}).once("close", () => {
|
|
427
|
-
this.#abortSignal?.abort();
|
|
428
|
-
}).once("end", () => {
|
|
429
|
-
controller.close();
|
|
430
|
-
});
|
|
412
|
+
if (!Number.parseInt(this[kNodeReq].headers["content-length"] || "")) {
|
|
413
|
+
const isChunked = (this[kNodeReq].headers["transfer-encoding"] || "").split(",").map((e) => e.trim()).filter(Boolean).includes("chunked");
|
|
414
|
+
if (!isChunked) {
|
|
415
|
+
this.#hasBody = false;
|
|
416
|
+
return false;
|
|
431
417
|
}
|
|
418
|
+
}
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
get body() {
|
|
422
|
+
if (!this._hasBody) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
if (!this.#bodyStream) {
|
|
426
|
+
this.#bodyUsed = true;
|
|
427
|
+
this.#bodyStream = new ReadableStream({
|
|
428
|
+
start: (controller) => {
|
|
429
|
+
this[kNodeReq].on("data", (chunk) => {
|
|
430
|
+
controller.enqueue(chunk);
|
|
431
|
+
}).once("error", (error) => {
|
|
432
|
+
controller.error(error);
|
|
433
|
+
this.#abortSignal?.abort();
|
|
434
|
+
}).once("close", () => {
|
|
435
|
+
this.#abortSignal?.abort();
|
|
436
|
+
}).once("end", () => {
|
|
437
|
+
controller.close();
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
return this.#bodyStream;
|
|
443
|
+
}
|
|
444
|
+
bytes() {
|
|
445
|
+
if (!this.#bodyBytes) {
|
|
446
|
+
const _bodyStream = this.body;
|
|
447
|
+
this.#bodyBytes = _bodyStream ? _readStream(_bodyStream) : Promise.resolve(new Uint8Array());
|
|
448
|
+
}
|
|
449
|
+
return this.#bodyBytes;
|
|
450
|
+
}
|
|
451
|
+
arrayBuffer() {
|
|
452
|
+
return this.bytes().then((buff) => {
|
|
453
|
+
return buff.buffer.slice(
|
|
454
|
+
buff.byteOffset,
|
|
455
|
+
buff.byteOffset + buff.byteLength
|
|
456
|
+
);
|
|
432
457
|
});
|
|
433
458
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
459
|
+
blob() {
|
|
460
|
+
if (!this.#blobBody) {
|
|
461
|
+
this.#blobBody = this.bytes().then((bytes) => {
|
|
462
|
+
return new Blob([bytes], {
|
|
463
|
+
type: this[kNodeReq].headers["content-type"]
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
return this.#blobBody;
|
|
440
468
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
this.#blobBody = this.bytes().then((bytes) => {
|
|
454
|
-
return new Blob([bytes], {
|
|
455
|
-
type: this[kNodeReq].headers["content-type"]
|
|
469
|
+
formData() {
|
|
470
|
+
if (!this.#formDataBody) {
|
|
471
|
+
this.#formDataBody = new Response(this.body, {
|
|
472
|
+
headers: this.headers
|
|
473
|
+
}).formData();
|
|
474
|
+
}
|
|
475
|
+
return this.#formDataBody;
|
|
476
|
+
}
|
|
477
|
+
text() {
|
|
478
|
+
if (!this.#textBody) {
|
|
479
|
+
this.#textBody = this.bytes().then((bytes) => {
|
|
480
|
+
return new TextDecoder().decode(bytes);
|
|
456
481
|
});
|
|
457
|
-
}
|
|
482
|
+
}
|
|
483
|
+
return this.#textBody;
|
|
458
484
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
485
|
+
json() {
|
|
486
|
+
if (!this.#jsonBody) {
|
|
487
|
+
this.#jsonBody = this.text().then((txt) => {
|
|
488
|
+
return JSON.parse(txt);
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
return this.#jsonBody;
|
|
466
492
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
text() {
|
|
470
|
-
if (!this.#textBody) {
|
|
471
|
-
this.#textBody = this.bytes().then((bytes) => {
|
|
472
|
-
return new TextDecoder().decode(bytes);
|
|
473
|
-
});
|
|
493
|
+
get [(Symbol.toStringTag)]() {
|
|
494
|
+
return "Request";
|
|
474
495
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
});
|
|
496
|
+
[kNodeInspect]() {
|
|
497
|
+
return {
|
|
498
|
+
method: this.method,
|
|
499
|
+
url: this.url,
|
|
500
|
+
headers: this.headers
|
|
501
|
+
};
|
|
482
502
|
}
|
|
483
|
-
return this.#jsonBody;
|
|
484
|
-
}
|
|
485
|
-
get [(Symbol.toStringTag)]() {
|
|
486
|
-
return "Request";
|
|
487
|
-
}
|
|
488
|
-
[kNodeInspect]() {
|
|
489
|
-
return {
|
|
490
|
-
method: this.method,
|
|
491
|
-
url: this.url,
|
|
492
|
-
headers: this.headers
|
|
493
|
-
};
|
|
494
503
|
}
|
|
504
|
+
Object.setPrototypeOf(NodeRequestProxy2.prototype, Request.prototype);
|
|
505
|
+
return NodeRequestProxy2;
|
|
495
506
|
})();
|
|
496
507
|
async function _readStream(stream) {
|
|
497
508
|
const chunks = [];
|
package/dist/types.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import * as Bun from 'bun';
|
|
|
4
4
|
import * as CF from '@cloudflare/workers-types';
|
|
5
5
|
|
|
6
6
|
type MaybePromise<T> = T | Promise<T>;
|
|
7
|
-
declare const Response: globalThis.Response;
|
|
7
|
+
declare const Response: typeof globalThis.Response;
|
|
8
8
|
/**
|
|
9
9
|
* Create a new server instance.
|
|
10
10
|
*/
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "srvx",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"type": "module",
|
|
9
|
+
"types": "./dist/types.d.mts",
|
|
9
10
|
"exports": {
|
|
10
11
|
"./types": "./dist/types.d.mts",
|
|
11
12
|
"./deno": "./dist/adapters/deno.mjs",
|
|
@@ -16,7 +17,8 @@
|
|
|
16
17
|
"deno": "./dist/adapters/deno.mjs",
|
|
17
18
|
"bun": "./dist/adapters/bun.mjs",
|
|
18
19
|
"workerd": "./dist/adapters/cloudflare.mjs",
|
|
19
|
-
"node": "./dist/adapters/node.mjs"
|
|
20
|
+
"node": "./dist/adapters/node.mjs",
|
|
21
|
+
"types": "./dist/types.d.mts"
|
|
20
22
|
}
|
|
21
23
|
},
|
|
22
24
|
"files": [
|