@sweidos/eidos 1.1.0 → 1.2.0
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 +75 -0
- package/dist/action.js +167 -94
- package/dist/cli.js +102 -0
- package/dist/devtools.js +80 -20
- package/dist/eidos-sw.js +280 -188
- package/dist/eidos.cjs +2 -2
- package/dist/index.d.ts +99 -4
- package/dist/index.js +42 -39
- package/dist/push.cjs +120 -0
- package/dist/push.d.ts +28 -0
- package/dist/push.js +113 -0
- package/dist/runtime.js +37 -20
- package/dist/sw-bridge.js +44 -31
- package/dist/version.js +1 -1
- package/package.json +10 -2
package/dist/runtime.js
CHANGED
|
@@ -1,32 +1,49 @@
|
|
|
1
|
-
import { useEidosStore as
|
|
2
|
-
import { registerBgSyncHandler as
|
|
3
|
-
import { idbGetQueue as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
async function
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { useEidosStore as a } from "./store.js";
|
|
2
|
+
import { registerBgSyncHandler as u, registerServiceWorker as c } from "./sw-bridge.js";
|
|
3
|
+
import { idbGetQueue as m, idbQueueStorage as d } from "./idb.js";
|
|
4
|
+
import { _getQueueStorage as y } from "./queue-storage.js";
|
|
5
|
+
import { replayQueue as p } from "./action.js";
|
|
6
|
+
import { subscribeReplayOnReconnect as f } from "./replay.js";
|
|
7
|
+
async function l(e) {
|
|
8
|
+
if (e.schemaVersion === 2 && e.idempotencyKey) return e;
|
|
9
|
+
const t = {
|
|
10
|
+
...e,
|
|
11
|
+
schemaVersion: 2,
|
|
12
|
+
idempotencyKey: e.idempotencyKey ?? crypto.randomUUID()
|
|
13
|
+
};
|
|
14
|
+
return await (y() ?? d).update(t.id, {
|
|
15
|
+
schemaVersion: t.schemaVersion,
|
|
16
|
+
idempotencyKey: t.idempotencyKey
|
|
17
|
+
}).catch(() => {
|
|
18
|
+
}), t;
|
|
19
|
+
}
|
|
20
|
+
var r = !1, i = null;
|
|
21
|
+
async function K(e = {}) {
|
|
22
|
+
if (typeof window > "u" || r) return;
|
|
23
|
+
r = !0;
|
|
24
|
+
const t = e.swPath ?? "/eidos-sw.js", n = e.autoReplay ?? !0;
|
|
11
25
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
26
|
+
const o = await m();
|
|
27
|
+
if (o.length > 0) {
|
|
28
|
+
const s = await Promise.all(o.map(l));
|
|
29
|
+
a.getState().hydrateQueue(s);
|
|
30
|
+
}
|
|
14
31
|
} catch {
|
|
15
32
|
}
|
|
16
33
|
try {
|
|
17
|
-
await
|
|
34
|
+
await c(t);
|
|
18
35
|
} catch {
|
|
19
36
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}), n && (
|
|
37
|
+
u(() => {
|
|
38
|
+
a.getState().isOnline && setTimeout(p, 200);
|
|
39
|
+
}), n && (i = f());
|
|
23
40
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
41
|
+
function R() {
|
|
42
|
+
i?.(), i = null, r = !1;
|
|
26
43
|
}
|
|
27
44
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
R as _resetEidos,
|
|
46
|
+
K as initEidos
|
|
30
47
|
};
|
|
31
48
|
|
|
32
49
|
//# sourceMappingURL=runtime.js.map
|
package/dist/sw-bridge.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { useEidosStore as
|
|
1
|
+
import { useEidosStore as a } from "./store.js";
|
|
2
2
|
var s = null, o = [];
|
|
3
|
-
function
|
|
3
|
+
function E() {
|
|
4
4
|
return s;
|
|
5
5
|
}
|
|
6
|
-
async function
|
|
6
|
+
async function p(e) {
|
|
7
7
|
if (typeof navigator > "u" || !("serviceWorker" in navigator)) {
|
|
8
|
-
|
|
8
|
+
a.getState().setSwStatus("unsupported");
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const t =
|
|
11
|
+
const t = a.getState();
|
|
12
12
|
t.setSwStatus("registering");
|
|
13
13
|
try {
|
|
14
|
-
s = await navigator.serviceWorker.register(e, { scope: "/" }), await
|
|
14
|
+
s = await navigator.serviceWorker.register(e, { scope: "/" }), await d(s), t.setSwStatus("active"), navigator.serviceWorker.addEventListener("message", g), window.addEventListener("online", () => t.setOnline(!0)), window.addEventListener("offline", () => t.setOnline(!1)), l();
|
|
15
15
|
} catch (n) {
|
|
16
16
|
t.setSwStatus("error", String(n));
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function d(e) {
|
|
20
20
|
return new Promise((t) => {
|
|
21
21
|
if (e.active) {
|
|
22
22
|
t();
|
|
@@ -27,43 +27,55 @@ function f(e) {
|
|
|
27
27
|
t();
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const i = setTimeout(t, 1e4);
|
|
31
31
|
n.addEventListener("statechange", function r() {
|
|
32
|
-
n.state === "activated" && (clearTimeout(
|
|
32
|
+
n.state === "activated" && (clearTimeout(i), n.removeEventListener("statechange", r), t());
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function S(e) {
|
|
37
37
|
const t = s?.active;
|
|
38
38
|
t ? t.postMessage(e) : o.push(e);
|
|
39
39
|
}
|
|
40
|
-
var
|
|
41
|
-
function
|
|
42
|
-
|
|
40
|
+
var u = null;
|
|
41
|
+
function w(e) {
|
|
42
|
+
u = e;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function h() {
|
|
45
45
|
try {
|
|
46
46
|
return typeof navigator < "u" && "serviceWorker" in navigator && s !== null && "sync" in s;
|
|
47
47
|
} catch {
|
|
48
48
|
return !1;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
var c = {};
|
|
52
|
+
function O(e) {
|
|
53
|
+
c = e;
|
|
54
|
+
}
|
|
55
|
+
function g(e) {
|
|
52
56
|
const t = e.data;
|
|
53
57
|
if (!t?.type) return;
|
|
54
|
-
const n =
|
|
55
|
-
if (
|
|
56
|
-
|
|
58
|
+
const n = a.getState(), { type: i, url: r } = t;
|
|
59
|
+
if (i === "EIDOS_BACKGROUND_SYNC") {
|
|
60
|
+
u?.();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (i === "EIDOS_NOTIFICATION_CLICK") {
|
|
64
|
+
c.onNotificationClick?.(t.data);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (i === "EIDOS_SUBSCRIPTION_EXPIRED") {
|
|
68
|
+
c.onSubscriptionExpired?.(t.subscription);
|
|
57
69
|
return;
|
|
58
70
|
}
|
|
59
71
|
if (r)
|
|
60
|
-
switch (
|
|
72
|
+
switch (i) {
|
|
61
73
|
case "EIDOS_CACHE_HIT": {
|
|
62
|
-
const
|
|
74
|
+
const f = n.resources[r];
|
|
63
75
|
n.updateResource(r, {
|
|
64
76
|
status: "fresh",
|
|
65
77
|
lastEvent: "cache-hit",
|
|
66
|
-
cacheHits: (
|
|
78
|
+
cacheHits: (f?.cacheHits ?? 0) + 1
|
|
67
79
|
});
|
|
68
80
|
break;
|
|
69
81
|
}
|
|
@@ -82,13 +94,13 @@ function d(e) {
|
|
|
82
94
|
break;
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
97
|
+
function _(e) {
|
|
98
|
+
S({
|
|
87
99
|
type: "EIDOS_SIMULATE_OFFLINE",
|
|
88
100
|
enabled: e
|
|
89
|
-
}),
|
|
101
|
+
}), a.getState().setOnline(!e);
|
|
90
102
|
}
|
|
91
|
-
function
|
|
103
|
+
function l() {
|
|
92
104
|
const e = s?.active;
|
|
93
105
|
if (e) {
|
|
94
106
|
for (const t of o) e.postMessage(t);
|
|
@@ -96,12 +108,13 @@ function S() {
|
|
|
96
108
|
}
|
|
97
109
|
}
|
|
98
110
|
export {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
E as getSwRegistration,
|
|
112
|
+
h as isBgSyncSupported,
|
|
113
|
+
w as registerBgSyncHandler,
|
|
114
|
+
O as registerPushCallbacks,
|
|
115
|
+
p as registerServiceWorker,
|
|
116
|
+
S as sendToWorker,
|
|
117
|
+
_ as setOfflineSimulation
|
|
105
118
|
};
|
|
106
119
|
|
|
107
120
|
//# sourceMappingURL=sw-bridge.js.map
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sweidos/eidos",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Describe intent. The runtime figures out how. An abstraction layer for offline-first web apps.",
|
|
5
5
|
"author": "Aditya Raj",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"main": "./dist/eidos.cjs",
|
|
43
43
|
"module": "./dist/index.js",
|
|
44
44
|
"types": "./dist/index.d.ts",
|
|
45
|
+
"bin": {
|
|
46
|
+
"eidos": "./dist/cli.js"
|
|
47
|
+
},
|
|
45
48
|
"exports": {
|
|
46
49
|
".": {
|
|
47
50
|
"types": "./dist/index.d.ts",
|
|
@@ -61,6 +64,11 @@
|
|
|
61
64
|
"import": "./dist/query.js",
|
|
62
65
|
"require": "./dist/query.cjs"
|
|
63
66
|
},
|
|
67
|
+
"./push": {
|
|
68
|
+
"types": "./dist/push.d.ts",
|
|
69
|
+
"import": "./dist/push.js",
|
|
70
|
+
"require": "./dist/push.cjs"
|
|
71
|
+
},
|
|
64
72
|
"./testing": {
|
|
65
73
|
"types": "./dist/testing.d.ts",
|
|
66
74
|
"import": "./dist/testing.js",
|
|
@@ -141,7 +149,7 @@
|
|
|
141
149
|
"vitest": "^4.1.8"
|
|
142
150
|
},
|
|
143
151
|
"scripts": {
|
|
144
|
-
"build": "vite build && vite build --config vite.cjs.config.ts && vite build --config vite.plugin.config.ts && vite build --config vite.query.config.ts && vite build --config vite.testing.config.ts && vite build --config vite.nextjs.config.ts && vite build --config vite.sveltekit.config.ts && vite build --config vite.devtools.config.ts && vite build --config vite.react-native.config.ts && node scripts/copy-sw.mjs",
|
|
152
|
+
"build": "vite build && vite build --config vite.cjs.config.ts && vite build --config vite.plugin.config.ts && vite build --config vite.query.config.ts && vite build --config vite.push.config.ts && vite build --config vite.testing.config.ts && vite build --config vite.nextjs.config.ts && vite build --config vite.sveltekit.config.ts && vite build --config vite.devtools.config.ts && vite build --config vite.react-native.config.ts && vite build --config vite.cli.config.ts && node scripts/copy-sw.mjs",
|
|
145
153
|
"dev": "vite build --watch",
|
|
146
154
|
"type-check": "tsc --noEmit",
|
|
147
155
|
"test": "vitest run",
|