@statewalker/webrun-http-browser 0.9.0 → 0.12.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/README.md +155 -10
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/service-worker-control.d.ts +2 -1
- package/dist/core/service-worker-control.d.ts.map +1 -1
- package/dist/core/sw-scope.d.ts +31 -0
- package/dist/core/sw-scope.d.ts.map +1 -0
- package/dist/index.js +908 -221
- package/dist/link/http-link.d.ts +16 -3
- package/dist/link/http-link.d.ts.map +1 -1
- package/dist/relay/index-sw.d.ts +8 -2
- package/dist/relay/index-sw.d.ts.map +1 -1
- package/dist/relay/index.d.ts +1 -1
- package/dist/relay/index.d.ts.map +1 -1
- package/dist/relay-sw.js +470 -81
- package/dist/relay-worker.d.ts +1 -0
- package/dist/relay-worker.d.ts.map +1 -1
- package/dist/relay-worker.js +470 -81
- package/dist/sw/handler-endpoint.d.ts +5 -2
- package/dist/sw/handler-endpoint.d.ts.map +1 -1
- package/dist/sw/http-sw-dispatcher.d.ts +114 -7
- package/dist/sw/http-sw-dispatcher.d.ts.map +1 -1
- package/dist/sw/index.d.ts +1 -0
- package/dist/sw/index.d.ts.map +1 -1
- package/dist/sw/protocol.d.ts +3 -0
- package/dist/sw/protocol.d.ts.map +1 -1
- package/dist/sw/sw-dispatcher.d.ts +5 -2
- package/dist/sw/sw-dispatcher.d.ts.map +1 -1
- package/dist/sw/sw-http-adapter.d.ts +19 -4
- package/dist/sw/sw-http-adapter.d.ts.map +1 -1
- package/dist/sw/worker-service.d.ts +5 -2
- package/dist/sw/worker-service.d.ts.map +1 -1
- package/dist/sw-worker.js +681 -141
- package/dist/sw.js +896 -218
- package/dist/worker.js +689 -115
- package/dist/ws/server.d.ts +50 -2
- package/dist/ws/server.d.ts.map +1 -1
- package/dist/ws/socket-core.d.ts +5 -2
- package/dist/ws/socket-core.d.ts.map +1 -1
- package/dist/ws/upgrade.d.ts +12 -1
- package/dist/ws/upgrade.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/core/index.ts +1 -0
- package/src/core/service-worker-control.ts +5 -3
- package/src/core/sw-scope.ts +27 -0
- package/src/link/http-link.ts +20 -4
- package/src/relay/index-sw.ts +15 -2
- package/src/relay/index.ts +2 -2
- package/src/relay-worker.ts +1 -0
- package/src/sw/handler-endpoint.ts +17 -4
- package/src/sw/http-sw-dispatcher.ts +267 -67
- package/src/sw/index.ts +5 -0
- package/src/sw/protocol.ts +11 -1
- package/src/sw/sw-dispatcher.ts +17 -11
- package/src/sw/sw-http-adapter.ts +36 -10
- package/src/sw/worker-service.ts +11 -4
- package/src/ws/server.ts +166 -11
- package/src/ws/socket-core.ts +7 -2
- package/src/ws/upgrade.ts +22 -4
|
@@ -67,8 +67,11 @@ export declare class HandlerEndpoint {
|
|
|
67
67
|
* fetched it: it reaches the handler its url routes to.
|
|
68
68
|
*/
|
|
69
69
|
fetch(request: Request): Promise<Response>;
|
|
70
|
-
/**
|
|
71
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Opens a socket to the handler `url` routes to, through the ServiceWorker. The handler sees
|
|
72
|
+
* `headers` on the upgrade request, and so does a `route` function choosing it.
|
|
73
|
+
*/
|
|
74
|
+
connectWebSocket(url: string, protocols?: string[], headers?: HeadersInit): Promise<WebSocketConnection>;
|
|
72
75
|
close(): Promise<void>;
|
|
73
76
|
private _drop;
|
|
74
77
|
private _routerLost;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-endpoint.d.ts","sourceRoot":"","sources":["../../src/sw/handler-endpoint.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,eAAe,EAGrB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAI3D,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ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ope } from "../core/sw-scope.js";
|
|
1
2
|
import { type HttpLink } from "../link/http-link.js";
|
|
2
3
|
import { PortRendezvous } from "../link/rendezvous.js";
|
|
3
4
|
import type { WebSocketConnection } from "../ws/client.js";
|
|
4
5
|
import { type HandlerInfo, HandlerTable, type RouteFunction } from "./handler-table.js";
|
|
6
|
+
/**
|
|
7
|
+
* The key a request's url belongs to, or `undefined` when it is none of this dispatcher's (the
|
|
8
|
+
* request then goes to the network). `scope` is the worker's scope, with its trailing slash.
|
|
9
|
+
*/
|
|
10
|
+
export type KeyFunction = (url: URL, scope: string) => string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* The default key: the url's first path segment under `scope`, decoded; none outside it, at the
|
|
13
|
+
* scope itself, or for a segment that does not decode.
|
|
14
|
+
*/
|
|
15
|
+
export declare function scopeKey(url: URL, scope: string): string | undefined;
|
|
16
|
+
/** What went wrong with a request the dispatcher took, for the `failure` option. */
|
|
17
|
+
export interface DispatchFailure {
|
|
18
|
+
/**
|
|
19
|
+
* - `"timeout"`: no handler `route` accepts attached within `attachTimeoutMs` (a hand-over,
|
|
20
|
+
* or `route` waiting for one handler in particular);
|
|
21
|
+
* - `"gone"`: the key was served before, and no handler is left (its tab closed);
|
|
22
|
+
* - `"lost"`: sending to the handler failed: lost while the request was in flight
|
|
23
|
+
* (`error` is then a `LinkLostError`), or the stream failed otherwise (a `streamTimeout`, a
|
|
24
|
+
* request body that errored). A handler lost once the response head is out fails the body
|
|
25
|
+
* instead, and never reaches `failure`.
|
|
26
|
+
*/
|
|
27
|
+
kind: "timeout" | "gone" | "lost";
|
|
28
|
+
error?: unknown;
|
|
29
|
+
}
|
|
5
30
|
export interface SwHttpDispatcherOptions {
|
|
6
|
-
self:
|
|
31
|
+
self: ServiceWorkerScope;
|
|
7
32
|
log?: (...args: unknown[]) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Which key a url belongs to. Default `scopeKey`: the first path segment under the scope, and
|
|
35
|
+
* none outside it. A host with another layout gives its own: a project at the origin's root,
|
|
36
|
+
* projects under a base path. It decides for `dispatch()` (and so a handler's `service.fetch`),
|
|
37
|
+
* for sockets, and for `fetch` events of this origin's urls.
|
|
38
|
+
*
|
|
39
|
+
* A key it gives a url of another origin serves handlers' `service.fetch` (through
|
|
40
|
+
* `dispatch()`) and sockets, which this worker brokers whoever opens them (pages of this origin
|
|
41
|
+
* included). A page's own `fetch` to that origin stays the browser's: `fetch` events for other
|
|
42
|
+
* origins are left alone, so it goes to the network as it would without the worker.
|
|
43
|
+
*
|
|
44
|
+
* It runs synchronously, in the `fetch` listener; it must not throw. A handler registered in a
|
|
45
|
+
* page (`SwHttpAdapter.register`) serves only urls under its own `baseUrl` (prefix `""` makes
|
|
46
|
+
* that the scope): a url the function maps to its key from elsewhere reaches the page and gets
|
|
47
|
+
* a 404 there, where a handler in a worker (`serveHttpInWorker`) takes any url.
|
|
48
|
+
*/
|
|
49
|
+
key?: KeyFunction;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the dispatcher listens to `fetch` events itself. Default `true`. With `false` the
|
|
52
|
+
* host's own `fetch` listener runs instead: it answers its own routes and hands the rest to
|
|
53
|
+
* `dispatcher.handleFetch(event)`. For a dispatcher the host constructs (`new
|
|
54
|
+
* SwHttpDispatcher`): `startHttpDispatcher` refuses it, as nothing could call `handleFetch`
|
|
55
|
+
* then. The `install`/`activate` handlers (`skipWaiting`, `clients.claim`) stay on either way.
|
|
56
|
+
*/
|
|
57
|
+
handleFetch?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The answer to a request the dispatcher took and could not deliver (`DispatchFailure`).
|
|
60
|
+
* Default: 503 for `"timeout"`, 404 for `"gone"`, a plain-text 502 with the error for
|
|
61
|
+
* `"lost"`. A host whose callers expect another shape (an error its RPC layer rethrows, say)
|
|
62
|
+
* answers in it here. If it throws, the default answers.
|
|
63
|
+
*/
|
|
64
|
+
failure?: (request: Request, failure: DispatchFailure) => Response | Promise<Response>;
|
|
65
|
+
/**
|
|
66
|
+
* The headers a socket's upgrade carries to `route` and to its handler, by who asked for it:
|
|
67
|
+
* `"page"` (a page's `connectWebSocket`, `serviceWorkerWebSocketClass`) or `"handler"` (a
|
|
68
|
+
* handler's `service.connectWebSocket`). Default: as given. A host whose handlers trust some
|
|
69
|
+
* headers (routing between its own workers) drops them from pages' sockets here, as it would
|
|
70
|
+
* from pages' fetches. `from` says which path a socket came by, not whom to trust: any page of
|
|
71
|
+
* this origin can attach a handler and ask as one.
|
|
72
|
+
*/
|
|
73
|
+
socketHeaders?: (headers: [string, string][] | undefined, from: "page" | "handler") => [string, string][] | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* The answer to a navigation under the scope whose key nobody serves (also one taken before
|
|
76
|
+
* the stored keys are read, after a restart). Default `fetch(request)`, the network. A host
|
|
77
|
+
* with a page of its own for such urls answers with it here. Other requests nobody serves
|
|
78
|
+
* always go to the network.
|
|
79
|
+
*/
|
|
80
|
+
unserved?: (request: Request) => Response | Promise<Response>;
|
|
8
81
|
/**
|
|
9
82
|
* Picks the handler of a request among the live handlers of its key.
|
|
10
83
|
* Default `leastInflightRoute`: the fewest requests in flight, the oldest on
|
|
@@ -29,6 +102,11 @@ export interface SwHttpDispatcherOptions {
|
|
|
29
102
|
wsConnectTimeoutMs?: number;
|
|
30
103
|
/** Per-stream inactivity timeout of the links (webrun-rpc's). Default none. */
|
|
31
104
|
streamTimeout?: number;
|
|
105
|
+
/**
|
|
106
|
+
* The window, in bytes, of the links to the handlers: `HttpLinkOptions.window`.
|
|
107
|
+
* Default 256 KiB; 0 turns it off.
|
|
108
|
+
*/
|
|
109
|
+
window?: number;
|
|
32
110
|
/**
|
|
33
111
|
* Period of the backup liveness check, in ms: handlers whose owner lock is
|
|
34
112
|
* no longer held are dropped. Default 5 s; 0 turns it off.
|
|
@@ -61,7 +139,8 @@ export declare const HANDLER_LOST_MESSAGE = "The handler was lost while this req
|
|
|
61
139
|
* (`SwHttpAdapter.register`) or in Dedicated Workers
|
|
62
140
|
* (`SwHttpAdapter.attachWorker` + `serveHttpInWorker`).
|
|
63
141
|
*
|
|
64
|
-
* A url `<scope>/<key>/...` belongs to the handlers of `key
|
|
142
|
+
* A url `<scope>/<key>/...` belongs to the handlers of `key` (the `key`
|
|
143
|
+
* option maps urls to keys some other way). Of those, the
|
|
65
144
|
* `route` option picks one per request. Requests and responses stream with
|
|
66
145
|
* backpressure in both directions, and an aborted fetch reaches the handler
|
|
67
146
|
* as a cancellation (webrun-rpc + webrun-http-streams).
|
|
@@ -79,7 +158,9 @@ export declare const HANDLER_LOST_MESSAGE = "The handler was lost while this req
|
|
|
79
158
|
* This worker holds a router lock that handlers watch the same way.
|
|
80
159
|
*/
|
|
81
160
|
export declare class SwHttpDispatcher {
|
|
82
|
-
readonly self:
|
|
161
|
+
readonly self: ServiceWorkerScope;
|
|
162
|
+
/** `self`, with the WebWorker lib's types this module compiles with. */
|
|
163
|
+
private readonly _sw;
|
|
83
164
|
readonly log: (...args: unknown[]) => void;
|
|
84
165
|
readonly options: SwHttpDispatcherOptions;
|
|
85
166
|
readonly table: HandlerTable<HandlerEntry>;
|
|
@@ -101,7 +182,7 @@ export declare class SwHttpDispatcher {
|
|
|
101
182
|
private readonly _vacant;
|
|
102
183
|
constructor(options: SwHttpDispatcherOptions);
|
|
103
184
|
get scope(): string;
|
|
104
|
-
/** The key `url` belongs to
|
|
185
|
+
/** The key `url` belongs to (the `key` option; by default its first path segment under the scope). */
|
|
105
186
|
keyOf(url: string | URL): string | undefined;
|
|
106
187
|
/** Whether `key` has ever been served on this worker. */
|
|
107
188
|
isClaimedKey(key: string): boolean;
|
|
@@ -111,10 +192,17 @@ export declare class SwHttpDispatcher {
|
|
|
111
192
|
stop(): Promise<void>;
|
|
112
193
|
/**
|
|
113
194
|
* Answers `request` as a fetch under the scope would be: through the
|
|
114
|
-
* handler its key routes to. A url
|
|
115
|
-
* worker never served, goes to the network.
|
|
195
|
+
* handler its key routes to. A url with no key (by default, one outside the
|
|
196
|
+
* scope), or of a key this worker never served, goes to the network.
|
|
116
197
|
*/
|
|
117
198
|
dispatch(request: Request): Promise<Response>;
|
|
199
|
+
/**
|
|
200
|
+
* After `start()`: settles once the keys this worker served before a restart are read back
|
|
201
|
+
* (whatever the outcome). Until then `serves()` may answer `false` for a key it will serve.
|
|
202
|
+
*/
|
|
203
|
+
get ready(): Promise<void>;
|
|
204
|
+
private _socketHeaders;
|
|
205
|
+
private _failed;
|
|
118
206
|
/**
|
|
119
207
|
* Opens a socket to the handler `url` routes to: the handler accepts or
|
|
120
208
|
* refuses it like an HTTP upgrade, and the socket's port comes back. After
|
|
@@ -122,7 +210,24 @@ export declare class SwHttpDispatcher {
|
|
|
122
210
|
* worker is not on its data path.
|
|
123
211
|
*/
|
|
124
212
|
connectWebSocket(url: string, protocols?: string[], headers?: [string, string][]): Promise<WebSocketConnection>;
|
|
125
|
-
|
|
213
|
+
/**
|
|
214
|
+
* Answers `event` if it is the dispatcher's, with `request` (default `event.request`; a host
|
|
215
|
+
* may pass a rewritten one, with headers it adds). Returns whether it called `respondWith`;
|
|
216
|
+
* when it did not, the event is the caller's to answer or to leave to the network. For a host
|
|
217
|
+
* that listens to `fetch` itself (`handleFetch: false`); call it synchronously in the event's
|
|
218
|
+
* listener, as `respondWith` must be.
|
|
219
|
+
*
|
|
220
|
+
* It takes a same-origin request whose key (the `key` option) a handler serves, and also:
|
|
221
|
+
* - a navigation under the scope whose key nobody serves (answered by `unserved`);
|
|
222
|
+
* - before the stored keys are read (the first requests after a restart), every request with
|
|
223
|
+
* a key, since only then is it known whose it is: one nobody serves gets what it would have
|
|
224
|
+
* got after, `unserved` for a navigation and the network for anything else.
|
|
225
|
+
* So a host with a page of its own for urls nobody serves gives it as `unserved`, rather than
|
|
226
|
+
* deciding before calling this.
|
|
227
|
+
*/
|
|
228
|
+
handleFetch(event: FetchEventLike, request?: Request): boolean;
|
|
229
|
+
/** What a request the dispatcher took, and no handler serves, gets: `unserved`, or the network. */
|
|
230
|
+
private _unserved;
|
|
126
231
|
private _attach;
|
|
127
232
|
private _add;
|
|
128
233
|
/**
|
|
@@ -144,6 +249,8 @@ export declare class SwHttpDispatcher {
|
|
|
144
249
|
* its key, waiting for one when there is none.
|
|
145
250
|
*/
|
|
146
251
|
private _acquire;
|
|
252
|
+
/** Waits for attaches until `route` accepts a handler, or `until` passes. */
|
|
253
|
+
private _waitToPick;
|
|
147
254
|
private _pick;
|
|
148
255
|
/**
|
|
149
256
|
* Asks every window to attach its links again, and waits until a handler
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-sw-dispatcher.d.ts","sourceRoot":"","sources":["../../src/sw/http-sw-dispatcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-sw-dispatcher.d.ts","sourceRoot":"","sources":["../../src/sw/http-sw-dispatcher.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG9E,OAAO,EAGL,KAAK,QAAQ,EAId,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EACL,KAAK,WAAW,EAChB,YAAY,EAEZ,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAgB5B;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAapE;AAED,oFAAoF;AACpF,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB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O,CAAC,IAAI;IAUZ;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAqBtB,2EAA2E;IAC3E,OAAO,CAAC,KAAK;IAKb;;;OAGG;YACW,OAAO;IAarB,OAAO,CAAC,MAAM;IAYd;;;OAGG;YACW,QAAQ;IA0BtB,6EAA6E;YAC/D,WAAW;YAkBX,KAAK;IAenB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;YAUN,UAAU;IAwBxB,yEAAyE;IACzE,OAAO,CAAC,cAAc;IA0BtB,OAAO,CAAC,UAAU;IAoClB,OAAO,CAAC,YAAY;YAUN,MAAM;YAUN,mBAAmB;CAIlC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,IAAI,CAYhF"}
|
package/dist/sw/index.d.ts
CHANGED
package/dist/sw/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sw/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sw/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
|
package/dist/sw/protocol.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export type ControlMessage = {
|
|
|
85
85
|
id: string;
|
|
86
86
|
url: string;
|
|
87
87
|
protocols: string[];
|
|
88
|
+
headers?: [string, string][];
|
|
88
89
|
} | {
|
|
89
90
|
t: "ws-opened";
|
|
90
91
|
id: string;
|
|
@@ -114,4 +115,6 @@ export type WorkerControlMessage = {
|
|
|
114
115
|
} | {
|
|
115
116
|
type: "keepalive";
|
|
116
117
|
};
|
|
118
|
+
/** `headers` as pairs a `postMessage` can carry (a `Headers` object cannot be cloned). */
|
|
119
|
+
export declare function headerPairs(headers: HeadersInit | undefined): [string, string][] | undefined;
|
|
117
120
|
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/sw/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,uFAAuF;AACvF,eAAO,MAAM,WAAW,8BAA8B,CAAC;AACvD,uDAAuD;AACvD,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAChD,6FAA6F;AAC7F,eAAO,MAAM,UAAU,sBAAsB,CAAC;AAC9C,2DAA2D;AAC3D,eAAO,MAAM,eAAe,2BAA2B,CAAC;AACxD,oFAAoF;AACpF,eAAO,MAAM,eAAe,2BAA2B,CAAC;AACxD;;;;GAIG;AACH,eAAO,MAAM,YAAY,qBAAqB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qEAAqE;IACrE,GAAG,CAAC,EAAE,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IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAEjC;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1B,0FAA0F;AAC1F,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,SAAS,CAO5F"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ServiceWorkerScope } from "../core/sw-scope.js";
|
|
1
2
|
export interface SwPortHandlerOptions {
|
|
2
3
|
key: string;
|
|
3
4
|
scope?: string;
|
|
@@ -63,7 +64,7 @@ export declare class SwPortHandler {
|
|
|
63
64
|
stop(): Promise<void>;
|
|
64
65
|
}
|
|
65
66
|
export interface SwPortDispatcherOptions {
|
|
66
|
-
self:
|
|
67
|
+
self: ServiceWorkerScope;
|
|
67
68
|
log?: (...args: unknown[]) => void;
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
@@ -71,7 +72,9 @@ export interface SwPortDispatcherOptions {
|
|
|
71
72
|
* clientId, persisted in IndexedDB so it can reclaim ports across SW restarts.
|
|
72
73
|
*/
|
|
73
74
|
export declare class SwPortDispatcher {
|
|
74
|
-
readonly self:
|
|
75
|
+
readonly self: ServiceWorkerScope;
|
|
76
|
+
/** `self`, with the WebWorker lib's types this module compiles with. */
|
|
77
|
+
private readonly _sw;
|
|
75
78
|
readonly log: (...args: unknown[]) => void;
|
|
76
79
|
readonly handlersIndex: Map<string, ChannelInfo>;
|
|
77
80
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sw-dispatcher.d.ts","sourceRoot":"","sources":["../../src/sw/sw-dispatcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sw-dispatcher.d.ts","sourceRoot":"","sources":["../../src/sw/sw-dispatcher.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG9D,MAAM,WA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,IAAI,CAAC,CAuD3B;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAS1B;CACF;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,kBAAkB,CAAC;IACzB,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACpC;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,wEAAwE;IACxE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA2B;IAC/C,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,aAAa,2BAAkC;IACxD;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,cAAqB;IACzC,OAAO,CAAC,QAAQ,CAAC,CAAa;IAC9B,OAAO,CAAC,kBAAkB,CAAC,CAAgB;IAE3C,YAAY,EAAE,IAAI,EAAE,GAAc,EAAE,EAAE,uBAAuB,EAI5D;IAED,IAAI,KAAK,IAAI,MAAM,CAIlB;IAED;;;;OAIG;IACG,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAgBnE;IAED,yDAAyD;IACzD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEjC;IAED,KAAK,IAAI,IAAI,CAgCZ;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAK1B;IAED,OAAO,CAAC,gBAAgB;YAOV,SAAS;YAgBT,kBAAkB;YAWlB,cAAc;YAOd,gBAAgB;CAY/B"}
|
|
@@ -4,8 +4,23 @@ import { KEEPALIVE_MESSAGE, WAKE_MESSAGE } from "./protocol.js";
|
|
|
4
4
|
export interface SwHttpAdapterOptions {
|
|
5
5
|
/** The first path segment under the scope that this page's handlers serve. */
|
|
6
6
|
key: string;
|
|
7
|
+
/** The worker's scope. Default: the folder of `serviceWorkerUrl`, or `registration`'s scope. */
|
|
7
8
|
scope?: string;
|
|
8
9
|
serviceWorkerUrl?: string;
|
|
10
|
+
/**
|
|
11
|
+
* How the browser loads the worker script: `"module"` for an ES-module worker (one that
|
|
12
|
+
* `import`s `startHttpDispatcher` from this package's `sw.js`), `"classic"` — the default — for
|
|
13
|
+
* one that `importScripts` `sw-worker.js`. A script registered again with another type than
|
|
14
|
+
* its registration's fails to update, so this must match how the page registers it.
|
|
15
|
+
*/
|
|
16
|
+
type?: WorkerType;
|
|
17
|
+
/**
|
|
18
|
+
* A registration the page made itself, for a worker it registers its own way (its own script,
|
|
19
|
+
* scope or type). The adapter then registers nothing, and `stop()` leaves the registration in
|
|
20
|
+
* place: it is not the adapter's to remove. `scope` defaults to the registration's, and
|
|
21
|
+
* `type` is not used.
|
|
22
|
+
*/
|
|
23
|
+
registration?: ServiceWorkerRegistration;
|
|
9
24
|
/**
|
|
10
25
|
* Upper bound, in ms, for `start()`'s wait for the worker to activate, take
|
|
11
26
|
* control of the page and answer the handshake. `start()` rejects with a
|
|
@@ -119,7 +134,7 @@ export declare class SwHttpAdapter {
|
|
|
119
134
|
* again.
|
|
120
135
|
*/
|
|
121
136
|
start(): Promise<void>;
|
|
122
|
-
/** Detaches every link, and unregisters the worker. */
|
|
137
|
+
/** Detaches every link, and unregisters the worker (unless the page passed its `registration`). */
|
|
123
138
|
stop(): Promise<void>;
|
|
124
139
|
/**
|
|
125
140
|
* Registers an HTTP handler on a prefix. Returns the resulting base URL and a
|
|
@@ -136,10 +151,10 @@ export declare class SwHttpAdapter {
|
|
|
136
151
|
/**
|
|
137
152
|
* Opens the transport of a socket to the handler `url` routes to: a handler
|
|
138
153
|
* of this page directly, any other through the ServiceWorker. Resolves once
|
|
139
|
-
* the handler accepted.
|
|
140
|
-
* `createWebSocketClass(adapter.connectWebSocket)`.
|
|
154
|
+
* the handler accepted. The handler sees `headers` on the upgrade request. An arrow function,
|
|
155
|
+
* so it can be handed around: `createWebSocketClass(adapter.connectWebSocket)`.
|
|
141
156
|
*/
|
|
142
|
-
connectWebSocket: (url: string | URL, protocols?: string[]) => Promise<WebSocketConnection>;
|
|
157
|
+
connectWebSocket: (url: string | URL, protocols?: string[], headers?: HeadersInit) => Promise<WebSocketConnection>;
|
|
143
158
|
/**
|
|
144
159
|
* A WHATWG `WebSocket` class whose sockets reach this adapter's handlers:
|
|
145
160
|
* `new adapter.WebSocket(`${baseUrl}chat`, ["v1"])`. The global
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sw-http-adapter.d.ts","sourceRoot":"","sources":["../../src/sw/sw-http-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAUpE,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,
|
|
1
|
+
{"version":3,"file":"sw-http-adapter.d.ts","sourceRoot":"","sources":["../../src/sw/sw-http-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAUpE,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAOL,iBAAiB,EAGjB,YAAY,EAIb,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,GAAG,EAAE,MAAM,CAAC;IACZ,gGAAgG;IAChG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,yBAAyB,CAAC;IACzC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAC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AAI,CAIb;IAED,wEAAwE;IACxE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAoDtB;IAEK,KAAK,CAAC,EAAE,EAAE,EAAE,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAcvD;IAEK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAU5B;IAED,OAAO,CAAC,OAAO;CAIhB"}
|
|
@@ -16,8 +16,11 @@ export interface WorkerHttpService {
|
|
|
16
16
|
* with `LinkLostError` rather than hanging, and the next waits for a link.
|
|
17
17
|
*/
|
|
18
18
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Opens the transport of a socket to the handler `url` routes to. The handler sees `headers`
|
|
21
|
+
* on the upgrade request (cookies, origin, the routing a host needs), as with `ws-connect`.
|
|
22
|
+
*/
|
|
23
|
+
connectWebSocket(url: string | URL, protocols?: string[], headers?: HeadersInit): Promise<WebSocketConnection>;
|
|
21
24
|
/** A WHATWG `WebSocket` class over `connectWebSocket`. */
|
|
22
25
|
readonly WebSocket: PortWebSocketClass;
|
|
23
26
|
/** Whether the worker has a live link. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-service.d.ts","sourceRoot":"","sources":["../../src/sw/worker-service.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,sBAAsB,EAC5B,MAAM,uBAAuB,CAAC;AAG/B,MAAM,WAAW,wBACf,SAAQ,IAAI,CAAC,sBAAsB,EAAE,eAAe,GAAG,WAAW,CAAC;IACnE,mFAAmF;IACnF,KAAK,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,kBAAkB,GAAG,qBAAqB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