@statewalker/webrun-http-browser 0.10.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 +816 -211
- 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 +433 -83
- package/dist/relay-worker.d.ts +1 -0
- package/dist/relay-worker.d.ts.map +1 -1
- package/dist/relay-worker.js +433 -83
- 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 +596 -132
- package/dist/sw.js +811 -209
- package/dist/worker.js +604 -106
- 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 +3 -2
- 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
package/README.md
CHANGED
|
@@ -179,6 +179,7 @@ const stop = startRelayServiceWorker(self, {
|
|
|
179
179
|
| `takeover` | `"last-wins"` | `"first-wins"` keeps a live holder's key; a second page gets `"<key>" is already served by another client`. A holder that reloaded is no longer live, so it can always re-register. |
|
|
180
180
|
| `decorateResponse` | none | `(response, request) => Response`. Stamps headers on responses the relay makes, including its error responses. Not applied to requests the worker leaves to the network. |
|
|
181
181
|
| `streamTimeout` | none | Per-stream inactivity timeout, in ms, of the links to services. |
|
|
182
|
+
| `window` | `262144` | Window, in bytes, of the links to services, under which bodies are pipelined. `0` turns it off. |
|
|
182
183
|
|
|
183
184
|
`UNREGISTER` is accepted only from the client that holds the key, or, once
|
|
184
185
|
that client is gone, from any client `canRegister` allows: any page of the
|
|
@@ -264,13 +265,36 @@ worker's default scope covers them:
|
|
|
264
265
|
importScripts("/path/to/@statewalker/webrun-http-browser/dist/sw-worker.js");
|
|
265
266
|
```
|
|
266
267
|
|
|
268
|
+
A module worker imports the dispatcher instead (a module worker cannot
|
|
269
|
+
`importScripts`), and the adapter registers it with `type: "module"`. A
|
|
270
|
+
ServiceWorker resolves no bare specifiers (it has no import map): bundle it, or
|
|
271
|
+
import the built `dist/sw.js` by url.
|
|
272
|
+
|
|
273
|
+
```js
|
|
274
|
+
// sw.js, registered with { type: "module" }
|
|
275
|
+
import { startHttpDispatcher } from "@statewalker/webrun-http-browser/sw";
|
|
276
|
+
startHttpDispatcher({ self });
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
A page that registers its worker itself (its own script, scope or type) passes
|
|
280
|
+
the registration instead, and the adapter registers nothing (`type` is then
|
|
281
|
+
not used). The worker routes under the registration's scope, whichever folder
|
|
282
|
+
its script is in:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
const registration = await navigator.serviceWorker.register("/sw.js", { type: "module" });
|
|
286
|
+
const adapter = new SwHttpAdapter({ key: KEY, registration });
|
|
287
|
+
```
|
|
288
|
+
|
|
267
289
|
`SwHttpAdapter` options:
|
|
268
290
|
|
|
269
291
|
| Option | Default | Meaning |
|
|
270
292
|
| --- | --- | --- |
|
|
271
293
|
| `key` | required | First URL segment under the scope that the worker routes to this page. |
|
|
272
294
|
| `serviceWorkerUrl` | `sw-worker.js` at the scope | Resolved against `location.href`. An unresolvable value throws `Invalid serviceWorkerUrl: "<value>" (relative to <href>)`. |
|
|
273
|
-
| `scope` | directory of `serviceWorkerUrl` | Registration scope. |
|
|
295
|
+
| `scope` | directory of `serviceWorkerUrl`, or `registration`'s scope | Registration scope. |
|
|
296
|
+
| `type` | `"classic"` | How the worker script loads: `"module"` for an ES-module worker. It must match how the script is registered elsewhere, or the update fails. |
|
|
297
|
+
| `registration` | none | A registration the page made itself. The adapter registers nothing, and `stop()` leaves it registered. |
|
|
274
298
|
| `timeout` | `30_000` | Upper bound, in ms, for activation, control and the adapter's handshake. Past it `start()` rejects with a `ServiceWorkerControlError`. |
|
|
275
299
|
| `reloadIfUncontrolled` | `false` | Reload the page once instead of rejecting when it stays uncontrolled. |
|
|
276
300
|
| `streamTimeout` | none | Per-stream inactivity timeout of the links, in ms. Unset, a slow reader is throttled, never failed. |
|
|
@@ -335,14 +359,53 @@ your own passes the options to `startHttpDispatcher({ self, ...options })`.
|
|
|
335
359
|
|
|
336
360
|
| Option | Default | What it does |
|
|
337
361
|
| --- | --- | --- |
|
|
338
|
-
| `
|
|
362
|
+
| `key` | `scopeKey` | `(url, scope) => key \| undefined`: which key a url belongs to, for `dispatch()` (a handler's `service.fetch`), sockets, and `fetch` events of this origin. By default the first path segment under the scope; give your own for another layout (a site at the origin's root, projects under a base path). A key for another origin's url serves handlers' `service.fetch` and sockets (whoever opens them); a page's own `fetch` to that origin stays the browser's. Synchronous; must not throw. A handler registered in a page serves only urls under its own `baseUrl`. |
|
|
363
|
+
| `handleFetch` | `true` | `false` leaves `fetch` events to the host's own listener, which passes what it does not answer itself to `dispatcher.handleFetch(event, request?)` (see below). Only for a dispatcher you construct: `startHttpDispatcher` refuses it. |
|
|
364
|
+
| `unserved` | `fetch(request)` | The answer to a navigation under the scope whose key nobody serves (also one taken before the stored keys are read, after a restart). A host page for such urls goes here. Other requests nobody serves go to the network. |
|
|
365
|
+
| `failure` | 503 / 404 / 502 | `(request, { kind, error })`: the answer to a request the dispatcher took and could not deliver: `"timeout"` (no handler `route` accepts attached in time), `"gone"` (the key's handlers are gone), `"lost"` (lost in flight). |
|
|
366
|
+
| `socketHeaders` | as given | `(headers, from)`: the headers a socket's upgrade carries to `route` and its handler, by `from`: `"page"` or `"handler"`. Drop from pages' sockets what only your handlers may send. |
|
|
367
|
+
| `route` | `leastInflightRoute` | Picks the handler. `undefined` makes the request wait until it accepts one that attaches, up to `attachTimeoutMs` (then `failure` `"timeout"`). |
|
|
339
368
|
| `attachTimeoutMs` | `15_000` | How long a request waits for a handler during a hand-over. Past it, `503`. |
|
|
340
369
|
| `relinkTimeoutMs` | `3_000` | How long a request waits for the pages to attach again after a restart. |
|
|
341
370
|
| `handoverMs` | `5_000` | How long a replaced handler may finish its requests. |
|
|
342
371
|
| `wsConnectTimeoutMs` | `15_000` | How long a socket waits for its handler's answer. |
|
|
343
372
|
| `streamTimeout` | none | Per-stream inactivity timeout of the links. |
|
|
373
|
+
| `window` | `262144` | Window, in bytes, of the links to the handlers, under which bodies are pipelined. `0` turns it off. |
|
|
344
374
|
| `livenessCheckMs` | `5_000` | Period of the backup liveness check (`navigator.locks.query()`); `0` turns it off. |
|
|
345
375
|
|
|
376
|
+
A host whose worker has its own `fetch` handling (routes of its own, cookies
|
|
377
|
+
it adds before dispatching, a page for urls no tab serves) constructs the
|
|
378
|
+
dispatcher with `handleFetch: false`. Its own listener answers its routes and
|
|
379
|
+
passes the rest to `handleFetch(event, request?)`, which returns whether it
|
|
380
|
+
called `respondWith`:
|
|
381
|
+
|
|
382
|
+
```js
|
|
383
|
+
// a module ServiceWorker of your own
|
|
384
|
+
import { SwHttpDispatcher } from "@statewalker/webrun-http-browser/sw";
|
|
385
|
+
const dispatcher = new SwHttpDispatcher({
|
|
386
|
+
self,
|
|
387
|
+
handleFetch: false,
|
|
388
|
+
unserved: (request) => hostPage(request), // what no handler serves
|
|
389
|
+
});
|
|
390
|
+
dispatcher.start();
|
|
391
|
+
self.addEventListener("fetch", (event) => {
|
|
392
|
+
if (isMine(event.request)) return event.respondWith(answer(event.request));
|
|
393
|
+
if (!dispatcher.handleFetch(event, withCookies(event.request))) {
|
|
394
|
+
// not the dispatcher's: answer it, or leave it to the network
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
While `route` declines every handler of a key (it waits for one in particular, a shard
|
|
400
|
+
say), a request waits for attaches until it accepts one, up to `attachTimeoutMs`.
|
|
401
|
+
`dispatcher.ready` settles once the keys served before a restart are read back.
|
|
402
|
+
|
|
403
|
+
`handleFetch` takes every request with a key before the worker has read which
|
|
404
|
+
keys it serves (the first requests after a restart), and every navigation
|
|
405
|
+
under the scope, so whether a url is served cannot be decided before calling
|
|
406
|
+
it: a page for urls nobody serves belongs in `unserved`. The `install` and
|
|
407
|
+
`activate` handlers (`skipWaiting`, `clients.claim`) stay on.
|
|
408
|
+
|
|
346
409
|
`link.drain({ ms })` hands a slot over: no new requests reach the handler (they
|
|
347
410
|
wait for the next owner of the key, up to `attachTimeoutMs`), and those in
|
|
348
411
|
flight may finish for up to `ms`. Then the link is closed. A drain or detach
|
|
@@ -415,18 +478,45 @@ const WS = serviceWorkerWebSocketClass(); // any controlled
|
|
|
415
478
|
const WS2 = service.WebSocket; // in a worker, via the router
|
|
416
479
|
```
|
|
417
480
|
|
|
481
|
+
A socket that needs headers (what a `route` function picks the handler by, a
|
|
482
|
+
shard, an origin) opens through `connectWebSocket(url, protocols, headers)`,
|
|
483
|
+
from a page's adapter or a worker's service; the handler sees them on the
|
|
484
|
+
upgrade request. They are the caller's word: nothing checks them, so a handler
|
|
485
|
+
trusts a `cookie` or an `authorization` there no more than its caller. An
|
|
486
|
+
older ServiceWorker (still active while a newer one waits) drops them, so a
|
|
487
|
+
handler that needs one should refuse an upgrade without it:
|
|
488
|
+
|
|
489
|
+
```ts
|
|
490
|
+
const WS3 = createWebSocketClass((url, protocols) =>
|
|
491
|
+
service.connectWebSocket(url, protocols, { "x-shard": "7" }),
|
|
492
|
+
);
|
|
493
|
+
```
|
|
494
|
+
|
|
418
495
|
The ServiceWorker only brokers the port: it routes the url like a fetch, asks
|
|
419
496
|
the handler, and hands the accepted port to the caller. The socket then runs
|
|
420
497
|
between the two directly, so it survives a ServiceWorker restart. A socket to
|
|
421
498
|
a handler in the same page needs no ServiceWorker at all.
|
|
422
499
|
|
|
500
|
+
- **A server end of your own.** `webSocketUpgradeResponse(port, protocol)` is
|
|
501
|
+
the 101 for a socket whose server end the handler runs itself on the other
|
|
502
|
+
end of `port`; the host hands `port` to the caller as for `upgradeWebSocket`.
|
|
423
503
|
- **Upgrade request.** A browser drops `Upgrade` and `Sec-*` headers from every
|
|
424
504
|
`new Request()`, so the upgrade request carries them as its own `headers`
|
|
425
505
|
property. `requestedProtocols(request)` reads the subprotocols.
|
|
426
506
|
- **Server end.** `ServerWebSocket` delivers events only after `accept()`
|
|
427
507
|
(frames that arrive earlier are queued), answers pings before it, and has
|
|
428
508
|
`send`, `close`, `bufferedAmount` and `whenDrained(limit)` for
|
|
429
|
-
backpressure.
|
|
509
|
+
backpressure. It closes with 1006 once the client's pings stop; with
|
|
510
|
+
`upgradeWebSocket(request, { watch: "first-ping" })` it starts watching only
|
|
511
|
+
at the first ping, for a peer that never pings (two ends kept in one realm).
|
|
512
|
+
Other platforms' server ends (workerd's `WebSocketPair`) build on it with
|
|
513
|
+
`heartbeatPeriod: "first"` (keep the first ping's period: a closing tab
|
|
514
|
+
turns hidden, and announces a longer one, on its way out),
|
|
515
|
+
`sendBeforeAccept`, `deliverWhileClosing`, `defaultCloseCode: 1005`,
|
|
516
|
+
`closeTimeoutMs: Infinity`, a
|
|
517
|
+
`binaryType` of `"blob"`, an overridden `checkClose(code, reason)`, and
|
|
518
|
+
`detach()`, which hands an unaccepted end's port, with the frames that
|
|
519
|
+
reached it, to another holder.
|
|
430
520
|
- **Client.** `createWebSocketClass(connect, options)` validates as the
|
|
431
521
|
standard does (url, scheme, fragment, subprotocol tokens, close codes and
|
|
432
522
|
reasons), has `binaryType`, the `on*` handlers and the close handshake.
|
|
@@ -495,8 +585,8 @@ new WebSocket(...) ──WS_CONNECT──► same-origin worker ──ct
|
|
|
495
585
|
Every link is one `MessagePort` (`down`: requests a handler serves; `up`:
|
|
496
586
|
requests a worker sends; `ctl`: socket hand-over). Calls on a link are
|
|
497
587
|
multiplexed by `@statewalker/webrun-rpc` (`connect` / `serve` over `overPipe`),
|
|
498
|
-
each a stream with
|
|
499
|
-
them with `fetchOverDuplex` / `serveFetchOverDuplex` from
|
|
588
|
+
each a stream with backpressure in both directions (see below for the window
|
|
589
|
+
its bodies are pipelined under), and HTTP runs over them with `fetchOverDuplex` / `serveFetchOverDuplex` from
|
|
500
590
|
`@statewalker/webrun-http-streams`. The relay uses the same links, one per
|
|
501
591
|
`CONNECT`. Every hand-shake carries `HTTP_LINK_PROTOCOL`: a peer of version 1
|
|
502
592
|
(this package's own stream transport) is still served over that transport, and
|
|
@@ -644,21 +734,65 @@ answered by the worker and can load uncontrolled in Firefox; call
|
|
|
644
734
|
- `incompatible`: answered the handshake but runs an older version of this
|
|
645
735
|
package (reload the page once the updated worker is active).
|
|
646
736
|
|
|
737
|
+
### A link pipelines its bodies under a 256 KiB window
|
|
738
|
+
|
|
739
|
+
The calling end of every link asks each request's port for a flow-control
|
|
740
|
+
window of 256 KiB (`HttpLinkOptions.window`, webrun-rpc's `window`). Under it,
|
|
741
|
+
request and response bodies are pipelined: chunks leave without waiting for a
|
|
742
|
+
confirmation each, and only the window holds the sender back. On a
|
|
743
|
+
`MessageChannel` a body in 256 B chunks moved 2.0-2.6x as fast as one
|
|
744
|
+
confirmed chunk at a time over 9 runs of `pnpm bench` on an idle machine (each
|
|
745
|
+
the median ratio of 7 pairs), and one in 4 KiB chunks 1.8-2.3x. On a loaded
|
|
746
|
+
machine, where both modes ran slower, runs gave as little as 1.83x at 256 B
|
|
747
|
+
and 1.56x at 4 KiB.
|
|
748
|
+
The larger the chunk, the more of its time goes to the link's own cost per
|
|
749
|
+
chunk (`ReadableStream`, request framing, the copy on receipt), which no
|
|
750
|
+
window removes. The answering end needs no option: it applies whatever window
|
|
751
|
+
each port asks for.
|
|
752
|
+
|
|
753
|
+
The size is a trade. The window belongs to each request's port, not to the
|
|
754
|
+
link: a reader that stops holds about one window of its body in flight, per
|
|
755
|
+
direction, on each link (each hop) the body crosses. N stalled requests on one
|
|
756
|
+
link hold about N × the window per direction, up to the link's `maxPorts`
|
|
757
|
+
ceiling on requests in flight (by default 1024 × 256 KiB, 256 MiB per
|
|
758
|
+
direction). On page → ServiceWorker → worker, each of the two hops holds its
|
|
759
|
+
own. What that looks like: ServiceWorker or page memory that grows with the
|
|
760
|
+
number of stalled downloads: bodies a page or worker stopped reading without
|
|
761
|
+
cancelling them. Lower `window` (or `maxPorts`) where many readers can stall at
|
|
762
|
+
once. 64 KiB gave the same throughput on a `MessageChannel`, and 1 MiB gained
|
|
763
|
+
at most 5% for four times the memory.
|
|
764
|
+
|
|
765
|
+
`window: 0` turns it off: the link then puts exactly the envelopes of a link
|
|
766
|
+
with no window on the wire, one confirmed chunk at a time. Every link that
|
|
767
|
+
calls takes the option, so it can be set on each of them: the ServiceWorkers'
|
|
768
|
+
links to their handlers (`startHttpDispatcher` / `SwHttpDispatcher`,
|
|
769
|
+
`startRelayServiceWorker`), and the links a page or worker opens itself
|
|
770
|
+
(`callHttpService`, `sendOverConnection`, and the `up` link of
|
|
771
|
+
`serveHttpInWorker` and `HandlerEndpoint`). Each link's calling end decides
|
|
772
|
+
its window, so turning it off everywhere means `window: 0` on the ServiceWorker
|
|
773
|
+
and on the pages and workers that call through it.
|
|
774
|
+
|
|
775
|
+
An end of an older version is safe on either side. One that does not answer
|
|
776
|
+
the pipelining handshake gets confirmed chunks, and one with no window at all
|
|
777
|
+
is never waited on. Nothing changes in `HTTP_LINK_PROTOCOL`.
|
|
778
|
+
|
|
647
779
|
### Backpressure, and where the browser buffers
|
|
648
780
|
|
|
649
781
|
Both modes move requests over webrun-rpc links: a handler producing a body is
|
|
650
|
-
never more than
|
|
651
|
-
|
|
782
|
+
never more than about one window (256 KiB) per hop ahead of whoever reads it
|
|
783
|
+
through this package's links (one window per stalled request, per direction,
|
|
784
|
+
per hop: see above), and a reader that stops (an aborted `fetch`, a cancelled body) releases
|
|
652
785
|
the producer. Between a ServiceWorker's `respondWith` and the page, though,
|
|
653
786
|
Chromium buffers by itself, tens of megabytes of a fast stream: a page reading
|
|
654
787
|
slowly sees the handler run that far ahead before backpressure reaches it
|
|
655
788
|
(about 55 MiB, the same for a plain ServiceWorker with no library). Firefox
|
|
656
789
|
sets no such bound: it keeps reading a ServiceWorker's response while the page
|
|
657
790
|
does not, so there a handler streaming to a page that stopped reading keeps
|
|
658
|
-
producing (this package still holds only
|
|
791
|
+
producing (this package still holds only about one window of it). A worker
|
|
659
792
|
reading through `service.fetch` has no such buffer. `links.browser.ts` pins
|
|
660
|
-
the split: once a page stops reading, the handler is never more than
|
|
661
|
-
chunks ahead of what the ServiceWorker
|
|
793
|
+
the split: once a page stops reading, the handler is never more than about one
|
|
794
|
+
window (plus a few chunks: 256 KiB + 3 × 64 KiB) ahead of what the ServiceWorker
|
|
795
|
+
handed to Chromium, and stops.
|
|
662
796
|
|
|
663
797
|
`sendStream` / `handleStreams`, and the `sendHttpRequest` /
|
|
664
798
|
`handleHttpRequests` pair built on them, are version 1's transport, kept for
|
|
@@ -769,6 +903,17 @@ All four runtime dependencies are bundled into `dist/`:
|
|
|
769
903
|
### Tests
|
|
770
904
|
|
|
771
905
|
- `pnpm test`: unit tests under Node, against the source.
|
|
906
|
+
- `pnpm bench`: the throughput benchmark, kept out of `pnpm test` so that a
|
|
907
|
+
loaded machine cannot fail the suite. It compares the default window with
|
|
908
|
+
`window: 0` in one run (median of 7 pairs after a warm-up pair) and fails
|
|
909
|
+
below 2x at 256 B chunks and below 1.5x at 4 KiB chunks. The 4 KiB bar is the lower one
|
|
910
|
+
because the link's own cost per chunk caps the gain there. Each pair runs
|
|
911
|
+
both modes back to back, alternating which goes first, and the bar is held
|
|
912
|
+
against the median of the pairs' ratios. The 256 B bar sits at the bottom of
|
|
913
|
+
the run-to-run spread (above), so a busy machine can fail a run of a sound
|
|
914
|
+
build (`AssertionError: expected <ratio> to be greater than or equal to 2`): rerun on an idle
|
|
915
|
+
one before reading a failure as a regression. The 4 KiB bar sits below
|
|
916
|
+
every run measured, but a loaded machine came within 5% of it.
|
|
772
917
|
- `pnpm run test:browser`: builds, then runs `tests/browser/` in Chromium and
|
|
773
918
|
Firefox through Playwright against the built bundles, plus
|
|
774
919
|
`tests/packaging/`, which checks the published exports map. Needs the
|
package/dist/core/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export * from "./data-channels.js";
|
|
|
4
4
|
export * from "./message-target.js";
|
|
5
5
|
export * from "./registry.js";
|
|
6
6
|
export * from "./service-worker-control.js";
|
|
7
|
+
export type { FetchEventLike, ServiceWorkerClientLike, ServiceWorkerScope } from "./sw-scope.js";
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAC;AAE5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAC;AAE5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ServiceWorkerScope } from "./sw-scope.js";
|
|
1
2
|
/**
|
|
2
3
|
* How long, by default, the page waits for its ServiceWorker to activate and
|
|
3
4
|
* to take control before giving up. Generous: a first install downloads and
|
|
@@ -70,5 +71,5 @@ export declare function awaitServiceWorkerControl(registration: ServiceWorkerReg
|
|
|
70
71
|
* `clients.claim()`, which takes over every uncontrolled client in scope.
|
|
71
72
|
* Returns a function that stops answering.
|
|
72
73
|
*/
|
|
73
|
-
export declare function handleClaimRequests(self:
|
|
74
|
+
export declare function handleClaimRequests(self: ServiceWorkerScope): () => void;
|
|
74
75
|
//# sourceMappingURL=service-worker-control.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-worker-control.d.ts","sourceRoot":"","sources":["../../src/core/service-worker-control.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service-worker-control.d.ts","sourceRoot":"","sources":["../../src/core/service-worker-control.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,QAAS,CAAC;AAUrD,kFAAkF;AAClF,eAAO,MAAM,UAAU,UAAU,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,MAAM,2BAA2B,GACnC,oBAAoB,GACpB,cAAc,GACd,cAAc,GACd,cAAc,CAAC;AAEnB;;;;GAIG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;IAC7C,YAAY,MAAM,EAAE,2BAA2B,EAAE,OAAO,EAAE,MAAM,EAI/D;CACF;AAED,MAAM,WAAW,yBAAyB;IACxC,uFAAuF;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gCAAiC,SAAQ,yBAAyB;IACjF;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,oDAAoD;IACpD,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACpC;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,YAAY,EAAE,yBAAyB,EACvC,EAAE,OAAwC,EAAE,GAAE,yBAA8B,GAC3E,OAAO,CAAC,aAAa,CAAC,CAaxB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,yBAAyB,CAC7C,YAAY,EAAE,yBAAyB,EACvC,EACE,OAAwC,EACxC,oBAA4B,EAC5B,SAAmC,GACpC,GAAE,gCAAqC,GACvC,OAAO,CAAC,aAAa,CAAC,CA6CxB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAOxE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A ServiceWorker's global scope, as this package's API takes it: structurally, so that code
|
|
3
|
+
* importing the package's declarations compiles with the DOM lib alone. TypeScript's
|
|
4
|
+
* `ServiceWorkerGlobalScope` is in the WebWorker lib, which a page's or a library's
|
|
5
|
+
* compilation does not load. A ServiceWorker's `self` is one.
|
|
6
|
+
*/
|
|
7
|
+
export interface ServiceWorkerScope extends EventTarget {
|
|
8
|
+
readonly location: {
|
|
9
|
+
readonly href: string;
|
|
10
|
+
readonly origin: string;
|
|
11
|
+
};
|
|
12
|
+
readonly registration?: {
|
|
13
|
+
readonly scope: string;
|
|
14
|
+
};
|
|
15
|
+
readonly clients: unknown;
|
|
16
|
+
skipWaiting(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/** A ServiceWorker's `fetch` event, structurally (see `ServiceWorkerScope`). */
|
|
19
|
+
export interface FetchEventLike extends Event {
|
|
20
|
+
readonly request: Request;
|
|
21
|
+
respondWith(response: Response | PromiseLike<Response>): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A ServiceWorker's client (a page or a worker it controls), structurally (see
|
|
25
|
+
* `ServiceWorkerScope`). A `Client` is one.
|
|
26
|
+
*/
|
|
27
|
+
export interface ServiceWorkerClientLike {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly url: string;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=sw-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-scope.d.ts","sourceRoot":"","sources":["../../src/core/sw-scope.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,QAAQ,CAAC,YAAY,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,gFAAgF;AAChF,MAAM,WAAW,cAAe,SAAQ,KAAK;IAC3C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;CAC/D;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB"}
|