crossws 0.4.4 → 0.4.5
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/adapters/bunny.d.ts +2 -0
- package/dist/THIRD-PARTY-LICENSES.md +33 -0
- package/dist/_chunks/_request.mjs +1 -4
- package/dist/_chunks/_types.d.mts +2 -3
- package/dist/_chunks/adapter.d.mts +5 -13
- package/dist/_chunks/adapter.mjs +6 -7
- package/dist/_chunks/bun.d.mts +0 -3
- package/dist/_chunks/bunny.d.mts +22 -0
- package/dist/_chunks/cloudflare.d.mts +0 -3
- package/dist/_chunks/deno.d.mts +0 -3
- package/dist/_chunks/error.mjs +1 -4
- package/dist/_chunks/libs/ws.mjs +66 -1168
- package/dist/_chunks/node.d.mts +36 -7
- package/dist/_chunks/node.mjs +129 -0
- package/dist/_chunks/peer.mjs +1 -59
- package/dist/_chunks/rolldown-runtime.mjs +7 -15
- package/dist/_chunks/sse.d.mts +0 -3
- package/dist/_chunks/web.d.mts +0 -2
- package/dist/adapters/bun.mjs +1 -6
- package/dist/adapters/bunny.d.mts +2 -0
- package/dist/adapters/bunny.mjs +68 -0
- package/dist/adapters/cloudflare.mjs +7 -12
- package/dist/adapters/deno.mjs +1 -6
- package/dist/adapters/node.d.mts +2 -2
- package/dist/adapters/node.mjs +2 -125
- package/dist/adapters/sse.mjs +1 -6
- package/dist/adapters/uws.d.mts +0 -5
- package/dist/adapters/uws.mjs +2 -7
- package/dist/index.d.mts +81 -1
- package/dist/index.mjs +161 -2
- package/dist/server/bun.d.mts +0 -6
- package/dist/server/bun.mjs +3 -7
- package/dist/server/bunny.d.mts +5 -0
- package/dist/server/bunny.mjs +23 -0
- package/dist/server/cloudflare.d.mts +0 -6
- package/dist/server/cloudflare.mjs +3 -7
- package/dist/server/default.d.mts +0 -6
- package/dist/server/default.mjs +3 -7
- package/dist/server/deno.d.mts +0 -6
- package/dist/server/deno.mjs +3 -7
- package/dist/server/node.d.mts +0 -6
- package/dist/server/node.mjs +3 -9
- package/dist/websocket/native.d.mts +0 -2
- package/dist/websocket/native.mjs +1 -5
- package/dist/websocket/node.d.mts +0 -2
- package/dist/websocket/node.mjs +1 -7
- package/dist/websocket/sse.d.mts +0 -3
- package/dist/websocket/sse.mjs +1 -4
- package/package.json +42 -40
- package/server/bunny.d.ts +2 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Licenses of Bundled Dependencies
|
|
2
|
+
|
|
3
|
+
The published artifact additionally contains code with the following licenses:
|
|
4
|
+
MIT
|
|
5
|
+
|
|
6
|
+
# Bundled Dependencies
|
|
7
|
+
|
|
8
|
+
## ws
|
|
9
|
+
|
|
10
|
+
License: MIT
|
|
11
|
+
By: Einar Otto Stangvik
|
|
12
|
+
Repository: https://github.com/websockets/ws
|
|
13
|
+
|
|
14
|
+
> Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
|
15
|
+
> Copyright (c) 2013 Arnout Kazemier and contributors
|
|
16
|
+
> Copyright (c) 2016 Luigi Pinca and contributors
|
|
17
|
+
>
|
|
18
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
19
|
+
> this software and associated documentation files (the "Software"), to deal in
|
|
20
|
+
> the Software without restriction, including without limitation the rights to
|
|
21
|
+
> use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
22
|
+
> the Software, and to permit persons to whom the Software is furnished to do so,
|
|
23
|
+
> subject to the following conditions:
|
|
24
|
+
>
|
|
25
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
26
|
+
> copies or substantial portions of the Software.
|
|
27
|
+
>
|
|
28
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
30
|
+
> FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
31
|
+
> COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
32
|
+
> IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
33
|
+
> CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/_request.ts
|
|
2
1
|
const StubRequest = /* @__PURE__ */ (() => {
|
|
3
2
|
class StubRequest {
|
|
4
3
|
url;
|
|
@@ -78,6 +77,4 @@ const StubRequest = /* @__PURE__ */ (() => {
|
|
|
78
77
|
Object.setPrototypeOf(StubRequest.prototype, globalThis.Request.prototype);
|
|
79
78
|
return StubRequest;
|
|
80
79
|
})();
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
|
-
export { StubRequest as t };
|
|
80
|
+
export { StubRequest as t };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { a as Hooks } from "./adapter.mjs";
|
|
2
2
|
import { n as BunOptions } from "./bun.mjs";
|
|
3
|
+
import { n as BunnyOptions } from "./bunny.mjs";
|
|
3
4
|
import { n as CloudflareOptions } from "./cloudflare.mjs";
|
|
4
5
|
import { n as DenoOptions } from "./deno.mjs";
|
|
5
6
|
import { n as NodeOptions } from "./node.mjs";
|
|
6
7
|
import { n as SSEOptions } from "./sse.mjs";
|
|
7
8
|
import { Server, ServerOptions, ServerPlugin, ServerRequest } from "srvx";
|
|
8
|
-
|
|
9
|
-
//#region src/server/_types.d.ts
|
|
10
9
|
type WSOptions = Partial<Hooks> & {
|
|
11
10
|
resolve?: (req: ServerRequest) => Partial<Hooks> | Promise<Partial<Hooks>>;
|
|
12
11
|
options?: {
|
|
13
12
|
bun?: BunOptions;
|
|
13
|
+
bunny?: BunnyOptions;
|
|
14
14
|
deno?: DenoOptions;
|
|
15
15
|
node?: NodeOptions;
|
|
16
16
|
sse?: SSEOptions;
|
|
@@ -20,5 +20,4 @@ type WSOptions = Partial<Hooks> & {
|
|
|
20
20
|
type ServerWithWSOptions = ServerOptions & {
|
|
21
21
|
websocket?: WSOptions;
|
|
22
22
|
};
|
|
23
|
-
//#endregion
|
|
24
23
|
export { WSOptions as n, ServerWithWSOptions as t };
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { a as WebSocket } from "./web.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/error.d.ts
|
|
4
2
|
declare class WSError extends Error {
|
|
5
3
|
constructor(...args: any[]);
|
|
6
4
|
}
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/utils.d.ts
|
|
9
5
|
declare const kNodeInspect: unique symbol;
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/peer.d.ts
|
|
12
6
|
interface PeerContext extends Record<string, unknown> {}
|
|
13
7
|
interface AdapterInternal {
|
|
14
8
|
ws: unknown;
|
|
@@ -66,8 +60,6 @@ declare abstract class Peer<Internal extends AdapterInternal = AdapterInternal>
|
|
|
66
60
|
[Symbol.toStringTag](): "WebSocket";
|
|
67
61
|
[kNodeInspect](): unknown;
|
|
68
62
|
}
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/message.d.ts
|
|
71
63
|
declare class Message implements Partial<MessageEvent> {
|
|
72
64
|
#private;
|
|
73
65
|
/** Access to the original [message event](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event) if available. */
|
|
@@ -116,8 +108,6 @@ declare class Message implements Partial<MessageEvent> {
|
|
|
116
108
|
[Symbol.toPrimitive](): string;
|
|
117
109
|
[kNodeInspect](): unknown;
|
|
118
110
|
}
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/hooks.d.ts
|
|
121
111
|
declare function defineHooks<T extends Partial<Hooks> = Partial<Hooks>>(hooks: T): T;
|
|
122
112
|
type ResolveHooks = (request: Request & {
|
|
123
113
|
readonly context?: PeerContext;
|
|
@@ -131,6 +121,10 @@ interface Hooks {
|
|
|
131
121
|
* - You can return { headers } to modify the response.
|
|
132
122
|
* - You can return { namespace } to change the pub/sub namespace.
|
|
133
123
|
* - You can return { context } to provide a custom peer context.
|
|
124
|
+
* - You can return { handled: true } to signal that the upgrade has
|
|
125
|
+
* already been performed by the hook (e.g. delegated to an external
|
|
126
|
+
* node-style `(req, socket, head)` handler). The adapter will then
|
|
127
|
+
* leave the socket alone and skip its own upgrade.
|
|
134
128
|
*
|
|
135
129
|
* @param request
|
|
136
130
|
* @throws {Response}
|
|
@@ -141,6 +135,7 @@ interface Hooks {
|
|
|
141
135
|
headers?: HeadersInit;
|
|
142
136
|
namespace?: string;
|
|
143
137
|
context?: PeerContext;
|
|
138
|
+
handled?: boolean;
|
|
144
139
|
} | Response | void>;
|
|
145
140
|
/** A message is received */
|
|
146
141
|
message: (peer: Peer, message: Message) => MaybePromise<void>;
|
|
@@ -154,8 +149,6 @@ interface Hooks {
|
|
|
154
149
|
/** An error occurs */
|
|
155
150
|
error: (peer: Peer, error: WSError) => MaybePromise<void>;
|
|
156
151
|
}
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/adapter.d.ts
|
|
159
152
|
interface AdapterInstance {
|
|
160
153
|
readonly peers: Map<string, Set<Peer>>;
|
|
161
154
|
readonly publish: (topic: string, data: unknown, options?: {
|
|
@@ -170,5 +163,4 @@ interface AdapterOptions {
|
|
|
170
163
|
}
|
|
171
164
|
type Adapter<AdapterT extends AdapterInstance = AdapterInstance, Options extends AdapterOptions = AdapterOptions> = (options?: Options) => AdapterT;
|
|
172
165
|
declare function defineWebSocketAdapter<AdapterT extends AdapterInstance = AdapterInstance, Options extends AdapterOptions = AdapterOptions>(factory: Adapter<AdapterT, Options>): Adapter<AdapterT, Options>;
|
|
173
|
-
//#endregion
|
|
174
166
|
export { Hooks as a, Message as c, PeerContext as d, WSError as f, defineWebSocketAdapter as i, AdapterInternal as l, AdapterInstance as n, ResolveHooks as o, AdapterOptions as r, defineHooks as s, Adapter as t, Peer as u };
|
package/dist/_chunks/adapter.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/hooks.ts
|
|
2
1
|
var AdapterHookable = class {
|
|
3
2
|
options;
|
|
4
3
|
constructor(options) {
|
|
@@ -32,6 +31,11 @@ var AdapterHookable = class {
|
|
|
32
31
|
namespace,
|
|
33
32
|
endResponse: res
|
|
34
33
|
};
|
|
34
|
+
if (res.handled) return {
|
|
35
|
+
context,
|
|
36
|
+
namespace,
|
|
37
|
+
handled: true
|
|
38
|
+
};
|
|
35
39
|
if (res.headers) return {
|
|
36
40
|
context,
|
|
37
41
|
namespace,
|
|
@@ -55,9 +59,6 @@ var AdapterHookable = class {
|
|
|
55
59
|
function defineHooks(hooks) {
|
|
56
60
|
return hooks;
|
|
57
61
|
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/adapter.ts
|
|
61
62
|
function adapterUtils(globalPeers) {
|
|
62
63
|
return {
|
|
63
64
|
peers: globalPeers,
|
|
@@ -88,6 +89,4 @@ function getPeers(globalPeers, namespace) {
|
|
|
88
89
|
function defineWebSocketAdapter(factory) {
|
|
89
90
|
return factory;
|
|
90
91
|
}
|
|
91
|
-
|
|
92
|
-
//#endregion
|
|
93
|
-
export { defineHooks as a, AdapterHookable as i, defineWebSocketAdapter as n, getPeers as r, adapterUtils as t };
|
|
92
|
+
export { defineHooks as a, AdapterHookable as i, defineWebSocketAdapter as n, getPeers as r, adapterUtils as t };
|
package/dist/_chunks/bun.d.mts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { d as PeerContext, n as AdapterInstance, r as AdapterOptions, t as Adapter, u as Peer } from "./adapter.mjs";
|
|
2
2
|
import { Server, ServerWebSocket, WebSocketHandler } from "bun";
|
|
3
|
-
|
|
4
|
-
//#region src/adapters/bun.d.ts
|
|
5
3
|
interface BunAdapter extends AdapterInstance {
|
|
6
4
|
websocket: WebSocketHandler<ContextData>;
|
|
7
5
|
handleUpgrade(req: Request, server: Server<ContextData>): Promise<Response | undefined>;
|
|
@@ -34,5 +32,4 @@ declare class BunPeer extends Peer<{
|
|
|
34
32
|
close(code?: number, reason?: string): void;
|
|
35
33
|
terminate(): void;
|
|
36
34
|
}
|
|
37
|
-
//#endregion
|
|
38
35
|
export { BunOptions as n, bunAdapter as r, BunAdapter as t };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { n as AdapterInstance, r as AdapterOptions, t as Adapter } from "./adapter.mjs";
|
|
2
|
+
interface BunnyAdapter extends AdapterInstance {
|
|
3
|
+
handleUpgrade(req: Request): Promise<Response>;
|
|
4
|
+
}
|
|
5
|
+
interface BunnyOptions extends AdapterOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The WebSocket subprotocol to use for the connection.
|
|
8
|
+
*/
|
|
9
|
+
protocol?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The number of seconds to wait for a pong response before closing the connection.
|
|
12
|
+
* If the client does not respond within this timeout, the connection is deemed
|
|
13
|
+
* unhealthy and closed, emitting the close and error events.
|
|
14
|
+
* If no data is transmitted from the client for 2 minutes, the connection
|
|
15
|
+
* will be closed regardless of this configuration.
|
|
16
|
+
*
|
|
17
|
+
* @default 30
|
|
18
|
+
*/
|
|
19
|
+
idleTimeout?: number;
|
|
20
|
+
}
|
|
21
|
+
declare const bunnyAdapter: Adapter<BunnyAdapter, BunnyOptions>;
|
|
22
|
+
export { BunnyOptions as n, bunnyAdapter as r, BunnyAdapter as t };
|
|
@@ -2,8 +2,6 @@ import { n as AdapterInstance, r as AdapterOptions, t as Adapter } from "./adapt
|
|
|
2
2
|
import { a as WebSocket$1 } from "./web.mjs";
|
|
3
3
|
import { DurableObject } from "cloudflare:workers";
|
|
4
4
|
import * as CF from "@cloudflare/workers-types";
|
|
5
|
-
|
|
6
|
-
//#region src/adapters/cloudflare.d.ts
|
|
7
5
|
type WSDurableObjectStub = CF.DurableObjectStub & {
|
|
8
6
|
webSocketPublish?: (topic: string, data: unknown, opts: any) => Promise<void>;
|
|
9
7
|
};
|
|
@@ -41,5 +39,4 @@ interface CloudflareDurableAdapter extends AdapterInstance {
|
|
|
41
39
|
handleDurablePublish: (obj: DurableObject, topic: string, data: unknown, opts: any) => Promise<void>;
|
|
42
40
|
handleDurableClose(obj: DurableObject, ws: WebSocket | CF.WebSocket | WebSocket$1, code: number, reason: string, wasClean: boolean): Promise<void>;
|
|
43
41
|
}
|
|
44
|
-
//#endregion
|
|
45
42
|
export { CloudflareOptions as n, cloudflareAdapter as r, CloudflareDurableAdapter as t };
|
package/dist/_chunks/deno.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { n as AdapterInstance, r as AdapterOptions, t as Adapter } from "./adapter.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/adapters/deno.d.ts
|
|
4
2
|
interface DenoAdapter extends AdapterInstance {
|
|
5
3
|
handleUpgrade(req: Request, info: ServeHandlerInfo): Promise<Response>;
|
|
6
4
|
}
|
|
@@ -13,5 +11,4 @@ type ServeHandlerInfo = {
|
|
|
13
11
|
};
|
|
14
12
|
};
|
|
15
13
|
declare const denoAdapter: Adapter<DenoAdapter, DenoOptions>;
|
|
16
|
-
//#endregion
|
|
17
14
|
export { DenoOptions as n, denoAdapter as r, DenoAdapter as t };
|