resora 1.2.7 → 1.2.8

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 CHANGED
@@ -1271,6 +1271,7 @@ const resetPluginsForTests = () => {
1271
1271
  */
1272
1272
  var ServerResponse = class {
1273
1273
  _status = 200;
1274
+ sent = false;
1274
1275
  headers = {};
1275
1276
  constructor(response, body) {
1276
1277
  this.response = response;
@@ -1366,6 +1367,7 @@ var ServerResponse = class {
1366
1367
  * @returns The dispatched response body
1367
1368
  */
1368
1369
  send(body) {
1370
+ if (this.sent || this.#rawResponseSent()) return this.body;
1369
1371
  if (typeof body !== "undefined") this.body = body;
1370
1372
  const beforeSend = runPluginHook("beforeSend", {
1371
1373
  response: this,
@@ -1383,6 +1385,7 @@ var ServerResponse = class {
1383
1385
  else if ("code" in this.response && typeof this.response.code === "function") this.response.code(this._status);
1384
1386
  this.response.__resoraStatus = this._status;
1385
1387
  this.response.send(this.body);
1388
+ this.sent = true;
1386
1389
  runPluginHook("afterSend", {
1387
1390
  response: this,
1388
1391
  rawResponse: this.response,
@@ -1400,6 +1403,7 @@ var ServerResponse = class {
1400
1403
  this.response.body = this.body;
1401
1404
  this.response.__resoraStatus = this._status;
1402
1405
  }
1406
+ this.sent = true;
1403
1407
  runPluginHook("afterSend", {
1404
1408
  response: this,
1405
1409
  rawResponse: this.response,
@@ -1409,6 +1413,10 @@ var ServerResponse = class {
1409
1413
  });
1410
1414
  return this.body;
1411
1415
  }
1416
+ #rawResponseSent() {
1417
+ const raw = this.response;
1418
+ return Boolean(raw?.headersSent || raw?.sent || raw?.raw?.headersSent);
1419
+ }
1412
1420
  /**
1413
1421
  * Promise-like then method to allow chaining with async/await or .then() syntax
1414
1422
  *
@@ -1559,7 +1567,8 @@ var BaseSerializer = class {
1559
1567
  * @param body
1560
1568
  */
1561
1569
  sendRawResponseBody(raw, body) {
1562
- if (raw && typeof raw.send === "function") raw.send(body);
1570
+ const response = raw;
1571
+ if (response && typeof response.send === "function" && !response.headersSent && !response.sent && !response.raw?.headersSent) response.send(body);
1563
1572
  }
1564
1573
  /**
1565
1574
  * Add additional metadata to the response. If called without arguments.
package/dist/index.d.cts CHANGED
@@ -411,6 +411,7 @@ declare class ServerResponse<R extends NonCollectible | Collectible | ResourceDa
411
411
  private response;
412
412
  private body;
413
413
  private _status;
414
+ private sent;
414
415
  headers: Record<string, string>;
415
416
  constructor(response: H3Event['res'], body: R);
416
417
  constructor(response: Response, body: R);
package/dist/index.d.mts CHANGED
@@ -411,6 +411,7 @@ declare class ServerResponse<R extends NonCollectible | Collectible | ResourceDa
411
411
  private response;
412
412
  private body;
413
413
  private _status;
414
+ private sent;
414
415
  headers: Record<string, string>;
415
416
  constructor(response: H3Event['res'], body: R);
416
417
  constructor(response: Response, body: R);
package/dist/index.mjs CHANGED
@@ -1242,6 +1242,7 @@ const resetPluginsForTests = () => {
1242
1242
  */
1243
1243
  var ServerResponse = class {
1244
1244
  _status = 200;
1245
+ sent = false;
1245
1246
  headers = {};
1246
1247
  constructor(response, body) {
1247
1248
  this.response = response;
@@ -1337,6 +1338,7 @@ var ServerResponse = class {
1337
1338
  * @returns The dispatched response body
1338
1339
  */
1339
1340
  send(body) {
1341
+ if (this.sent || this.#rawResponseSent()) return this.body;
1340
1342
  if (typeof body !== "undefined") this.body = body;
1341
1343
  const beforeSend = runPluginHook("beforeSend", {
1342
1344
  response: this,
@@ -1354,6 +1356,7 @@ var ServerResponse = class {
1354
1356
  else if ("code" in this.response && typeof this.response.code === "function") this.response.code(this._status);
1355
1357
  this.response.__resoraStatus = this._status;
1356
1358
  this.response.send(this.body);
1359
+ this.sent = true;
1357
1360
  runPluginHook("afterSend", {
1358
1361
  response: this,
1359
1362
  rawResponse: this.response,
@@ -1371,6 +1374,7 @@ var ServerResponse = class {
1371
1374
  this.response.body = this.body;
1372
1375
  this.response.__resoraStatus = this._status;
1373
1376
  }
1377
+ this.sent = true;
1374
1378
  runPluginHook("afterSend", {
1375
1379
  response: this,
1376
1380
  rawResponse: this.response,
@@ -1380,6 +1384,10 @@ var ServerResponse = class {
1380
1384
  });
1381
1385
  return this.body;
1382
1386
  }
1387
+ #rawResponseSent() {
1388
+ const raw = this.response;
1389
+ return Boolean(raw?.headersSent || raw?.sent || raw?.raw?.headersSent);
1390
+ }
1383
1391
  /**
1384
1392
  * Promise-like then method to allow chaining with async/await or .then() syntax
1385
1393
  *
@@ -1530,7 +1538,8 @@ var BaseSerializer = class {
1530
1538
  * @param body
1531
1539
  */
1532
1540
  sendRawResponseBody(raw, body) {
1533
- if (raw && typeof raw.send === "function") raw.send(body);
1541
+ const response = raw;
1542
+ if (response && typeof response.send === "function" && !response.headersSent && !response.sent && !response.raw?.headersSent) response.send(body);
1534
1543
  }
1535
1544
  /**
1536
1545
  * Add additional metadata to the response. If called without arguments.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resora",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "A structured API response layer for Node.js and TypeScript with automatic JSON responses, collection support, and pagination handling.",
5
5
  "keywords": [
6
6
  "api",