@vercel/functions 3.7.0 → 3.7.1
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/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
> **experimental\_upgradeWebSocket**(`handler`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`Response`](https://developer.mozilla.org/docs/Web/API/Response)\>
|
|
8
8
|
|
|
9
|
-
Defined in: [packages/functions/src/websocket/index.ts:
|
|
9
|
+
Defined in: [packages/functions/src/websocket/index.ts:16](https://github.com/vercel/vercel/blob/main/packages/functions/src/websocket/index.ts#L16)
|
|
10
10
|
|
|
11
11
|
## Parameters
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"require": "./middleware.js"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"version": "3.7.
|
|
33
|
+
"version": "3.7.1",
|
|
34
34
|
"repository": {
|
|
35
35
|
"directory": "packages/functions",
|
|
36
36
|
"type": "git",
|
|
@@ -58,11 +58,15 @@
|
|
|
58
58
|
"vitest": "2.0.1"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@aws-sdk/credential-provider-web-identity": "*"
|
|
61
|
+
"@aws-sdk/credential-provider-web-identity": "*",
|
|
62
|
+
"ws": ">=8"
|
|
62
63
|
},
|
|
63
64
|
"peerDependenciesMeta": {
|
|
64
65
|
"@aws-sdk/credential-provider-web-identity": {
|
|
65
66
|
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"ws": {
|
|
69
|
+
"optional": true
|
|
66
70
|
}
|
|
67
71
|
},
|
|
68
72
|
"engines": {
|
|
@@ -73,7 +77,6 @@
|
|
|
73
77
|
"access": "public"
|
|
74
78
|
},
|
|
75
79
|
"dependencies": {
|
|
76
|
-
"ws": "8.20.0",
|
|
77
80
|
"@vercel/oidc": "3.6.1"
|
|
78
81
|
},
|
|
79
82
|
"scripts": {
|
package/websocket/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { WebSocket } from 'ws';
|
|
2
2
|
export declare function experimental_upgradeWebSocket(handler: (ws: WebSocket) => void | Promise<void>): Promise<Response>;
|
package/websocket/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,14 +17,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var websocket_exports = {};
|
|
20
30
|
__export(websocket_exports, {
|
|
21
31
|
experimental_upgradeWebSocket: () => experimental_upgradeWebSocket
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(websocket_exports);
|
|
24
|
-
var import_ws = require("ws");
|
|
25
34
|
var import_get_context = require("../get-context");
|
|
35
|
+
async function loadWebSocketServer() {
|
|
36
|
+
try {
|
|
37
|
+
const ws = await import("ws");
|
|
38
|
+
return ws.WebSocketServer;
|
|
39
|
+
} catch {
|
|
40
|
+
throw new Error(
|
|
41
|
+
'The "ws" package is required for experimental_upgradeWebSocket(). Install it with: npm install ws'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
26
45
|
async function experimental_upgradeWebSocket(handler) {
|
|
27
46
|
const ctx = (0, import_get_context.getContext)();
|
|
28
47
|
if (typeof ctx.upgradeWebSocket !== "function") {
|
|
@@ -30,8 +49,9 @@ async function experimental_upgradeWebSocket(handler) {
|
|
|
30
49
|
"experimental_upgradeWebSocket is not available in the current runtime environment. This feature requires a Vercel runtime that supports WebSocket upgrades."
|
|
31
50
|
);
|
|
32
51
|
}
|
|
52
|
+
const WebSocketServer = await loadWebSocketServer();
|
|
33
53
|
const { req, socket, head } = ctx.upgradeWebSocket();
|
|
34
|
-
const wss = new
|
|
54
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
35
55
|
const ws = await new Promise((resolve, reject) => {
|
|
36
56
|
const cleanup = () => {
|
|
37
57
|
socket.removeListener("error", onError);
|