resora 1.2.5 → 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/README.md +9 -9
- package/dist/index.cjs +10 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +10 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/resora)
|
|
4
4
|
[](https://www.npmjs.com/package/resora)
|
|
5
|
-
[](https://github.com/arkstack-
|
|
6
|
-
[](https://github.com/arkstack-tmp/resora/blob/main/LICENSE)
|
|
6
|
+
[](https://github.com/arkstack-tmp/resora/actions/workflows/ci.yml)
|
|
7
|
+
[](https://github.com/arkstack-tmp/resora/actions/workflows/deploy-docs.yml)
|
|
8
|
+
[](https://codecov.io/gh/arkstack-tmp/resora)
|
|
9
9
|
|
|
10
10
|
Resora is a structured API response layer for Node.js and TypeScript backends.
|
|
11
11
|
|
|
@@ -242,7 +242,7 @@ Plugins can:
|
|
|
242
242
|
|
|
243
243
|
Available plugins:
|
|
244
244
|
|
|
245
|
-
- [`@resora/plugin-clear-router`](https://arkstack-
|
|
245
|
+
- [`@resora/plugin-clear-router`](https://arkstack-tmp.github.io/resora/plugins/clear-router.md)
|
|
246
246
|
|
|
247
247
|
## Conditional Rendering Example
|
|
248
248
|
|
|
@@ -274,10 +274,10 @@ It is intentionally not opinionated about routing, validation, or persistence.
|
|
|
274
274
|
|
|
275
275
|
## Documentation
|
|
276
276
|
|
|
277
|
-
- Getting Started: https://arkstack-
|
|
278
|
-
- Configuration: https://arkstack-
|
|
279
|
-
- Conditional Rendering: https://arkstack-
|
|
280
|
-
- Pagination & Cursor Recipes: https://arkstack-
|
|
277
|
+
- Getting Started: https://arkstack-tmp.github.io/resora/guide/getting-started
|
|
278
|
+
- Configuration: https://arkstack-tmp.github.io/resora/guide/configuration
|
|
279
|
+
- Conditional Rendering: https://arkstack-tmp.github.io/resora/guide/conditional-attributes
|
|
280
|
+
- Pagination & Cursor Recipes: https://arkstack-tmp.github.io/resora/guide/pagination-cursor-recipes
|
|
281
281
|
|
|
282
282
|
## License
|
|
283
283
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"json",
|
|
15
15
|
"response"
|
|
16
16
|
],
|
|
17
|
-
"homepage": "https://arkstack-
|
|
17
|
+
"homepage": "https://arkstack-tmp.github.io/resora",
|
|
18
18
|
"bugs": {
|
|
19
|
-
"url": "https://github.com/arkstack-
|
|
19
|
+
"url": "https://github.com/arkstack-tmp/resora/issues"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
|
-
"url": "git+https://github.com/arkstack-
|
|
23
|
+
"url": "git+https://github.com/arkstack-tmp/resora.git"
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"author": "3m1n1nce <3m1n1nce@toneflix.net>",
|