@statewalker/webrun-http-browser 0.6.5 → 0.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/README.md +302 -52
- package/dist/core/data-calls.d.ts +17 -0
- package/dist/core/data-calls.d.ts.map +1 -1
- package/dist/core/service-worker-control.d.ts +3 -1
- package/dist/core/service-worker-control.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4218 -301
- package/dist/link/async-dispose.d.ts +10 -0
- package/dist/link/async-dispose.d.ts.map +1 -0
- package/dist/link/errors.d.ts +2 -0
- package/dist/link/errors.d.ts.map +1 -0
- package/dist/link/http-link.d.ts +72 -0
- package/dist/link/http-link.d.ts.map +1 -0
- package/dist/link/index.d.ts +4 -0
- package/dist/link/index.d.ts.map +1 -0
- package/dist/link/locks.d.ts +39 -0
- package/dist/link/locks.d.ts.map +1 -0
- package/dist/link/rendezvous.d.ts +21 -0
- package/dist/link/rendezvous.d.ts.map +1 -0
- package/dist/relay/index-sw.d.ts +12 -2
- package/dist/relay/index-sw.d.ts.map +1 -1
- package/dist/relay/index.d.ts +66 -8
- package/dist/relay/index.d.ts.map +1 -1
- package/dist/relay-sw.js +1328 -64
- package/dist/relay-worker.js +1329 -64
- package/dist/sw/handler-endpoint.d.ts +81 -0
- package/dist/sw/handler-endpoint.d.ts.map +1 -0
- package/dist/sw/handler-table.d.ts +53 -0
- package/dist/sw/handler-table.d.ts.map +1 -0
- package/dist/sw/http-sw-dispatcher.d.ts +162 -21
- package/dist/sw/http-sw-dispatcher.d.ts.map +1 -1
- package/dist/sw/index.d.ts +5 -0
- package/dist/sw/index.d.ts.map +1 -1
- package/dist/sw/protocol.d.ts +115 -0
- package/dist/sw/protocol.d.ts.map +1 -0
- package/dist/sw/sw-dispatcher.d.ts.map +1 -1
- package/dist/sw/sw-http-adapter.d.ts +199 -0
- package/dist/sw/sw-http-adapter.d.ts.map +1 -0
- package/dist/sw/sw-websocket.d.ts +16 -0
- package/dist/sw/sw-websocket.d.ts.map +1 -0
- package/dist/sw/worker-service.d.ts +45 -0
- package/dist/sw/worker-service.d.ts.map +1 -0
- package/dist/sw/worker-url.d.ts +9 -0
- package/dist/sw/worker-url.d.ts.map +1 -0
- package/dist/sw-worker.js +2403 -265
- package/dist/sw.d.ts +2 -0
- package/dist/sw.d.ts.map +1 -1
- package/dist/sw.js +4189 -546
- package/dist/worker.d.ts +10 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +3780 -0
- package/dist/ws/client.d.ts +73 -0
- package/dist/ws/client.d.ts.map +1 -0
- package/dist/ws/frames.d.ts +68 -0
- package/dist/ws/frames.d.ts.map +1 -0
- package/dist/ws/index.d.ts +6 -0
- package/dist/ws/index.d.ts.map +1 -0
- package/dist/ws/server.d.ts +53 -0
- package/dist/ws/server.d.ts.map +1 -0
- package/dist/ws/socket-core.d.ts +91 -0
- package/dist/ws/socket-core.d.ts.map +1 -0
- package/dist/ws/upgrade.d.ts +93 -0
- package/dist/ws/upgrade.d.ts.map +1 -0
- package/package.json +10 -5
- package/src/core/data-calls.ts +52 -2
- package/src/core/service-worker-control.ts +7 -1
- package/src/index.ts +3 -0
- package/src/link/async-dispose.ts +22 -0
- package/src/link/errors.ts +3 -0
- package/src/link/http-link.ts +238 -0
- package/src/link/index.ts +3 -0
- package/src/link/locks.ts +97 -0
- package/src/link/rendezvous.ts +60 -0
- package/src/relay/index-sw.ts +84 -12
- package/src/relay/index.ts +203 -27
- package/src/sw/handler-endpoint.ts +278 -0
- package/src/sw/handler-table.ts +130 -0
- package/src/sw/http-sw-dispatcher.ts +649 -90
- package/src/sw/index.ts +5 -0
- package/src/sw/protocol.ts +103 -0
- package/src/sw/sw-dispatcher.ts +1 -20
- package/src/sw/sw-http-adapter.ts +613 -0
- package/src/sw/sw-websocket.ts +43 -0
- package/src/sw/worker-service.ts +133 -0
- package/src/sw/worker-url.ts +19 -0
- package/src/sw-worker.ts +8 -3
- package/src/sw.ts +2 -0
- package/src/worker.ts +9 -0
- package/src/ws/client.ts +346 -0
- package/src/ws/frames.ts +119 -0
- package/src/ws/index.ts +11 -0
- package/src/ws/server.ts +132 -0
- package/src/ws/socket-core.ts +251 -0
- package/src/ws/upgrade.ts +200 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { HttpHandler } from "@statewalker/webrun-http-streams";
|
|
2
|
+
import { type PortWebSocketClass, type WebSocketClassOptions, type WebSocketConnection } from "../ws/client.js";
|
|
3
|
+
import { KEEPALIVE_MESSAGE, WAKE_MESSAGE } from "./protocol.js";
|
|
4
|
+
export interface SwHttpAdapterOptions {
|
|
5
|
+
/** The first path segment under the scope that this page's handlers serve. */
|
|
6
|
+
key: string;
|
|
7
|
+
scope?: string;
|
|
8
|
+
serviceWorkerUrl?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Upper bound, in ms, for `start()`'s wait for the worker to activate, take
|
|
11
|
+
* control of the page and answer the handshake. `start()` rejects with a
|
|
12
|
+
* `ServiceWorkerControlError` past it instead of waiting forever.
|
|
13
|
+
* Default `DEFAULT_SERVICE_WORKER_TIMEOUT` (30 s).
|
|
14
|
+
*/
|
|
15
|
+
timeout?: number;
|
|
16
|
+
/**
|
|
17
|
+
* If the page is still uncontrolled once the worker is active — after a
|
|
18
|
+
* hard reload, say — and the worker does not take it over when asked,
|
|
19
|
+
* reload the page once instead of rejecting. Default `false`.
|
|
20
|
+
*/
|
|
21
|
+
reloadIfUncontrolled?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Per-stream inactivity timeout of the links, in ms (webrun-rpc's): a
|
|
24
|
+
* request or response body with no chunk for that long fails. Unset — the
|
|
25
|
+
* default — means none: a slow reader is throttled, never failed.
|
|
26
|
+
*/
|
|
27
|
+
streamTimeout?: number;
|
|
28
|
+
/** The handler slot of this page's own handlers. Default: one per adapter. */
|
|
29
|
+
id?: string;
|
|
30
|
+
/** What a `route` function in the ServiceWorker sees of this page's handlers. */
|
|
31
|
+
meta?: unknown;
|
|
32
|
+
/** Options of the `WebSocket` class (`adapter.WebSocket`). */
|
|
33
|
+
webSocket?: WebSocketClassOptions;
|
|
34
|
+
/** @deprecated Version 1 only; ignored. */
|
|
35
|
+
bindPort?: (port: MessagePort) => void | Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export interface SwHttpRegistration {
|
|
38
|
+
baseUrl: string;
|
|
39
|
+
prefix: string;
|
|
40
|
+
remove(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface AttachWorkerOptions {
|
|
43
|
+
/** The key the worker serves. Default: the adapter's. */
|
|
44
|
+
key?: string;
|
|
45
|
+
/** The handler slot. Attaching an id the key has already replaces it. Default: a fresh one. */
|
|
46
|
+
id?: string;
|
|
47
|
+
/** What a `route` function sees of this handler. */
|
|
48
|
+
meta?: unknown;
|
|
49
|
+
}
|
|
50
|
+
/** A Dedicated Worker attached as a handler. */
|
|
51
|
+
export interface WorkerLink {
|
|
52
|
+
readonly key: string;
|
|
53
|
+
readonly id: string;
|
|
54
|
+
/** Token of this attachment; `drain` and `detach` name it. */
|
|
55
|
+
readonly owner: string;
|
|
56
|
+
/**
|
|
57
|
+
* Hand-over: the worker gets no new requests (they wait for the next owner
|
|
58
|
+
* of the slot), and those in flight may finish for up to `ms`. Then the
|
|
59
|
+
* link is closed.
|
|
60
|
+
*/
|
|
61
|
+
drain(options?: {
|
|
62
|
+
ms?: number;
|
|
63
|
+
}): Promise<void>;
|
|
64
|
+
/** Removes the link now. Requests in flight fail. */
|
|
65
|
+
detach(): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The page side of the same-origin ServiceWorker: registers the worker, and
|
|
69
|
+
* attaches handler links to it.
|
|
70
|
+
*
|
|
71
|
+
* - `register(prefix, handler)` serves a handler in this page, under
|
|
72
|
+
* `<scope>/<key>/...`.
|
|
73
|
+
* - `attachWorker(worker)` links a Dedicated Worker that runs
|
|
74
|
+
* `serveHttpInWorker(handler)`: the ServiceWorker then talks to the worker
|
|
75
|
+
* directly, and this page carries nothing.
|
|
76
|
+
* - `connectWebSocket(url, protocols)` and `WebSocket` open sockets to
|
|
77
|
+
* handlers, through the ServiceWorker or straight to a handler of this page.
|
|
78
|
+
*
|
|
79
|
+
* Links are attached again whenever the ServiceWorker asks (after a restart),
|
|
80
|
+
* and requests in flight on a handler that dies fail at once.
|
|
81
|
+
*/
|
|
82
|
+
export declare class SwHttpAdapter {
|
|
83
|
+
readonly options: SwHttpAdapterOptions;
|
|
84
|
+
private readonly _handlers;
|
|
85
|
+
private readonly _endpoint;
|
|
86
|
+
private readonly _ownerLock;
|
|
87
|
+
private readonly _id;
|
|
88
|
+
private readonly _owner;
|
|
89
|
+
private readonly _workers;
|
|
90
|
+
private _releaseOwner?;
|
|
91
|
+
private _serviceWorkerUrl?;
|
|
92
|
+
private _serviceWorker?;
|
|
93
|
+
private _registration?;
|
|
94
|
+
private _registrationPromise?;
|
|
95
|
+
private _cleanup;
|
|
96
|
+
private _attaching?;
|
|
97
|
+
private _routerLock?;
|
|
98
|
+
private _WebSocket?;
|
|
99
|
+
constructor(options: SwHttpAdapterOptions);
|
|
100
|
+
get key(): string;
|
|
101
|
+
get scope(): string;
|
|
102
|
+
/**
|
|
103
|
+
* The scope as a url on the worker's origin. Resolved against the worker's
|
|
104
|
+
* own url when one is given, not against this module's: a bundle that is
|
|
105
|
+
* not an ES module (an IIFE, Theia's frontend) has no `import.meta.url`, and
|
|
106
|
+
* `new URL(scope, undefined)` threw `Invalid URL` there. Only without a
|
|
107
|
+
* worker url does the module's location decide (its default `sw-worker.js`
|
|
108
|
+
* sits next to it).
|
|
109
|
+
*/
|
|
110
|
+
get rootUrl(): URL;
|
|
111
|
+
get serviceWorkerUrl(): string;
|
|
112
|
+
/**
|
|
113
|
+
* Registers the worker and waits until it is activated and controls this
|
|
114
|
+
* page, then attaches this page's handler link. The page must be controlled,
|
|
115
|
+
* because only a controlled page's `fetch()` reaches the worker. When the
|
|
116
|
+
* page loaded uncontrolled (a hard reload does that), the worker is asked to
|
|
117
|
+
* claim it. Rejects with a `ServiceWorkerControlError` when that fails or
|
|
118
|
+
* `timeout` passes (`reason` says which step); a later `start()` tries
|
|
119
|
+
* again.
|
|
120
|
+
*/
|
|
121
|
+
start(): Promise<void>;
|
|
122
|
+
/** Detaches every link, and unregisters the worker. */
|
|
123
|
+
stop(): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Registers an HTTP handler on a prefix. Returns the resulting base URL and a
|
|
126
|
+
* disposer.
|
|
127
|
+
*/
|
|
128
|
+
register(prefix: string, handler: HttpHandler): Promise<SwHttpRegistration>;
|
|
129
|
+
/**
|
|
130
|
+
* Links a Dedicated Worker that runs `serveHttpInWorker(handler)` as a
|
|
131
|
+
* handler of `key`. The ServiceWorker sends it requests directly, without
|
|
132
|
+
* this page relaying anything, so a busy or throttled page does not slow
|
|
133
|
+
* them down.
|
|
134
|
+
*/
|
|
135
|
+
attachWorker(worker: Worker, options?: AttachWorkerOptions): Promise<WorkerLink>;
|
|
136
|
+
/**
|
|
137
|
+
* Opens the transport of a socket to the handler `url` routes to: a handler
|
|
138
|
+
* of this page directly, any other through the ServiceWorker. Resolves once
|
|
139
|
+
* the handler accepted. An arrow function, so it can be handed around:
|
|
140
|
+
* `createWebSocketClass(adapter.connectWebSocket)`.
|
|
141
|
+
*/
|
|
142
|
+
connectWebSocket: (url: string | URL, protocols?: string[]) => Promise<WebSocketConnection>;
|
|
143
|
+
/**
|
|
144
|
+
* A WHATWG `WebSocket` class whose sockets reach this adapter's handlers:
|
|
145
|
+
* `new adapter.WebSocket(`${baseUrl}chat`, ["v1"])`. The global
|
|
146
|
+
* `WebSocket` is left alone.
|
|
147
|
+
*/
|
|
148
|
+
get WebSocket(): PortWebSocketClass;
|
|
149
|
+
/**
|
|
150
|
+
* Attaches again every link not made for the router holding
|
|
151
|
+
* `currentRouterLock` (every link, without it). The ServiceWorker asks for
|
|
152
|
+
* this after a restart; a page may call it too.
|
|
153
|
+
*/
|
|
154
|
+
relink(currentRouterLock?: string): Promise<void>;
|
|
155
|
+
/** @internal Posts a plain message to the ServiceWorker, which starts it if stopped. */
|
|
156
|
+
_poke(type: typeof WAKE_MESSAGE | typeof KEEPALIVE_MESSAGE): void;
|
|
157
|
+
/** @internal */
|
|
158
|
+
_worker(): ServiceWorker;
|
|
159
|
+
/** @internal */
|
|
160
|
+
_forget(link: WorkerLinkImpl): void;
|
|
161
|
+
/** @internal How long a call to the ServiceWorker may take. */
|
|
162
|
+
_callTimeout(): number;
|
|
163
|
+
private _attachPage;
|
|
164
|
+
private _findHandler;
|
|
165
|
+
private _handleHttpRequest;
|
|
166
|
+
}
|
|
167
|
+
declare class WorkerLinkImpl implements WorkerLink {
|
|
168
|
+
private readonly _adapter;
|
|
169
|
+
private readonly _control;
|
|
170
|
+
readonly key: string;
|
|
171
|
+
readonly id: string;
|
|
172
|
+
readonly owner: string;
|
|
173
|
+
routerLock?: string;
|
|
174
|
+
private readonly _meta;
|
|
175
|
+
private readonly _ownerLock?;
|
|
176
|
+
private _attaching?;
|
|
177
|
+
private _detached;
|
|
178
|
+
constructor(_adapter: SwHttpAdapter, _control: MessagePort, init: {
|
|
179
|
+
key: string;
|
|
180
|
+
id: string;
|
|
181
|
+
owner: string;
|
|
182
|
+
meta?: unknown;
|
|
183
|
+
ownerLock?: string;
|
|
184
|
+
});
|
|
185
|
+
/**
|
|
186
|
+
* Forgets this link without telling the ServiceWorker: another attachment
|
|
187
|
+
* took its slot, and the ServiceWorker retires it by itself.
|
|
188
|
+
*/
|
|
189
|
+
retire(): void;
|
|
190
|
+
/** Makes fresh channels and attaches them; the worker gets its ends. */
|
|
191
|
+
attach(): Promise<void>;
|
|
192
|
+
drain({ ms }?: {
|
|
193
|
+
ms?: number;
|
|
194
|
+
}): Promise<void>;
|
|
195
|
+
detach(): Promise<void>;
|
|
196
|
+
private _unlink;
|
|
197
|
+
}
|
|
198
|
+
export {};
|
|
199
|
+
//# sourceM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,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAS;IACrC,OAAO,CAAC,UAAU,CAAC,CAAgB;IACnC,OAAO,CAAC,SAAS,CAAS;IAE1B,YACmB,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,WAAW,EACtC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,EAerF;IAED;;;OAGG;IACH,MAAM,IAAI,IAAI,CAIb;IAED,wEAAwE;IACxE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAmDtB;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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type PortWebSocketClass, type WebSocketClassOptions, type WebSocketConnection } from "../ws/client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Opens the transport of a socket through the ServiceWorker controlling this
|
|
4
|
+
* page, for a page that has no adapter of its own: content a handler serves
|
|
5
|
+
* under the same-origin dispatcher, or under a relay. The ServiceWorker
|
|
6
|
+
* routes `url` like a fetch, and the handler accepts or refuses the upgrade.
|
|
7
|
+
*/
|
|
8
|
+
export declare function connectWebSocketThroughServiceWorker(url: string | URL, protocols?: string[], container?: ServiceWorkerContainer): Promise<WebSocketConnection>;
|
|
9
|
+
/**
|
|
10
|
+
* A WHATWG `WebSocket` class over `connectWebSocketThroughServiceWorker`.
|
|
11
|
+
* Install it where the page's code expects `WebSocket`, e.g.
|
|
12
|
+
* `globalThis.WebSocket = serviceWorkerWebSocketClass()` in content that only
|
|
13
|
+
* talks to its own handlers.
|
|
14
|
+
*/
|
|
15
|
+
export declare function serviceWorkerWebSocketClass(options?: WebSocketClassOptions): PortWebSocketClass;
|
|
16
|
+
//# sourceMappingURL=sw-websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-websocket.d.ts","sourceRoot":"","sources":["../../src/sw/sw-websocket.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AAGzB;;;;;GAKG;AACH,wBAAsB,oCAAoC,CACxD,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,SAAS,GAAE,MAAM,EAAO,EACxB,SAAS,GAAE,sBAAgD,GAC1D,OAAO,CAAC,mBAAmB,CAAC,CAU9B;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,kBAAkB,CAK/F"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type PortWebSocketClass, type WebSocketClassOptions, type WebSocketConnection } from "../ws/client.js";
|
|
2
|
+
import { type FetchHandler, type HandlerEndpointOptions } from "./handler-endpoint.js";
|
|
3
|
+
export interface ServeHttpInWorkerOptions extends Omit<HandlerEndpointOptions, "requestRelink" | "keepAlive"> {
|
|
4
|
+
/** Where the page's messages arrive. Default `globalThis` (the worker's scope). */
|
|
5
|
+
scope?: Pick<EventTarget, "addEventListener" | "removeEventListener">;
|
|
6
|
+
/** Options of the `WebSocket` class (`service.WebSocket`). */
|
|
7
|
+
webSocket?: WebSocketClassOptions;
|
|
8
|
+
}
|
|
9
|
+
/** What a worker serving HTTP can do besides serving. */
|
|
10
|
+
export interface WorkerHttpService {
|
|
11
|
+
/**
|
|
12
|
+
* Fetches through the ServiceWorker's router: a url under its scope reaches
|
|
13
|
+
* the handler it routes to (another worker, a page), any other the network.
|
|
14
|
+
* Needs no `fetch` event, so it works whether or not this worker is
|
|
15
|
+
* controlled; a call that is in flight when the ServiceWorker dies fails
|
|
16
|
+
* with `LinkLostError` rather than hanging, and the next waits for a link.
|
|
17
|
+
*/
|
|
18
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
19
|
+
/** Opens the transport of a socket to the handler `url` routes to. */
|
|
20
|
+
connectWebSocket(url: string | URL, protocols?: string[]): Promise<WebSocketConnection>;
|
|
21
|
+
/** A WHATWG `WebSocket` class over `connectWebSocket`. */
|
|
22
|
+
readonly WebSocket: PortWebSocketClass;
|
|
23
|
+
/** Whether the worker has a live link. */
|
|
24
|
+
readonly linked: boolean;
|
|
25
|
+
/** Stops serving; requests in flight fail. */
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Serves `handler` from a Dedicated Worker, on the links the page attaches
|
|
30
|
+
* with `adapter.attachWorker(worker)`:
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* // worker.ts
|
|
34
|
+
* const service = serveHttpInWorker(async (request) => new Response("hi"));
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* The worker holds an owner lock while it lives, so the ServiceWorker notices
|
|
38
|
+
* at once when it is terminated. It watches the ServiceWorker's router lock,
|
|
39
|
+
* and asks its page to attach it again when its links died and a call waits.
|
|
40
|
+
* While calls through the router are in flight it asks its page every 20 s to
|
|
41
|
+
* keep the ServiceWorker awake — only a message to the ServiceWorker object
|
|
42
|
+
* counts as an event, and a worker cannot post one.
|
|
43
|
+
*/
|
|
44
|
+
export declare function serveHttpInWorker(handler: FetchHandler, options?: ServeHttpInWorkerOptions): WorkerHttpService;
|
|
45
|
+
//# sourceMappingURL=worker-service.d.ts.map
|
|
@@ -0,0 +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,CAAC,CAAC;IACtE,8DAA8D;IAC9D,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AAED,yDAAyD;AACzD,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvE,sEAAsE;IACtE,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACxF,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;IACvC,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,8CAA8C;IAC9C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,EACrB,OAAO,GAAE,wBAA6B,GACrC,iBAAiB,CAuEnB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a `serviceWorkerUrl` option the way a page would: relative to the
|
|
3
|
+
* current document. Absolute urls pass through untouched. A url that cannot
|
|
4
|
+
* be resolved is reported with the option name and the offending value,
|
|
5
|
+
* because the raw `TypeError: Failed to construct 'URL': Invalid URL` says
|
|
6
|
+
* neither.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveWorkerUrl(serviceWorkerUrl: string): URL;
|
|
9
|
+
//# sourceMappingURL=worker-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-url.d.ts","sourceRoot":"","sources":["../../src/sw/worker-url.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,GAAG,GAAG,CAW9D"}
|