sst 2.21.2 → 2.21.4

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.
@@ -101,7 +101,15 @@ export async function useLocalServer(opts) {
101
101
  return http.createServer({}, rest);
102
102
  })();
103
103
  // Wire up websocket
104
- const wss = new WebSocketServer({ server });
104
+ const wss = new WebSocketServer({ noServer: true });
105
+ const wss2 = new WebSocketServer({ noServer: true });
106
+ const sockets = new Set();
107
+ wss2.on("connection", (socket, req) => {
108
+ sockets.add(socket);
109
+ socket.on("close", () => {
110
+ sockets.delete(socket);
111
+ });
112
+ });
105
113
  wss.on("connection", (socket, req) => {
106
114
  if (req.headers.origin?.endsWith("localhost:3000"))
107
115
  return;
@@ -116,6 +124,21 @@ export async function useLocalServer(opts) {
116
124
  console.log("Rejecting unauthorized connection from " + req.headers.origin);
117
125
  socket.terminate();
118
126
  });
127
+ server.on("upgrade", (req, socket, head) => {
128
+ if (req.url === "/socket") {
129
+ wss2.handleUpgrade(req, socket, head, (socket) => {
130
+ wss2.emit("connection", socket, req);
131
+ });
132
+ return;
133
+ }
134
+ if (req.url === "/") {
135
+ wss.handleUpgrade(req, socket, head, (socket) => {
136
+ wss.emit("connection", socket, req);
137
+ });
138
+ return;
139
+ }
140
+ socket.destroy();
141
+ });
119
142
  server.listen(cfg.port);
120
143
  const handler = applyWSSHandler({
121
144
  wss,
@@ -156,7 +179,24 @@ export async function useLocalServer(opts) {
156
179
  cb(func);
157
180
  });
158
181
  }
159
- bus.subscribe("function.invoked", (evt) => {
182
+ function publish(type, properties) {
183
+ const msg = JSON.stringify({
184
+ type,
185
+ properties,
186
+ });
187
+ [...sockets.values()].map((s) => s.send(msg));
188
+ }
189
+ bus.subscribe("function.invoked", async (evt) => {
190
+ publish("log", [
191
+ [
192
+ "s",
193
+ Date.now(),
194
+ evt.properties.functionID,
195
+ evt.properties.requestID,
196
+ false,
197
+ ],
198
+ ]);
199
+ publish("function.invoked", evt.properties);
160
200
  updateFunction(evt.properties.functionID, (draft) => {
161
201
  if (draft.invocations.length >= 25)
162
202
  draft.invocations.pop();
@@ -171,6 +211,17 @@ export async function useLocalServer(opts) {
171
211
  });
172
212
  });
173
213
  bus.subscribe("worker.stdout", (evt) => {
214
+ publish("log", [
215
+ [
216
+ "m",
217
+ Date.now(),
218
+ evt.properties.functionID,
219
+ evt.properties.requestID,
220
+ "info",
221
+ evt.properties.message,
222
+ Math.random().toString(),
223
+ ],
224
+ ]);
174
225
  updateFunction(evt.properties.functionID, (draft) => {
175
226
  const entry = draft.invocations.find((i) => i.id === evt.properties.requestID);
176
227
  if (!entry)
@@ -182,6 +233,10 @@ export async function useLocalServer(opts) {
182
233
  });
183
234
  });
184
235
  bus.subscribe("function.success", (evt) => {
236
+ publish("log", [
237
+ ["e", Date.now(), evt.properties.functionID, evt.properties.requestID],
238
+ ]);
239
+ publish("function.success", evt.properties);
185
240
  updateFunction(evt.properties.functionID, (draft) => {
186
241
  const invocation = draft.invocations.find((x) => x.id === evt.properties.requestID);
187
242
  if (!invocation)
@@ -194,6 +249,10 @@ export async function useLocalServer(opts) {
194
249
  });
195
250
  });
196
251
  bus.subscribe("function.error", (evt) => {
252
+ publish("log", [
253
+ ["e", Date.now(), evt.properties.functionID, evt.properties.requestID],
254
+ ]);
255
+ publish("function.error", evt.properties);
197
256
  updateFunction(evt.properties.functionID, (draft) => {
198
257
  const invocation = draft.invocations.find((x) => x.id === evt.properties.requestID);
199
258
  if (!invocation)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.21.2",
4
+ "version": "2.21.4",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
package/sst.mjs CHANGED
@@ -7081,7 +7081,15 @@ async function useLocalServer(opts) {
7081
7081
  }
7082
7082
  return http2.createServer({}, rest);
7083
7083
  })();
7084
- const wss = new WebSocketServer({ server });
7084
+ const wss = new WebSocketServer({ noServer: true });
7085
+ const wss2 = new WebSocketServer({ noServer: true });
7086
+ const sockets = /* @__PURE__ */ new Set();
7087
+ wss2.on("connection", (socket, req) => {
7088
+ sockets.add(socket);
7089
+ socket.on("close", () => {
7090
+ sockets.delete(socket);
7091
+ });
7092
+ });
7085
7093
  wss.on("connection", (socket, req) => {
7086
7094
  if (req.headers.origin?.endsWith("localhost:3000"))
7087
7095
  return;
@@ -7096,6 +7104,21 @@ async function useLocalServer(opts) {
7096
7104
  console.log("Rejecting unauthorized connection from " + req.headers.origin);
7097
7105
  socket.terminate();
7098
7106
  });
7107
+ server.on("upgrade", (req, socket, head) => {
7108
+ if (req.url === "/socket") {
7109
+ wss2.handleUpgrade(req, socket, head, (socket2) => {
7110
+ wss2.emit("connection", socket2, req);
7111
+ });
7112
+ return;
7113
+ }
7114
+ if (req.url === "/") {
7115
+ wss.handleUpgrade(req, socket, head, (socket2) => {
7116
+ wss.emit("connection", socket2, req);
7117
+ });
7118
+ return;
7119
+ }
7120
+ socket.destroy();
7121
+ });
7099
7122
  server.listen(cfg.port);
7100
7123
  const handler = applyWSSHandler({
7101
7124
  wss,
@@ -7136,7 +7159,24 @@ async function useLocalServer(opts) {
7136
7159
  cb(func);
7137
7160
  });
7138
7161
  }
7139
- bus.subscribe("function.invoked", (evt) => {
7162
+ function publish(type, properties) {
7163
+ const msg = JSON.stringify({
7164
+ type,
7165
+ properties
7166
+ });
7167
+ [...sockets.values()].map((s) => s.send(msg));
7168
+ }
7169
+ bus.subscribe("function.invoked", async (evt) => {
7170
+ publish("log", [
7171
+ [
7172
+ "s",
7173
+ Date.now(),
7174
+ evt.properties.functionID,
7175
+ evt.properties.requestID,
7176
+ false
7177
+ ]
7178
+ ]);
7179
+ publish("function.invoked", evt.properties);
7140
7180
  updateFunction(evt.properties.functionID, (draft) => {
7141
7181
  if (draft.invocations.length >= 25)
7142
7182
  draft.invocations.pop();
@@ -7151,6 +7191,17 @@ async function useLocalServer(opts) {
7151
7191
  });
7152
7192
  });
7153
7193
  bus.subscribe("worker.stdout", (evt) => {
7194
+ publish("log", [
7195
+ [
7196
+ "m",
7197
+ Date.now(),
7198
+ evt.properties.functionID,
7199
+ evt.properties.requestID,
7200
+ "info",
7201
+ evt.properties.message,
7202
+ Math.random().toString()
7203
+ ]
7204
+ ]);
7154
7205
  updateFunction(evt.properties.functionID, (draft) => {
7155
7206
  const entry = draft.invocations.find(
7156
7207
  (i) => i.id === evt.properties.requestID
@@ -7164,6 +7215,10 @@ async function useLocalServer(opts) {
7164
7215
  });
7165
7216
  });
7166
7217
  bus.subscribe("function.success", (evt) => {
7218
+ publish("log", [
7219
+ ["e", Date.now(), evt.properties.functionID, evt.properties.requestID]
7220
+ ]);
7221
+ publish("function.success", evt.properties);
7167
7222
  updateFunction(evt.properties.functionID, (draft) => {
7168
7223
  const invocation = draft.invocations.find(
7169
7224
  (x) => x.id === evt.properties.requestID
@@ -7178,6 +7233,10 @@ async function useLocalServer(opts) {
7178
7233
  });
7179
7234
  });
7180
7235
  bus.subscribe("function.error", (evt) => {
7236
+ publish("log", [
7237
+ ["e", Date.now(), evt.properties.functionID, evt.properties.requestID]
7238
+ ]);
7239
+ publish("function.error", evt.properties);
7181
7240
  updateFunction(evt.properties.functionID, (draft) => {
7182
7241
  const invocation = draft.invocations.find(
7183
7242
  (x) => x.id === evt.properties.requestID