@tinkered/bun 0.34.2 → 0.34.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/dist/index.d.mts +1 -0
- package/dist/index.mjs +18 -6
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,7 @@ type Socket = {
|
|
|
33
33
|
pusher: (ws: ServerWebSocket<Socket>, i: number) => (text: string) => void;
|
|
34
34
|
one: (ws: ServerWebSocket<Socket>, m: Msg) => Promise<unknown>;
|
|
35
35
|
run: (ws: ServerWebSocket<Socket>, m: Msg) => Promise<unknown>;
|
|
36
|
+
watch: (ws: ServerWebSocket<Socket>, m: Msg, left: AbortSignal, serve: () => Promise<boolean | undefined>) => Promise<unknown>;
|
|
36
37
|
};
|
|
37
38
|
/** Makes one WebSocket server. */
|
|
38
39
|
export declare function createWs(): {
|
package/dist/index.mjs
CHANGED
|
@@ -199,18 +199,22 @@ function createWs() {
|
|
|
199
199
|
});
|
|
200
200
|
return own.run(ws, m);
|
|
201
201
|
},
|
|
202
|
-
/**
|
|
202
|
+
/**
|
|
203
|
+
* A call or a watch, in its own session of the scope. A watch's stop is kept before the
|
|
204
|
+
* first await, so a stop in the same frame finds it.
|
|
205
|
+
*/
|
|
203
206
|
async run(ws, m) {
|
|
204
207
|
const { meta, execution } = idOff(Object(m.m));
|
|
205
208
|
const trace = traceparentOf(meta.traceparent);
|
|
206
209
|
const stop = m.w ? new AbortController() : void 0;
|
|
210
|
+
if (stop) own.watches.set(m.i, stop);
|
|
207
211
|
const left = AbortSignal.any(stop ? [stop.signal, own.gone.signal] : [own.gone.signal]);
|
|
208
212
|
const tags = [request(req), requestStop(left)];
|
|
209
213
|
const session = await Promise.resolve().then(() => scope.createSession({
|
|
210
214
|
trace,
|
|
211
215
|
tags
|
|
212
216
|
})).catch(() => null);
|
|
213
|
-
if (!session) return own.emit(ws, {
|
|
217
|
+
if (!session) return own.watches.delete(m.i), own.emit(ws, {
|
|
214
218
|
i: m.i,
|
|
215
219
|
e: 503
|
|
216
220
|
});
|
|
@@ -230,13 +234,21 @@ function createWs() {
|
|
|
230
234
|
t: reply
|
|
231
235
|
});
|
|
232
236
|
}
|
|
233
|
-
own.watches.set(m.i, stop);
|
|
234
237
|
const push = own.pusher(ws, m.i);
|
|
235
|
-
|
|
238
|
+
const served = () => session.run(serveStream, { input: {
|
|
236
239
|
...input,
|
|
237
240
|
left,
|
|
238
241
|
push
|
|
239
|
-
} })
|
|
242
|
+
} });
|
|
243
|
+
return own.watch(ws, m, left, served).finally(() => session.close());
|
|
244
|
+
},
|
|
245
|
+
/**
|
|
246
|
+
* A watch, until its key ends, its stop, or the socket's end. One stopped while its
|
|
247
|
+
* session opened serves nothing (ADR 0090: an aborted signal starts no body): its key
|
|
248
|
+
* would wait on a `closed` that aborted before it looked.
|
|
249
|
+
*/
|
|
250
|
+
async watch(ws, m, left, served) {
|
|
251
|
+
await Promise.resolve(left.aborted || served()).then((found) => own.emit(ws, found ? {
|
|
240
252
|
i: m.i,
|
|
241
253
|
end: 1
|
|
242
254
|
} : {
|
|
@@ -251,7 +263,7 @@ function createWs() {
|
|
|
251
263
|
i: m.i,
|
|
252
264
|
end: 1
|
|
253
265
|
});
|
|
254
|
-
}).finally(() =>
|
|
266
|
+
}).finally(() => own.watches.delete(m.i));
|
|
255
267
|
}
|
|
256
268
|
};
|
|
257
269
|
return bun.upgrade(req, { data: own }) ? null : new Response(null, { status: 426 });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinkered/bun",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.3",
|
|
4
4
|
"description": "Tinker on Bun: the host on Bun.serve, rpc over one WebSocket, and Bun's own databases (Bun.SQL, bun:sqlite).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tinkered/core": "^0.34.
|
|
27
|
+
"@tinkered/core": "^0.34.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@hughescr/stryker-bun-runner": "1.6.0",
|