keryx 0.11.2 → 0.11.3
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/classes/Connection.ts +12 -2
- package/index.ts +1 -0
- package/package.json +1 -1
package/classes/Connection.ts
CHANGED
|
@@ -13,9 +13,15 @@ import { ErrorType, TypedError } from "./TypedError";
|
|
|
13
13
|
/**
|
|
14
14
|
* Represents a client connection to the server — HTTP request, WebSocket, or internal caller.
|
|
15
15
|
* Each connection tracks its own session, channel subscriptions, and rate-limit state.
|
|
16
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* @typeParam T - Shape of the session data stored in Redis (persists across requests).
|
|
18
|
+
* @typeParam TMeta - Shape of request-scoped metadata that middleware and actions can
|
|
19
|
+
* read/write during a single `act()` call. Reset to `{}` at the start of each invocation.
|
|
17
20
|
*/
|
|
18
|
-
export class Connection<
|
|
21
|
+
export class Connection<
|
|
22
|
+
T extends Record<string, any> = Record<string, any>,
|
|
23
|
+
TMeta extends Record<string, any> = Record<string, any>,
|
|
24
|
+
> {
|
|
19
25
|
/** Transport type identifier (e.g., `"web"`, `"websocket"`). */
|
|
20
26
|
type: string;
|
|
21
27
|
/** A human-readable identifier for the connection, typically the remote IP or a session key. */
|
|
@@ -36,6 +42,8 @@ export class Connection<T extends Record<string, any> = Record<string, any>> {
|
|
|
36
42
|
rateLimitInfo?: RateLimitInfo;
|
|
37
43
|
/** Request correlation ID for distributed tracing. Propagated from the incoming `X-Request-Id` header when `config.server.web.correlationId.trustProxy` is enabled. */
|
|
38
44
|
correlationId?: string;
|
|
45
|
+
/** App-defined request-scoped metadata. Reset to `{}` at the start of each `act()` call so that long-lived connections (e.g., WebSockets) don't leak state between actions. */
|
|
46
|
+
metadata: Partial<TMeta>;
|
|
39
47
|
|
|
40
48
|
/**
|
|
41
49
|
* Create a new connection and register it in `api.connections`.
|
|
@@ -60,6 +68,7 @@ export class Connection<T extends Record<string, any> = Record<string, any>> {
|
|
|
60
68
|
this.sessionLoaded = false;
|
|
61
69
|
this.subscriptions = new Set();
|
|
62
70
|
this.rawConnection = rawConnection;
|
|
71
|
+
this.metadata = {};
|
|
63
72
|
|
|
64
73
|
api.connections.connections.set(this.id, this);
|
|
65
74
|
}
|
|
@@ -84,6 +93,7 @@ export class Connection<T extends Record<string, any> = Record<string, any>> {
|
|
|
84
93
|
method: Request["method"] = "",
|
|
85
94
|
url: string = "",
|
|
86
95
|
): Promise<{ response: Object; error?: TypedError }> {
|
|
96
|
+
this.metadata = {};
|
|
87
97
|
const reqStartTime = new Date().getTime();
|
|
88
98
|
let loggerResponsePrefix: "OK" | "ERROR" = "OK";
|
|
89
99
|
let response: Object = {};
|
package/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ export { HTTP_METHOD } from "./classes/Action";
|
|
|
22
22
|
export type { ActionMiddleware } from "./classes/Action";
|
|
23
23
|
export { CHANNEL_NAME_PATTERN } from "./classes/Channel";
|
|
24
24
|
export type { ChannelMiddleware } from "./classes/Channel";
|
|
25
|
+
export { Connection } from "./classes/Connection";
|
|
25
26
|
export { LogLevel } from "./classes/Logger";
|
|
26
27
|
export { ErrorStatusCodes, ErrorType, TypedError } from "./classes/TypedError";
|
|
27
28
|
export type { KeryxConfig } from "./config";
|