@statewalker/webrun-http-browser 0.3.2 → 0.3.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.
- package/LICENSE +1 -1
- package/README.md +321 -50
- package/demo/demo-1.html +109 -194
- package/demo/demo-2.html +119 -580
- package/dist/core/data-calls.d.ts +5 -0
- package/dist/core/data-calls.d.ts.map +1 -0
- package/dist/core/data-channels.d.ts +17 -0
- package/dist/core/data-channels.d.ts.map +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/message-target.d.ts +16 -0
- package/dist/core/message-target.d.ts.map +1 -0
- package/dist/core/registry.d.ts +18 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/http/http-send-recieve.d.ts +23 -0
- package/dist/http/http-send-recieve.d.ts.map +1 -0
- package/dist/http/index.d.ts +4 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2541 -807
- package/dist/relay/index-sw.d.ts +7 -0
- package/dist/relay/index-sw.d.ts.map +1 -0
- package/dist/relay/index.d.ts +69 -0
- package/dist/relay/index.d.ts.map +1 -0
- package/dist/relay/split-service-url.d.ts +13 -0
- package/dist/relay/split-service-url.d.ts.map +1 -0
- package/dist/relay-sw.d.ts +2 -0
- package/dist/relay-sw.d.ts.map +1 -0
- package/dist/relay-sw.js +878 -0
- package/dist/sw/http-sw-dispatcher.d.ts +28 -0
- package/dist/sw/http-sw-dispatcher.d.ts.map +1 -0
- package/dist/sw/index.d.ts +3 -0
- package/dist/sw/index.d.ts.map +1 -0
- package/dist/sw/sw-dispatcher.d.ts +74 -0
- package/dist/sw/sw-dispatcher.d.ts.map +1 -0
- package/dist/sw-worker.d.ts +2 -0
- package/dist/sw-worker.d.ts.map +1 -0
- package/dist/sw-worker.js +813 -0
- package/dist/sw.d.ts +2 -0
- package/dist/sw.d.ts.map +1 -0
- package/dist/sw.js +1076 -0
- package/package.json +50 -37
- package/public/index.html +61 -97
- package/public/index.js +7 -4
- package/public/sw-worker.js +4 -0
- package/public-relay/heartbeat.js +4 -3
- package/public-relay/relay-sw.js +4 -6
- package/public-relay/relay.html +16 -11
- package/src/core/data-calls.ts +46 -0
- package/src/core/data-channels.ts +224 -0
- package/src/core/index.ts +9 -0
- package/src/core/message-target.ts +18 -0
- package/src/core/registry.ts +54 -0
- package/src/http/http-send-recieve.ts +81 -0
- package/src/http/index.ts +7 -0
- package/src/index.ts +3 -0
- package/src/relay/index-sw.ts +145 -0
- package/src/relay/index.ts +261 -0
- package/src/relay/split-service-url.ts +30 -0
- package/src/relay-sw.ts +7 -0
- package/src/sw/http-sw-dispatcher.ts +122 -0
- package/src/sw/index.ts +2 -0
- package/src/sw/sw-dispatcher.ts +307 -0
- package/src/sw-worker.ts +7 -0
- package/src/sw.ts +1 -0
- package/CHANGELOG.md +0 -1
- package/demo/demo-3.html +0 -167
- package/dist/index-sw-umd.js +0 -798
- package/dist/index-sw-umd.min.js +0 -2
- package/dist/index-sw.js +0 -791
- package/dist/index-sw.min.js +0 -2
- package/dist/index-umd.js +0 -853
- package/dist/index-umd.min.js +0 -2
- package/dist/index.min.js +0 -2
- package/index.js +0 -1
- package/src/core/data-calls.js +0 -36
- package/src/core/data-channels.js +0 -192
- package/src/core/data-send-recieve.js +0 -28
- package/src/core/errors.js +0 -13
- package/src/core/index.js +0 -4
- package/src/http/HttpError.js +0 -59
- package/src/http/http-send-recieve.js +0 -40
- package/src/http/http-stubs.js +0 -135
- package/src/http/index.js +0 -3
- package/src/http/readable-streams.js +0 -33
- package/src/index.js +0 -7
- package/src/relay/index-sw.js +0 -216
- package/src/relay/index.js +0 -263
- package/src/relay/splitServiceUrl.js +0 -24
- package/src/sw/http-sw-dispatcher.js +0 -128
- package/src/sw/sw-dispatcher.js +0 -264
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boots the relay ServiceWorker: routes fetches shaped `<origin>/~<key>/…` to
|
|
3
|
+
* the client that registered `key`, and exposes REGISTER/UNREGISTER/CONNECT
|
|
4
|
+
* channel calls used by the page-side relay client.
|
|
5
|
+
*/
|
|
6
|
+
export declare function startRelayServiceWorker(self: ServiceWorkerGlobalScope): () => void;
|
|
7
|
+
//# sourceMappingURL=index-sw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-sw.d.ts","sourceRoot":"","sources":["../../src/relay/index-sw.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,wBAAwB,GAAG,MAAM,IAAI,CAwElF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { HttpHandler } from "@statewalker/webrun-http-streams";
|
|
2
|
+
import type { MessageTarget } from "../core/message-target.js";
|
|
3
|
+
export * from "./split-service-url.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns a MessagePort that transparently bridges messages to/from the
|
|
6
|
+
* ServiceWorker controlling this page.
|
|
7
|
+
*/
|
|
8
|
+
export declare function newServiceWorkerPort(): MessagePort;
|
|
9
|
+
export interface InitServiceWorkerOptions {
|
|
10
|
+
swUrl: string;
|
|
11
|
+
scopeUrl?: string;
|
|
12
|
+
type?: WorkerType;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Registers a ServiceWorker and resolves once it's activated and controlling the page.
|
|
16
|
+
*/
|
|
17
|
+
export declare function initServiceWorker({ swUrl, scopeUrl, type, }: InitServiceWorkerOptions): Promise<ServiceWorker>;
|
|
18
|
+
export interface ServiceOptions {
|
|
19
|
+
key: string;
|
|
20
|
+
port: MessageTarget;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Registers `handler` as the server for the given service `key` on the relay.
|
|
24
|
+
* Returns a cleanup function that unregisters the service.
|
|
25
|
+
*/
|
|
26
|
+
export declare function initHttpService(handler: HttpHandler, { key, port }: ServiceOptions): Promise<() => void>;
|
|
27
|
+
/**
|
|
28
|
+
* Sends a `Request` to the service registered under `key` on the relay and
|
|
29
|
+
* resolves with the corresponding `Response`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function callHttpService(request: Request, { key, port }: ServiceOptions): Promise<Response>;
|
|
32
|
+
export interface RelayWindowHandlerOptions {
|
|
33
|
+
swUrl?: string;
|
|
34
|
+
scopeUrl?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns a `window.onmessage` handler for use inside the relay iframe:
|
|
38
|
+
* it accepts a CONNECT message, starts the relay ServiceWorker, and bridges
|
|
39
|
+
* the parent's MessagePort with the SW.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getRelayWindowMessageHandler({ swUrl, scopeUrl, }?: RelayWindowHandlerOptions): (ev: MessageEvent) => Promise<void>;
|
|
42
|
+
export interface RemoteRelayChannelOptions {
|
|
43
|
+
baseUrl?: URL;
|
|
44
|
+
url?: URL;
|
|
45
|
+
container?: HTMLElement;
|
|
46
|
+
}
|
|
47
|
+
export interface RemoteRelayChannel {
|
|
48
|
+
baseUrl: URL;
|
|
49
|
+
port: MessagePort;
|
|
50
|
+
close(): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Embeds a hidden relay iframe, establishes a MessageChannel with it, and
|
|
54
|
+
* returns the port to be used with `initHttpService` / `callHttpService`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function newRemoteRelayChannel({ baseUrl, url, container, }?: RemoteRelayChannelOptions): Promise<RemoteRelayChannel>;
|
|
57
|
+
export interface InitializeConnectionOptions {
|
|
58
|
+
key: string;
|
|
59
|
+
communicationPort: MessageTarget;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
}
|
|
62
|
+
export declare function initializeConnection({ key, communicationPort, ...options }: InitializeConnectionOptions): Promise<MessagePort | null>;
|
|
63
|
+
export interface RegisterConnectionsHandlerOptions {
|
|
64
|
+
key: string;
|
|
65
|
+
handler: (event: MessageEvent, data: unknown, port: MessagePort) => boolean | Promise<boolean>;
|
|
66
|
+
communicationPort: MessageTarget;
|
|
67
|
+
}
|
|
68
|
+
export declare function registerConnectionsHandler({ key, handler, communicationPort, }: RegisterConnectionsHandlerOptions): Promise<() => void>;
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI/D,cAAc,wBAAwB,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,WAAW,CASlD;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,KAAK,EACL,QAAQ,EACR,IAAI,GACL,EAAE,wBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC,CAKnD;AAiCD,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,aAAa,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,WAAW,EACpB,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,cAAc,GAC5B,OAAO,CAAC,MAAM,IAAI,CAAC,CASrB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,cAAc,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAInB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;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
|
|
1
|
+
export interface SplitServiceUrl {
|
|
2
|
+
url: string;
|
|
3
|
+
key: string;
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
path: string;
|
|
6
|
+
[extra: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Splits a URL of the form `<base>/<separator><key>/<path>` into parts.
|
|
10
|
+
* Example: `https://host/~FS/a/b` → `{ baseUrl: "https://host/~FS/", key: "FS", path: "a/b" }`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function splitServiceUrl(url: URL | string, separator?: string): SplitServiceUrl;
|
|
13
|
+
//# sourceMappingURL=split-service-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split-service-url.d.ts","sourceRoot":"","sources":["../../src/relay/split-service-url.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,SAAS,SAAM,GAAG,eAAe,CAiBnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-sw.d.ts","sourceRoot":"","sources":["../src/relay-sw.ts"],"names":[],"mappings":""}
|