@faasjs/http 8.0.0-beta.1 → 8.0.0-beta.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/dist/index.cjs +29 -3
- package/dist/index.mjs +29 -3
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -202,6 +202,19 @@ var HttpError = class _HttpError extends Error {
|
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
var Name = "http";
|
|
205
|
+
function stringToStream(text) {
|
|
206
|
+
return new ReadableStream({
|
|
207
|
+
start(controller) {
|
|
208
|
+
try {
|
|
209
|
+
const encoder = new TextEncoder();
|
|
210
|
+
controller.enqueue(encoder.encode(text));
|
|
211
|
+
controller.close();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
controller.error(error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
205
218
|
function deepClone(obj) {
|
|
206
219
|
if (obj === null || typeof obj !== "object") return obj;
|
|
207
220
|
if (Array.isArray(obj)) return JSON.parse(JSON.stringify(obj));
|
|
@@ -325,6 +338,9 @@ var Http = class {
|
|
|
325
338
|
data.response = error;
|
|
326
339
|
}
|
|
327
340
|
this.session.update();
|
|
341
|
+
if (this.response.body && !data.response) {
|
|
342
|
+
data.response = this.response.body;
|
|
343
|
+
}
|
|
328
344
|
if (data.response)
|
|
329
345
|
if (data.response instanceof Error || data.response.constructor?.name === "Error") {
|
|
330
346
|
data.logger.error(data.response);
|
|
@@ -341,9 +357,12 @@ var Http = class {
|
|
|
341
357
|
this.response = data.response;
|
|
342
358
|
else if (data.response instanceof ReadableStream)
|
|
343
359
|
this.response.body = data.response;
|
|
344
|
-
else
|
|
360
|
+
else
|
|
361
|
+
this.response.body = JSON.stringify({
|
|
362
|
+
data: data.response === void 0 ? null : data.response
|
|
363
|
+
});
|
|
345
364
|
if (!this.response.statusCode)
|
|
346
|
-
this.response.statusCode =
|
|
365
|
+
this.response.statusCode = data.response ? 200 : 204;
|
|
347
366
|
this.response.headers = Object.assign(
|
|
348
367
|
{
|
|
349
368
|
"content-type": this.response.body instanceof ReadableStream ? "text/plain; charset=utf-8" : "application/json; charset=utf-8",
|
|
@@ -360,10 +379,17 @@ var Http = class {
|
|
|
360
379
|
data.response.isBase64Encoded = true;
|
|
361
380
|
return;
|
|
362
381
|
}
|
|
382
|
+
if (originBody === void 0 && data.response.statusCode === 204) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
363
385
|
if (originBody && typeof originBody !== "string")
|
|
364
386
|
data.response.body = JSON.stringify(originBody);
|
|
365
|
-
if (
|
|
387
|
+
else if (originBody === void 0)
|
|
388
|
+
data.response.body = JSON.stringify({ data: null });
|
|
389
|
+
if (!data.response.body || typeof data.response.body !== "string" || data.response.body.length < 1024) {
|
|
390
|
+
data.response.body = stringToStream(data.response.body);
|
|
366
391
|
return;
|
|
392
|
+
}
|
|
367
393
|
const acceptEncoding = this.headers["accept-encoding"] || this.headers["Accept-Encoding"];
|
|
368
394
|
if (!acceptEncoding || !/(br|gzip|deflate)/.test(acceptEncoding)) return;
|
|
369
395
|
try {
|
package/dist/index.mjs
CHANGED
|
@@ -200,6 +200,19 @@ var HttpError = class _HttpError extends Error {
|
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
202
|
var Name = "http";
|
|
203
|
+
function stringToStream(text) {
|
|
204
|
+
return new ReadableStream({
|
|
205
|
+
start(controller) {
|
|
206
|
+
try {
|
|
207
|
+
const encoder = new TextEncoder();
|
|
208
|
+
controller.enqueue(encoder.encode(text));
|
|
209
|
+
controller.close();
|
|
210
|
+
} catch (error) {
|
|
211
|
+
controller.error(error);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
203
216
|
function deepClone(obj) {
|
|
204
217
|
if (obj === null || typeof obj !== "object") return obj;
|
|
205
218
|
if (Array.isArray(obj)) return JSON.parse(JSON.stringify(obj));
|
|
@@ -323,6 +336,9 @@ var Http = class {
|
|
|
323
336
|
data.response = error;
|
|
324
337
|
}
|
|
325
338
|
this.session.update();
|
|
339
|
+
if (this.response.body && !data.response) {
|
|
340
|
+
data.response = this.response.body;
|
|
341
|
+
}
|
|
326
342
|
if (data.response)
|
|
327
343
|
if (data.response instanceof Error || data.response.constructor?.name === "Error") {
|
|
328
344
|
data.logger.error(data.response);
|
|
@@ -339,9 +355,12 @@ var Http = class {
|
|
|
339
355
|
this.response = data.response;
|
|
340
356
|
else if (data.response instanceof ReadableStream)
|
|
341
357
|
this.response.body = data.response;
|
|
342
|
-
else
|
|
358
|
+
else
|
|
359
|
+
this.response.body = JSON.stringify({
|
|
360
|
+
data: data.response === void 0 ? null : data.response
|
|
361
|
+
});
|
|
343
362
|
if (!this.response.statusCode)
|
|
344
|
-
this.response.statusCode =
|
|
363
|
+
this.response.statusCode = data.response ? 200 : 204;
|
|
345
364
|
this.response.headers = Object.assign(
|
|
346
365
|
{
|
|
347
366
|
"content-type": this.response.body instanceof ReadableStream ? "text/plain; charset=utf-8" : "application/json; charset=utf-8",
|
|
@@ -358,10 +377,17 @@ var Http = class {
|
|
|
358
377
|
data.response.isBase64Encoded = true;
|
|
359
378
|
return;
|
|
360
379
|
}
|
|
380
|
+
if (originBody === void 0 && data.response.statusCode === 204) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
361
383
|
if (originBody && typeof originBody !== "string")
|
|
362
384
|
data.response.body = JSON.stringify(originBody);
|
|
363
|
-
if (
|
|
385
|
+
else if (originBody === void 0)
|
|
386
|
+
data.response.body = JSON.stringify({ data: null });
|
|
387
|
+
if (!data.response.body || typeof data.response.body !== "string" || data.response.body.length < 1024) {
|
|
388
|
+
data.response.body = stringToStream(data.response.body);
|
|
364
389
|
return;
|
|
390
|
+
}
|
|
365
391
|
const acceptEncoding = this.headers["accept-encoding"] || this.headers["Accept-Encoding"];
|
|
366
392
|
if (!acceptEncoding || !/(br|gzip|deflate)/.test(acceptEncoding)) return;
|
|
367
393
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/http",
|
|
3
|
-
"version": "v8.0.0-beta.
|
|
3
|
+
"version": "v8.0.0-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@faasjs/func": ">=v8.0.0-beta.
|
|
34
|
-
"@faasjs/logger": ">=v8.0.0-beta.
|
|
33
|
+
"@faasjs/func": ">=v8.0.0-beta.2",
|
|
34
|
+
"@faasjs/logger": ">=v8.0.0-beta.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@faasjs/func": ">=v8.0.0-beta.
|
|
38
|
-
"@faasjs/logger": ">=v8.0.0-beta.
|
|
37
|
+
"@faasjs/func": ">=v8.0.0-beta.2",
|
|
38
|
+
"@faasjs/logger": ">=v8.0.0-beta.2"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=24.0.0",
|