@declarion/react 0.419.0 → 0.421.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/dist-lib/api/events.js +2 -1
- package/dist-lib/hooks/useSSE.js +136 -134
- package/dist-lib/lib/versionTracker.js +15 -12
- package/package.json +1 -1
package/dist-lib/api/events.js
CHANGED
|
@@ -74,7 +74,8 @@ async function* u(i = {}) {
|
|
|
74
74
|
entity: e.entity,
|
|
75
75
|
degradedSeq: e.degraded_seq
|
|
76
76
|
});
|
|
77
|
-
} else if (m === "
|
|
77
|
+
} else if (m === "version_changed") yield { type: "version_changed" };
|
|
78
|
+
else if (m === "cache_reset" && h) {
|
|
78
79
|
let e = JSON.parse(h);
|
|
79
80
|
yield {
|
|
80
81
|
type: "cache_reset",
|
package/dist-lib/hooks/useSSE.js
CHANGED
|
@@ -5,29 +5,30 @@ import "./useChildrenData.js";
|
|
|
5
5
|
import "./useActionData.js";
|
|
6
6
|
import { useRealtimeThresholds as o } from "./useRealtimeThresholds.js";
|
|
7
7
|
import { RECORD_DOCUMENTS_KEY as s } from "../lib/record-documents-key.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
8
|
+
import { fetchProbe as c } from "../lib/versionTracker.js";
|
|
9
|
+
import { reconcileListCaches as l } from "../lib/realtime-reconcile.js";
|
|
10
|
+
import { ENTITY_AGGREGATE_KEY as u, entityOfRealtimeQueryKey as d, isEntityRowsKey as f, isRealtimeBackedQueryKey as p } from "../lib/realtime-query-keys.js";
|
|
11
|
+
import { openResync as m, useResyncEngine as h } from "../lib/realtime-resync.js";
|
|
12
|
+
import { isEntityLive as g, useRealtimeStore as _ } from "../stores/realtime.js";
|
|
13
|
+
import { cachedSchema as v } from "./useSchema.js";
|
|
14
|
+
import { awaitEmbedToken as y, clearEmbedToken as b, getEmbedToken as x, isEmbedTokenMode as S } from "../embed/token.js";
|
|
15
|
+
import { refetchWhenIdle as C } from "../lib/refetch-when-idle.js";
|
|
16
|
+
import { useEffect as w, useRef as T, useState as E } from "react";
|
|
17
|
+
import { useQueryClient as D } from "@tanstack/react-query";
|
|
17
18
|
// src/hooks/useSSE.ts
|
|
18
|
-
var
|
|
19
|
-
function
|
|
19
|
+
var O = 3e4, k = 1e3, A = 50, j = "replay_gap";
|
|
20
|
+
function M() {
|
|
20
21
|
return typeof document > "u" || document.visibilityState !== "hidden";
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
-
let [e, t] =
|
|
24
|
-
return
|
|
23
|
+
function N() {
|
|
24
|
+
let [e, t] = E(M);
|
|
25
|
+
return w(() => {
|
|
25
26
|
if (typeof document > "u") return;
|
|
26
|
-
let e = () => t(
|
|
27
|
+
let e = () => t(M());
|
|
27
28
|
return document.addEventListener("visibilitychange", e), () => document.removeEventListener("visibilitychange", e);
|
|
28
29
|
}, []), e;
|
|
29
30
|
}
|
|
30
|
-
async function
|
|
31
|
+
async function P(e, t, n) {
|
|
31
32
|
if (t.length === 0) return;
|
|
32
33
|
let r = /* @__PURE__ */ new Map();
|
|
33
34
|
for (let e of t) {
|
|
@@ -35,10 +36,10 @@ async function N(e, t, n) {
|
|
|
35
36
|
keylessReason: null,
|
|
36
37
|
keyless: !1,
|
|
37
38
|
rows: /* @__PURE__ */ new Map()
|
|
38
|
-
}, n =
|
|
39
|
-
if (n === null) t.keyless = !0, t.keylessReason =
|
|
39
|
+
}, n = H(e);
|
|
40
|
+
if (n === null) t.keyless = !0, t.keylessReason = z(t.keylessReason, e.reason ?? "");
|
|
40
41
|
else for (let r of n) {
|
|
41
|
-
let n =
|
|
42
|
+
let n = V(r), i = t.rows.get(n);
|
|
42
43
|
t.rows.set(n, {
|
|
43
44
|
pk: r,
|
|
44
45
|
createdOnly: (i?.createdOnly ?? !0) && e.action === "created"
|
|
@@ -50,46 +51,46 @@ async function N(e, t, n) {
|
|
|
50
51
|
for (let [t, a] of r) e.invalidateQueries({ predicate: (e) => {
|
|
51
52
|
let n = e.queryKey;
|
|
52
53
|
return n[0] === "entity-children" && n[3] === t;
|
|
53
|
-
} }), t === "generated_document" && e.invalidateQueries({ predicate: (e) => e.queryKey[0] === s }), a.keyless ?
|
|
54
|
-
if (n) for (let n of ["entity-count",
|
|
54
|
+
} }), t === "generated_document" && e.invalidateQueries({ predicate: (e) => e.queryKey[0] === s }), a.keyless ? I(e, t, a.keylessReason) : (W(e, t, [...a.rows.values()].map((e) => e.pk)), i.push(l(e, t, [...a.rows.values()], n).then((n) => {
|
|
55
|
+
if (n) for (let n of ["entity-count", u]) for (let r of e.getQueryCache().findAll({ queryKey: [n, t] })) C(e, r);
|
|
55
56
|
})));
|
|
56
57
|
await Promise.all(i);
|
|
57
58
|
}
|
|
58
|
-
function
|
|
59
|
+
function F(e, t, n, r) {
|
|
59
60
|
let i = n.filter((e) => Object.keys(e).length > 0);
|
|
60
61
|
if (i.length === 0 || i.length !== n.length) {
|
|
61
62
|
r();
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
64
|
-
let a = i.map((e) => ({ pk: e })), o =
|
|
65
|
+
let a = i.map((e) => ({ pk: e })), o = q(e, [{
|
|
65
66
|
entity: t,
|
|
66
67
|
action: "updated",
|
|
67
|
-
ids: i.map(
|
|
68
|
+
ids: i.map(V),
|
|
68
69
|
objects: a
|
|
69
70
|
}]);
|
|
70
|
-
o.length === 0 ? r() :
|
|
71
|
+
o.length === 0 ? r() : P(e, o);
|
|
71
72
|
}
|
|
72
|
-
function
|
|
73
|
-
let r = (e) =>
|
|
74
|
-
n ===
|
|
73
|
+
function I(e, t, n) {
|
|
74
|
+
let r = (e) => B(e, t);
|
|
75
|
+
n === R ? L(e, r) : e.invalidateQueries({ predicate: (e) => r(e.queryKey) });
|
|
75
76
|
}
|
|
76
|
-
function
|
|
77
|
+
function L(e, t) {
|
|
77
78
|
e.removeQueries({ predicate: (e) => t(e.queryKey) && e.getObserversCount() > 0 }), e.invalidateQueries({
|
|
78
79
|
predicate: (e) => t(e.queryKey),
|
|
79
80
|
refetchType: "none"
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
|
-
var
|
|
83
|
-
function R(e, t) {
|
|
84
|
-
return e === L || t === L ? L : e ?? t;
|
|
85
|
-
}
|
|
83
|
+
var R = "access_not_projectable";
|
|
86
84
|
function z(e, t) {
|
|
87
|
-
return e
|
|
85
|
+
return e === R || t === R ? R : e ?? t;
|
|
88
86
|
}
|
|
89
|
-
function B(e) {
|
|
90
|
-
return
|
|
87
|
+
function B(e, t) {
|
|
88
|
+
return e[1] === t && f(e);
|
|
91
89
|
}
|
|
92
90
|
function V(e) {
|
|
91
|
+
return JSON.stringify(Object.keys(e).sort().map((t) => [t, e[t]]));
|
|
92
|
+
}
|
|
93
|
+
function H(e) {
|
|
93
94
|
if (e.ids.length === 0 || !e.objects || e.objects.length === 0) return null;
|
|
94
95
|
let t = [];
|
|
95
96
|
for (let n of e.objects) {
|
|
@@ -98,186 +99,187 @@ function V(e) {
|
|
|
98
99
|
}
|
|
99
100
|
return t;
|
|
100
101
|
}
|
|
101
|
-
function
|
|
102
|
+
function U(e) {
|
|
102
103
|
let t = Object.keys(e).sort(), n = [JSON.stringify(t.map((t) => [t, e[t]]))];
|
|
103
104
|
return t.length === 1 && n.push(JSON.stringify(e[t[0]])), n;
|
|
104
105
|
}
|
|
105
|
-
function
|
|
106
|
+
function W(e, t, n) {
|
|
106
107
|
if (n.length === 0) return;
|
|
107
108
|
let r = /* @__PURE__ */ new Set();
|
|
108
|
-
for (let e of n) for (let t of
|
|
109
|
+
for (let e of n) for (let t of U(e)) r.add(t);
|
|
109
110
|
e.invalidateQueries({ predicate: (e) => {
|
|
110
111
|
let n = e.queryKey;
|
|
111
112
|
return n[0] === "entity-item" && n[1] === t && r.has(JSON.stringify(n[2] ?? null));
|
|
112
113
|
} });
|
|
113
114
|
}
|
|
114
|
-
function W(e) {
|
|
115
|
-
return f(e) || e[0] === "action-data" || e[0] === "action-data-cursor";
|
|
116
|
-
}
|
|
117
115
|
function G(e) {
|
|
118
|
-
|
|
116
|
+
return p(e) || e[0] === "action-data" || e[0] === "action-data-cursor";
|
|
119
117
|
}
|
|
120
|
-
function K(e
|
|
121
|
-
|
|
122
|
-
return t.filter((e) => h(n?.entities?.[e.entity]?.realtime, r, e.entity));
|
|
118
|
+
function K(e) {
|
|
119
|
+
L(e, G);
|
|
123
120
|
}
|
|
124
|
-
function q(e) {
|
|
125
|
-
let
|
|
121
|
+
function q(e, t) {
|
|
122
|
+
let n = v(e), r = _.getState().degradedEntities;
|
|
123
|
+
return t.filter((e) => g(n?.entities?.[e.entity]?.realtime, r, e.entity));
|
|
124
|
+
}
|
|
125
|
+
function J(e) {
|
|
126
|
+
let t = v(e), n = _.getState().degradedEntities;
|
|
126
127
|
e.invalidateQueries({
|
|
127
128
|
predicate: (e) => {
|
|
128
|
-
let r =
|
|
129
|
-
return r !== null && !
|
|
129
|
+
let r = d(e.queryKey);
|
|
130
|
+
return r !== null && !g(t?.entities?.[r]?.realtime, n, r);
|
|
130
131
|
},
|
|
131
132
|
refetchType: "active"
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
|
-
function
|
|
135
|
+
function Y(e, t) {
|
|
135
136
|
return e.snapshotPoint !== null && t !== void 0 && Number(t) > e.snapshotPoint;
|
|
136
137
|
}
|
|
137
|
-
function
|
|
138
|
-
let s = e((e) => e.isAuthenticated),
|
|
139
|
-
|
|
140
|
-
let o =
|
|
138
|
+
function X() {
|
|
139
|
+
let s = e((e) => e.isAuthenticated), l = e((e) => e.activeTenant?.id ?? ""), u = D(), d = T(null), f = T(""), p = T(""), g = T(Promise.resolve()), v = T(0), C = N(), E = T(!C);
|
|
140
|
+
h(u), o(), w(() => {
|
|
141
|
+
let o = _.getState();
|
|
141
142
|
if (!s) {
|
|
142
|
-
|
|
143
|
+
f.current = "", p.current = "", E.current = !C, o.clearConnectionInterruption();
|
|
143
144
|
return;
|
|
144
145
|
}
|
|
145
|
-
if (!
|
|
146
|
-
|
|
146
|
+
if (!C) {
|
|
147
|
+
E.current = !0, d.current?.abort(), d.current = null, o.clearConnectionInterruption();
|
|
147
148
|
return;
|
|
148
149
|
}
|
|
149
|
-
o.holdConnectionInterruption(),
|
|
150
|
-
let
|
|
151
|
-
|
|
150
|
+
o.holdConnectionInterruption(), E.current && (E.current = !1, f.current && J(u)), p.current !== l && (f.current = "", p.current = l);
|
|
151
|
+
let h = !0, w = 0, T = null, D = [], M = null, N = null, F = (e) => {
|
|
152
|
+
g.current = g.current.then(e).catch((e) => {
|
|
152
153
|
console.error("realtime: applying a change batch failed", e);
|
|
153
154
|
});
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
},
|
|
155
|
+
}, I = (e, t) => {
|
|
156
|
+
p.current === t && (f.current = e);
|
|
157
|
+
}, L = (e) => {
|
|
157
158
|
if (!e) return;
|
|
158
|
-
|
|
159
|
-
let t =
|
|
160
|
-
|
|
161
|
-
}, L = () => {
|
|
162
|
-
if (j !== null && (clearTimeout(j), j = null), E.length === 0) return;
|
|
163
|
-
let e = E.splice(0, E.length), t = u.current?.signal, n = f.current;
|
|
164
|
-
P(() => N(l, K(l, e), t).finally(() => {
|
|
165
|
-
for (let t of e) t.eventID && F(t.eventID, n);
|
|
166
|
-
}));
|
|
159
|
+
R();
|
|
160
|
+
let t = p.current;
|
|
161
|
+
F(() => I(e, t));
|
|
167
162
|
}, R = () => {
|
|
168
|
-
|
|
163
|
+
if (M !== null && (clearTimeout(M), M = null), D.length === 0) return;
|
|
164
|
+
let e = D.splice(0, D.length), t = d.current?.signal, n = p.current;
|
|
165
|
+
F(() => P(u, q(u, e), t).finally(() => {
|
|
166
|
+
for (let t of e) t.eventID && I(t.eventID, n);
|
|
167
|
+
}));
|
|
169
168
|
}, z = () => {
|
|
170
|
-
M
|
|
171
|
-
}, B = (
|
|
172
|
-
|
|
173
|
-
let t = g.getState().thresholds;
|
|
174
|
-
t !== null && t !== "unreadable" && (M = setTimeout(() => {
|
|
175
|
-
M = null, m && w === e && (e.silent = !0, g.getState().holdConnectionInterruption());
|
|
176
|
-
}, t.silenceMs));
|
|
169
|
+
M === null && (M = setTimeout(R, A));
|
|
170
|
+
}, B = () => {
|
|
171
|
+
N !== null && (clearTimeout(N), N = null);
|
|
177
172
|
}, V = (e) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
B();
|
|
174
|
+
let t = _.getState().thresholds;
|
|
175
|
+
t !== null && t !== "unreadable" && (N = setTimeout(() => {
|
|
176
|
+
N = null, h && T === e && (e.silent = !0, _.getState().holdConnectionInterruption());
|
|
177
|
+
}, t.silenceMs));
|
|
178
|
+
}, H = (e) => {
|
|
179
|
+
h && T === e && e.stated && (e.silent && (e.silent = !1, _.getState().clearConnectionInterruption()), V(e));
|
|
180
|
+
}, U = _.subscribe((e, t) => {
|
|
181
|
+
e.thresholds !== t.thresholds && T?.stated && !T.silent && V(T);
|
|
182
|
+
}), W = (e) => {
|
|
183
|
+
let t = _.getState(), n = new Set(e), r = /* @__PURE__ */ new Map();
|
|
183
184
|
for (let [e, { mark: i }] of t.degradedEntities) n.has(e) || r.set(e, i);
|
|
184
185
|
let i = [...n].filter((e) => !t.degradedEntities.has(e));
|
|
185
186
|
for (let e of n) t.markDegraded(e);
|
|
186
|
-
r.size > 0 &&
|
|
187
|
+
r.size > 0 && m(u, {
|
|
187
188
|
scope: {
|
|
188
189
|
kind: "entities",
|
|
189
190
|
entities: new Set(r.keys())
|
|
190
191
|
},
|
|
191
192
|
jitter: !0,
|
|
192
193
|
carriedMarks: r
|
|
193
|
-
}), i.length > 0 &&
|
|
194
|
+
}), i.length > 0 && P(u, i.map((e) => ({
|
|
194
195
|
entity: e,
|
|
195
196
|
action: "updated",
|
|
196
197
|
ids: []
|
|
197
198
|
})));
|
|
198
199
|
};
|
|
199
|
-
async function
|
|
200
|
-
for (;
|
|
200
|
+
async function G() {
|
|
201
|
+
for (; h;) {
|
|
201
202
|
let o = new AbortController();
|
|
202
|
-
|
|
203
|
-
let s =
|
|
204
|
-
seq: ++
|
|
205
|
-
presented:
|
|
203
|
+
d.current = o;
|
|
204
|
+
let s = S(), l = s ? x() : null, p = {
|
|
205
|
+
seq: ++v.current,
|
|
206
|
+
presented: f.current !== "",
|
|
206
207
|
stated: !1,
|
|
207
208
|
silent: !1,
|
|
208
209
|
snapshotPoint: null
|
|
209
210
|
};
|
|
210
|
-
|
|
211
|
-
let
|
|
212
|
-
|
|
213
|
-
let
|
|
211
|
+
T = p;
|
|
212
|
+
let g = _.getState();
|
|
213
|
+
g.holdConnectionInterruption(), p.presented ? g.startReplay() : g.endReplay();
|
|
214
|
+
let C = /* @__PURE__ */ new Set();
|
|
214
215
|
try {
|
|
215
216
|
for await (let t of n({
|
|
216
217
|
signal: o.signal,
|
|
217
|
-
lastEventID:
|
|
218
|
-
bearerToken:
|
|
218
|
+
lastEventID: f.current,
|
|
219
|
+
bearerToken: l ?? void 0,
|
|
219
220
|
credentials: s ? "omit" : void 0,
|
|
220
|
-
onActivity: () =>
|
|
221
|
+
onActivity: () => H(p)
|
|
221
222
|
})) {
|
|
222
|
-
if (!
|
|
223
|
-
let n =
|
|
223
|
+
if (!h) break;
|
|
224
|
+
let n = _.getState();
|
|
224
225
|
if (t.type === "session_refresh") {
|
|
225
|
-
|
|
226
|
+
K(u);
|
|
226
227
|
try {
|
|
227
|
-
s ? (
|
|
228
|
+
s ? (b(), await y()) : await i(), u.invalidateQueries({ queryKey: ["schema"] }), e.getState().refreshMe();
|
|
228
229
|
} catch {}
|
|
229
230
|
break;
|
|
230
231
|
}
|
|
231
232
|
if (t.type === "snapshot_complete") {
|
|
232
|
-
|
|
233
|
+
w = 0, p.stated = !0, p.snapshotPoint = t.asOf ?? null, n.clearConnectionInterruption(), V(p);
|
|
233
234
|
let e = t.known && t.asOf !== void 0;
|
|
234
|
-
e ? n.clearRelayInterruption() : n.holdRelayInterruption(),
|
|
235
|
+
e ? n.clearRelayInterruption() : n.holdRelayInterruption(), p.presented || (t.asOf && L(String(t.asOf)), m(u, { scope: { kind: "all" } })), e && W(C ?? []), C = null;
|
|
235
236
|
} else if (t.type === "replay_complete") {
|
|
236
|
-
|
|
237
|
-
let e =
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
R();
|
|
238
|
+
let e = p.seq;
|
|
239
|
+
F(() => {
|
|
240
|
+
v.current === e && _.getState().endReplay();
|
|
240
241
|
});
|
|
241
|
-
} else if (t.type === "checkpoint")
|
|
242
|
-
else if (t.type === "
|
|
242
|
+
} else if (t.type === "checkpoint") L(t.eventID);
|
|
243
|
+
else if (t.type === "version_changed") c().catch(() => {});
|
|
244
|
+
else if (t.type === "cache_reset") L(t.eventID), t.reason !== j && Y(p, t.eventID) && n.holdRelayInterruption(), m(u, {
|
|
243
245
|
scope: { kind: "all" },
|
|
244
246
|
jitter: !0
|
|
245
247
|
});
|
|
246
248
|
else if (t.type === "realtime_streaming") {
|
|
247
|
-
if (
|
|
248
|
-
n.clearRelayInterruption(),
|
|
249
|
+
if (L(t.eventID), !Y(p, t.eventID)) continue;
|
|
250
|
+
n.clearRelayInterruption(), W(t.degraded);
|
|
249
251
|
} else if (t.type === "realtime_degraded") {
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
+
if (C !== null) {
|
|
253
|
+
C.add(t.entity);
|
|
252
254
|
continue;
|
|
253
255
|
}
|
|
254
|
-
if (
|
|
255
|
-
n.markDegraded(t.entity),
|
|
256
|
+
if (L(t.eventID), !Y(p, t.eventID)) continue;
|
|
257
|
+
n.markDegraded(t.entity), P(u, [{
|
|
256
258
|
entity: t.entity,
|
|
257
259
|
action: "updated",
|
|
258
260
|
ids: []
|
|
259
261
|
}]);
|
|
260
|
-
} else t.type === "entity_changed" && (
|
|
262
|
+
} else t.type === "entity_changed" && (D.push({
|
|
261
263
|
entity: t.entity,
|
|
262
264
|
action: t.action,
|
|
263
265
|
eventID: t.eventID,
|
|
264
266
|
ids: t.ids,
|
|
265
267
|
objects: t.objects,
|
|
266
268
|
reason: t.reason
|
|
267
|
-
}),
|
|
269
|
+
}), z());
|
|
268
270
|
}
|
|
269
271
|
} catch (e) {
|
|
270
|
-
if (!
|
|
272
|
+
if (!h || e instanceof DOMException && e.name === "AbortError") break;
|
|
271
273
|
if (e instanceof t) {
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
+
if (_.getState().holdConnectionInterruption(), B(), s) try {
|
|
275
|
+
b(), await y(), w = 0;
|
|
274
276
|
continue;
|
|
275
277
|
} catch {
|
|
276
278
|
a()();
|
|
277
279
|
return;
|
|
278
280
|
}
|
|
279
281
|
try {
|
|
280
|
-
await i(),
|
|
282
|
+
await i(), w = 0;
|
|
281
283
|
continue;
|
|
282
284
|
} catch (e) {
|
|
283
285
|
if (e instanceof r) {
|
|
@@ -287,20 +289,20 @@ function Y() {
|
|
|
287
289
|
}
|
|
288
290
|
}
|
|
289
291
|
}
|
|
290
|
-
if (
|
|
291
|
-
|
|
292
|
-
let
|
|
293
|
-
await new Promise((e) => setTimeout(e,
|
|
292
|
+
if (B(), !h) break;
|
|
293
|
+
_.getState().holdConnectionInterruption();
|
|
294
|
+
let E = Math.min(k * 2 ** w, O), A = E * .5 * Math.random();
|
|
295
|
+
await new Promise((e) => setTimeout(e, E + A)), w++;
|
|
294
296
|
}
|
|
295
297
|
}
|
|
296
|
-
return
|
|
297
|
-
|
|
298
|
+
return G(), () => {
|
|
299
|
+
h = !1, T = null, d.current?.abort(), d.current = null, B(), U(), R();
|
|
298
300
|
};
|
|
299
301
|
}, [
|
|
300
302
|
s,
|
|
301
|
-
c,
|
|
302
303
|
l,
|
|
303
|
-
|
|
304
|
+
u,
|
|
305
|
+
C
|
|
304
306
|
]);
|
|
305
307
|
}
|
|
306
|
-
export {
|
|
308
|
+
export { P as applyEntityChanges, K as evictEntityBackedQueries, q as liveEntityChanges, J as refetchQueriesReplayDoesNotCover, F as settleOwnWrite, X as useSSE };
|
|
@@ -23,22 +23,25 @@ function l() {
|
|
|
23
23
|
c.channel || typeof BroadcastChannel > "u" || (c.channel = s(), c.channel && c.channel.addEventListener("message", (e) => {
|
|
24
24
|
let t = e.data;
|
|
25
25
|
if (t && t.type === "drift" && t.delta && !c.hasReportedDrift) {
|
|
26
|
-
c.hasReportedDrift = !0;
|
|
26
|
+
t.delta.kind === "schema-only" ? u(t.delta) : c.hasReportedDrift = !0;
|
|
27
27
|
for (let e of c.listeners) e(t.delta);
|
|
28
28
|
}
|
|
29
29
|
}));
|
|
30
30
|
}
|
|
31
31
|
function u(e) {
|
|
32
|
+
c.firstSeen = e.observed, e.components && (c.firstComponents = e.components);
|
|
33
|
+
}
|
|
34
|
+
function d(e) {
|
|
32
35
|
if (l(), !e) return;
|
|
33
36
|
let t = e.get(a);
|
|
34
|
-
t && (c.firstSeen ? t !== c.firstSeen && (c.hasReportedDrift ||
|
|
35
|
-
|
|
37
|
+
t && (c.firstSeen ? t !== c.firstSeen && (c.hasReportedDrift || f().catch(() => {
|
|
38
|
+
m({
|
|
36
39
|
kind: "unknown",
|
|
37
40
|
observed: t
|
|
38
41
|
});
|
|
39
42
|
})) : c.firstSeen = t);
|
|
40
43
|
}
|
|
41
|
-
async function
|
|
44
|
+
async function f() {
|
|
42
45
|
l();
|
|
43
46
|
let e;
|
|
44
47
|
try {
|
|
@@ -66,20 +69,20 @@ async function d() {
|
|
|
66
69
|
asset: t.asset_fingerprint,
|
|
67
70
|
binary: t.binary_fingerprint
|
|
68
71
|
} : void 0;
|
|
69
|
-
c.firstSeen ||= n, !c.firstComponents && a && n === c.firstSeen && (c.firstComponents = a), n !== c.firstSeen &&
|
|
70
|
-
kind:
|
|
72
|
+
c.firstSeen ||= n, !c.firstComponents && a && n === c.firstSeen && (c.firstComponents = a), n !== c.firstSeen && m({
|
|
73
|
+
kind: p(c.firstComponents, a),
|
|
71
74
|
observed: n,
|
|
72
75
|
components: a
|
|
73
76
|
});
|
|
74
77
|
}
|
|
75
|
-
function
|
|
78
|
+
function p(e, t) {
|
|
76
79
|
if (!e || !t) return "unknown";
|
|
77
80
|
let n = e.schema !== t.schema, r = e.asset !== t.asset, i = e.binary !== t.binary;
|
|
78
81
|
return n && !r && !i ? "schema-only" : r || i ? "asset-or-binary" : "unknown";
|
|
79
82
|
}
|
|
80
|
-
function
|
|
83
|
+
function m(i) {
|
|
81
84
|
if (!c.hasReportedDrift) {
|
|
82
|
-
|
|
85
|
+
i.kind === "schema-only" ? u(i) : (c.hasReportedDrift = !0, c.pendingReload = i);
|
|
83
86
|
for (let e of c.listeners) e(i);
|
|
84
87
|
if (c.channel) try {
|
|
85
88
|
c.channel.postMessage({
|
|
@@ -90,12 +93,12 @@ function p(i) {
|
|
|
90
93
|
r() && i.kind !== "schema-only" && t(n(), e.reloadRequired, { reason: `version drift: ${i.kind}` });
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
|
-
function
|
|
96
|
+
function h() {
|
|
94
97
|
return c.pendingReload;
|
|
95
98
|
}
|
|
96
|
-
function
|
|
99
|
+
function g(e) {
|
|
97
100
|
return c.listeners.add(e), () => {
|
|
98
101
|
c.listeners.delete(e);
|
|
99
102
|
};
|
|
100
103
|
}
|
|
101
|
-
export {
|
|
104
|
+
export { f as fetchProbe, d as observe, h as pendingReload, g as subscribe };
|