@lunora/client 1.0.0-alpha.21 → 1.0.0-alpha.23
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/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/index.d.mts +249 -4
- package/dist/index.d.ts +249 -4
- package/dist/index.mjs +10 -4
- package/dist/packem_shared/ClientServiceWorker-C3PAFwy0.mjs +100 -0
- package/dist/packem_shared/{LunoraClient-kXpHNyaE.mjs → LunoraClient-BBCQjjbl.mjs} +382 -243
- package/dist/packem_shared/{OfflineQueue-GGYJRmhF.mjs → OfflineQueue-B4HUF7rt.mjs} +1 -1
- package/dist/packem_shared/SubscriptionRegistry-CxS_Inha.mjs +31 -0
- package/dist/packem_shared/TabCoordinator-BwRR8H06.mjs +222 -0
- package/dist/packem_shared/createClientQuery-CQ51bWAE.mjs +71 -0
- package/dist/packem_shared/createLocalStore-BtqUmOQA.mjs +2 -0
- package/dist/packem_shared/createReply-lI4tVS2w.mjs +36 -0
- package/dist/packem_shared/{createServerClient-DF-3mLmb.mjs → createServerClient-CTTAmvMx.mjs} +1 -1
- package/dist/packem_shared/createSnapshotPrecondition-CxQ1T4ZP.mjs +18 -0
- package/dist/packem_shared/httpStream-BJU-aflc.mjs +159 -0
- package/dist/packem_shared/{local-store-BveBeFEo.mjs → local-store-DIq-UWfD.mjs} +1 -1
- package/dist/packem_shared/{lunora-client.d-BYkEjCEJ.d.mts → lunora-client.d-JvtVpf8A.d.mts} +302 -18
- package/dist/packem_shared/{lunora-client.d-BYkEjCEJ.d.ts → lunora-client.d-JvtVpf8A.d.ts} +302 -18
- package/dist/packem_shared/{offline-queue-B9vfdSqp.mjs → offline-queue-CF4_Co5k.mjs} +29 -0
- package/dist/packem_shared/{preload.d-B-vyHnml.d.ts → preload.d-C4_d_l5v.d.ts} +1 -1
- package/dist/packem_shared/{preload.d-DrfuisCE.d.mts → preload.d-DKbjGN5O.d.mts} +1 -1
- package/dist/packem_shared/wire-key-Djie6aaR.mjs +266 -0
- package/dist/query/index.d.mts +2 -2
- package/dist/query/index.d.ts +2 -2
- package/dist/ssr/index.d.mts +3 -3
- package/dist/ssr/index.d.ts +3 -3
- package/dist/ssr/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/SubscriptionRegistry-DjGKZsqq.mjs +0 -1
- package/dist/packem_shared/createLocalStore-jRoqmazl.mjs +0 -2
- package/dist/packem_shared/subscription-BjynOXCU.mjs +0 -68
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
class ClientServiceWorker {
|
|
2
|
+
swUrl;
|
|
3
|
+
scope;
|
|
4
|
+
#registration = void 0;
|
|
5
|
+
#status = "unregistered";
|
|
6
|
+
#onStatusChange;
|
|
7
|
+
#messageHandlers = /* @__PURE__ */ new Set();
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.swUrl = options.swUrl;
|
|
10
|
+
this.scope = options.scope ?? "/";
|
|
11
|
+
this.#onStatusChange = options.onStatusChange;
|
|
12
|
+
}
|
|
13
|
+
// ── Status ──────────────────────────────────────────────────────────
|
|
14
|
+
/** Current registration status. */
|
|
15
|
+
get status() {
|
|
16
|
+
return this.#status;
|
|
17
|
+
}
|
|
18
|
+
/** The underlying `ServiceWorkerRegistration`, if registered. */
|
|
19
|
+
get registration() {
|
|
20
|
+
return this.#registration;
|
|
21
|
+
}
|
|
22
|
+
/** Whether the SW is currently controlling this page. */
|
|
23
|
+
get active() {
|
|
24
|
+
return this.#registration?.active !== null && this.#registration?.active !== void 0;
|
|
25
|
+
}
|
|
26
|
+
// ── Registration ────────────────────────────────────────────────────
|
|
27
|
+
/**
|
|
28
|
+
* Register the service worker.
|
|
29
|
+
*
|
|
30
|
+
* Returns `false` when the browser does not support service workers.
|
|
31
|
+
*/
|
|
32
|
+
async register() {
|
|
33
|
+
if (!("serviceWorker" in navigator)) {
|
|
34
|
+
this.#setStatus("unsupported");
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
this.#setStatus("registering");
|
|
38
|
+
try {
|
|
39
|
+
this.#registration = await navigator.serviceWorker.register(this.swUrl, {
|
|
40
|
+
scope: this.scope
|
|
41
|
+
});
|
|
42
|
+
this.#setStatus("active");
|
|
43
|
+
navigator.serviceWorker.addEventListener("message", this.#onMessage);
|
|
44
|
+
} catch {
|
|
45
|
+
this.#setStatus("error");
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Remove the active service worker registration and clear listeners.
|
|
52
|
+
*
|
|
53
|
+
* Returns `false` when no registration is currently held.
|
|
54
|
+
*/
|
|
55
|
+
async unregister() {
|
|
56
|
+
if (!this.#registration) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
navigator.serviceWorker.removeEventListener("message", this.#onMessage);
|
|
60
|
+
const ok = await this.#registration.unregister();
|
|
61
|
+
this.#registration = void 0;
|
|
62
|
+
this.#setStatus("unregistered");
|
|
63
|
+
return ok;
|
|
64
|
+
}
|
|
65
|
+
// ── Messaging ───────────────────────────────────────────────────────
|
|
66
|
+
/**
|
|
67
|
+
* Send a message to the active service worker.
|
|
68
|
+
*/
|
|
69
|
+
postMessage(message) {
|
|
70
|
+
const active = this.#registration?.active;
|
|
71
|
+
if (active) {
|
|
72
|
+
active.postMessage(message);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Register a handler for messages **from** the service worker.
|
|
77
|
+
* @returns Unsubscribe function.
|
|
78
|
+
*/
|
|
79
|
+
onMessage(handler) {
|
|
80
|
+
this.#messageHandlers.add(handler);
|
|
81
|
+
return () => {
|
|
82
|
+
this.#messageHandlers.delete(handler);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// ── Internals ───────────────────────────────────────────────────────
|
|
86
|
+
#setStatus(status) {
|
|
87
|
+
this.#status = status;
|
|
88
|
+
this.#onStatusChange?.(status);
|
|
89
|
+
}
|
|
90
|
+
#onMessage = (event) => {
|
|
91
|
+
for (const handler of this.#messageHandlers) {
|
|
92
|
+
try {
|
|
93
|
+
handler(event);
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { ClientServiceWorker };
|