@adonix.org/cloud-spark 2.2.0 → 2.3.0

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.d.ts CHANGED
@@ -2,6 +2,7 @@ import CacheLib from 'cache-control-parser';
2
2
  import { W as WorkerClass, M as Method, a as Worker, b as Middleware } from './middleware-CfKw8AlN.js';
3
3
  export { D as DELETE, G as GET, H as HEAD, O as OPTIONS, d as PATCH, c as POST, P as PUT } from './middleware-CfKw8AlN.js';
4
4
  import { MatchFunction } from 'path-to-regexp';
5
+ export { C as CustomEventMap, a as CustomEventType, E as EventOptions, d as ExtendedEventListener, b as ExtendedEventMap, c as ExtendedEventType, e as WSAttachment, W as WarnEvent, f as WebSocketConnection } from './websocket-DR6W2q9z.js';
5
6
 
6
7
  /**
7
8
  * @see {@link https://github.com/etienne-martin/cache-control-parser | cache-control-parser}
@@ -1,119 +1,4 @@
1
- /**
2
- * Represents a warning event emitted by a WebSocket.
3
- */
4
- type WarnEvent = {
5
- type: "warn";
6
- message: string;
7
- };
8
- /**
9
- * Map of custom WebSocket events.
10
- * - `warn`: internal warning notifications
11
- * - `open`: triggered when the WebSocket is accepted
12
- */
13
- type CustomEventMap = {
14
- warn: WarnEvent;
15
- open: Event;
16
- };
17
- /** Options for registering WebSocket event listeners. */
18
- type EventOptions = {
19
- once?: boolean;
20
- };
21
- /** Map of all events, combining native WebSocket events and custom events. */
22
- type ExtendedEventMap = WebSocketEventMap & CustomEventMap;
23
- /** Names of all events, including standard and custom WebSocket events. */
24
- type ExtendedEventType = keyof ExtendedEventMap;
25
- /** Event listener type for an extended WebSocket event. */
26
- type ExtendedEventListener<K extends ExtendedEventType> = (ev: ExtendedEventMap[K]) => void;
27
- /**
28
- * Represents a user-defined attachment object that can be associated with a WebSocket connection.
29
- */
30
- type WSAttachment = object;
31
- /**
32
- * Represents a managed WebSocket connection with typed attachment and extended event support.
33
- *
34
- * @template A - Type of the attachment object associated with this connection.
35
- */
36
- interface WebSocketConnection<A extends WSAttachment> {
37
- /**
38
- * Current readyState of the WebSocket (0 = CONNECTING, 1 = OPEN, 2 = CLOSING, 3 = CLOSED).
39
- */
40
- get readyState(): number;
41
- /**
42
- * Checks whether the WebSocket is currently in one of the provided states.
43
- *
44
- * @param states - List of WebSocket readyState values to check against.
45
- * @returns `true` if the WebSocket's readyState matches any of the provided states.
46
- */
47
- isState(...states: number[]): boolean;
48
- /**
49
- * Accepts the WebSocket connection if not already accepted.
50
- *
51
- * @returns The readonly native WebSocket instance.
52
- */
53
- accept(): Readonly<WebSocket>;
54
- /**
55
- * Accepts the WebSocket connection in the context of a Durable Object.
56
- * Optionally associates tags for filtering.
57
- *
58
- * @param ctx - DurableObjectState for the WebSocket.
59
- * @param tags - Optional list of string tags.
60
- * @returns The readonly native WebSocket instance.
61
- */
62
- acceptWebSocket(ctx: DurableObjectState, tags?: string[]): Readonly<WebSocket>;
63
- /**
64
- * Retrieves the user-defined attachment object associated with this connection.
65
- *
66
- * The returned object is a read-only view of the attachment to prevent
67
- * accidental mutation. To modify the attachment, call {@link attach}.
68
- *
69
- * @returns A read-only view of the current attachment.
70
- */
71
- get attachment(): Readonly<A>;
72
- /**
73
- * Attaches or updates a user-defined object on this connection.
74
- *
75
- * Passing a partial object merges the new properties into the existing
76
- * attachment, leaving other fields unchanged. Pass `null` to clear
77
- * the attachment entirely.
78
- *
79
- * @param attachment - Partial object containing metadata to attach or update,
80
- * or `null` to clear the attachment.
81
- */
82
- attach(attachment?: Partial<A> | null): void;
83
- /**
84
- * Sends a message to the connected WebSocket client.
85
- *
86
- * @param message - Message to send, either string or binary data.
87
- */
88
- send(message: string | ArrayBuffer): void;
89
- /**
90
- * Closes the WebSocket connection with an optional code and reason.
91
- *
92
- * @param code - Close code (default is `1000` NORMAL).
93
- * @param reason - Optional reason string (sanitized to valid characters).
94
- */
95
- close(code?: number, reason?: string): void;
96
- /**
97
- * Registers an event listener for a WebSocket event.
98
- *
99
- * Supports both standard WebSocket events (`message`, `close`, etc.)
100
- * and custom events (`open`, `warn`).
101
- *
102
- * @param type - Event type to listen for.
103
- * @param listener - Callback invoked when the event occurs.
104
- * @param options - Optional event listener options (`once`).
105
- */
106
- addEventListener<K extends ExtendedEventType>(type: K, listener: ExtendedEventListener<K>, options?: EventOptions): void;
107
- /**
108
- * Removes a previously registered WebSocket event listener.
109
- *
110
- * Works for both standard and custom events.
111
- *
112
- * @param type - Event type to remove.
113
- * @param listener - Listener function to remove.
114
- */
115
- removeEventListener<K extends ExtendedEventType>(type: K, listener: ExtendedEventListener<K>): void;
116
- }
1
+ import { e as WSAttachment, f as WebSocketConnection } from './websocket-DR6W2q9z.js';
117
2
 
118
3
  /**
119
4
  * Manages active WebSocket connections in a Cloudflare Workers environment.
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Represents a warning event emitted by a WebSocket.
3
+ */
4
+ type WarnEvent = {
5
+ type: "warn";
6
+ message: string;
7
+ };
8
+ /**
9
+ * Map of custom WebSocket events.
10
+ * - `warn`: internal warning notifications
11
+ * - `open`: triggered when the WebSocket is accepted
12
+ */
13
+ type CustomEventMap = {
14
+ warn: WarnEvent;
15
+ open: Event;
16
+ };
17
+ /** Options for registering WebSocket event listeners. */
18
+ type EventOptions = {
19
+ once?: boolean;
20
+ };
21
+ /** Names of custom WebSocket events (`warn`, `open`). */
22
+ type CustomEventType = keyof CustomEventMap;
23
+ /** Map of all events, combining native WebSocket events and custom events. */
24
+ type ExtendedEventMap = WebSocketEventMap & CustomEventMap;
25
+ /** Names of all events, including standard and custom WebSocket events. */
26
+ type ExtendedEventType = keyof ExtendedEventMap;
27
+ /** Event listener type for an extended WebSocket event. */
28
+ type ExtendedEventListener<K extends ExtendedEventType> = (ev: ExtendedEventMap[K]) => void;
29
+ /**
30
+ * Represents a user-defined attachment object that can be associated with a WebSocket connection.
31
+ */
32
+ type WSAttachment = object;
33
+ /**
34
+ * Represents a managed WebSocket connection with typed attachment and extended event support.
35
+ *
36
+ * @template A - Type of the attachment object associated with this connection.
37
+ */
38
+ interface WebSocketConnection<A extends WSAttachment> {
39
+ /**
40
+ * Current readyState of the WebSocket (0 = CONNECTING, 1 = OPEN, 2 = CLOSING, 3 = CLOSED).
41
+ */
42
+ get readyState(): number;
43
+ /**
44
+ * Checks whether the WebSocket is currently in one of the provided states.
45
+ *
46
+ * @param states - List of WebSocket readyState values to check against.
47
+ * @returns `true` if the WebSocket's readyState matches any of the provided states.
48
+ */
49
+ isState(...states: number[]): boolean;
50
+ /**
51
+ * Accepts the WebSocket connection if not already accepted.
52
+ *
53
+ * @returns The readonly native WebSocket instance.
54
+ */
55
+ accept(): Readonly<WebSocket>;
56
+ /**
57
+ * Accepts the WebSocket connection in the context of a Durable Object.
58
+ * Optionally associates tags for filtering.
59
+ *
60
+ * @param ctx - DurableObjectState for the WebSocket.
61
+ * @param tags - Optional list of string tags.
62
+ * @returns The readonly native WebSocket instance.
63
+ */
64
+ acceptWebSocket(ctx: DurableObjectState, tags?: string[]): Readonly<WebSocket>;
65
+ /**
66
+ * Retrieves the user-defined attachment object associated with this connection.
67
+ *
68
+ * The returned object is a read-only view of the attachment to prevent
69
+ * accidental mutation. To modify the attachment, call {@link attach}.
70
+ *
71
+ * @returns A read-only view of the current attachment.
72
+ */
73
+ get attachment(): Readonly<A>;
74
+ /**
75
+ * Attaches or updates a user-defined object on this connection.
76
+ *
77
+ * Passing a partial object merges the new properties into the existing
78
+ * attachment, leaving other fields unchanged. Pass `null` to clear
79
+ * the attachment entirely.
80
+ *
81
+ * @param attachment - Partial object containing metadata to attach or update,
82
+ * or `null` to clear the attachment.
83
+ */
84
+ attach(attachment?: Partial<A> | null): void;
85
+ /**
86
+ * Sends a message to the connected WebSocket client.
87
+ *
88
+ * @param message - Message to send, either string or binary data.
89
+ */
90
+ send(message: string | ArrayBuffer): void;
91
+ /**
92
+ * Closes the WebSocket connection with an optional code and reason.
93
+ *
94
+ * @param code - Close code (default is `1000` NORMAL).
95
+ * @param reason - Optional reason string (sanitized to valid characters).
96
+ */
97
+ close(code?: number, reason?: string): void;
98
+ /**
99
+ * Registers an event listener for a WebSocket event.
100
+ *
101
+ * Supports both standard WebSocket events (`message`, `close`, etc.)
102
+ * and custom events (`open`, `warn`).
103
+ *
104
+ * @param type - Event type to listen for.
105
+ * @param listener - Callback invoked when the event occurs.
106
+ * @param options - Optional event listener options (`once`).
107
+ */
108
+ addEventListener<K extends ExtendedEventType>(type: K, listener: ExtendedEventListener<K>, options?: EventOptions): void;
109
+ /**
110
+ * Removes a previously registered WebSocket event listener.
111
+ *
112
+ * Works for both standard and custom events.
113
+ *
114
+ * @param type - Event type to remove.
115
+ * @param listener - Listener function to remove.
116
+ */
117
+ removeEventListener<K extends ExtendedEventType>(type: K, listener: ExtendedEventListener<K>): void;
118
+ }
119
+
120
+ export type { CustomEventMap as C, EventOptions as E, WarnEvent as W, CustomEventType as a, ExtendedEventMap as b, ExtendedEventType as c, ExtendedEventListener as d, WSAttachment as e, WebSocketConnection as f };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonix.org/cloud-spark",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Ignite your Cloudflare Workers with a type-safe library for rapid development.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",