@bobfrankston/mailx-store-web 0.1.5
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/android-bootstrap.d.ts +16 -0
- package/android-bootstrap.d.ts.map +1 -0
- package/android-bootstrap.js +1438 -0
- package/android-bootstrap.js.map +1 -0
- package/android-bootstrap.ts +1450 -0
- package/db.d.ts +146 -0
- package/db.d.ts.map +1 -0
- package/db.js +725 -0
- package/db.js.map +1 -0
- package/db.ts +831 -0
- package/gmail-api-web.d.ts +11 -0
- package/gmail-api-web.d.ts.map +1 -0
- package/gmail-api-web.js +11 -0
- package/gmail-api-web.js.map +1 -0
- package/gmail-api-web.ts +11 -0
- package/imap-web-provider.d.ts +33 -0
- package/imap-web-provider.d.ts.map +1 -0
- package/imap-web-provider.js +140 -0
- package/imap-web-provider.js.map +1 -0
- package/imap-web-provider.ts +156 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/index.ts +10 -0
- package/main-thread-host.d.ts +15 -0
- package/main-thread-host.d.ts.map +1 -0
- package/main-thread-host.js +292 -0
- package/main-thread-host.js.map +1 -0
- package/main-thread-host.ts +322 -0
- package/package.json +41 -0
- package/provider-types.d.ts +7 -0
- package/provider-types.d.ts.map +1 -0
- package/provider-types.js +7 -0
- package/provider-types.js.map +1 -0
- package/provider-types.ts +7 -0
- package/sql-wasm-esm.js +10 -0
- package/sql.js.d.ts +29 -0
- package/sync-manager.d.ts +68 -0
- package/sync-manager.d.ts.map +1 -0
- package/sync-manager.js +506 -0
- package/sync-manager.js.map +1 -0
- package/sync-manager.ts +508 -0
- package/tsconfig.json +10 -0
- package/web-jsonrpc.d.ts +20 -0
- package/web-jsonrpc.d.ts.map +1 -0
- package/web-jsonrpc.js +112 -0
- package/web-jsonrpc.js.map +1 -0
- package/web-jsonrpc.ts +126 -0
- package/web-message-store.d.ts +16 -0
- package/web-message-store.d.ts.map +1 -0
- package/web-message-store.js +89 -0
- package/web-message-store.js.map +1 -0
- package/web-message-store.ts +97 -0
- package/web-service.d.ts +136 -0
- package/web-service.d.ts.map +1 -0
- package/web-service.js +687 -0
- package/web-service.js.map +1 -0
- package/web-service.ts +754 -0
- package/web-settings.d.ts +91 -0
- package/web-settings.d.ts.map +1 -0
- package/web-settings.js +518 -0
- package/web-settings.js.map +1 -0
- package/web-settings.ts +547 -0
- package/worker-bundle.js +6838 -0
- package/worker-entry.d.ts +8 -0
- package/worker-entry.d.ts.map +1 -0
- package/worker-entry.js +218 -0
- package/worker-entry.js.map +1 -0
- package/worker-entry.ts +245 -0
- package/worker-tcp-transport.d.ts +28 -0
- package/worker-tcp-transport.d.ts.map +1 -0
- package/worker-tcp-transport.js +98 -0
- package/worker-tcp-transport.js.map +1 -0
- package/worker-tcp-transport.ts +101 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkerTcpTransport — TcpTransport implementation for Web Workers.
|
|
3
|
+
* Proxies TCP operations to the main thread via postMessage, where the
|
|
4
|
+
* main thread relays them to msgapi.tcp (the C# native bridge).
|
|
5
|
+
*
|
|
6
|
+
* Same interface as BridgeTcpTransport, but works in a Worker context
|
|
7
|
+
* where window/msgapi aren't available.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Function to send messages to the main thread. Set during worker init. */
|
|
11
|
+
let postToMain: (msg: any) => void = () => { throw new Error("Worker TCP transport not initialized"); };
|
|
12
|
+
let reqCounter = 0;
|
|
13
|
+
const pendingRequests = new Map<number, { resolve: (v: any) => void; reject: (e: Error) => void }>();
|
|
14
|
+
const instances = new Map<number, WorkerTcpTransport>();
|
|
15
|
+
|
|
16
|
+
/** Call once from worker-entry to wire up the postMessage channel. */
|
|
17
|
+
export function initWorkerTcp(post: (msg: any) => void): void {
|
|
18
|
+
postToMain = post;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Route incoming TCP messages from the main thread to the right transport instance. */
|
|
22
|
+
export function handleTcpMessage(msg: any): void {
|
|
23
|
+
if (msg.type === "tcp-response") {
|
|
24
|
+
const pending = pendingRequests.get(msg.reqId);
|
|
25
|
+
if (pending) {
|
|
26
|
+
pendingRequests.delete(msg.reqId);
|
|
27
|
+
if (msg.error) pending.reject(new Error(msg.error));
|
|
28
|
+
else pending.resolve(msg.result);
|
|
29
|
+
}
|
|
30
|
+
} else if (msg.type === "tcp-data") {
|
|
31
|
+
instances.get(msg.streamId)?.dataHandler?.(msg.data);
|
|
32
|
+
} else if (msg.type === "tcp-close") {
|
|
33
|
+
const t = instances.get(msg.streamId);
|
|
34
|
+
if (t) {
|
|
35
|
+
t._connected = false;
|
|
36
|
+
instances.delete(msg.streamId);
|
|
37
|
+
t.closeHandler?.(msg.hadError);
|
|
38
|
+
}
|
|
39
|
+
} else if (msg.type === "tcp-error") {
|
|
40
|
+
const t = instances.get(msg.streamId);
|
|
41
|
+
if (t) {
|
|
42
|
+
t.errorHandler?.(new Error(msg.message));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function tcpRequest(op: string, params: any): Promise<any> {
|
|
48
|
+
const reqId = ++reqCounter;
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
pendingRequests.set(reqId, { resolve, reject });
|
|
51
|
+
postToMain({ type: "tcp", op, reqId, ...params });
|
|
52
|
+
// 30s timeout
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
if (pendingRequests.has(reqId)) {
|
|
55
|
+
pendingRequests.delete(reqId);
|
|
56
|
+
reject(new Error(`TCP ${op} timeout`));
|
|
57
|
+
}
|
|
58
|
+
}, 30000);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class WorkerTcpTransport {
|
|
63
|
+
streamId: number | null = null;
|
|
64
|
+
dataHandler: ((data: string) => void) | null = null;
|
|
65
|
+
closeHandler: ((hadError: boolean) => void) | null = null;
|
|
66
|
+
errorHandler: ((err: Error) => void) | null = null;
|
|
67
|
+
_connected = false;
|
|
68
|
+
|
|
69
|
+
get connected(): boolean { return this._connected; }
|
|
70
|
+
|
|
71
|
+
async connect(host: string, port: number, tls: boolean, _servername?: string): Promise<void> {
|
|
72
|
+
const streamId = await tcpRequest("connect", { host, port, tls });
|
|
73
|
+
this.streamId = Number(streamId);
|
|
74
|
+
this._connected = true;
|
|
75
|
+
instances.set(this.streamId, this);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async upgradeTLS(servername?: string): Promise<void> {
|
|
79
|
+
if (this.streamId == null) throw new Error("Not connected");
|
|
80
|
+
await tcpRequest("upgradeTLS", { streamId: this.streamId, servername: servername || "" });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async write(data: string | Uint8Array): Promise<void> {
|
|
84
|
+
if (this.streamId == null) throw new Error("Not connected");
|
|
85
|
+
const s = typeof data === "string" ? data : new TextDecoder().decode(data);
|
|
86
|
+
await tcpRequest("write", { streamId: this.streamId, data: s });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
onData(handler: (data: string) => void): void { this.dataHandler = handler; }
|
|
90
|
+
onClose(handler: (hadError: boolean) => void): void { this.closeHandler = handler; }
|
|
91
|
+
onError(handler: (err: Error) => void): void { this.errorHandler = handler; }
|
|
92
|
+
|
|
93
|
+
close(): void {
|
|
94
|
+
if (this.streamId != null) {
|
|
95
|
+
postToMain({ type: "tcp", op: "close", streamId: this.streamId });
|
|
96
|
+
instances.delete(this.streamId);
|
|
97
|
+
this.streamId = null;
|
|
98
|
+
this._connected = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|