@adaas/a-server 0.0.23 → 0.0.24
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/browser/index.d.mts +30 -0
- package/dist/browser/index.mjs +68 -2
- package/dist/browser/index.mjs.map +1 -1
- package/dist/node/{A-Response.entity-BVYAc6-8.d.mts → A-Response.entity-6qhiV7BE.d.mts} +30 -0
- package/dist/node/{A-Response.entity-CRc-t-vr.d.ts → A-Response.entity-bjh6bofZ.d.ts} +30 -0
- package/dist/node/controllers/A-CommandController/A-CommandController.component.d.mts +1 -1
- package/dist/node/controllers/A-CommandController/A-CommandController.component.d.ts +1 -1
- package/dist/node/controllers/A-EntityController/A-EntityController.component.d.mts +1 -1
- package/dist/node/controllers/A-EntityController/A-EntityController.component.d.ts +1 -1
- package/dist/node/controllers/A-ListingController/A-ListingController.component.d.mts +1 -1
- package/dist/node/controllers/A-ListingController/A-ListingController.component.d.ts +1 -1
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.mts +1 -1
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.ts +1 -1
- package/dist/node/index.d.mts +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/lib/A-Response/A-Response.entity.d.mts +1 -1
- package/dist/node/lib/A-Response/A-Response.entity.d.ts +1 -1
- package/dist/node/lib/A-Response/A-Response.entity.js +65 -1
- package/dist/node/lib/A-Response/A-Response.entity.js.map +1 -1
- package/dist/node/lib/A-Response/A-Response.entity.mjs +65 -1
- package/dist/node/lib/A-Response/A-Response.entity.mjs.map +1 -1
- package/dist/node/lib/A-Response/A-Response.types.d.mts +1 -1
- package/dist/node/lib/A-Response/A-Response.types.d.ts +1 -1
- package/dist/node/lib/A-Server/A-HttpServer.container.d.mts +1 -1
- package/dist/node/lib/A-Server/A-HttpServer.container.d.ts +1 -1
- package/dist/node/lib/A-Server/A-HttpServer.container.js +3 -1
- package/dist/node/lib/A-Server/A-HttpServer.container.js.map +1 -1
- package/dist/node/lib/A-Server/A-HttpServer.container.mjs +3 -1
- package/dist/node/lib/A-Server/A-HttpServer.container.mjs.map +1 -1
- package/dist/node/lib/A-ServerController/A-ServerController.component.d.mts +1 -1
- package/dist/node/lib/A-ServerController/A-ServerController.component.d.ts +1 -1
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.d.mts +1 -1
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.d.ts +1 -1
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.d.mts +1 -1
- package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.d.ts +1 -1
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.d.mts +1 -1
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.d.ts +1 -1
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.d.mts +1 -1
- package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.d.ts +1 -1
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.d.mts +1 -1
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.d.ts +1 -1
- package/package.json +1 -1
- package/src/lib/A-Response/A-Response.entity.ts +63 -1
- package/src/lib/A-Server/A-HttpServer.container.ts +6 -1
package/dist/browser/index.d.mts
CHANGED
|
@@ -1002,6 +1002,10 @@ declare class A_Response<_ResponseType = any> extends A_Entity<A_Response_Constr
|
|
|
1002
1002
|
* Event listeners map for A_Response events
|
|
1003
1003
|
*/
|
|
1004
1004
|
private _listeners;
|
|
1005
|
+
/**
|
|
1006
|
+
* Whether this response is operating as a persistent SSE stream
|
|
1007
|
+
*/
|
|
1008
|
+
private _isStreaming;
|
|
1005
1009
|
constructor(params: A_Response_Constructor, options?: A_Response_Options);
|
|
1006
1010
|
/**
|
|
1007
1011
|
* Initialize from new entity parameters
|
|
@@ -1027,6 +1031,12 @@ declare class A_Response<_ResponseType = any> extends A_Entity<A_Response_Constr
|
|
|
1027
1031
|
* Gets response size in bytes
|
|
1028
1032
|
*/
|
|
1029
1033
|
get size(): number;
|
|
1034
|
+
/**
|
|
1035
|
+
* Whether this response is in SSE streaming mode.
|
|
1036
|
+
* When true the server container will NOT auto-send and destroy() will
|
|
1037
|
+
* leave the underlying socket open.
|
|
1038
|
+
*/
|
|
1039
|
+
get isStreaming(): boolean;
|
|
1030
1040
|
/**
|
|
1031
1041
|
* Initialize the response
|
|
1032
1042
|
*/
|
|
@@ -1053,6 +1063,26 @@ declare class A_Response<_ResponseType = any> extends A_Entity<A_Response_Constr
|
|
|
1053
1063
|
* [!] Note: This method ends the response immediately.
|
|
1054
1064
|
*/
|
|
1055
1065
|
redirect(url: string): Promise<void>;
|
|
1066
|
+
/**
|
|
1067
|
+
* Upgrade this response to a persistent SSE stream.
|
|
1068
|
+
* Sends the required headers and writes the initial `:ok` comment to flush
|
|
1069
|
+
* the connection. After calling this the response will NOT be auto-closed
|
|
1070
|
+
* by the server container or by destroy().
|
|
1071
|
+
*/
|
|
1072
|
+
sseOpen(): void;
|
|
1073
|
+
/**
|
|
1074
|
+
* Write a named SSE event onto the open stream.
|
|
1075
|
+
* Format: `event: <name>\ndata: <JSON>\n\n`
|
|
1076
|
+
*
|
|
1077
|
+
* Compatible with browser EventSource `addEventListener(name, handler)`.
|
|
1078
|
+
*
|
|
1079
|
+
* @returns false when the channel is no longer writable
|
|
1080
|
+
*/
|
|
1081
|
+
sseWrite(event: string, data?: any): boolean;
|
|
1082
|
+
/**
|
|
1083
|
+
* Close the SSE stream gracefully.
|
|
1084
|
+
*/
|
|
1085
|
+
sseClose(): void;
|
|
1056
1086
|
/**
|
|
1057
1087
|
* Write head with status and headers
|
|
1058
1088
|
*/
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1093,6 +1093,10 @@ var A_Response = class extends A_Entity {
|
|
|
1093
1093
|
* Event listeners map for A_Response events
|
|
1094
1094
|
*/
|
|
1095
1095
|
this._listeners = /* @__PURE__ */ new Map();
|
|
1096
|
+
/**
|
|
1097
|
+
* Whether this response is operating as a persistent SSE stream
|
|
1098
|
+
*/
|
|
1099
|
+
this._isStreaming = false;
|
|
1096
1100
|
this._options = {
|
|
1097
1101
|
autoCompress: true,
|
|
1098
1102
|
compressionThreshold: 1024,
|
|
@@ -1162,6 +1166,14 @@ var A_Response = class extends A_Entity {
|
|
|
1162
1166
|
get size() {
|
|
1163
1167
|
return this.original.getHeader("Content-Length") || 0;
|
|
1164
1168
|
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Whether this response is in SSE streaming mode.
|
|
1171
|
+
* When true the server container will NOT auto-send and destroy() will
|
|
1172
|
+
* leave the underlying socket open.
|
|
1173
|
+
*/
|
|
1174
|
+
get isStreaming() {
|
|
1175
|
+
return this._isStreaming;
|
|
1176
|
+
}
|
|
1165
1177
|
// ======================================================================================
|
|
1166
1178
|
// --------------------------------------------------------------------------
|
|
1167
1179
|
// A-Response Primary Methods
|
|
@@ -1183,7 +1195,7 @@ var A_Response = class extends A_Entity {
|
|
|
1183
1195
|
* Destroy the response
|
|
1184
1196
|
*/
|
|
1185
1197
|
async destroy() {
|
|
1186
|
-
if (!this.original.destroyed) {
|
|
1198
|
+
if (!this.original.destroyed && !this._isStreaming) {
|
|
1187
1199
|
this.original.end();
|
|
1188
1200
|
this._listeners.clear();
|
|
1189
1201
|
this.original.removeAllListeners();
|
|
@@ -1282,6 +1294,58 @@ var A_Response = class extends A_Entity {
|
|
|
1282
1294
|
}));
|
|
1283
1295
|
}
|
|
1284
1296
|
}
|
|
1297
|
+
// ======================================================================================
|
|
1298
|
+
// --------------------------------------------------------------------------
|
|
1299
|
+
// A-Response SSE (Server-Sent Events) Methods
|
|
1300
|
+
// --------------------------------------------------------------------------
|
|
1301
|
+
// ======================================================================================
|
|
1302
|
+
/**
|
|
1303
|
+
* Upgrade this response to a persistent SSE stream.
|
|
1304
|
+
* Sends the required headers and writes the initial `:ok` comment to flush
|
|
1305
|
+
* the connection. After calling this the response will NOT be auto-closed
|
|
1306
|
+
* by the server container or by destroy().
|
|
1307
|
+
*/
|
|
1308
|
+
sseOpen() {
|
|
1309
|
+
if (this.headersSent || this._isStreaming) return;
|
|
1310
|
+
this._isStreaming = true;
|
|
1311
|
+
this.original.writeHead(200, {
|
|
1312
|
+
"Content-Type": "text/event-stream",
|
|
1313
|
+
"Cache-Control": "no-cache, no-transform",
|
|
1314
|
+
"Connection": "keep-alive",
|
|
1315
|
+
"X-Accel-Buffering": "no"
|
|
1316
|
+
});
|
|
1317
|
+
this.original.write(":ok\n\n");
|
|
1318
|
+
this.original.once("close", () => {
|
|
1319
|
+
this._isStreaming = false;
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Write a named SSE event onto the open stream.
|
|
1324
|
+
* Format: `event: <name>\ndata: <JSON>\n\n`
|
|
1325
|
+
*
|
|
1326
|
+
* Compatible with browser EventSource `addEventListener(name, handler)`.
|
|
1327
|
+
*
|
|
1328
|
+
* @returns false when the channel is no longer writable
|
|
1329
|
+
*/
|
|
1330
|
+
sseWrite(event, data) {
|
|
1331
|
+
if (!this._isStreaming || this.original.destroyed) return false;
|
|
1332
|
+
try {
|
|
1333
|
+
return this.original.write(`event: ${event}
|
|
1334
|
+
data: ${JSON.stringify(data ?? {})}
|
|
1335
|
+
|
|
1336
|
+
`);
|
|
1337
|
+
} catch {
|
|
1338
|
+
return false;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Close the SSE stream gracefully.
|
|
1343
|
+
*/
|
|
1344
|
+
sseClose() {
|
|
1345
|
+
if (!this._isStreaming || this.original.destroyed) return;
|
|
1346
|
+
this._isStreaming = false;
|
|
1347
|
+
this.original.end();
|
|
1348
|
+
}
|
|
1285
1349
|
/**
|
|
1286
1350
|
* Write head with status and headers
|
|
1287
1351
|
*/
|
|
@@ -1820,7 +1884,9 @@ var A_HttpServer = class extends A_Service {
|
|
|
1820
1884
|
await onRequestFeature.process(scope);
|
|
1821
1885
|
await onAfterRequestFeature.process(scope);
|
|
1822
1886
|
req.clearTimeout();
|
|
1823
|
-
|
|
1887
|
+
if (!res.isStreaming) {
|
|
1888
|
+
await res.status(200).send();
|
|
1889
|
+
}
|
|
1824
1890
|
resolve();
|
|
1825
1891
|
} catch (error) {
|
|
1826
1892
|
req.clearTimeout();
|