@aerogel/plugin-local-first 0.0.0 → 0.1.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.
Files changed (35) hide show
  1. package/dist/aerogel-plugin-local-first.d.ts +48 -17
  2. package/dist/aerogel-plugin-local-first.js +1219 -1232
  3. package/dist/aerogel-plugin-local-first.js.map +1 -1
  4. package/package.json +5 -5
  5. package/src/components/Account.vue +9 -0
  6. package/src/components/AccountLoggedIn.vue +85 -0
  7. package/src/components/AccountLoggedOut.vue +26 -0
  8. package/src/components/AccountLoginModal.vue +36 -0
  9. package/src/components/AccountModal.vue +206 -0
  10. package/src/components/index.ts +5 -3
  11. package/src/components/settings/PurgeData.vue +43 -0
  12. package/src/components/settings/index.ts +10 -0
  13. package/src/index.css +1 -0
  14. package/src/index.ts +5 -1
  15. package/src/jobs/Migrate.test.ts +1 -1
  16. package/src/jobs/Migrate.ts +8 -1
  17. package/src/jobs/Sync.test.ts +313 -35
  18. package/src/jobs/Sync.ts +183 -77
  19. package/src/jobs/mixins/LoadsChildren.ts +48 -31
  20. package/src/jobs/mixins/LoadsTypeIndex.ts +7 -5
  21. package/src/jobs/mixins/TracksLocalModels.ts +4 -4
  22. package/src/lib/mirroring.ts +45 -21
  23. package/src/services/Cloud.ts +84 -25
  24. package/src/services/DocumentsCache.ts +6 -2
  25. package/src/testing/cloud.ts +1 -1
  26. package/src/testing/setup.ts +3 -2
  27. package/src/testing/stubs/Person.schema.ts +9 -0
  28. package/src/testing/stubs/Person.ts +18 -0
  29. package/src/testing/stubs/Post.schema.ts +17 -0
  30. package/src/testing/stubs/Post.ts +18 -0
  31. package/dist/InruptAuthenticator.lazy-BvpQLGoj-BvpQLGoj.js +0 -9
  32. package/dist/InruptAuthenticator.lazy-BvpQLGoj-BvpQLGoj.js.map +0 -1
  33. package/dist/LegacyAuthenticator.lazy-ChFFqP14-ChFFqP14.js +0 -5
  34. package/dist/LegacyAuthenticator.lazy-ChFFqP14-ChFFqP14.js.map +0 -1
  35. package/src/components/AGCloudStatus.vue +0 -31
@@ -1,1041 +1,471 @@
1
- var ct = Object.defineProperty;
2
- var dt = (n, t, e) => t in n ? ct(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var g = (n, t, e) => dt(n, typeof t != "symbol" ? t + "" : t, e);
4
- import { defineServiceState as je, requiredStringProp as ut, computedAsync as ht, Cache as ae, useForm as ft, requiredStringInput as gt, App as S, AGMarkdown as q, AGButton as O, AGForm as mt, AGInput as pt, AGLink as yt, persistent as wt, Events as d, UI as le, translateWithDefault as m, Colors as St, Storage as bt, Errors as X, Job as Ue, Service as vt, replaceExisting as ke, dispatch as ce, bootServices as Mt } from "@aerogel/core";
5
- import { facade as ne, after as T, required as w, Storage as de, fail as N, tap as K, arrayUnique as Te, objectWithout as ye, asyncMemo as qe, hasLocationQueryParameter as j, getLocationQueryParameter as Q, arrayFilter as Ke, setAsyncMemo as Oe, urlRoot as Ct, requireUrlParse as It, objectWithoutEmpty as Rt, parseBoolean as we, arrayWithout as Ut, arr as Lt, PromisedValue as Pt, JSError as Le, map as v, isInstanceOf as A, arrayRemove as Dt, toString as At, urlRoute as xt, urlResolveDirectory as Et, requireUrlParentDirectory as Z, IndexedDBMap as $t, arrayFrom as kt, arrayChunk as Tt, mixed as Be, objectMap as qt, round as Ot, Semaphore as Ft, isArray as _t } from "@noeldemartin/utils";
6
- import { SolidTypeIndex as J, SolidContainer as k, SolidACLAuthorization as Ge, SolidDocument as He, SolidEngine as Wt, SolidModel as F, SolidContainsRelation as Ve, isContainerClass as _, Metadata as Nt, Operation as Jt, isContainer as P, Tombstone as W, PropertyOperation as ee } from "soukai-solid";
7
- import { fetchLoginUserProfile as zt, MalformedSolidDocumentError as Ye } from "@noeldemartin/solid-utils";
8
- import { setEngine as jt, bootModels as Kt, requireEngine as Bt, DocumentNotFound as Gt } from "soukai";
9
- import { defineComponent as Pe, createElementBlock as te, openBlock as D, unref as f, computed as Qe, renderSlot as V, createCommentVNode as ue, createVNode as R, createElementVNode as Fe, withCtx as L, createTextVNode as E, toDisplayString as $, createBlock as B, watchEffect as Xe, shallowRef as Ht, triggerRef as he, toRaw as fe } from "vue";
10
- var Vt = Object.defineProperty, Yt = (n, t, e) => t in n ? Vt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, C = (n, t, e) => Yt(n, typeof t != "symbol" ? t + "" : t, e);
11
- class Qt extends Le {
12
- }
13
- function Xt(n, t) {
14
- return n;
15
- }
16
- class Se extends Le {
17
- constructor(t, e, i) {
18
- super(Xt(t), i), C(this, "description"), this.description = e;
19
- }
20
- }
21
- class Zt extends Le {
22
- constructor(t, e) {
23
- super(`Container at ${t.url} is already in use`, e);
24
- }
25
- }
26
- const Y = {};
27
- class Ze {
28
- constructor() {
29
- C(this, "name"), C(this, "authenticatedFetch"), C(this, "booted"), C(this, "listeners", Lt([])), C(this, "_engine");
30
- }
31
- get engine() {
32
- return this._engine = this._engine ?? new Wt(this.requireAuthenticatedFetch()), this._engine;
33
- }
34
- getAuthenticatedFetch() {
35
- return this.authenticatedFetch ?? null;
36
- }
37
- requireAuthenticatedFetch() {
38
- return this.authenticatedFetch ?? N("Authenticated fetch is not ready");
39
- }
40
- addListener(t) {
41
- return this.listeners.includes(t) || this.listeners.push(t), () => {
42
- this.removeListener(t);
43
- };
44
- }
45
- removeListener(t) {
46
- this.listeners.includes(t) && this.listeners.remove(t);
47
- }
48
- async boot() {
49
- if (this.booted)
50
- return this.booted;
51
- this.booted = new Pt(), await this.restoreSession(), this.booted.resolve();
52
- }
53
- async initAuthenticatedFetch(t) {
54
- this.authenticatedFetch = t, await this.notifyListeners("onAuthenticatedFetchReady", t);
55
- }
56
- async startSession(t) {
57
- const e = {
58
- authenticator: this,
59
- ...t
60
- };
61
- return await this.notifyListeners("onSessionStarted", e), e;
62
- }
63
- async failSession(t, e) {
64
- await this.notifyListeners("onSessionFailed", t, e);
65
- }
66
- async endSession() {
67
- await this.notifyListeners("onSessionEnded");
68
- }
69
- async notifyListeners(t, ...e) {
70
- await Promise.all(
71
- this.listeners.toArray().map(async (i) => {
72
- const s = i[t];
73
- await (s == null ? void 0 : s(...e));
74
- })
75
- );
76
- }
77
- }
78
- const ge = "inrupt-authenticator";
79
- class ei extends Ze {
1
+ var Ze = Object.defineProperty;
2
+ var Ge = (o, s, e) => s in o ? Ze(o, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[s] = e;
3
+ var w = (o, s, e) => Ge(o, typeof s != "symbol" ? s + "" : s, e);
4
+ import { Service as Xe, appNamespace as et, Events as D, App as oe, Job as ye, Errors as Z, defineServiceState as tt, replaceExisting as $e, translateWithDefault as $, dispatch as ae, Modal as Ee, Markdown as T, Link as he, Button as q, UI as le, Storage as nt, defineSettings as st, useEvent as ot, SettingsModal as Te, ProgressBar as it, AdvancedOptions as rt, Checkbox as ce, EditableContent as at, DropdownMenu as lt, bootServices as ct } from "@aerogel/core";
5
+ import { facade as we, IndexedDBMap as dt, isInstanceOf as E, arrayFilter as ut, after as G, arrayRemove as ht, required as A, tap as qe, urlRoute as Pe, urlResolveDirectory as ft, objectWithout as mt, requireUrlParentDirectory as X, fail as Oe, arrayFrom as gt, map as L, arrayChunk as pt, mixed as _e, objectMap as yt, round as wt, toString as Mt, Semaphore as bt, isArray as Ct, isTesting as Se, hasLocationQueryParameter as De, parseBoolean as ke, getLocationQueryParameter as Re } from "@noeldemartin/utils";
6
+ import { Solid as C, SolidLogin as vt, SolidAvatar as xe } from "@aerogel/plugin-solid";
7
+ import { SolidModel as J, SolidContainsRelation as Je, SolidACLAuthorization as $t, SolidDocument as St, Metadata as Dt, Operation as kt, SolidContainer as W, isContainerClass as x, isContainer as U, Tombstone as N, PropertyOperation as ee, isSolidModel as Rt } from "soukai-solid";
8
+ import { getTrackedModels as Me, trackModelsCollection as te, ignoreModelsCollection as Lt, trackModels as Ut } from "@aerogel/plugin-soukai";
9
+ import { watchEffect as At, markRaw as O, createElementBlock as M, openBlock as f, createElementVNode as m, defineComponent as j, createBlock as R, unref as d, withCtx as b, createVNode as u, createTextVNode as K, toDisplayString as S, createCommentVNode as _, useTemplateRef as It, ref as zt, computed as Y, normalizeClass as Et } from "vue";
10
+ import { bootModels as Tt, requireEngine as qt, DocumentNotFound as Pt, InvalidModelAttributes as Ot, requireBootedModel as _t, getBootedModels as xt } from "soukai";
11
+ import { MalformedSolidDocumentError as Jt } from "@noeldemartin/solid-utils";
12
+ class Nt extends Xe {
80
13
  constructor() {
81
- super(...arguments), C(this, "_events"), C(this, "_fetch"), C(this, "_login"), C(this, "_logout"), C(this, "_handleIncomingRedirect");
82
- }
83
- async login(t) {
84
- de.set(ge, t);
85
- const e = {
86
- oidcIssuer: t
87
- };
88
- return Y.clientID && (e.clientId = Y.clientID.client_id, e.clientName = Y.clientID.client_name, e.redirectUrl = Y.clientID.redirect_uris[0]), await this._login(e), await T({ seconds: 60 }), N("Browser should have redirected, but it didn't");
89
- }
90
- async logout() {
91
- await this._logout(), await this.endSession();
92
- }
93
- async restoreSession() {
94
- const { events: t, fetch: e, handleIncomingRedirect: i, login: s, logout: o } = await import("./InruptAuthenticator.lazy-BvpQLGoj-BvpQLGoj.js");
95
- this._fetch = e, this._login = s, this._logout = o, this._events = t, this._handleIncomingRedirect = i, await this.loginFromRedirect();
96
- }
97
- async loginFromRedirect() {
98
- const t = de.get(ge);
99
- if (!t)
100
- return;
101
- this._events().on("error", (i, s) => {
102
- i ?? (i = "Error using Inrupt Authenticator method"), typeof s == "object" ? this.failSession(t, new Se(i, null, { cause: s })) : this.failSession(t, new Se(i, s));
103
- });
104
- const e = await this._handleIncomingRedirect(globalThis.location.href);
105
- de.remove(ge), e != null && e.isLoggedIn && e.webId && await this.initSession(e.webId);
106
- }
107
- async initSession(t) {
108
- await this.initAuthenticatedFetch(this._fetch);
109
- try {
110
- const e = await y.requireUserProfile(t);
111
- await this.startSession({ user: e, loginUrl: t });
112
- } catch (e) {
113
- await this.failSession(t, e);
114
- }
115
- }
116
- }
117
- class ti extends Ze {
118
- constructor() {
119
- super(), C(this, "store"), this.store = wt("legacy-authenticator", {});
120
- }
121
- async login(t, e) {
122
- const { SolidAuthClient: i } = await import("./LegacyAuthenticator.lazy-ChFFqP14-ChFFqP14.js");
123
- throw this.store.webId = e == null ? void 0 : e.webId, this.store.loginUrl = (e == null ? void 0 : e.oidcIssuerUrl) ?? t, await i.login(this.store.loginUrl) === null ? (delete this.store.webId, delete this.store.loginUrl, new Se("Could not log in with Solid using the legacy authenticator")) : (await T({ seconds: 60 }), new Error("Browser should have redirected, but it didn't"));
124
- }
125
- async logout() {
126
- const { SolidAuthClient: t } = await import("./LegacyAuthenticator.lazy-ChFFqP14-ChFFqP14.js");
127
- delete this.store.webId, delete this.store.loginUrl, await t.logout(), await this.endSession();
128
- }
129
- async restoreSession() {
130
- if (!this.store.loginUrl)
131
- return;
132
- const { SolidAuthClient: t } = await import("./LegacyAuthenticator.lazy-ChFFqP14-ChFFqP14.js"), e = await t.currentSession(), i = w(this.store.loginUrl);
133
- await this.initAuthenticatedFetch((s, o) => t.fetch(s, o));
134
- try {
135
- const s = await y.requireUserProfile(w((e == null ? void 0 : e.webId) ?? this.store.webId));
136
- await this.startSession({ user: s, loginUrl: i });
137
- } catch (s) {
138
- await this.failSession(i, s);
139
- }
140
- }
141
- }
142
- const ii = {};
143
- new ei(), new ti();
144
- function si(n) {
145
- return ii[n];
146
- }
147
- const et = { autoReconnect: !0 }, ni = je({
148
- name: "solid",
149
- persist: ["autoReconnect", "dismissed", "previousSession", "profiles", "staleProfiles"],
150
- initialState: {
151
- autoReconnect: et.autoReconnect,
152
- dismissed: !1,
153
- ignorePreviousSessionError: !1,
154
- loginStartupError: null,
155
- loginOngoing: !1,
156
- preferredAuthenticator: null,
157
- previousSession: null,
158
- profiles: {},
159
- session: null,
160
- loginStale: !1,
161
- staleProfiles: []
162
- },
163
- serialize(n) {
164
- var t;
165
- return ((t = n.previousSession) == null ? void 0 : t.error) instanceof Error && (n.previousSession.error = n.previousSession.error.message), n;
166
- },
167
- computed: {
168
- user: (n) => {
169
- var t, e;
170
- return ((t = n.session) == null ? void 0 : t.user) ?? ((e = n.previousSession) == null ? void 0 : e.profile) ?? null;
171
- },
172
- authenticator: (n) => {
173
- var t;
174
- return ((t = n.session) == null ? void 0 : t.authenticator) ?? null;
175
- },
176
- fetch() {
177
- var n;
178
- return ((n = this.authenticator) == null ? void 0 : n.getAuthenticatedFetch()) ?? globalThis.fetch.bind(globalThis);
179
- },
180
- error(n) {
181
- var t;
182
- return n.loginStartupError ? n.loginStartupError ?? null : n.ignorePreviousSessionError ? null : ((t = n.previousSession) == null ? void 0 : t.error) ?? null;
183
- }
184
- }
185
- });
186
- class oi extends ni {
187
- isLoggedIn() {
188
- return !!this.session;
189
- }
190
- wasLoggedIn() {
191
- return !!this.previousSession;
192
- }
193
- hasLoggedIn() {
194
- return !!(this.session || this.previousSession);
195
- }
196
- requireAuthenticator() {
197
- return this.authenticator ?? N("Could not get authenticator");
198
- }
199
- requireUser() {
200
- return this.user ?? N("Could not get user profile (are you logged in?)");
201
- }
202
- requireUserProfile(t) {
203
- return this.getUserProfile(t, { required: !0 });
204
- }
205
- /* eslint-enable max-len */
206
- async getUserProfile(t, e = {}) {
207
- var i;
208
- let s = null;
209
- const o = e.markStale ?? !((i = this.authenticator) != null && i.getAuthenticatedFetch()), r = this.profiles[t] ?? await K(
210
- await zt(t, {
211
- fetch: this.fetch,
212
- required: e.required ?? !1,
213
- onLoaded(a) {
214
- s = a;
215
- }
216
- }),
217
- async (a) => {
218
- a && (s && await d.emit("solid:user-profile-loaded", [a, s]), this.rememberProfile(a));
219
- }
220
- );
221
- return r && o && this.setState({ staleProfiles: Te(this.staleProfiles.concat([r.webId])) }), r;
222
- }
223
- async refreshUserProfile() {
224
- if (!this.isLoggedIn())
225
- return;
226
- this.setState({ profiles: ye(this.profiles, [this.user.webId]) });
227
- const t = await this.requireUserProfile(this.user.webId);
228
- this.setState({
229
- session: {
230
- ...this.session,
231
- user: t
232
- }
233
- });
14
+ super(...arguments);
15
+ w(this, "cache", new dt(`${et()}-documents-cache`));
234
16
  }
235
- async login(t, e = {}) {
236
- if (S.development && t === "dev" && (t = "http://localhost:3000"), /^https?:\/\//.test(t) || (e.fallbackUrl ?? (e.fallbackUrl = `http://${t}`), t = `https://${t}`), this.isLoggedIn())
237
- return !0;
238
- if (this.loginOngoing)
239
- throw new Error("Authentication already in progress");
240
- return e.loading ? le.loading(m("solid.loggingIn", "Logging in..."), () => this.attemptLogin(t, e)) : this.attemptLogin(t, e);
241
- }
242
- async reconnect(t = {}) {
243
- const { force: e, ...i } = t;
244
- this.isLoggedIn() || !this.previousSession || this.previousSession.error !== null && !e || await this.login(this.previousSession.loginUrl, {
245
- authenticator: this.previousSession.authenticator,
246
- ...i,
247
- loading: i.loading ?? !1
248
- });
17
+ async isFresh(e, t) {
18
+ const n = await this.cache.get(e), i = typeof t != "number" ? t.getTime() : t;
19
+ return !!(n != null && n.modifiedAt) && n.modifiedAt >= i;
249
20
  }
250
- async logout(t = !1) {
251
- var e, i;
252
- const s = !S.plugin("@aerogel/local-first") || !!((e = S.service("$cloud")) != null && e.ready), o = !S.plugin("@aerogel/local-first") || !!((i = S.service("$cloud")) != null && i.dirty), [r, a] = t ? [!0, { wipeLocalData: s }] : await le.confirm(
253
- s ? m("solid.logoutConfirmTitle", "Log out from this device?") : m("solid.disconnectConfirmTitle", "Disconnect account?"),
254
- s ? o ? m(
255
- "solid.logoutConfirmMessageWithLocalChanges",
256
- "There are some changes that haven't been synchronized and will be lost, but the rest of the data will remain in your Solid POD."
257
- ) : m(
258
- "solid.logoutConfirmMessage",
259
- "Logging out will remove all the data from this device, but you'll still have it in your Solid POD."
260
- ) : m(
261
- "solid.disconnectConfirmMessage",
262
- "You'll need to introduce your credentials again to connect to your Solid POD."
263
- ),
264
- {
265
- acceptText: m("solid.logoutConfirmAccept", "Log out"),
266
- acceptColor: St.Danger,
267
- cancelText: m(
268
- "solid.logoutConfirmCancel",
269
- m("ui.cancel", "Cancel")
270
- ),
271
- checkboxes: s ? o ? {
272
- wipeLocalData: {
273
- label: m(
274
- "solid.logoutConfirmWipeNotice",
275
- "I understand that changes that haven't been synchronized will be lost."
276
- ),
277
- default: !1,
278
- required: !0
279
- }
280
- } : void 0 : {
281
- wipeLocalData: {
282
- label: m(
283
- "solid.logoutConfirmWipe",
284
- "Also remove all existing data (tasks, lists, etc.)"
285
- ),
286
- default: !1
287
- }
288
- }
289
- }
290
- );
291
- r && this.previousSession && await le.loading(m("solid.logoutOngoing", "Logging out..."), async () => {
292
- this.setState({
293
- dismissed: !1,
294
- ignorePreviousSessionError: !1,
295
- loginStartupError: null,
296
- previousSession: null,
297
- ...et
298
- }), this.isLoggedIn() && await this.authenticator.logout(), (a.wipeLocalData ?? !0) && await bt.purge(), await d.emit("auth:logout"), await d.emit("auth:after-logout");
21
+ async remember(e, t) {
22
+ await this.cache.set(e, {
23
+ modifiedAt: typeof t != "number" ? t.getTime() : t
299
24
  });
300
25
  }
301
- async whenLoggedIn(t) {
302
- return this.isLoggedIn() ? t(this.session) : new Promise((e) => {
303
- const i = (s) => e(t(s));
304
- d.once("auth:login", i);
305
- });
26
+ async forget(e) {
27
+ await this.cache.delete(e);
306
28
  }
307
- dismiss() {
308
- this.setState({ dismissed: !0 });
309
- }
310
- async findOrCreatePrivateTypeIndex() {
311
- return await this.findPrivateTypeIndex() ?? await this.createPrivateTypeIndex();
312
- }
313
- async findPrivateTypeIndex() {
314
- const { webId: t, privateTypeIndexUrl: e } = this.requireUser(), i = this.requireAuthenticator().engine;
315
- return e ? qe(`${t}-privateTypeIndex`, () => J.withEngine(i).find(e)) : null;
316
- }
317
- async findOrCreatePublicTypeIndex() {
318
- return await this.findPublicTypeIndex() ?? await this.createPublicTypeIndex();
319
- }
320
- async findPublicTypeIndex() {
321
- const { webId: t, publicTypeIndexUrl: e } = this.requireUser(), i = this.requireAuthenticator().engine;
322
- return e ? qe(`${t}-publicTypeIndex`, () => J.withEngine(i).find(e)) : null;
323
- }
324
- async createPrivateContainer(t) {
325
- const e = this.requireAuthenticator().engine;
326
- return k.withEngine(e, async () => {
327
- const i = await k.find(t.url);
328
- if (i && !t.reuseExisting)
329
- throw new Zt(i);
330
- const s = i ?? new k({ url: t.url, name: t.name });
331
- if (await s.save(), t.registerFor) {
332
- const o = await this.findOrCreatePrivateTypeIndex();
333
- await s.register(o, t.registerFor);
334
- }
335
- return s;
336
- });
29
+ async clear() {
30
+ await this.cache.clear();
337
31
  }
338
32
  async boot() {
339
- var t, e;
340
- await X.booted, j("authenticator") && this.setState({
341
- preferredAuthenticator: Q("authenticator")
342
- }), j("refreshProfile") && this.setState({
343
- staleProfiles: Te(
344
- this.staleProfiles.concat(Ke([(t = this.session) == null ? void 0 : t.user.webId, (e = this.previousSession) == null ? void 0 : e.loginUrl]))
345
- )
346
- }), await this.restorePreviousSession(), await this.startupReconnect();
347
- }
348
- async createPrivateTypeIndex() {
349
- const t = this.requireUser(), e = this.requireAuthenticator(), i = await J.withEngine(e.engine).createPrivate(t);
350
- return K(i, () => {
351
- t.privateTypeIndexUrl = i.url, Oe(`${t.webId}-privateTypeIndex`, i), this.rememberProfile(t);
352
- });
353
- }
354
- async createPublicTypeIndex() {
355
- const t = this.requireUser(), e = this.requireAuthenticator(), i = await J.withEngine(e.engine).createPublic(t);
356
- return K(i, () => {
357
- t.privateTypeIndexUrl = i.url, Oe(`${t.webId}-publicTypeIndex`, i), this.rememberProfile(t);
358
- });
359
- }
360
- async attemptLogin(t, e) {
361
- const i = e.authenticator ?? this.preferredAuthenticator ?? "default", s = e.onError ?? ((a) => S.isMounted() ? X.report(a) : this.setState({ loginStartupError: a })), o = setTimeout(() => this.loginStale = !0, 1e4), r = {
362
- dismissed: this.dismissed,
363
- ignorePreviousSessionError: this.ignorePreviousSessionError,
364
- previousSession: this.previousSession
365
- };
366
- this.loginOngoing = !0;
367
- try {
368
- const a = await this.getUserProfile(t, { markStale: !0 }), l = (a == null ? void 0 : a.oidcIssuerUrl) ?? Ct((a == null ? void 0 : a.webId) ?? t), c = await this.bootAuthenticator(i), { domain: u } = It(t);
369
- return this.setState({
370
- dismissed: !1,
371
- ignorePreviousSessionError: !0,
372
- previousSession: Rt({
373
- profile: a,
374
- loginUrl: t,
375
- authenticator: i,
376
- error: m(
377
- "auth.stuckConnecting",
378
- `We didn't hear back from the identity provider at \`${u}\`, maybe try reconnecting?`
379
- )
380
- })
381
- }), await d.emit("auth:before-login"), await c.login(l, a), !0;
382
- } catch (a) {
383
- return this.setState(r), a instanceof Qt ? !1 : e.fallbackUrl ? T().then(() => this.login(e.fallbackUrl ?? "", ye(e, "fallbackUrl"))) : (s(a), !1);
384
- } finally {
385
- clearTimeout(o), this.setState({
386
- loginOngoing: !1,
387
- loginStale: !1
388
- });
389
- }
390
- }
391
- async restorePreviousSession() {
392
- this.previousSession && await this.bootAuthenticator(this.previousSession.authenticator);
393
- }
394
- async startupReconnect() {
395
- this.reconnectOnStartup() && await this.reconnect({ force: this.forcingReconnect() });
396
- }
397
- reconnectOnStartup() {
398
- return j("autoReconnect") ? we(Q("autoReconnect")) : this.autoReconnect;
399
- }
400
- forcingReconnect() {
401
- return j("autoReconnect") && we(Q("autoReconnect"));
402
- }
403
- async bootAuthenticator(t) {
404
- const e = si(t);
405
- return e.addListener({
406
- onSessionStarted: async (i) => {
407
- this.setState({
408
- session: i,
409
- previousSession: {
410
- authenticator: e.name,
411
- loginUrl: i.loginUrl,
412
- profile: i.user,
413
- error: null
414
- }
415
- }), this.staleProfiles.includes(i.user.webId) && await this.refreshUserProfile(), S.plugin("@aerogel/local-first") || jt(i.authenticator.engine), Ge.setEngine(i.authenticator.engine), J.setEngine(i.authenticator.engine), He.setEngine(i.authenticator.engine), await d.emit("auth:login", i);
416
- },
417
- onSessionFailed: async (i, s) => {
418
- var o;
419
- this.setState({
420
- session: null,
421
- previousSession: {
422
- profile: (o = this.previousSession) == null ? void 0 : o.profile,
423
- authenticator: e.name,
424
- loginUrl: i,
425
- error: s
426
- }
427
- });
428
- },
429
- onSessionEnded: () => this.setState({ session: null }),
430
- onAuthenticatedFetchReady: (i) => d.emit("auth:fetch-ready", i)
431
- }), await e.boot(), e;
432
- }
433
- rememberProfile(t) {
434
- this.setState({
435
- profiles: {
436
- ...this.profiles,
437
- [t.webId]: t
438
- },
439
- staleProfiles: Ut(this.staleProfiles, t.webId)
33
+ D.on("auth:logout", async () => {
34
+ await this.cache.clear(), this.cache.close();
440
35
  });
441
36
  }
442
37
  }
443
- const y = ne(oi), ri = ["src"];
444
- ut();
445
- const ai = { class: "flex flex-col gap-3" }, li = { class: "flex flex-col" }, ci = {
446
- key: 1,
447
- class: "mt-1 self-center text-sm text-red-800"
448
- }, di = /* @__PURE__ */ Pe({
449
- __name: "AGSolidStatus",
450
- setup(n) {
451
- const t = ft({ url: gt() }), e = Qe(
452
- () => S.development && (!t.url || t.url === "dev" || t.url.trim().length === 0)
453
- );
454
- return (i, s) => (D(), te("div", null, [
455
- i.$solid.loginStale ? V(i.$slots, "login-stale", { key: 0 }, () => [
456
- R(f(q), {
457
- text: i.$td("solid.loginStale", "This is taking too long...")
458
- }, null, 8, ["text"])
459
- ]) : ue("", !0),
460
- i.$solid.loginOngoing ? V(i.$slots, "login-ongoing", { key: 1 }, () => [
461
- R(f(q), {
462
- text: i.$td("ui.loading", "Loading...")
463
- }, null, 8, ["text"])
464
- ]) : i.$solid.isLoggedIn() ? V(i.$slots, "logged-in", {
465
- key: 2,
466
- session: i.$solid.session
467
- }, () => [
468
- Fe("div", ai, [
469
- R(f(q), {
470
- text: i.$td("solid.loggedIn", "You are logged in as [{userName}]({userWebId})", {
471
- userName: i.$solid.user.name ?? i.$solid.user.webId,
472
- userWebId: i.$solid.user.webId
473
- })
474
- }, null, 8, ["text"]),
475
- R(f(O), {
476
- onClick: s[0] || (s[0] = (o) => i.$solid.logout())
477
- }, {
478
- default: L(() => [
479
- E($(i.$td("solid.logout", "Logout")), 1)
480
- ]),
481
- _: 1
482
- })
483
- ])
484
- ]) : V(i.$slots, "logged-out", { key: 3 }, () => {
485
- var o;
486
- return [
487
- Fe("div", li, [
488
- R(f(mt), {
489
- form: f(t),
490
- class: "flex",
491
- onSubmit: s[2] || (s[2] = (r) => i.$solid.login(f(t).url))
492
- }, {
493
- default: L(() => [
494
- R(f(pt), {
495
- name: "url",
496
- "aria-label": i.$td("solid.url", "Login url"),
497
- placeholder: i.$td("solid.placeholder", "https://...")
498
- }, null, 8, ["aria-label", "placeholder"]),
499
- e.value ? (D(), B(f(O), {
500
- key: 0,
501
- submit: "",
502
- onClick: s[1] || (s[1] = (r) => f(t).url = "dev")
503
- }, {
504
- default: L(() => [
505
- E($(i.$td("solid.devLogin", "Dev login")), 1)
506
- ]),
507
- _: 1
508
- })) : (D(), B(f(O), {
509
- key: 1,
510
- submit: ""
511
- }, {
512
- default: L(() => [
513
- E($(i.$td("solid.login", "Login")), 1)
514
- ]),
515
- _: 1
516
- }))
517
- ]),
518
- _: 1
519
- }, 8, ["form"]),
520
- i.$solid.wasLoggedIn() ? (D(), B(f(O), {
521
- key: 0,
522
- class: "mt-3",
523
- onClick: s[3] || (s[3] = (r) => i.$solid.reconnect({ force: !0 }))
524
- }, {
525
- default: L(() => [
526
- E($(i.$td("solid.reconnect", "Reconnect")), 1)
527
- ]),
528
- _: 1
529
- })) : ue("", !0),
530
- (o = i.$solid.previousSession) != null && o.error || i.$solid.loginStartupError ? (D(), te("p", ci, [
531
- R(f(q), {
532
- text: i.$td("solid.previousLoginError", "Previous login attempt failed"),
533
- inline: ""
534
- }, null, 8, ["text"]),
535
- R(f(yt), {
536
- onClick: s[4] || (s[4] = (r) => {
537
- var a;
538
- return i.$errors.inspect(((a = i.$solid.previousSession) == null ? void 0 : a.error) || i.$solid.loginStartupError);
539
- })
540
- }, {
541
- default: L(() => [
542
- E(" (" + $(i.$td("errors.viewDetails", "View details")) + ") ", 1)
543
- ]),
544
- _: 1
545
- })
546
- ])) : ue("", !0)
547
- ])
548
- ];
549
- })
550
- ]));
551
- }
552
- });
553
- let De = /* @__PURE__ */ new WeakMap();
554
- function ui(n) {
555
- const t = Ht(v([], "id")), e = Qe(() => t.value.getItems()), i = /* @__PURE__ */ new Set([n.collection]), s = {
556
- modelsMap: t,
557
- modelsArray: e,
558
- collectionsSet: i,
559
- async refresh() {
560
- const o = v([], "id");
561
- for (const r of i)
562
- (await n.withCollection(r, () => n.all())).forEach((a) => o.add(a));
563
- t.value = o;
564
- }
565
- };
566
- return De.set(n, s), n.on("created", (o) => (t.value.add(fe(o)), he(t))), n.on("deleted", (o) => (t.value.delete(fe(o)), he(t))), n.on("updated", (o) => (t.value.add(fe(o)), he(t))), d.on("purge-storage", () => t.value = v([], "id")), d.on("cloud:migration-completed", () => s.refresh()), d.on("cloud:migration-cancelled", () => s.refresh()), d.on("cloud:backup-completed", () => s.refresh()), s;
567
- }
568
- function Ae() {
569
- return De;
570
- }
571
- function hi(n) {
572
- return De.get(n) ?? ui(n);
573
- }
574
- function xe(n) {
575
- var t;
576
- return ((t = Ae().get(n)) == null ? void 0 : t.modelsArray.value) ?? [];
577
- }
578
- function fi(n, t) {
579
- w(
580
- Ae().get(n),
581
- "Failed ignoring models collection, please track the model first using trackModels()"
582
- ).collectionsSet.delete(t);
583
- }
584
- async function ie(n, t, e = {}) {
585
- const i = e.refresh ?? !0, s = w(
586
- Ae().get(n),
587
- "Failed tracking models collection, please track the model first using trackModels()"
588
- );
589
- if (!s.collectionsSet.has(t) && (s.collectionsSet.add(t), i)) {
590
- const o = s.modelsArray.value;
591
- (await n.withCollection(t, () => n.all())).forEach((r) => o.push(r)), s.modelsMap.value = v(o, "id");
592
- }
593
- }
594
- async function gi(n, t) {
595
- const { service: e, property: i, transform: s, ...o } = t ?? {}, r = s ?? ((l) => l), a = hi(n);
596
- for (const [l, c] of Object.entries(o))
597
- n.on(l, c);
598
- e && i && Xe(() => e.setState(i, r(a.modelsArray.value))), await a.refresh();
599
- }
600
- const me = /* @__PURE__ */ new WeakMap();
601
- function be(n) {
602
- return Ke(
603
- M(n).map((t) => {
604
- const e = n.instance().requireRelation(t).relatedClass;
605
- return _(e) ? !1 : e;
38
+ const P = we(Nt), de = /* @__PURE__ */ new WeakMap();
39
+ function fe(o) {
40
+ return ut(
41
+ k(o).map((s) => {
42
+ const e = o.instance().requireRelation(s).relatedClass;
43
+ return x(e) ? !1 : e;
606
44
  })
607
45
  );
608
46
  }
609
- function M(n) {
610
- return me.has(n) || me.set(
611
- n,
612
- n.relations.filter((t) => F.reservedRelations.includes(t) ? !1 : n.instance().requireRelation(t) instanceof Ve)
613
- ), me.get(n) ?? [];
47
+ function k(o) {
48
+ return de.has(o) || de.set(
49
+ o,
50
+ o.relations.filter((s) => J.reservedRelations.includes(s) ? !1 : o.instance().requireRelation(s) instanceof Je)
51
+ ), de.get(o) ?? [];
614
52
  }
615
- function tt(n) {
616
- return M(n.static()).reduce(
617
- (e, i) => e.concat(n.getRelationModels(i) ?? []),
53
+ function Ne(o) {
54
+ return k(o.static()).reduce(
55
+ (e, t) => e.concat(o.getRelationModels(t) ?? []),
618
56
  []
619
57
  );
620
58
  }
621
- function _e(n) {
622
- const t = /* @__PURE__ */ new Set(), e = n.instance();
623
- t.add(n);
624
- for (const i of n.relations)
625
- n.reservedRelations.includes(i) || t.add(e.requireRelation(i).relatedClass);
626
- return [...t.values()];
59
+ function Le(o) {
60
+ const s = /* @__PURE__ */ new Set(), e = o.instance();
61
+ s.add(o);
62
+ for (const t of o.relations)
63
+ o.reservedRelations.includes(t) || s.add(e.requireRelation(t).relatedClass);
64
+ return [...s.values()];
627
65
  }
628
- function ve(n) {
629
- return n.getRelatedModels().filter(
630
- (t) => !A(t, Ge) && !A(t, He) && !A(t, Nt) && !A(t, Jt) && t.static() !== k
66
+ function ne(o) {
67
+ return o.getRelatedModels().filter(
68
+ (s) => !E(s, $t) && !E(s, St) && !E(s, Dt) && !E(s, kt) && s.static() !== W
631
69
  );
632
70
  }
633
- function it(n) {
634
- if (n.isDirty())
71
+ function We(o) {
72
+ if (o.isDirty())
635
73
  return !0;
636
- if (!(n instanceof k))
74
+ if (!(o instanceof W))
637
75
  return !1;
638
- const t = (e) => {
639
- var i;
640
- return (i = n.getRelationModels(e)) == null ? void 0 : i.some((s) => it(s));
76
+ const s = (e) => {
77
+ var t;
78
+ return (t = o.getRelationModels(e)) == null ? void 0 : t.some((n) => We(n));
641
79
  };
642
- return M(n.static()).some(t);
80
+ return k(o.static()).some(s);
643
81
  }
644
- const mi = w(() => S.service("$cloud"));
645
- class pi {
82
+ const Wt = A(() => oe.service("$cloud"));
83
+ class jt {
646
84
  constructor() {
647
- g(this, "models", /* @__PURE__ */ new Set());
648
- g(this, "promises", []);
85
+ w(this, "models", /* @__PURE__ */ new Set());
86
+ w(this, "promises", []);
649
87
  }
650
- push(t) {
651
- this.models.add(t), this.syncAfter(T({ seconds: 1 }));
88
+ push(s) {
89
+ this.models.add(s), this.syncAfter(G({ seconds: 1 }));
652
90
  }
653
- clear(t) {
654
- if (!t) {
91
+ clear(s) {
92
+ if (!s) {
655
93
  this.models = /* @__PURE__ */ new Set();
656
94
  return;
657
95
  }
658
- for (const e of t)
96
+ for (const e of s)
659
97
  this.models.delete(e);
660
98
  }
661
- async syncAfter(t) {
662
- const e = typeof t == "function" ? t() : t;
663
- return this.promises.push(e), e.then(() => Dt(this.promises, e)), this.promises.length === 1 && this.schedule(), e;
99
+ async syncAfter(s) {
100
+ const e = typeof s == "function" ? s() : s;
101
+ return this.promises.push(e), e.then(() => ht(this.promises, e)), this.promises.length === 1 && this.schedule(), e;
664
102
  }
665
103
  schedule() {
666
- Promise.all(this.promises).then(() => T()).then(() => {
104
+ Promise.all(this.promises).then(() => G()).then(() => {
667
105
  if (this.promises.length !== 0) {
668
106
  this.schedule();
669
107
  return;
670
108
  }
671
- const t = this.consume();
672
- t.length !== 0 && mi.syncIfOnline(t);
109
+ const s = this.consume();
110
+ s.length !== 0 && Wt.syncIfOnline(s);
673
111
  });
674
112
  }
675
113
  consume() {
676
- const t = [], e = /* @__PURE__ */ new Set();
677
- for (const i of this.models)
678
- P(i) && (this.models.delete(i), tt(i).forEach((s) => e.add(s)), t.push(i));
679
- for (const i of this.models)
680
- this.models.delete(i), !e.has(i) && t.push(i);
681
- return t;
114
+ const s = [], e = /* @__PURE__ */ new Set();
115
+ for (const t of this.models)
116
+ U(t) && (this.models.delete(t), Ne(t).forEach((n) => e.add(n)), s.push(t));
117
+ for (const t of this.models)
118
+ this.models.delete(t), !e.has(t) && s.push(t);
119
+ return s;
682
120
  }
683
121
  }
684
- const se = ne(pi), h = w(() => S.service("$cloud")), st = /* @__PURE__ */ new WeakMap(), Ee = /* @__PURE__ */ new WeakMap();
685
- function yi(n) {
686
- const t = n.getRelatedModels().concat([n]);
687
- for (const e of t)
122
+ const se = we(jt), g = A(() => oe.service("$cloud")), je = /* @__PURE__ */ new WeakMap(), be = /* @__PURE__ */ new WeakMap();
123
+ function Bt(o) {
124
+ const s = o.getRelatedModels().concat([o]);
125
+ for (const e of s)
688
126
  e.cleanDirty(!0);
689
127
  }
690
- function wi(n) {
691
- const t = ve(n).concat([n]);
692
- for (const e of t) {
128
+ function Vt(o) {
129
+ const s = ne(o).concat([o]);
130
+ for (const e of s) {
693
131
  if (!e.operations || e.operations.length === 0)
694
132
  continue;
695
- const i = (e.operations ?? []).filter((s) => !(s instanceof ee) || !e.ignoreRdfPropertyHistory(s.property, !0));
696
- if (!i.some((s) => !s.isInception(e))) {
133
+ const t = (e.operations ?? []).filter((n) => !(n instanceof ee) || !e.ignoreRdfPropertyHistory(n.property, !0));
134
+ if (!t.some((n) => !n.isInception(e))) {
697
135
  e.setRelationModels("operations", []);
698
136
  continue;
699
137
  }
700
- e.setRelationModels("operations", i);
138
+ e.setRelationModels("operations", t);
701
139
  }
702
140
  }
703
- async function We(n) {
704
- h.setState({
141
+ async function Ue(o) {
142
+ g.setState({
705
143
  localModelUpdates: {
706
- ...h.localModelUpdates,
707
- [n.url]: 1
144
+ ...g.localModelUpdates,
145
+ [o.url]: 1
708
146
  }
709
- }), Ui(n.static()) && await Me(n.static(), Z(n.url)), h.autoPush && h.ready && !h.syncing && se.push(n);
147
+ }), Xt(o.static()) && await me(o.static(), X(o.url)), g.autoPush && g.ready && !g.syncing && se.push(o);
710
148
  }
711
- async function Me(n, t) {
712
- var e;
713
- (e = h.modelCollections[n.modelName]) != null && e.includes(t) || (h.setState("modelCollections", {
714
- ...h.modelCollections,
715
- [n.modelName]: (h.modelCollections[n.modelName] ?? []).concat(t)
716
- }), await ie(n, t));
149
+ async function me(o, s) {
150
+ var e, t;
151
+ (e = g.modelCollections[o.modelName]) != null && e.includes(s) || (g.setState("modelCollections", {
152
+ ...g.modelCollections,
153
+ [o.modelName]: (g.modelCollections[o.modelName] ?? []).concat(s)
154
+ }), (t = g.modelCollections[o.modelName]) != null && t.includes(o.collection) || (o.collection = s), await te(o, s));
717
155
  }
718
- async function Ne(n) {
719
- if (Si(n))
156
+ async function Ae(o) {
157
+ if (Ft(o))
720
158
  return;
721
- const t = h.localModelUpdates[n.url] ?? 0;
722
- h.setState({
723
- localModelUpdates: n.isSoftDeleted() ? ye(h.localModelUpdates, n.url) : {
724
- ...h.localModelUpdates,
725
- [n.url]: t + 1
159
+ const s = g.localModelUpdates[o.url] ?? 0;
160
+ g.setState({
161
+ localModelUpdates: o.isSoftDeleted() ? mt(g.localModelUpdates, o.url) : {
162
+ ...g.localModelUpdates,
163
+ [o.url]: s + 1
726
164
  }
727
- }), h.autoPush && h.ready && !h.syncing && se.push(n);
165
+ }), await P.forget(o.requireDocumentUrl()), g.autoPush && g.ready && !g.syncing && se.push(o);
728
166
  }
729
- function Ce(n, t) {
730
- const e = n == null ? void 0 : n.map((s) => At(s.getDeletedPrimaryKey() ?? s.getPrimaryKey())), i = {};
731
- for (const [s, o] of Object.entries(h.localModelUpdates)) {
732
- const r = xt(s);
733
- (!e || e.some(
734
- (l) => s === l || l.endsWith("/") && s.startsWith(l)
735
- )) && !(t != null && t.has(r)) || (i[s] = o);
736
- }
737
- h.setState({ localModelUpdates: i });
167
+ function ge(o, s) {
168
+ const e = {}, t = Array.from(o);
169
+ for (const [n, i] of Object.entries(g.localModelUpdates)) {
170
+ const l = Pe(n);
171
+ (o.has(n) || t.some((r) => r.endsWith("/") && n.startsWith(r))) && !(s != null && s.has(l)) || (e[n] = i);
172
+ }
173
+ g.setState({ localModelUpdates: e });
738
174
  }
739
- function $e(n, t = {}) {
175
+ function Ce(o, s = {}) {
740
176
  const e = /* @__PURE__ */ new Set();
741
- if (e.add(n.static()), n instanceof k)
742
- for (const s of M(n.static()))
743
- e.add(n.requireRelation(s).relatedClass);
744
- const i = [...e.values()].map(
745
- (s) => [s, x(s)]
177
+ if (e.add(o.static()), o instanceof W)
178
+ for (const n of k(o.static()))
179
+ e.add(o.requireRelation(n).relatedClass);
180
+ const t = [...e.values()].map(
181
+ (n) => [n, z(n)]
746
182
  );
747
- return K(n.clone({ constructors: i }), (s) => {
748
- wi(s), t.clean && yi(s);
183
+ return qe(o.clone({ constructors: t }), (n) => {
184
+ Vt(n), s.clean && Bt(n);
749
185
  });
750
186
  }
751
- function nt(n) {
752
- const t = /* @__PURE__ */ new Set();
753
- if (t.add(n.static()), n instanceof k)
754
- for (const i of M(n.static()))
755
- t.add(n.requireRelation(i).relatedClass);
756
- const e = [...t.values()].map(
757
- (i) => [i, Pi(i)]
187
+ function Be(o) {
188
+ const s = /* @__PURE__ */ new Set();
189
+ if (s.add(o.static()), o instanceof W)
190
+ for (const t of k(o.static()))
191
+ s.add(o.requireRelation(t).relatedClass);
192
+ const e = [...s.values()].map(
193
+ (t) => [t, tn(t)]
758
194
  );
759
- return n.clone({ constructors: e });
195
+ return o.clone({ constructors: e });
760
196
  }
761
- async function Je(n, t, e) {
762
- const i = x(W), s = t.map((a) => a.url), o = n.filter((a) => !s.includes(a.url)).map((a) => a.requireDocumentUrl()).filter((a) => !e.has(a)), r = await i.all({ $in: o });
763
- return t.concat(r);
197
+ async function Ie(o, s, e) {
198
+ const t = z(N), n = s.map((a) => a.url), i = o.filter((a) => !n.includes(a.url)).map((a) => a.requireDocumentUrl()).filter((a) => !e.has(a)), l = await t.all({ $in: i });
199
+ return s.concat(l);
764
200
  }
765
- function Si(n) {
766
- var e;
767
- const t = (e = n.metadata.updatedAt) == null ? void 0 : e.getTime();
768
- return !n.operations.some((i) => i.date.getTime() !== t ? !1 : i instanceof ee ? !n.ignoreRdfPropertyHistory(i.property, !0) : !0);
201
+ function Ft(o) {
202
+ return !o.getDocumentModels().flatMap(
203
+ (t) => {
204
+ var n;
205
+ return ((n = t.operations) == null ? void 0 : n.map((i) => [t, i])) ?? [];
206
+ }
207
+ ).some(([t, n]) => {
208
+ var i, l;
209
+ return n.date.getTime() !== ((l = (i = t.metadata) == null ? void 0 : i.updatedAt) == null ? void 0 : l.getTime()) ? !1 : n instanceof ee ? !t.ignoreRdfPropertyHistory(n.property, !0) : !0;
210
+ });
769
211
  }
770
- function bi(n, t) {
771
- return t.get(n.url) ?? nt(n);
212
+ function Ht(o, s) {
213
+ return s.get(o.url) ?? Be(o);
772
214
  }
773
- function Ie() {
774
- return [...h.registeredModels].map(({ modelClass: n }) => xe(n)).flat();
215
+ function pe() {
216
+ return [...g.registeredModels].map(({ modelClass: o }) => Me(o, { includeSoftDeleted: !0 })).flat();
775
217
  }
776
- function vi() {
777
- return h.schemaMigrations;
218
+ function Kt() {
219
+ return g.schemaMigrations;
778
220
  }
779
- function Mi() {
780
- h.schemaMigrations.clear();
221
+ function Yt() {
222
+ g.schemaMigrations.clear();
781
223
  }
782
- function ze(n) {
783
- return h.schemaMigrations.get(n);
224
+ function ze(o) {
225
+ return g.schemaMigrations.get(o);
784
226
  }
785
- function x(n) {
786
- return st.get(n) ?? Li(n);
227
+ function z(o) {
228
+ return je.get(o) ?? en(o);
787
229
  }
788
- function pe(n) {
789
- const t = y.requireUser().storageUrls[0];
790
- return n ? Et((n.startsWith("/") ? t.slice(0, -1) : t) + n) : t;
230
+ function ue(o, s) {
231
+ const e = C.requireUser().storageUrls[0], t = x(o) && k(o).map((n) => {
232
+ const i = o.instance().requireRelation(n).relatedClass;
233
+ return x(i) ? null : i;
234
+ }).filter(Boolean)[0];
235
+ return s ?? (s = `/${(t || o).modelName.toLowerCase()}s/`), ft((s.startsWith("/") ? e.slice(0, -1) : e) + s);
791
236
  }
792
- function Ci(n, t) {
793
- return t.get(n.url) ?? $e(n);
237
+ function Qt(o, s) {
238
+ return s.get(o.url) ?? Ce(o);
794
239
  }
795
- function Ii(n) {
796
- for (const { modelClass: t } of h.registeredModels)
797
- if (xe(t).some((i) => i.url === n.url))
240
+ function Zt(o) {
241
+ for (const { modelClass: s } of g.registeredModels)
242
+ if (Me(s).some((t) => t.url === o.url))
798
243
  return !0;
799
244
  return !1;
800
245
  }
801
- function Re(n) {
802
- return Ee.has(n.static());
246
+ function Q(o) {
247
+ return be.has(o.static());
803
248
  }
804
- function Ri(n) {
805
- return !Re(n);
249
+ function Gt(o) {
250
+ return !Q(o);
806
251
  }
807
- function Ui(n) {
808
- return h.registeredModels.some(({ modelClass: t }) => t === n);
252
+ function Xt(o) {
253
+ return g.registeredModels.some(({ modelClass: s }) => s === o);
809
254
  }
810
- function Li(n) {
811
- var s;
812
- const t = n, e = (o, r) => {
813
- o.timestamps = t.timestamps, o.history = t.history, r(), o.timestamps = [], o.history = !1;
814
- }, i = (s = class extends t {
815
- initialize(o, r) {
816
- e(this._proxy.static(), () => super.initialize(o, r));
255
+ function en(o) {
256
+ var n;
257
+ const s = o, e = (i, l) => {
258
+ i.timestamps = s.timestamps, i.history = s.history, l(), i.timestamps = [], i.history = !1;
259
+ }, t = (n = class extends s {
260
+ initialize(i, l) {
261
+ e(this._proxy.static(), () => super.initialize(i, l));
817
262
  }
818
263
  initializeRelations() {
819
264
  super.initializeRelations();
820
- for (const o of Object.values(this._relations))
821
- o instanceof Ve && (o.relatedClass = x(o.relatedClass));
265
+ for (const i of Object.values(this._relations))
266
+ i instanceof Je && (i.relatedClass = z(i.relatedClass));
822
267
  }
823
268
  fixMalformedAttributes() {
824
269
  e(this.static(), () => super.fixMalformedAttributes());
825
270
  }
826
- }, g(s, "timestamps", !1), g(s, "history", !1), s);
827
- return st.set(t, i), Ee.set(i, t), t.on("schema-updated", async (o) => {
828
- await i.updateSchema({
829
- ...o,
271
+ }, w(n, "timestamps", !1), w(n, "history", !1), n);
272
+ return je.set(s, t), be.set(t, s), s.on("schema-updated", async (i) => {
273
+ await t.updateSchema({
274
+ ...i,
830
275
  timestamps: !1,
831
276
  history: !1
832
277
  });
833
- }), Kt({ [`Remote${n.modelName}`]: i }), i;
278
+ }), Tt({ [`Remote${o.modelName}`]: t }), t;
834
279
  }
835
- function Pi(n) {
836
- return Ee.get(n) ?? N(`Couldn't find local class for ${n.modelName}`);
280
+ function tn(o) {
281
+ return be.get(o) ?? Oe(`Couldn't find local class for ${o.modelName}`);
837
282
  }
838
- class Di extends Ue {
283
+ class nn extends ye {
839
284
  constructor() {
840
285
  super(...arguments);
841
- g(this, "urlMigrations", []);
842
- g(this, "collectionMigrations", []);
286
+ w(this, "urlMigrations", []);
287
+ w(this, "collectionMigrations", []);
843
288
  }
844
- migrateUrl(e, i, s) {
289
+ migrateUrl(e, t, n) {
845
290
  this.urlMigrations.push({
846
291
  modelClass: e,
847
- local: i,
848
- remote: s
292
+ local: t,
293
+ remote: n
849
294
  });
850
295
  }
851
- migrateCollection(e, i, s) {
296
+ migrateCollection(e, t, n) {
852
297
  this.collectionMigrations.push({
853
298
  modelClass: e,
854
- local: i,
855
- remote: s
299
+ local: t,
300
+ remote: n
856
301
  });
857
302
  }
858
303
  async run() {
859
- const e = Bt(), i = await e.getCollections();
860
- for (const s of i) {
861
- const o = await e.readMany(s);
862
- for (const [r, a] of Object.entries(o)) {
863
- const l = this.replaceUrl(r);
864
- await e.create(Z(l), this.replaceDocumentUrls(a), l), await e.delete(s, r);
304
+ const e = qt(), t = await e.getCollections();
305
+ for (const n of t) {
306
+ const i = await e.readMany(n);
307
+ for (const [l, a] of Object.entries(i)) {
308
+ const r = this.replaceUrl(l);
309
+ await e.create(X(r), this.replaceDocumentUrls(a), r), await e.delete(n, l);
865
310
  }
866
311
  }
867
- for (const { modelClass: s, remote: o } of this.urlMigrations)
868
- ie(s, Z(o), { refresh: !1 });
869
- for (const { modelClass: s, local: o, remote: r } of this.collectionMigrations)
870
- fi(s, o), ie(s, r, { refresh: !1 });
312
+ for (const { modelClass: n, remote: i } of this.urlMigrations)
313
+ te(n, X(i), { refresh: !1 });
314
+ for (const { modelClass: n, local: i, remote: l } of this.collectionMigrations)
315
+ Lt(n, i), te(n, l, { refresh: !1 });
871
316
  }
872
317
  replaceDocumentUrls(e) {
873
- for (const [i, s] of Object.entries(e)) {
874
- if (i === "@id" && typeof s == "string") {
875
- e[i] = this.replaceUrl(s);
318
+ for (const [t, n] of Object.entries(e)) {
319
+ if (t === "@id" && typeof n == "string") {
320
+ e[t] = this.replaceUrl(n);
876
321
  continue;
877
322
  }
878
- typeof s != "object" || s === null || (e[i] = this.replaceDocumentUrls(s));
323
+ typeof n != "object" || n === null || (e[t] = this.replaceDocumentUrls(n));
879
324
  }
880
325
  return e;
881
326
  }
882
327
  replaceUrl(e) {
883
- for (const { local: i, remote: s } of this.urlMigrations)
884
- if (e.startsWith(i))
885
- return e.replace(i, s);
886
- for (const { local: i, remote: s } of this.collectionMigrations)
887
- if (e.startsWith(i))
888
- return e.replace(i, s);
328
+ for (const { local: t, remote: n } of this.urlMigrations)
329
+ if (e.startsWith(t))
330
+ return e.replace(t, n);
331
+ for (const { local: t, remote: n } of this.collectionMigrations)
332
+ if (e.startsWith(t))
333
+ return e.replace(t, n);
889
334
  return e;
890
335
  }
891
336
  }
892
- class Ai extends vt {
893
- constructor() {
894
- super(...arguments);
895
- g(this, "cache", new $t("documents-cache"));
896
- }
897
- async isFresh(e, i) {
898
- const s = await this.cache.get(e), o = typeof i != "number" ? i.getTime() : i;
899
- return !!(s != null && s.modifiedAt) && s.modifiedAt >= o;
900
- }
901
- async remember(e, i) {
902
- await this.cache.set(e, {
903
- modifiedAt: typeof i != "number" ? i.getTime() : i
904
- });
905
- }
906
- async forget(e) {
907
- await this.cache.delete(e);
908
- }
909
- async boot() {
910
- d.on("auth:logout", async () => {
911
- await this.cache.clear(), this.cache.close();
912
- });
913
- }
914
- }
915
- const G = ne(Ai);
916
- function xi(n) {
917
- const t = {};
918
- return async () => ("value" in t || (t.value = await n()), t.value);
337
+ function sn(o) {
338
+ const s = {};
339
+ return async () => ("value" in s || (s.value = await o()), s.value);
919
340
  }
920
- class ot {
921
- async loadContainedModels(t, e = {}) {
922
- var u;
923
- if (Ri(t)) {
924
- const p = [];
925
- for (const I of M(t.static())) {
926
- const U = await t.loadRelationIfUnloaded(I) ?? [];
927
- p.push(...kt(U));
341
+ class Ve {
342
+ async loadContainedModels(s, e = {}) {
343
+ if (Gt(s)) {
344
+ const h = [];
345
+ for (const p of k(s.static())) {
346
+ const y = await s.loadRelationIfUnloaded(p) ?? [];
347
+ h.push(...gt(y));
928
348
  }
929
- return p;
349
+ return h;
930
350
  }
931
- const i = {}, s = [], o = v(t.documents, "url"), r = Tt(t.resourceUrls, 10), a = r.flat().map((p) => ({
932
- documentUrl: p,
351
+ const t = {}, n = [], i = L(s.documents, "url"), l = pt(s.resourceUrls, 10), a = l.flat().map((h) => ({
352
+ documentUrl: h,
933
353
  completed: !1
934
- })), l = v(a, "documentUrl");
354
+ })), r = L(a, "documentUrl");
935
355
  e.status && (e.status.children = a);
936
- for (const p of r) {
356
+ for (const h of l)
937
357
  await Promise.all(
938
- p.map(async (I) => {
939
- const { children: U, tombstones: H } = await this.loadDocumentChildren(t, I, o, e.onMalformedDocument);
940
- s.push(...H);
941
- for (const [re, lt] of Object.entries(U))
942
- (i[re] ?? (i[re] = [])).push(...lt);
358
+ h.map(async (p) => {
359
+ var ve;
360
+ const { children: y, tombstones: V } = await this.loadDocumentChildren(
361
+ s,
362
+ p,
363
+ i,
364
+ e.onDocumentError,
365
+ e.onDocumentRead
366
+ );
367
+ n.push(...V);
368
+ for (const [re, Qe] of Object.entries(y))
369
+ (t[re] ?? (t[re] = [])).push(...Qe);
370
+ p.endsWith("/") || (A(r.get(p)).completed = !0, await ((ve = e.onDocumentLoaded) == null ? void 0 : ve.call(e)));
943
371
  })
944
372
  );
945
- for (const I of p)
946
- I.endsWith("/") || (w(l.get(I)).completed = !0);
947
- await ((u = e.onLoaded) == null ? void 0 : u.call(e, p));
948
- }
949
- for (const [p, I] of Object.entries(i))
950
- t.setRelationModels(p, I);
951
- const c = e.ignoreTombstones ? Object.values(i).flat() : Object.values(i).flat().concat(s);
952
- return e.status && (e.status.children = c.map((p) => w(l.get(p.requireDocumentUrl())))), c;
953
- }
954
- async loadDocumentChildren(t, e, i, s) {
955
- var r;
956
- const o = i.get(e);
957
- return o && await G.isFresh(o.url, o.updatedAt ?? /* @__PURE__ */ new Date()) && ((r = this.localModels) != null && r.hasKey(t.url)) ? {
958
- children: await this.loadDocumentChildrenFromLocal(t, o),
373
+ for (const [h, p] of Object.entries(t))
374
+ s.setRelationModels(h, p);
375
+ const c = e.ignoreTombstones ? Object.values(t).flat() : Object.values(t).flat().concat(n);
376
+ return e.status && (e.status.children = c.map((h) => A(r.get(h.requireDocumentUrl())))), c;
377
+ }
378
+ async loadDocumentChildren(s, e, t, n, i) {
379
+ var a;
380
+ const l = t.get(e);
381
+ return l && l.updatedAt && await P.isFresh(l.url, l.updatedAt) && ((a = this.localModels) != null && a.hasKey(s.url)) ? {
382
+ children: await this.loadDocumentChildrenFromLocal(s, l),
959
383
  tombstones: []
960
- } : this.loadDocumentChildrenFromRemote(t, e, s);
384
+ } : this.loadDocumentChildrenFromRemote(s, e, n, i);
961
385
  }
962
- async loadDocumentChildrenFromLocal(t, e) {
963
- var s, o;
964
- const i = {};
965
- for (const r of M(t.static())) {
966
- const a = t.requireRelation(r);
386
+ async loadDocumentChildrenFromLocal(s, e) {
387
+ var n, i;
388
+ const t = {};
389
+ for (const l of k(s.static())) {
390
+ const a = s.requireRelation(l);
967
391
  if (a.loaded) {
968
- i[r] = a.getLoadedModels();
392
+ t[l] = a.getLoadedModels();
969
393
  continue;
970
394
  }
971
- const l = ((o = (s = this.localModels) == null ? void 0 : s.get(t.url)) == null ? void 0 : o.getRelationModels(r)) ?? [];
972
- i[r] = l.filter((c) => c.getDocumentUrl() === e.url).map((c) => $e(c, { clean: !0 }));
395
+ const r = ((i = (n = this.localModels) == null ? void 0 : n.get(s.url)) == null ? void 0 : i.getRelationModels(l)) ?? [];
396
+ t[l] = r.filter((c) => c.getDocumentUrl() === e.url).map((c) => Ce(c, { clean: !0 }));
973
397
  }
974
- return i;
398
+ return t;
975
399
  }
976
- async loadDocumentChildrenFromRemote(t, e, i) {
977
- const s = {}, o = [], r = xi(async () => {
400
+ async loadDocumentChildrenFromRemote(s, e, t, n) {
401
+ const i = {}, l = [], a = sn(async () => {
978
402
  try {
979
- const a = await t.requireEngine().readOne(t.static("collection"), e), l = await W.createManyFromEngineDocuments({
980
- [e]: a
403
+ const r = s.documents.find((p) => p.url === e), c = await s.requireEngine().readOne(s.static("collection"), e), h = await N.createManyFromEngineDocuments({
404
+ [e]: c
981
405
  });
982
- return o.push(...l), a;
983
- } catch (a) {
984
- if (A(a, Gt))
406
+ return l.push(...h), r && (n == null || n(r)), c;
407
+ } catch (r) {
408
+ if (E(r, Pt))
985
409
  return null;
986
- if (A(a, Ye))
987
- return console.warn(a.message), await (i == null ? void 0 : i(e)), null;
988
- throw a;
410
+ if (!t)
411
+ throw r;
412
+ return t(r), null;
989
413
  }
990
414
  });
991
- for (const a of M(t.static())) {
992
- const l = t.requireRelation(a);
993
- if (l.loaded) {
994
- s[a] = l.getLoadedModels();
415
+ for (const r of k(s.static())) {
416
+ const c = s.requireRelation(r);
417
+ if (c.loaded) {
418
+ i[r] = c.getLoadedModels();
995
419
  continue;
996
420
  }
997
- const c = await r();
998
- if (!c)
999
- continue;
1000
- const u = await l.relatedClass.createManyFromEngineDocuments({
1001
- [e]: c
1002
- });
1003
- s[a] = u;
421
+ const h = await a();
422
+ if (h)
423
+ try {
424
+ const p = await c.relatedClass.createManyFromEngineDocuments({
425
+ [e]: h
426
+ });
427
+ i[r] = p;
428
+ } catch (p) {
429
+ if (!t)
430
+ throw p;
431
+ t(p);
432
+ }
1004
433
  }
1005
- return { children: s, tombstones: o };
434
+ return { children: i, tombstones: l };
1006
435
  }
1007
436
  }
1008
- const z = /* @__PURE__ */ new WeakMap();
1009
- class rt {
1010
- async loadTypeIndex(t = {}) {
1011
- const e = y.requireUser();
1012
- return t.create && !z.get(e) ? z.set(e, await y.findOrCreatePrivateTypeIndex()) : z.has(e) || z.set(e, await y.findPrivateTypeIndex()), z.get(e) ?? null;
437
+ const B = /* @__PURE__ */ new WeakMap();
438
+ class Fe {
439
+ async loadTypeIndex(s = {}) {
440
+ const e = C.requireUser();
441
+ return (s.fresh || !B.has(e)) && B.set(e, await C.findPrivateTypeIndex({ fresh: s.fresh })), s.create && !B.get(e) && B.set(e, await C.findOrCreatePrivateTypeIndex()), B.get(e) ?? null;
1013
442
  }
1014
443
  }
1015
- class at {
1016
- async indexLocalModels(t) {
1017
- for (const e of t)
444
+ class He {
445
+ async indexLocalModels(s) {
446
+ for (const e of s)
1018
447
  await this.addLocalModel(e);
1019
448
  }
1020
- async addLocalModel(t) {
1021
- if (!(!this.localModels || this.localModels.hasKey(t.url))) {
1022
- this.localModels.add(t);
1023
- for (const e of M(t.static()))
1024
- await t.loadRelationIfUnloaded(e);
1025
- for (const e of t.getRelatedModels())
449
+ async addLocalModel(s) {
450
+ if (!this.localModels.hasKey(s.url)) {
451
+ this.localModels.add(s);
452
+ for (const e of k(s.static()))
453
+ await s.loadRelationIfUnloaded(e);
454
+ for (const e of ne(s))
1026
455
  await this.addLocalModel(e);
1027
456
  }
1028
457
  }
1029
458
  }
1030
- const Ei = Ue;
1031
- class oe extends Be(Ei, [ot, rt, at]) {
459
+ const on = ye;
460
+ class ie extends _e(on, [Ve, Fe, He]) {
1032
461
  constructor() {
1033
- super(...arguments);
1034
- g(this, "_models");
462
+ super();
463
+ w(this, "_models");
464
+ this.localModels = L([], "url");
1035
465
  }
1036
466
  static restore(e) {
1037
- return K(new oe(), (i) => {
1038
- i.status = e;
467
+ return qe(new ie(), (t) => {
468
+ t.status = e;
1039
469
  });
1040
470
  }
1041
471
  get models() {
@@ -1043,13 +473,13 @@ class oe extends Be(Ei, [ot, rt, at]) {
1043
473
  }
1044
474
  set models(e) {
1045
475
  if (!e) {
1046
- delete this._models, delete this.localModels;
476
+ delete this._models, this.localModels = L([], "url");
1047
477
  return;
1048
478
  }
1049
- const i = qt(this.status.children ?? [], "modelUrl");
1050
- this._models = e, this.localModels = v([], "url"), this.status.children = e.map(
1051
- (s) => i[s.url] ?? {
1052
- modelUrl: s.url,
479
+ const t = yt(this.status.children ?? [], "modelUrl");
480
+ this._models = e, this.localModels = L([], "url"), this.status.children = e.map(
481
+ (n) => t[n.url] ?? {
482
+ modelUrl: n.url,
1053
483
  completed: !1
1054
484
  }
1055
485
  );
@@ -1058,84 +488,100 @@ class oe extends Be(Ei, [ot, rt, at]) {
1058
488
  if (!this.models)
1059
489
  throw new Error("Cant start migration without models");
1060
490
  await this.indexLocalModels(this.models);
1061
- const e = this.status.children ?? [], i = await this.loadTypeIndex();
1062
- for (const s of e) {
1063
- const o = this.models.find(({ url: r }) => s.modelUrl === r);
1064
- !o || s.completed || (await this.migrateRegisteredModel(o, s, i), await this.updateProgress(() => s.completed = !0));
491
+ const e = this.status.children ?? [], t = await this.loadTypeIndex();
492
+ for (const n of e) {
493
+ const i = this.models.find(({ url: l }) => n.modelUrl === l);
494
+ !i || n.completed || (await this.migrateRegisteredModel(i, n, t), await this.updateProgress(() => n.completed = !0));
1065
495
  }
1066
- for (const [s, o] of vi())
1067
- await s.updateSchema(o);
1068
- Mi();
496
+ for (const [n, i] of Kt())
497
+ await n.updateSchema(i);
498
+ Yt();
1069
499
  }
1070
- async migrateRegisteredModel(e, i, s) {
1071
- if (await this.migrate(e, i), !P(e))
500
+ async migrateRegisteredModel(e, t, n) {
501
+ if (await this.migrate(e, t), !U(e))
1072
502
  return;
1073
- const o = be(e.static()), r = s == null ? void 0 : s.registrations.find(({ instanceContainer: a }) => a === e.url);
1074
- !s || !r || o.length === 0 || (r.setAttribute(
503
+ const i = fe(e.static()), l = n == null ? void 0 : n.registrations.find(({ instanceContainer: a }) => a === e.url);
504
+ !n || !l || i.length === 0 || (l.setAttribute(
1075
505
  "forClass",
1076
- o.map((a) => {
1077
- var l;
1078
- return ((l = ze(a)) == null ? void 0 : l.rdfsClasses) ?? a.rdfsClass;
506
+ i.map((a) => {
507
+ var r;
508
+ return ((r = ze(a)) == null ? void 0 : r.rdfsClasses) ?? a.rdfsClass;
1079
509
  }).flat()
1080
- ), await s.save());
510
+ ), await n.save());
1081
511
  }
1082
- async migrate(e, i) {
1083
- this.assertNotCancelled(), await this.migrateChildren(e, i);
1084
- const s = ze(e.static());
1085
- if (!s)
512
+ async migrate(e, t) {
513
+ this.assertNotCancelled(), await this.migrateChildren(e, t);
514
+ const n = ze(e.static());
515
+ if (!n)
1086
516
  return;
1087
- const o = await x(e.static()).find(e.url), r = await (o == null ? void 0 : o.migrateSchema(s));
1088
- await e.migrateSchema(s, {
517
+ const i = await z(e.static()).find(e.url), l = await (i == null ? void 0 : i.migrateSchema(n));
518
+ await e.migrateSchema(n, {
1089
519
  mintOperationUrl: (a) => {
1090
- var l, c;
1091
- return (c = (l = r == null ? void 0 : r.operations) == null ? void 0 : l.find((u) => !A(a, ee) || !A(u, ee) ? !1 : a.property === u.property && a.date.getTime() === u.date.getTime())) == null ? void 0 : c.url;
520
+ var r, c;
521
+ return (c = (r = l == null ? void 0 : l.operations) == null ? void 0 : r.find((h) => !E(a, ee) || !E(h, ee) ? !1 : a.property === h.property && a.date.getTime() === h.date.getTime())) == null ? void 0 : c.url;
1092
522
  }
1093
523
  });
1094
524
  }
1095
- async migrateChildren(e, i) {
1096
- if (!P(e))
525
+ async migrateChildren(e, t) {
526
+ if (!U(e))
1097
527
  return;
1098
- const s = await this.loadContainedModels(e, { ignoreTombstones: !0 });
1099
- i.children ?? (i.children = s.map((o) => ({
1100
- modelUrl: o.url,
528
+ const n = await this.loadContainedModels(e, { ignoreTombstones: !0 });
529
+ t.children ?? (t.children = n.map((i) => ({
530
+ modelUrl: i.url,
1101
531
  completed: !1
1102
532
  })));
1103
- for (const o of i.children) {
1104
- const r = s.find(({ url: a }) => o.modelUrl === a);
1105
- !r || o.completed || (await this.migrate(r, o), await this.updateProgress(() => o.completed = !0));
533
+ for (const i of t.children) {
534
+ const l = n.find(({ url: a }) => i.modelUrl === a);
535
+ !l || i.completed || (await this.migrate(l, i), await this.updateProgress(() => i.completed = !0));
1106
536
  }
1107
537
  }
1108
538
  }
1109
- const $i = w(() => S.service("$cloud")), ki = Ue;
1110
- function Ti(n) {
1111
- return !!n && "root" in n;
539
+ const rn = A(() => oe.service("$cloud")), an = ye;
540
+ function ln(o) {
541
+ return !!o && "root" in o;
1112
542
  }
1113
- class qi extends Be(ki, [ot, rt, at]) {
543
+ class cn extends _e(an, [Ve, Fe, He]) {
1114
544
  constructor(e) {
1115
545
  super();
1116
- g(this, "models");
1117
- g(this, "dirtyRemoteModels");
1118
- g(this, "rootLocalModels");
1119
- g(this, "tombstones");
1120
- g(this, "malformedDocuments");
1121
- g(this, "documentsModifiedAt");
1122
- g(this, "localModels");
1123
- this.models = e, this.rootLocalModels = [], this.localModels = v([], "url"), this.tombstones = v([], "resourceUrl"), this.malformedDocuments = /* @__PURE__ */ new Set(), this.documentsModifiedAt = {};
546
+ w(this, "documentsWithErrors");
547
+ w(this, "models");
548
+ w(this, "dirtyRemoteModels");
549
+ w(this, "rootLocalModels");
550
+ w(this, "tombstones");
551
+ w(this, "syncedModelUrls");
552
+ w(this, "documentsModifiedAt");
553
+ w(this, "screenLock", null);
554
+ w(this, "localModels");
555
+ this.documentsWithErrors = /* @__PURE__ */ new Set(), this.models = e, this.rootLocalModels = [], this.localModels = L([], "url"), this.tombstones = L([], "resourceUrl"), this.syncedModelUrls = /* @__PURE__ */ new Set(), this.documentsModifiedAt = {};
1124
556
  }
1125
557
  async run() {
1126
- const e = y.requireAuthenticator().engine, i = (o, { headers: r }) => {
1127
- const a = r == null ? void 0 : r.get("last-modified");
1128
- !a || o.endsWith("/") || (this.documentsModifiedAt[o] = new Date(a));
1129
- }, s = e.listeners.add({
1130
- onDocumentRead: i,
1131
- onDocumentUpdated: i
558
+ const e = C.requireAuthenticator().engine, t = (i, { headers: l }, a) => {
559
+ const r = (l == null ? void 0 : l.get("last-modified")) ?? a;
560
+ !r || i.endsWith("/") || (this.documentsModifiedAt[i] = new Date(r));
561
+ }, n = e.listeners.add({
562
+ onDocumentRead: (i, l) => t(i, l),
563
+ onDocumentUpdated: (i, l) => t(i, l, /* @__PURE__ */ new Date())
1132
564
  });
1133
565
  try {
1134
- this.rootLocalModels = this.models ?? Ie(), await this.indexLocalModels(this.rootLocalModels), await this.pullChanges(), await this.pushChanges();
566
+ this.lockScreen(), this.rootLocalModels = this.models ?? pe(), await this.indexLocalModels(this.rootLocalModels), await this.pullChanges(), await this.pushChanges();
1135
567
  } finally {
1136
- s();
568
+ this.releaseScreen(), n();
1137
569
  }
1138
570
  }
571
+ lockScreen() {
572
+ const e = navigator;
573
+ if (e.wakeLock)
574
+ try {
575
+ this.screenLock = e.wakeLock.request("screen").catch((t) => {
576
+ Z.reportDevelopmentError(t, "Could not request screen wake lock");
577
+ });
578
+ } catch (t) {
579
+ Z.reportDevelopmentError(t, "Could not request screen wake lock");
580
+ }
581
+ }
582
+ releaseScreen() {
583
+ this.screenLock && (this.screenLock.then((e) => e == null ? void 0 : e.release()), this.screenLock = null);
584
+ }
1139
585
  getInitialStatus() {
1140
586
  return {
1141
587
  root: !0,
@@ -1144,240 +590,266 @@ class qi extends Be(ki, [ot, rt, at]) {
1144
590
  };
1145
591
  }
1146
592
  calculateCurrentProgress(e) {
1147
- return e ?? (e = this.status), Ti(e) ? Ot(
593
+ return e ?? (e = this.status), ln(e) ? wt(
1148
594
  this.calculateCurrentProgress(e.children[0]) * 0.9 + this.calculateCurrentProgress(e.children[1]) * 0.1,
1149
595
  2
1150
596
  ) : super.calculateCurrentProgress(e);
1151
597
  }
1152
598
  async pullChanges() {
1153
- const e = this.models ? await this.fetchRemoteModelsForLocal(this.models) : await this.fetchRemoteModels(), i = v(e, (s) => s instanceof W ? s.resourceUrl : s.url);
1154
- this.dirtyRemoteModels = await this.synchronizeModels(i), await this.updateProgress((s) => s.children[0].completed = !0);
599
+ const e = this.models ? await this.fetchRemoteModelsForLocal(this.models) : await this.fetchRemoteModels(), t = L(e, (n) => n instanceof N ? n.resourceUrl : n.url);
600
+ this.dirtyRemoteModels = await this.synchronizeModels(t), await this.updateProgress((n) => n.children[0].completed = !0);
1155
601
  }
1156
602
  async pushChanges() {
1157
- const e = this.dirtyRemoteModels ?? [], i = this.status.children[1].children = e.map(() => ({ completed: !1 }));
1158
- for (let s = 0; s < e.length; s++) {
1159
- const o = e[s], r = i[s];
1160
- if (o.isSoftDeleted()) {
1161
- o.enableHistory(), o.enableTombstone(), await o.delete(), await this.updateProgress(() => r.completed = !0);
603
+ const e = this.dirtyRemoteModels ?? [], t = this.status.children[1].children = e.map(() => ({ completed: !1 }));
604
+ for (let n = 0; n < e.length; n++) {
605
+ const i = e[n], l = t[n];
606
+ if (i.isSoftDeleted()) {
607
+ i.enableHistory(), i.enableTombstone(), await i.forceDelete(), await this.updateProgress(() => l.completed = !0);
1162
608
  return;
1163
609
  }
1164
- await this.saveModelAndChildren(o, r), await this.updateTypeRegistrations(o), await this.updateProgress(() => r.completed = !0);
610
+ await this.saveModelAndChildren(i, l), await this.updateTypeRegistrations(i), await this.updateProgress(() => l.completed = !0);
1165
611
  }
1166
- for (const [s, o] of Object.entries(this.documentsModifiedAt))
1167
- await G.remember(s, o);
1168
- Ce(this.models, this.malformedDocuments), await this.updateProgress((s) => s.children[1].completed = !0);
612
+ for (const [n, i] of Object.entries(this.documentsModifiedAt))
613
+ await P.remember(n, i);
614
+ ge(this.syncedModelUrls, this.documentsWithErrors), await this.updateProgress((n) => n.children[1].completed = !0);
1169
615
  }
1170
616
  async fetchRemoteModels() {
1171
- const e = this.status.children[0], i = await this.loadTypeIndex();
1172
- if (!i)
617
+ const e = this.status.children[0], t = await this.loadTypeIndex({ fresh: !0 });
618
+ if (!t)
1173
619
  return [];
1174
- const s = [], o = /* @__PURE__ */ new Set(), r = [...$i.registeredModels].map(({ modelClass: l }) => {
1175
- const c = _(l) ? be(l) : [];
1176
- return {
1177
- modelClass: l,
1178
- rdfsClasses: c.length > 0 ? c.map((u) => u.rdfsClasses).flat() : l.rdfsClasses
1179
- };
1180
- }), a = i.registrations.map((l) => {
1181
- const c = r.find(
1182
- ({ rdfsClasses: u }) => !!l.instanceContainer && u.some((p) => l.forClass.includes(p))
1183
- );
1184
- return !c || !l.instanceContainer || o.has(l.instanceContainer) ? null : (o.add(l.instanceContainer), [l, c]);
1185
- }).filter((l) => !!l);
1186
- e.children = a.map(() => ({ completed: !1 }));
1187
- for (let l = 0; l < a.length; l++)
1188
- await this.ignoringMalformedDocumentErrors(async () => {
1189
- var I;
1190
- const c = w(a[l])[0], u = w(a[l])[1], p = x(u.modelClass);
1191
- if (c.instanceContainer) {
1192
- if (_(p)) {
1193
- await Me(
1194
- u.modelClass,
1195
- Z(c.instanceContainer)
620
+ const n = [], i = this.getTypeRegistrations(t);
621
+ e.children = i.map(() => ({ completed: !1 }));
622
+ for (let l = 0; l < i.length; l++)
623
+ await this.ignoringDocumentErrors(async () => {
624
+ var h;
625
+ const { registration: a, registeredModel: r } = A(i[l]), c = z(r.modelClass);
626
+ if (a.instanceContainer) {
627
+ if (x(c)) {
628
+ await me(
629
+ r.modelClass,
630
+ X(a.instanceContainer)
1196
631
  );
1197
- const U = await p.find(c.instanceContainer);
1198
- U && (await this.loadChildren(U, w((I = e.children) == null ? void 0 : I[l])), s.push(U)), await this.updateProgress(() => {
1199
- var H;
1200
- return w((H = e.children) == null ? void 0 : H[l]).completed = !0;
632
+ const p = await c.find(a.instanceContainer);
633
+ p && (await this.loadChildren(p, A((h = e.children) == null ? void 0 : h[l])), n.push(p)), await this.updateProgress(() => {
634
+ var y;
635
+ return A((y = e.children) == null ? void 0 : y[l]).completed = !0;
1201
636
  });
1202
637
  return;
1203
638
  }
1204
- await Me(u.modelClass, c.instanceContainer), s.push(...await p.from(c.instanceContainer).all()), await this.updateProgress(() => {
1205
- var U;
1206
- return w((U = e.children) == null ? void 0 : U[l]).completed = !0;
639
+ await me(r.modelClass, a.instanceContainer), n.push(...await c.from(a.instanceContainer).all()), await this.updateProgress(() => {
640
+ var p;
641
+ return A((p = e.children) == null ? void 0 : p[l]).completed = !0;
1207
642
  });
1208
643
  }
1209
644
  });
1210
- return Je(this.rootLocalModels, s, this.malformedDocuments);
645
+ return Ie(this.rootLocalModels, n, this.documentsWithErrors);
1211
646
  }
1212
647
  async fetchRemoteModelsForLocal(e) {
1213
- const i = [], s = this.status.children[0].children = e.map(() => ({ completed: !1 }));
1214
- for (let o = 0; o < e.length; o++)
1215
- await this.ignoringMalformedDocumentErrors(async () => {
1216
- const r = e[o], a = s[o], l = await x(r.static()).find(r.url);
1217
- if (!l) {
648
+ const t = [], n = this.status.children[0].children = e.map(() => ({ completed: !1 }));
649
+ for (let i = 0; i < e.length; i++)
650
+ await this.ignoringDocumentErrors(async () => {
651
+ const l = e[i], a = n[i], r = await z(l.static()).find(l.url);
652
+ if (!r) {
1218
653
  await this.updateProgress(() => a.completed = !0);
1219
654
  return;
1220
655
  }
1221
- P(l) && await this.loadChildren(l, a), i.push(l), await this.updateProgress(() => a.completed = !0);
656
+ U(r) && await this.loadChildren(r, a), t.push(r), await this.updateProgress(() => a.completed = !0);
1222
657
  });
1223
- return Je(e, i, this.malformedDocuments);
658
+ return Ie(e, t, this.documentsWithErrors);
659
+ }
660
+ getTypeRegistrations(e) {
661
+ const t = /* @__PURE__ */ new Set(), n = [...rn.registeredModels].map(({ modelClass: a }) => {
662
+ const r = x(a) ? fe(a) : [];
663
+ return {
664
+ modelClass: a,
665
+ rdfsClasses: r.length > 0 ? r.map((c) => c.rdfsClasses).flat() : a.rdfsClasses
666
+ };
667
+ }), i = e.registrations.map((a) => {
668
+ const r = n.find(
669
+ ({ rdfsClasses: c }) => !!a.instanceContainer && c.some((h) => a.forClass.includes(h))
670
+ );
671
+ return !r || !a.instanceContainer || t.has(a.instanceContainer) ? null : (t.add(a.instanceContainer), { registration: a, registeredModel: r });
672
+ }).filter((a) => !!a), l = i.map(({ registration: a }) => a.instanceContainer);
673
+ return i.filter(({ registration: a }) => !l.some(
674
+ (r) => {
675
+ var c;
676
+ return r && r !== a.instanceContainer && ((c = a.instanceContainer) == null ? void 0 : c.startsWith(r));
677
+ }
678
+ ));
1224
679
  }
1225
680
  async updateTypeRegistrations(e) {
1226
- if (!P(e) || !Ii(e))
681
+ if (!Zt(e))
1227
682
  return;
1228
- const i = be(e.static());
1229
- if (i.length === 0)
683
+ const t = U(e) ? fe(e.static()) : [e.static()], n = z(W), i = U(e) ? e : new n({ url: e.requireContainerUrl() });
684
+ if (t.length === 0)
1230
685
  return;
1231
- const s = await this.loadTypeIndex({ create: !0 });
1232
- s.registrations.some((o) => o.instanceContainer === e.url) || await e.register(s, i);
686
+ const l = await this.loadTypeIndex({ create: !0 });
687
+ l.registrations.some((a) => a.instanceContainer === e.url) || await i.register(l, t);
1233
688
  }
1234
- async loadChildren(e, i) {
1235
- var o, r;
1236
- if (this.assertNotCancelled(), !P(e))
689
+ async loadChildren(e, t) {
690
+ var i, l;
691
+ if (this.assertNotCancelled(), !U(e))
1237
692
  return;
1238
- const s = await this.loadContainedModels(e, {
1239
- status: i,
1240
- onLoaded: async () => {
1241
- this.assertNotCancelled(), await this.updateProgress();
693
+ const n = await this.loadContainedModels(e, {
694
+ status: t,
695
+ onDocumentError: (a) => this.handleDocumentError(a),
696
+ onDocumentRead: (a) => {
697
+ a.url.endsWith("/") || !a.updatedAt || a.url in this.documentsModifiedAt || (this.documentsModifiedAt[a.url] = a.updatedAt);
1242
698
  },
1243
- onMalformedDocument: (a) => this.malformedDocuments.add(a)
699
+ onDocumentLoaded: async () => {
700
+ this.assertNotCancelled(), await this.updateProgress();
701
+ }
1244
702
  });
1245
- for (let a = 0; a < s.length; a++) {
1246
- const l = s[a];
1247
- if (l instanceof W) {
1248
- this.tombstones.add(l);
703
+ for (let a = 0; a < n.length; a++) {
704
+ const r = n[a];
705
+ if (r instanceof N) {
706
+ this.tombstones.add(r);
1249
707
  continue;
1250
708
  }
1251
- if (this.tombstones.hasKey(l.url)) {
1252
- await this.deleteChild(e, l);
709
+ if (this.tombstones.hasKey(r.url)) {
710
+ await this.deleteChild(e, r);
1253
711
  continue;
1254
712
  }
1255
- await this.loadChildren(l, (o = i == null ? void 0 : i.children) == null ? void 0 : o[a]), (r = i == null ? void 0 : i.children) != null && r[a] && await this.updateProgress(() => {
713
+ await this.loadChildren(r, (i = t == null ? void 0 : t.children) == null ? void 0 : i[a]), (l = t == null ? void 0 : t.children) != null && l[a] && await this.updateProgress(() => {
1256
714
  var c;
1257
- return w((c = i.children) == null ? void 0 : c[a]).completed = !0;
715
+ return A((c = t.children) == null ? void 0 : c[a]).completed = !0;
1258
716
  });
1259
717
  }
1260
718
  }
1261
- async deleteChild(e, i) {
1262
- for (const s of e.static("relations")) {
1263
- const o = e.requireRelation(s);
1264
- if (o.related) {
1265
- if (Array.isArray(o.related)) {
1266
- o.related = o.related.filter((r) => r !== i);
719
+ async deleteChild(e, t) {
720
+ for (const n of e.static("relations")) {
721
+ const i = e.requireRelation(n);
722
+ if (i.related) {
723
+ if (Array.isArray(i.related)) {
724
+ i.related = i.related.filter((l) => l !== t);
1267
725
  continue;
1268
726
  }
1269
- if (o.related === i) {
1270
- o.related = null;
727
+ if (i.related === t) {
728
+ i.related = null;
1271
729
  continue;
1272
730
  }
1273
731
  }
1274
732
  }
1275
- await i.delete();
733
+ await t.forceDelete();
1276
734
  }
1277
- async saveModelAndChildren(e, i) {
1278
- if (this.assertNotCancelled(), Re(e) && e.isSoftDeleted()) {
1279
- e.enableHistory(), e.enableTombstone(), await e.delete();
735
+ async saveModelAndChildren(e, t) {
736
+ if (this.assertNotCancelled(), Q(e) && e.isSoftDeleted()) {
737
+ e.enableHistory(), e.enableTombstone(), await e.forceDelete();
1280
738
  return;
1281
739
  }
1282
- if (this.malformedDocuments.has(e.requireDocumentUrl()))
740
+ if (this.documentsWithErrors.has(e.requireDocumentUrl()))
1283
741
  return;
1284
- if (await e.save(), !P(e)) {
1285
- if (Re(e)) {
1286
- const r = e.requireDocumentUrl(), a = this.documentsModifiedAt[r] ?? /* @__PURE__ */ new Date();
1287
- await G.remember(r, a), delete this.documentsModifiedAt[r];
742
+ const n = e.isDirty();
743
+ if (await e.save(), (n || Q(e)) && this.syncedModelUrls.add(e.url), !U(e)) {
744
+ if (Q(e)) {
745
+ const a = e.requireDocumentUrl(), r = this.documentsModifiedAt[a];
746
+ r && (await P.remember(a, r), delete this.documentsModifiedAt[a]);
1288
747
  }
1289
748
  return;
1290
749
  }
1291
- const s = M(e.static()).map((r) => e.getRelationModels(r) ?? []).flat(), o = i ? s.map(() => ({ completed: !1 })) : [];
1292
- i && (i.children = o);
1293
- for (let r = 0; r < s.length; r++) {
1294
- const a = s[r], l = o[r];
1295
- await this.saveModelAndChildren(a, l), l && await this.updateProgress(() => l.completed = !0);
750
+ const i = k(e.static()).map((a) => e.getRelationModels(a) ?? []).flat(), l = t ? i.map(() => ({ completed: !1 })) : [];
751
+ t && (t.children = l);
752
+ for (let a = 0; a < i.length; a++) {
753
+ const r = i[a], c = l[a];
754
+ await this.saveModelAndChildren(r, c), c && await this.updateProgress(() => c.completed = !0);
1296
755
  }
1297
756
  }
1298
757
  async synchronizeModels(e) {
1299
- const i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
1300
- for (const r of e.items()) {
1301
- if (r instanceof W) {
1302
- const l = this.localModels.get(r.resourceUrl);
1303
- l && (await l.delete(), s.add(l));
758
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
759
+ for (const l of e.items()) {
760
+ if (l instanceof N) {
761
+ const r = this.localModels.get(l.resourceUrl);
762
+ r && (await r.forceDelete(), n.add(r));
1304
763
  continue;
1305
764
  }
1306
- const a = bi(r, this.localModels);
1307
- await this.loadChildren(a), await F.synchronize(a, r), await this.reconcileInconsistencies(a, r), await this.saveModelAndChildren(a), await this.addLocalModel(a), this.rootLocalModels.push(a), i.add(a.url);
765
+ const a = Ht(l, this.localModels);
766
+ a.exists() || this.syncedModelUrls.add(a.url), await this.loadChildren(a), await J.synchronize(a, l), await this.reconcileInconsistencies(a, l), await this.saveModelAndChildren(a), await this.addLocalModel(a), this.rootLocalModels.push(a), t.add(a.url);
1308
767
  }
1309
- for (const r of this.rootLocalModels) {
1310
- if (s.has(r) || i.has(r.url))
768
+ for (const l of this.rootLocalModels) {
769
+ if (n.has(l) || t.has(l.url))
1311
770
  continue;
1312
- await this.loadChildren(r);
1313
- const a = Ci(r, e);
1314
- await F.synchronize(r, a), e.add(a);
771
+ await this.loadChildren(l);
772
+ const a = Qt(l, e);
773
+ await J.synchronize(l, a), e.add(a);
1315
774
  }
1316
- const o = [];
1317
- for (const r of e.getItems()) {
1318
- if (it(r)) {
1319
- o.push(r);
775
+ const i = [];
776
+ for (const l of e.getItems()) {
777
+ if (We(l)) {
778
+ i.push(l);
1320
779
  continue;
1321
780
  }
1322
- await this.rememberModelDocuments(r);
781
+ await this.rememberModelDocuments(l);
1323
782
  }
1324
- return o;
783
+ return i;
1325
784
  }
1326
- async reconcileInconsistencies(e, i, s) {
1327
- e.rebuildAttributesFromHistory(), e.setAttributes(i.getAttributes(!0)), s ?? (s = /* @__PURE__ */ new Set()), s.add(e);
1328
- for (const r of M(e.static()))
785
+ async reconcileInconsistencies(e, t, n) {
786
+ e.rebuildAttributesFromHistory(), e.setAttributes(t.getAttributes(!0)), n ?? (n = /* @__PURE__ */ new Set()), n.add(e);
787
+ for (const l of k(e.static()))
1329
788
  await this.synchronizeContainerDocuments(
1330
- e.requireRelation(r),
1331
- i.requireRelation(r)
789
+ e.requireRelation(l),
790
+ t.requireRelation(l)
791
+ );
792
+ const i = L(ne(t), "url");
793
+ for (const l of ne(e))
794
+ n.has(l) || !l.isRelationLoaded("operations") || !i.hasKey(l.url) || await this.reconcileInconsistencies(
795
+ l,
796
+ i.require(l.url),
797
+ n
1332
798
  );
1333
- const o = v(ve(i), "url");
1334
- for (const r of ve(e))
1335
- s.has(r) || !r.isRelationLoaded("operations") || !o.hasKey(r.url) || await this.reconcileInconsistencies(r, o.require(r.url));
1336
- e.isDirty() && (await e.save(), await F.synchronize(e, i));
1337
- }
1338
- async synchronizeContainerDocuments(e, i) {
1339
- const s = v(e.related ?? [], "url"), o = v(i.related ?? [], "url"), r = s.getKeys().filter((l) => !o.hasKey(l) && !o.hasKey(encodeURI(l))), a = o.getKeys().filter((l) => !s.hasKey(l) && !s.hasKey(encodeURI(l)));
1340
- for (const l of r) {
1341
- const c = s.require(l), u = $e(c);
1342
- i.addRelated(u), o.add(u);
799
+ e.isDirty() && await J.synchronize(e, t);
800
+ }
801
+ async synchronizeContainerDocuments(e, t) {
802
+ const n = L(e.related ?? [], "url"), i = L(t.related ?? [], "url"), l = n.getKeys().filter((r) => !i.hasKey(r) && !i.hasKey(encodeURI(r))), a = i.getKeys().filter((r) => !n.hasKey(r) && !n.hasKey(encodeURI(r)));
803
+ for (const r of l) {
804
+ const c = n.require(r), h = Ce(c);
805
+ t.addRelated(h), i.add(h);
1343
806
  }
1344
- for (const l of a) {
1345
- const c = o.require(l), u = nt(c);
1346
- e.addRelated(u), s.add(u);
807
+ for (const r of a) {
808
+ const c = i.require(r), h = Be(c);
809
+ e.addRelated(h), n.add(h), this.syncedModelUrls.add(h.url);
1347
810
  }
1348
- for (const l of s.items()) {
1349
- const c = o.require(l.url);
1350
- await F.synchronize(l, c), await this.saveModelAndChildren(l);
811
+ for (const r of n.items()) {
812
+ const c = i.require(r.url);
813
+ await J.synchronize(r, c), await this.saveModelAndChildren(r);
1351
814
  }
1352
815
  }
1353
816
  async rememberModelDocuments(e) {
1354
- if (!P(e)) {
1355
- const s = e.requireDocumentUrl(), o = this.documentsModifiedAt[s] ?? /* @__PURE__ */ new Date();
1356
- await G.remember(s, o), delete this.documentsModifiedAt[s];
817
+ if (!U(e)) {
818
+ const n = e.requireDocumentUrl(), i = this.documentsModifiedAt[n];
819
+ i && (await P.remember(n, i), delete this.documentsModifiedAt[n]);
1357
820
  return;
1358
821
  }
1359
- const i = M(e.static()).map((s) => e.getRelationModels(s) ?? []).flat();
1360
- for (const s of i)
1361
- await this.rememberModelDocuments(s);
822
+ const t = k(e.static()).map((n) => e.getRelationModels(n) ?? []).flat();
823
+ for (const n of t)
824
+ await this.rememberModelDocuments(n);
1362
825
  }
1363
- async ignoringMalformedDocumentErrors(e) {
826
+ async ignoringDocumentErrors(e) {
1364
827
  try {
1365
828
  await e();
1366
- } catch (i) {
1367
- if (A(i, Ye)) {
1368
- console.warn(i.message), i.documentUrl && this.malformedDocuments.add(i.documentUrl);
1369
- return;
1370
- }
1371
- throw i;
829
+ } catch (t) {
830
+ this.handleDocumentError(t);
1372
831
  }
1373
832
  }
833
+ handleDocumentError(e) {
834
+ if (E(e, Jt)) {
835
+ console.warn(e.message), e.documentUrl && this.documentsWithErrors.add(e.documentUrl);
836
+ return;
837
+ }
838
+ if (E(e, Ot)) {
839
+ console.warn(e.message);
840
+ const t = e.attributes[_t(e.modelName).primaryKey], n = t && Pe(Mt(t));
841
+ n && this.documentsWithErrors.add(n);
842
+ return;
843
+ }
844
+ throw e;
845
+ }
1374
846
  }
1375
- const b = {
847
+ const v = {
1376
848
  Disconnected: "disconnected",
1377
849
  Online: "online",
1378
850
  Syncing: "syncing",
1379
851
  Migrating: "migrating"
1380
- }, Oi = je({
852
+ }, dn = tt({
1381
853
  name: "cloud",
1382
854
  persist: [
1383
855
  "localModelUpdates",
@@ -1404,64 +876,64 @@ const b = {
1404
876
  setupDismissed: !1,
1405
877
  setupOngoing: !1,
1406
878
  startupSync: !0,
1407
- status: b.Disconnected,
879
+ status: v.Disconnected,
1408
880
  syncError: null,
1409
881
  syncJob: null
1410
882
  }),
1411
- serialize: (n) => {
1412
- var t;
1413
- return ke(n, { migrationJob: (t = n.migrationJob) == null ? void 0 : t.serialize() });
883
+ serialize: (o) => {
884
+ var s;
885
+ return $e(o, { migrationJob: (s = o.migrationJob) == null ? void 0 : s.serialize() });
1414
886
  },
1415
- restore: (n) => ke(n, {
1416
- migrationJob: n.migrationJob && oe.restore(n.migrationJob)
887
+ restore: (o) => $e(o, {
888
+ migrationJob: o.migrationJob && ie.restore(o.migrationJob)
1417
889
  }),
1418
890
  watch: {
1419
- migrationJob(n) {
1420
- n == null || n.listeners.add({ onUpdated: () => this.updatePersistedState("migrationJob") });
891
+ migrationJob(o) {
892
+ o == null || o.listeners.add({ onUpdated: () => this.updatePersistedState("migrationJob") });
1421
893
  }
1422
894
  },
1423
895
  computed: {
1424
- disconnected: ({ status: n }) => n === b.Disconnected,
1425
- online: ({ status: n }) => n === b.Online,
1426
- syncing: ({ status: n }) => n === b.Syncing,
1427
- migrating: ({ status: n }) => n === b.Migrating,
1428
- localChanges({ localModelUpdates: n }) {
1429
- return Object.values(n).reduce((t, e) => t + e, 0);
896
+ disconnected: ({ status: o }) => o === v.Disconnected,
897
+ online: ({ status: o }) => o === v.Online,
898
+ syncing: ({ status: o }) => o === v.Syncing,
899
+ migrating: ({ status: o }) => o === v.Migrating,
900
+ localChanges({ localModelUpdates: o }) {
901
+ return Object.values(o).reduce((s, e) => s + e, 0);
1430
902
  },
1431
903
  dirty() {
1432
904
  return this.localChanges > 0;
1433
905
  },
1434
- migrationStarted({ migrationJob: n }) {
1435
- return !!n;
906
+ migrationStarted({ migrationJob: o }) {
907
+ return !!o;
1436
908
  },
1437
- migrationDisabledReason({ status: n, ready: t }) {
1438
- return y.isLoggedIn() ? t ? n === b.Syncing || n === b.Migrating ? m(
909
+ migrationDisabledReason({ status: o, ready: s }) {
910
+ return C.isLoggedIn() ? s ? o === v.Syncing || o === v.Migrating ? $(
1439
911
  "cloud.migrationNotSyncing",
1440
912
  "Wait for syncing to finish before starting the migration"
1441
- ) : this.online ? null : m(
913
+ ) : this.online ? null : $(
1442
914
  "cloud.migrationNotOnline",
1443
915
  "You need to be online in order to start the migration"
1444
- ) : m(
916
+ ) : $(
1445
917
  "cloud.migrationNotReady",
1446
918
  "You need to backup your data before starting the migration"
1447
- ) : m(
919
+ ) : $(
1448
920
  "cloud.migrationNotLoggedIn",
1449
921
  "You need to reconnect before starting the migration"
1450
922
  );
1451
923
  }
1452
924
  }
1453
925
  });
1454
- class Fi extends Oi {
926
+ class un extends dn {
1455
927
  constructor() {
1456
928
  super(...arguments);
1457
- g(this, "asyncLock", new Ft());
1458
- g(this, "engine", null);
1459
- g(this, "pollingInterval", null);
929
+ w(this, "asyncLock", new bt());
930
+ w(this, "engine", null);
931
+ w(this, "pollingInterval", null);
1460
932
  }
1461
933
  async whenReady(e) {
1462
- return this.ready ? e() : new Promise((i) => {
1463
- const s = () => i(e());
1464
- d.once("cloud:ready", s);
934
+ return this.ready ? e() : new Promise((t) => {
935
+ const n = () => t(e());
936
+ D.once("cloud:ready", n);
1465
937
  });
1466
938
  }
1467
939
  async setup(e) {
@@ -1485,20 +957,32 @@ class Fi extends Oi {
1485
957
  this.online && await this.sync(e);
1486
958
  }
1487
959
  async sync(e = {}) {
1488
- const i = _t(e) ? { models: e } : e instanceof F ? { model: e } : e;
1489
- !y.isLoggedIn() || !this.ready || !this.online || await this.asyncLock.run(async () => {
1490
- const s = Date.now(), o = i.model ? [i.model] : i.models;
1491
- this.syncError = null, this.status = b.Syncing, se.clear(o);
960
+ const t = Ct(e) ? { models: e } : e instanceof J ? { model: e } : e;
961
+ !C.isLoggedIn() || !this.ready || !this.online || await this.asyncLock.run(async () => {
962
+ let n = t.model ? [t.model] : t.models;
963
+ const i = Date.now();
964
+ this.syncError = null, this.status = v.Syncing, se.clear(n);
1492
965
  try {
1493
- if (await d.emit("cloud:sync-started", o), i.refreshUserProfile && await y.refreshUserProfile(), this.syncJob = new qi(o), this.syncJob.listeners.add(i), await ce(this.syncJob), this.syncJob.cancelled)
1494
- return;
1495
- S.testing || await T({ milliseconds: Math.max(500, 1e3 - (Date.now() - s)) }), this.syncJob = null;
1496
- } catch (r) {
1497
- if (S.testing)
1498
- throw r;
1499
- this.syncJob = null, this.syncError = r, await X.report(r, m("cloud.syncFailed", "Sync failed"));
966
+ await D.emit("cloud:sync-started", n), t.refreshUserProfile && await C.refreshUserProfile();
967
+ const l = t.syncDirty ?? !0;
968
+ let a = 0;
969
+ do {
970
+ if (this.syncJob = new cn(n), this.syncJob.listeners.add(t), await ae(this.syncJob), this.syncJob.cancelled)
971
+ return;
972
+ a++, n = this.getDirtyLocalModels().filter(
973
+ (r) => {
974
+ var c;
975
+ return !((c = this.syncJob) != null && c.documentsWithErrors.has(r.requireDocumentUrl()));
976
+ }
977
+ );
978
+ } while (l && n.length > 0 && a < 3);
979
+ Se("unit") || await G({ milliseconds: Math.max(500, 1e3 - (Date.now() - i)) }), this.syncJob = null;
980
+ } catch (l) {
981
+ if (Se())
982
+ throw l;
983
+ this.syncJob = null, this.syncError = l, await Z.report(l, $("cloud.syncFailed", "Sync failed"));
1500
984
  } finally {
1501
- this.status = b.Online, await d.emit("cloud:sync-completed", o);
985
+ this.status = v.Online, await D.emit("cloud:sync-completed", n);
1502
986
  }
1503
987
  });
1504
988
  }
@@ -1506,107 +990,112 @@ class Fi extends Oi {
1506
990
  return this.schemaMigrations.size > 0;
1507
991
  }
1508
992
  async migrate(e) {
1509
- if (!this.online || !y.isLoggedIn() || !this.ready)
993
+ if (!this.online || !C.isLoggedIn() || !this.ready)
1510
994
  throw new Error("Data cannot be migrated at the moment");
1511
995
  this.shouldMigrate() && await this.asyncLock.run(async () => {
1512
- var r;
1513
- this.status = b.Migrating, this.migrationJob ?? (this.migrationJob = new oe());
1514
- const i = Date.now(), s = [], o = (r = this.migrationJob).models ?? (r.models = Ie());
1515
- se.clear(o);
996
+ var l;
997
+ this.status = v.Migrating, this.migrationJob ?? (this.migrationJob = new ie());
998
+ const t = Date.now(), n = [], i = (l = this.migrationJob).models ?? (l.models = pe());
999
+ se.clear(i);
1516
1000
  try {
1517
- if (e && s.push(this.migrationJob.listeners.add(e)), await d.emit("cloud:migration-started", o), await ce(this.migrationJob), this.migrationJob.cancelled) {
1518
- await d.emit("cloud:migration-cancelled", o);
1001
+ if (e && n.push(this.migrationJob.listeners.add(e)), await D.emit("cloud:migration-started", i), await ae(this.migrationJob), this.migrationJob.cancelled) {
1002
+ await D.emit("cloud:migration-cancelled", i);
1519
1003
  return;
1520
1004
  }
1521
- this.migrationJob = null, this.migrationDismissed = !1, this.migrationPostponed = !1, await T({ milliseconds: Math.max(0, 1e3 - (Date.now() - i)) }), await d.emit("cloud:migration-completed", o);
1005
+ this.migrationJob = null, this.migrationDismissed = !1, this.migrationPostponed = !1, await G({ milliseconds: Math.max(0, 1e3 - (Date.now() - t)) }), await D.emit("cloud:migration-completed", i);
1522
1006
  } catch (a) {
1523
- await X.report(a, m("cloud.migrationFailed", "Migration failed"));
1007
+ await Z.report(a, $("cloud.migrationFailed", "Migration failed"));
1524
1008
  } finally {
1525
- this.status = b.Online, s.forEach((a) => a == null ? void 0 : a());
1009
+ this.status = v.Online, n.forEach((a) => a == null ? void 0 : a());
1526
1010
  }
1527
1011
  });
1528
1012
  }
1529
- async register(e, i = {}) {
1530
- if (this.registeredModels.find((o) => e === o.modelClass))
1013
+ async register(e, t = {}) {
1014
+ if (this.registeredModels.find((i) => e === i.modelClass))
1531
1015
  return;
1532
- const s = this.engine;
1533
- s && _e(e).forEach((o) => x(o).setEngine(s)), this.whenReady(() => {
1534
- _(e) && (e.collection = pe(i.path));
1535
- }), await gi(e, {
1536
- created: (o) => We(o),
1537
- updated: (o) => Ne(o),
1538
- deleted: (o) => Ce([o])
1539
- }), _(e) && M(e).forEach((o) => {
1540
- const r = e.instance().requireRelation(o).relatedClass;
1541
- r.on("created", (a) => We(a)), r.on("updated", (a) => Ne(a)), r.on("deleted", (a) => Ce([a]));
1542
- }), this.registeredModels.push({ modelClass: e, path: i.path });
1543
- for (const o of this.modelCollections[e.modelName] ?? [])
1544
- await ie(e, o);
1545
- }
1546
- registerSchemaMigration(e, i) {
1547
- this.schemaMigrations.set(e, i);
1016
+ const n = this.engine;
1017
+ n && Le(e).forEach((i) => z(i).setEngine(n)), this.whenReady(() => {
1018
+ const [i] = this.modelCollections[e.modelName] ?? [];
1019
+ e.useSoftDeletes(!0), e.collection = i ?? ue(e, t.path);
1020
+ }), await Ut(e, {
1021
+ created: (i) => this.ready && Ue(i),
1022
+ updated: (i) => this.ready && Ae(i),
1023
+ deleted: (i) => this.ready && ge(/* @__PURE__ */ new Set([i.url ?? i.getDeletedPrimaryKey()]))
1024
+ }), x(e) && k(e).forEach((i) => {
1025
+ const l = e.instance().requireRelation(i).relatedClass;
1026
+ l.on("created", (a) => this.ready && Ue(a)), l.on("updated", (a) => this.ready && Ae(a)), l.on(
1027
+ "deleted",
1028
+ (a) => this.ready && ge(/* @__PURE__ */ new Set([a.url ?? a.getDeletedPrimaryKey()]))
1029
+ );
1030
+ }), this.registeredModels.push({ modelClass: e, path: t.path });
1031
+ for (const i of this.modelCollections[e.modelName] ?? [])
1032
+ await te(e, i);
1033
+ }
1034
+ registerSchemaMigration(e, t) {
1035
+ this.schemaMigrations.set(e, t);
1548
1036
  }
1549
1037
  requireRemoteCollection(e) {
1550
- for (const i of this.registeredModels)
1551
- if (e === i.modelClass)
1552
- return pe(i.path);
1038
+ for (const t of this.registeredModels)
1039
+ if (e === t.modelClass)
1040
+ return ue(t.modelClass, t.path);
1553
1041
  throw new Error(`Failed resolving remote collection for '${e.modelName}' model`);
1554
1042
  }
1555
1043
  async boot() {
1556
- await y.booted, y.isLoggedIn() && this.login(y.authenticator), d.on("auth:login", ({ authenticator: e }) => this.login(e)), d.on("auth:logout", () => this.logout()), d.once("application-ready", () => this.onApplicationReady()), d.once("application-mounted", () => this.onApplicationMounted()), Xe(() => {
1044
+ await C.booted, C.isLoggedIn() && this.login(C.authenticator), D.on("auth:login", ({ authenticator: e }) => this.login(e)), D.on("auth:logout", () => this.logout()), D.once("application-ready", () => this.onApplicationReady()), D.once("application-mounted", () => this.onApplicationMounted()), At(() => {
1557
1045
  if (this.pollingInterval && clearInterval(this.pollingInterval), !this.pollingEnabled || this.migrationJob) {
1558
1046
  this.pollingInterval = null;
1559
1047
  return;
1560
1048
  }
1561
1049
  this.pollingInterval = setInterval(() => this.sync(), this.pollingMinutes * 60 * 1e3);
1562
- });
1050
+ }), await this.bustDocumentsCache(), await this.registerModels();
1563
1051
  }
1564
1052
  getDirtyLocalModels() {
1565
- const e = Object.keys(this.localModelUpdates), i = [];
1566
- for (const { modelClass: s } of this.registeredModels)
1567
- for (const o of xe(s))
1568
- i.push(...this.getModelsIn(e, o));
1569
- return i;
1053
+ const e = Object.keys(this.localModelUpdates), t = [];
1054
+ for (const { modelClass: n } of this.registeredModels)
1055
+ for (const i of Me(n, { includeSoftDeleted: !0 }))
1056
+ t.push(...this.getModelsIn(e, i));
1057
+ return t;
1570
1058
  }
1571
- getModelsIn(e, i) {
1572
- const s = [];
1573
- return e.includes(i.url) && s.push(i), P(i) && s.push(
1574
- ...tt(i).map((o) => this.getModelsIn(e, o)).flat()
1575
- ), s;
1059
+ getModelsIn(e, t) {
1060
+ const n = [];
1061
+ return e.includes(t.url) && n.push(t), U(t) && n.push(
1062
+ ...Ne(t).map((i) => this.getModelsIn(e, i)).flat()
1063
+ ), n;
1576
1064
  }
1577
1065
  requireEngine() {
1578
- return this.engine ?? N("Could not get required Engine");
1066
+ return this.engine ?? Oe("Could not get required Engine");
1579
1067
  }
1580
1068
  async setReady(e) {
1581
- this.ready || !e || (await d.emit("cloud:ready"), this.ready = !0);
1069
+ this.ready || !e || (await D.emit("cloud:ready"), this.ready = !0);
1582
1070
  }
1583
1071
  async backup(e) {
1584
- await d.emit("cloud:backup-started"), e ?? (e = /* @__PURE__ */ new WeakMap());
1585
- const i = new Di();
1586
- for (const { modelClass: s, path: o } of this.registeredModels) {
1587
- if (!_(s))
1072
+ await D.emit("cloud:backup-started"), e ?? (e = /* @__PURE__ */ new WeakMap());
1073
+ const t = new nn();
1074
+ for (const { modelClass: n, path: i } of this.registeredModels) {
1075
+ if (!x(n))
1588
1076
  continue;
1589
- for (const [l, c] of Object.entries(e.get(s) ?? {}))
1590
- i.migrateUrl(s, l, c);
1591
- const r = s.collection, a = pe(o);
1592
- s.collection = a, i.migrateCollection(s, r, a);
1077
+ for (const [r, c] of Object.entries(e.get(n) ?? {}))
1078
+ t.migrateUrl(n, r, c);
1079
+ const l = n.collection, a = ue(n, i);
1080
+ n.collection = a, t.migrateCollection(n, l, a);
1593
1081
  }
1594
- await ce(i), await d.emit("cloud:backup-completed");
1082
+ await ae(t), await D.emit("cloud:backup-completed");
1595
1083
  }
1596
1084
  async onApplicationReady() {
1597
- this.ready || !y.isLoggedIn() || await this.setReady(!Ie().some((e) => e.url.startsWith("solid://")));
1085
+ this.ready || !C.isLoggedIn() || await this.setReady(!pe().some((e) => e.url.startsWith("solid://")));
1598
1086
  }
1599
1087
  async onApplicationMounted() {
1600
1088
  this.syncOnStartup() && await this.sync();
1601
1089
  }
1602
1090
  login(e) {
1603
- const i = [...this.registeredModels].map(({ modelClass: s }) => _e(s)).flat().concat([W]);
1604
- this.status = b.Online, this.engine = e.engine;
1605
- for (const s of i)
1606
- x(s).setEngine(this.engine);
1091
+ const t = [...this.registeredModels].map(({ modelClass: n }) => Le(n)).flat().concat([N]);
1092
+ this.status = v.Online, this.engine = e.engine, z(W).setEngine(this.engine);
1093
+ for (const n of t)
1094
+ z(n).setEngine(this.engine);
1607
1095
  }
1608
1096
  logout() {
1609
1097
  this.setState({
1098
+ autoPush: !0,
1610
1099
  localModelUpdates: {},
1611
1100
  migrationDismissed: !1,
1612
1101
  migrationJob: null,
@@ -1615,72 +1104,570 @@ class Fi extends Oi {
1615
1104
  pollingEnabled: !0,
1616
1105
  pollingMinutes: 10,
1617
1106
  ready: !1,
1107
+ schemaMigrations: /* @__PURE__ */ new Map(),
1618
1108
  setupDismissed: !1,
1619
1109
  setupOngoing: !1,
1620
1110
  startupSync: !0,
1621
- status: b.Disconnected
1111
+ status: v.Disconnected,
1112
+ syncError: null,
1113
+ syncJob: null
1622
1114
  });
1623
1115
  }
1624
1116
  syncOnStartup() {
1625
- return j("startupSync") ? we(Q("startupSync")) : this.migrationJob ? !1 : this.startupSync;
1117
+ return De("startupSync") ? ke(Re("startupSync")) : this.migrationJob ? !1 : this.startupSync;
1118
+ }
1119
+ async bustDocumentsCache() {
1120
+ !De("bustDocumentsCache") || !ke(Re("bustDocumentsCache")) || (await P.booted, await P.clear());
1121
+ }
1122
+ async registerModels() {
1123
+ const e = xt();
1124
+ for (const t of e.values())
1125
+ !Rt(t) || !t.cloud || await this.register(t, typeof t.cloud == "boolean" ? {} : t.cloud);
1126
+ }
1127
+ }
1128
+ const I = we(un), hn = {
1129
+ viewBox: "0 0 20 20",
1130
+ width: "1.2em",
1131
+ height: "1.2em"
1132
+ };
1133
+ function fn(o, s) {
1134
+ return f(), M("svg", hn, s[0] || (s[0] = [
1135
+ m("path", {
1136
+ fill: "currentColor",
1137
+ d: "m6 2l2-2h4l2 2h4v2H2V2zM3 6h14l-1 14H4zm5 2v10h1V8zm3 0v10h1V8z"
1138
+ }, null, -1)
1139
+ ]));
1140
+ }
1141
+ const mn = O({ name: "zondicons-trash", render: fn }), Ke = /* @__PURE__ */ j({
1142
+ __name: "AccountLoginModal",
1143
+ setup(o) {
1144
+ return (s, e) => (f(), R(d(Ee), {
1145
+ title: s.$td("cloud.logIn.title", "Connect account")
1146
+ }, {
1147
+ default: b(() => [
1148
+ u(d(T), {
1149
+ "lang-key": "cloud.logIn.info",
1150
+ "lang-default": "Log in to your [Solid account](https://solidproject.org) to keep data safe across devices."
1151
+ }),
1152
+ u(d(he), {
1153
+ class: "text-sm",
1154
+ onClick: e[0] || (e[0] = (t) => s.$ui.alert(
1155
+ s.$td("cloud.logIn.learnMore", "What is Solid?"),
1156
+ s.$td(
1157
+ "cloud.logIn.learnMoreMessage",
1158
+ `Solid is a decentralized storage protocol built on top of web standards. If you want to use this app across devices, you can use Solid to keep changes in sync. Even if you use it in a single device, this will also keep your data secure in case your device is lost.
1159
+
1160
+ In any case, Focus works 100% offline and you can connect your Solid POD later on. If you've never heard of Solid and you're just trying things out, you can keep using it without an account.
1161
+
1162
+ [Learn more](https://solidproject.org)`
1163
+ )
1164
+ ))
1165
+ }, {
1166
+ default: b(() => [
1167
+ K(S(s.$td("cloud.logIn.learnMore", "What is Solid?")), 1)
1168
+ ]),
1169
+ _: 1
1170
+ }),
1171
+ u(d(vt), {
1172
+ "no-loading": "",
1173
+ class: "mt-4"
1174
+ })
1175
+ ]),
1176
+ _: 1
1177
+ }, 8, ["title"]));
1178
+ }
1179
+ }), gn = {
1180
+ key: 0,
1181
+ class: "mt-4"
1182
+ }, pn = { class: "text-base font-semibold" }, yn = { class: "ml-1" }, wn = /* @__PURE__ */ j({
1183
+ __name: "PurgeData",
1184
+ setup(o) {
1185
+ async function s() {
1186
+ await le.confirm(
1187
+ $("settings.purgeConfirmTitle", "Delete everything?"),
1188
+ $(
1189
+ "settings.purgeConfirmMessage",
1190
+ "If you proceed, all your data will be deleted forever. If you want to save it before wiping this device, you can [connect to your Solid account](#action:connect) first."
1191
+ ),
1192
+ {
1193
+ acceptVariant: "danger",
1194
+ acceptText: $("settings.purgeConfirmAccept", "Purge data"),
1195
+ actions: { connect: () => le.modal(Ke) }
1196
+ }
1197
+ ) && (await le.closeAllModals(), await nt.purge());
1198
+ }
1199
+ return (e, t) => e.$solid.hasLoggedIn() ? _("", !0) : (f(), M("details", gn, [
1200
+ m("summary", null, [
1201
+ m("span", pn, S(e.$td("settings.dangerZone", "Danger zone")), 1)
1202
+ ]),
1203
+ u(d(q), {
1204
+ variant: "danger",
1205
+ class: "mt-4",
1206
+ onClick: t[0] || (t[0] = (n) => s())
1207
+ }, {
1208
+ default: b(() => [
1209
+ u(d(mn), { class: "size-4" }),
1210
+ m("span", yn, S(e.$td("settings.purge", "Purge data")), 1)
1211
+ ]),
1212
+ _: 1
1213
+ })
1214
+ ]));
1215
+ }
1216
+ }), Mn = st([
1217
+ {
1218
+ priority: 0,
1219
+ component: wn
1626
1220
  }
1221
+ ]), bn = {
1222
+ viewBox: "0 0 20 20",
1223
+ width: "1.2em",
1224
+ height: "1.2em"
1225
+ };
1226
+ function Cn(o, s) {
1227
+ return f(), M("svg", bn, s[0] || (s[0] = [
1228
+ m("path", {
1229
+ fill: "currentColor",
1230
+ d: "M2.93 17.07A10 10 0 1 1 17.07 2.93A10 10 0 0 1 2.93 17.07m12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32M6.7 9.29L9 11.6l4.3-4.3l1.4 1.42L9 14.4l-3.7-3.7l1.4-1.42z"
1231
+ }, null, -1)
1232
+ ]));
1233
+ }
1234
+ const vn = O({ name: "zondicons-checkmark-outline", render: Cn }), $n = {
1235
+ viewBox: "0 0 24 24",
1236
+ width: "1.2em",
1237
+ height: "1.2em"
1238
+ };
1239
+ function Sn(o, s) {
1240
+ return f(), M("svg", $n, s[0] || (s[0] = [
1241
+ m("path", {
1242
+ fill: "currentColor",
1243
+ d: "M19.35 10.04A7.49 7.49 0 0 0 12 4C9.11 4 6.6 5.64 5.35 8.04A5.994 5.994 0 0 0 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5c0-2.64-2.05-4.78-4.65-4.96M14 13v4h-4v-4H7l5-5l5 5z"
1244
+ }, null, -1)
1245
+ ]));
1246
+ }
1247
+ const Dn = O({ name: "ic-sharp-cloud-upload", render: Sn }), kn = {
1248
+ viewBox: "0 0 20 20",
1249
+ width: "1.2em",
1250
+ height: "1.2em"
1251
+ };
1252
+ function Rn(o, s) {
1253
+ return f(), M("svg", kn, s[0] || (s[0] = [
1254
+ m("path", {
1255
+ fill: "currentColor",
1256
+ d: "M3.94 6.5L2.22 3.64l1.42-1.42L6.5 3.94c.52-.3 1.1-.54 1.7-.7L9 0h2l.8 3.24c.6.16 1.18.4 1.7.7l2.86-1.72l1.42 1.42l-1.72 2.86c.3.52.54 1.1.7 1.7L20 9v2l-3.24.8c-.16.6-.4 1.18-.7 1.7l1.72 2.86l-1.42 1.42l-2.86-1.72c-.52.3-1.1.54-1.7.7L11 20H9l-.8-3.24c-.6-.16-1.18-.4-1.7-.7l-2.86 1.72l-1.42-1.42l1.72-2.86c-.3-.52-.54-1.1-.7-1.7L0 11V9l3.24-.8c.16-.6.4-1.18.7-1.7M10 13a3 3 0 1 0 0-6a3 3 0 0 0 0 6"
1257
+ }, null, -1)
1258
+ ]));
1259
+ }
1260
+ const Ye = O({ name: "zondicons-cog", render: Rn }), Ln = {
1261
+ viewBox: "0 0 24 24",
1262
+ width: "1.2em",
1263
+ height: "1.2em"
1264
+ };
1265
+ function Un(o, s) {
1266
+ return f(), M("svg", Ln, s[0] || (s[0] = [
1267
+ m("path", {
1268
+ fill: "currentColor",
1269
+ d: "M5 21q-.825 0-1.412-.587T3 19V5q0-.825.588-1.412T5 3h6q.425 0 .713.288T12 4t-.288.713T11 5H5v14h6q.425 0 .713.288T12 20t-.288.713T11 21zm12.175-8H10q-.425 0-.712-.288T9 12t.288-.712T10 11h7.175L15.3 9.125q-.275-.275-.275-.675t.275-.7t.7-.313t.725.288L20.3 11.3q.3.3.3.7t-.3.7l-3.575 3.575q-.3.3-.712.288t-.713-.313q-.275-.3-.262-.712t.287-.688z"
1270
+ }, null, -1)
1271
+ ]));
1272
+ }
1273
+ const An = O({ name: "material-symbols-logout-rounded", render: Un }), In = {
1274
+ viewBox: "0 0 20 20",
1275
+ width: "1.2em",
1276
+ height: "1.2em"
1277
+ };
1278
+ function zn(o, s) {
1279
+ return f(), M("svg", In, s[0] || (s[0] = [
1280
+ m("path", {
1281
+ fill: "currentColor",
1282
+ d: "M10 3v2a5 5 0 0 0-3.54 8.54l-1.41 1.41A7 7 0 0 1 10 3m4.95 2.05A7 7 0 0 1 10 17v-2a5 5 0 0 0 3.54-8.54zM10 20l-4-4l4-4zm0-12V0l4 4z"
1283
+ }, null, -1)
1284
+ ]));
1627
1285
  }
1628
- const _i = ne(Fi), Wi = {
1286
+ const F = O({ name: "zondicons-refresh", render: zn }), En = {
1287
+ viewBox: "0 0 24 24",
1288
+ width: "1.2em",
1289
+ height: "1.2em"
1290
+ };
1291
+ function Tn(o, s) {
1292
+ return f(), M("svg", En, s[0] || (s[0] = [
1293
+ m("path", {
1294
+ fill: "currentColor",
1295
+ d: "M6 6h12v12H6z"
1296
+ }, null, -1)
1297
+ ]));
1298
+ }
1299
+ const qn = O({ name: "ic-baseline-stop", render: Tn }), Pn = {
1300
+ viewBox: "0 0 512 512",
1301
+ width: "1.2em",
1302
+ height: "1.2em"
1303
+ };
1304
+ function On(o, s) {
1305
+ return f(), M("svg", Pn, s[0] || (s[0] = [
1306
+ m("path", {
1307
+ fill: "currentColor",
1308
+ d: "M449.07 399.08L278.64 82.58c-12.08-22.44-44.26-22.44-56.35 0L51.87 399.08A32 32 0 0 0 80 446.25h340.89a32 32 0 0 0 28.18-47.17m-198.6-1.83a20 20 0 1 1 20-20a20 20 0 0 1-20 20m21.72-201.15l-5.74 122a16 16 0 0 1-32 0l-5.74-121.95a21.73 21.73 0 0 1 21.5-22.69h.21a21.74 21.74 0 0 1 21.73 22.7Z"
1309
+ }, null, -1)
1310
+ ]));
1311
+ }
1312
+ const H = O({ name: "ion-warning", render: On }), _n = { class: "relative flex items-center rounded-md bg-gray-100 p-4 pr-12" }, xn = { class: "flex flex-col overflow-hidden" }, Jn = { class: "font-semibold" }, Nn = { class: "px-2" }, Wn = {
1313
+ key: 0,
1314
+ class: "mt-4 flex items-center gap-2"
1315
+ }, jn = { class: "flex w-full flex-col" }, Bn = {
1629
1316
  key: 1,
1630
- class: "flex flex-col gap-3"
1631
- }, Yi = /* @__PURE__ */ Pe({
1632
- __name: "AGCloudStatus",
1633
- emits: ["sync"],
1634
- setup(n) {
1635
- return (t, e) => (D(), B(f(di), null, {
1636
- "logged-in": L(({ session: i }) => [
1637
- t.$cloud.syncing ? (D(), B(f(q), {
1638
- key: 0,
1639
- text: t.$td("cloud.syncing", "Syncing...")
1640
- }, null, 8, ["text"])) : (D(), te("div", Wi, [
1641
- R(f(q), {
1642
- text: t.$td("solid.loggedIn", "You are logged in as [{userName}]({userWebId})", {
1643
- userName: i.user.name ?? i.user.webId,
1644
- userWebId: i.user.webId
1645
- })
1646
- }, null, 8, ["text"]),
1647
- R(f(O), {
1648
- onClick: e[0] || (e[0] = (s) => (t.$cloud.sync(), t.$emit("sync")))
1649
- }, {
1650
- default: L(() => [
1651
- E($(t.$td("cloud.sync", "Synchronize")), 1)
1652
- ]),
1653
- _: 1
1654
- }),
1655
- R(f(O), {
1656
- onClick: e[1] || (e[1] = (s) => t.$solid.logout())
1657
- }, {
1658
- default: L(() => [
1659
- E($(t.$td("solid.logout", "Logout")), 1)
1317
+ class: "mt-4 flex items-center gap-2"
1318
+ }, Vn = {
1319
+ key: 2,
1320
+ class: "mt-4 flex items-center gap-2"
1321
+ }, Fn = {
1322
+ key: 3,
1323
+ class: "mt-4 flex items-center gap-2"
1324
+ }, Hn = {
1325
+ key: 4,
1326
+ class: "mt-4 flex items-center gap-2"
1327
+ }, Kn = {
1328
+ key: 5,
1329
+ class: "mt-4 flex items-center gap-2"
1330
+ }, Yn = {
1331
+ key: 6,
1332
+ class: "mt-4 flex items-center gap-2"
1333
+ }, Qn = { class: "flex flex-col gap-2" }, Zn = { class: "flex items-center" }, Gn = { "aria-hidden": "true" }, Xn = {
1334
+ key: 0,
1335
+ "aria-hidden": "true"
1336
+ }, es = {
1337
+ key: 0,
1338
+ class: "mt-4 flex flex-row-reverse justify-start gap-2"
1339
+ }, ts = /* @__PURE__ */ j({
1340
+ __name: "AccountModal",
1341
+ setup(o) {
1342
+ const s = It("$modalRef"), e = zt(!1), t = $("cloud.advanced.polling", "Synchronize every {minutes} minutes", {
1343
+ minutes: "%%separator%%"
1344
+ }).split("%%separator%%"), n = Y(() => C.error ?? I.syncError), i = Y(() => {
1345
+ if (n.value)
1346
+ return typeof n.value == "string" ? n.value : $("cloud.info.error", "There has been an error connecting.");
1347
+ }), l = Y(() => n.value && typeof n.value != "string");
1348
+ async function a() {
1349
+ I.syncJob && (e.value = !0, await Promise.race([I.syncJob.cancel(), I.syncJob.completed]), e.value = !1);
1350
+ }
1351
+ return ot("auth:logout", () => {
1352
+ var r;
1353
+ return (r = s.value) == null ? void 0 : r.close();
1354
+ }), (r, c) => (f(), R(d(Ee), {
1355
+ ref: "$modalRef",
1356
+ "title-hidden": "",
1357
+ "close-hidden": "",
1358
+ title: r.$td("account.title", "Account")
1359
+ }, {
1360
+ default: b(() => {
1361
+ var h, p;
1362
+ return [
1363
+ m("div", _n, [
1364
+ u(d(xe), { class: "mr-2 size-16 shrink-0" }),
1365
+ m("div", xn, [
1366
+ m("span", Jn, S(((h = r.$solid.user) == null ? void 0 : h.name) ?? r.$td("user.anonymous", "Anonymous")), 1),
1367
+ u(d(he), {
1368
+ href: (p = r.$solid.user) == null ? void 0 : p.webId,
1369
+ class: "mt-0.5 truncate text-sm font-light text-gray-500"
1370
+ }, {
1371
+ default: b(() => {
1372
+ var y;
1373
+ return [
1374
+ K(S((y = r.$solid.user) == null ? void 0 : y.webId), 1)
1375
+ ];
1376
+ }),
1377
+ _: 1
1378
+ }, 8, ["href"])
1660
1379
  ]),
1661
- _: 1
1662
- })
1663
- ]))
1380
+ u(d(q), {
1381
+ size: "icon",
1382
+ variant: "ghost",
1383
+ class: "absolute top-1 right-1 hover:bg-gray-200",
1384
+ "aria-label": r.$td("user.settings", "Settings"),
1385
+ title: r.$td("user.settings", "Settings"),
1386
+ onClick: c[0] || (c[0] = (y) => r.$ui.modal(d(Te)))
1387
+ }, {
1388
+ default: b(() => [
1389
+ u(d(Ye), { class: "size-5" })
1390
+ ]),
1391
+ _: 1
1392
+ }, 8, ["aria-label", "title"])
1393
+ ]),
1394
+ m("div", Nn, [
1395
+ r.$cloud.syncing ? (f(), M("div", Wn, [
1396
+ u(d(F), { class: "mt-0.5 size-6 shrink-0 animate-spin self-start text-green-500" }),
1397
+ m("div", jn, [
1398
+ u(d(T), {
1399
+ "lang-key": "cloud.info.syncing",
1400
+ "lang-default": "Synchronizing..."
1401
+ }),
1402
+ r.$cloud.syncJob ? (f(), R(d(it), {
1403
+ key: 0,
1404
+ job: r.$cloud.syncJob,
1405
+ "filled-class": "bg-green-500"
1406
+ }, null, 8, ["job"])) : _("", !0)
1407
+ ])
1408
+ ])) : r.$solid.loginOngoing ? (f(), M("div", Bn, [
1409
+ u(d(F), { class: "mt-0.5 size-6 shrink-0 animate-spin self-start text-green-500" }),
1410
+ u(d(T), {
1411
+ "lang-key": "cloud.info.reconnecting",
1412
+ "lang-default": "Reconnecting..."
1413
+ })
1414
+ ])) : n.value ? (f(), M("div", Vn, [
1415
+ u(d(H), { class: "mt-0.5 size-6 shrink-0 self-start text-red-500" }),
1416
+ m("div", null, [
1417
+ u(d(T), { text: i.value }, null, 8, ["text"]),
1418
+ l.value ? (f(), R(d(he), {
1419
+ key: 0,
1420
+ class: "text-sm text-red-700 opacity-50 hover:opacity-75 focus-visible:opacity-75",
1421
+ onClick: c[1] || (c[1] = (y) => r.$errors.inspect(n.value))
1422
+ }, {
1423
+ default: b(() => [
1424
+ K(S(r.$td("errors.viewDetails", "View details")), 1)
1425
+ ]),
1426
+ _: 1
1427
+ })) : _("", !0)
1428
+ ])
1429
+ ])) : r.$cloud.ready ? r.$cloud.dirty ? (f(), M("div", Hn, [
1430
+ u(d(H), { class: "mt-0.5 size-6 shrink-0 self-start text-yellow-500" }),
1431
+ u(d(T), {
1432
+ "lang-key": "cloud.info.changes",
1433
+ "lang-default": "Everything is up to date. | There is one local change. | There are {n} local changes.",
1434
+ "lang-params": r.$cloud.localChanges
1435
+ }, null, 8, ["lang-params"])
1436
+ ])) : r.$cloud.online ? (f(), M("div", Kn, [
1437
+ u(d(vn), { class: "mt-0.5 size-6 shrink-0 self-start text-green-500" }),
1438
+ u(d(T), {
1439
+ "lang-key": "cloud.info.changes",
1440
+ "lang-default": "Everything is up to date.",
1441
+ "lang-params": 0
1442
+ })
1443
+ ])) : (f(), M("div", Yn, [
1444
+ u(d(H), { class: "mt-0.5 size-6 shrink-0 self-start text-yellow-500" }),
1445
+ u(d(T), {
1446
+ "lang-key": "cloud.info.disconnected",
1447
+ "lang-default": "You are disconnected from your Solid account, all the changes you make will remain in your device."
1448
+ })
1449
+ ])) : (f(), M("div", Fn, [
1450
+ u(d(H), { class: "mt-0.5 size-6 shrink-0 self-start text-yellow-500" }),
1451
+ u(d(T), {
1452
+ "lang-key": "cloud.info.setup",
1453
+ "lang-default": "Your data is not backed up yet."
1454
+ })
1455
+ ])),
1456
+ u(d(rt), { class: "mt-2" }, {
1457
+ default: b(() => [
1458
+ m("ul", Qn, [
1459
+ m("li", null, [
1460
+ u(d(ce), {
1461
+ modelValue: r.$solid.autoReconnect,
1462
+ "onUpdate:modelValue": c[2] || (c[2] = (y) => r.$solid.autoReconnect = y),
1463
+ "label-class": "text-base",
1464
+ label: r.$td("cloud.advanced.reconnect", "Reconnect on startup")
1465
+ }, null, 8, ["modelValue", "label"])
1466
+ ]),
1467
+ m("li", null, [
1468
+ u(d(ce), {
1469
+ modelValue: r.$cloud.startupSync,
1470
+ "onUpdate:modelValue": c[3] || (c[3] = (y) => r.$cloud.startupSync = y),
1471
+ "label-class": "text-base",
1472
+ label: r.$td("cloud.advanced.startupSync", "Synchronize on startup")
1473
+ }, null, 8, ["modelValue", "label"])
1474
+ ]),
1475
+ m("li", null, [
1476
+ u(d(ce), {
1477
+ modelValue: r.$cloud.pollingEnabled,
1478
+ "onUpdate:modelValue": c[5] || (c[5] = (y) => r.$cloud.pollingEnabled = y),
1479
+ "label-class": "text-base"
1480
+ }, {
1481
+ default: b(() => [
1482
+ m("div", Zn, [
1483
+ m("span", Gn, S(d(t)[0]), 1),
1484
+ u(d(at), {
1485
+ type: "number",
1486
+ text: `${r.$cloud.pollingMinutes}`,
1487
+ "aria-label": r.$td("cloud.advanced.pollingMinutes", "Synchronization interval (in minutes)"),
1488
+ class: "focus-within:border-primary-600 mx-1 -mb-px border-b",
1489
+ onUpdate: c[4] || (c[4] = (y) => r.$cloud.pollingMinutes = y)
1490
+ }, {
1491
+ default: b(() => [
1492
+ K(S(r.$cloud.pollingMinutes), 1)
1493
+ ]),
1494
+ _: 1
1495
+ }, 8, ["text", "aria-label"]),
1496
+ d(t).length > 1 ? (f(), M("span", Xn, S(d(t)[1]), 1)) : _("", !0)
1497
+ ])
1498
+ ]),
1499
+ _: 1
1500
+ }, 8, ["modelValue"])
1501
+ ])
1502
+ ])
1503
+ ]),
1504
+ _: 1
1505
+ })
1506
+ ]),
1507
+ r.$solid.loginOngoing ? _("", !0) : (f(), M("div", es, [
1508
+ r.$cloud.syncing ? (f(), R(d(q), {
1509
+ key: 0,
1510
+ variant: "secondary",
1511
+ disabled: e.value,
1512
+ onClick: c[6] || (c[6] = (y) => a())
1513
+ }, {
1514
+ default: b(() => [
1515
+ u(d(qn), { class: "size-5" }),
1516
+ m("span", null, S(e.value ? r.$td("cloud.stopping", "Stopping...") : r.$td("cloud.stop", "Stop synchronization")), 1)
1517
+ ]),
1518
+ _: 1
1519
+ }, 8, ["disabled"])) : r.$solid.isLoggedIn() ? r.$cloud.ready ? (f(), R(d(q), {
1520
+ key: 2,
1521
+ onClick: c[8] || (c[8] = (y) => r.$cloud.sync({ refreshUserProfile: !0 }))
1522
+ }, {
1523
+ default: b(() => [
1524
+ u(d(F), { class: "size-5" }),
1525
+ m("span", null, S(r.$td("cloud.sync", "Synchronize")), 1)
1526
+ ]),
1527
+ _: 1
1528
+ })) : (f(), R(d(q), {
1529
+ key: 3,
1530
+ onClick: c[9] || (c[9] = (y) => {
1531
+ var V;
1532
+ return r.$cloud.setupDismissed = !1, (V = s.value) == null ? void 0 : V.close();
1533
+ })
1534
+ }, {
1535
+ default: b(() => [
1536
+ u(d(Dn), { class: "size-5" }),
1537
+ m("span", null, S(r.$td("cloud.setup.submit", "Back up now")), 1)
1538
+ ]),
1539
+ _: 1
1540
+ })) : (f(), R(d(q), {
1541
+ key: 1,
1542
+ onClick: c[7] || (c[7] = (y) => r.$solid.reconnect({ force: !0 }))
1543
+ }, {
1544
+ default: b(() => [
1545
+ u(d(F), { class: "size-5" }),
1546
+ m("span", null, S(r.$td("cloud.reconnect", "Reconnect")), 1)
1547
+ ]),
1548
+ _: 1
1549
+ })),
1550
+ r.$cloud.syncing ? _("", !0) : (f(), R(d(q), {
1551
+ key: 4,
1552
+ variant: "secondary",
1553
+ onClick: c[10] || (c[10] = (y) => r.$solid.logout())
1554
+ }, {
1555
+ default: b(() => [
1556
+ u(d(An), { class: "size-5" }),
1557
+ m("span", null, S(r.$cloud.ready ? r.$td("cloud.logOut", "Log out") : r.$td("cloud.disconnect", "Disconnect")), 1)
1558
+ ]),
1559
+ _: 1
1560
+ }))
1561
+ ]))
1562
+ ];
1563
+ }),
1564
+ _: 1
1565
+ }, 8, ["title"]));
1566
+ }
1567
+ }), ns = { class: "relative size-12" }, ss = ["aria-label", "title"], os = {
1568
+ key: 0,
1569
+ class: "absolute -inset-1 animate-spin rounded-full border-2 border-[currentColor_transparent] text-green-500"
1570
+ }, is = { class: "sr-only" }, rs = /* @__PURE__ */ j({
1571
+ __name: "AccountLoggedIn",
1572
+ setup(o) {
1573
+ const s = Y(() => I.syncing || C.loginOngoing ? {
1574
+ loading: !0,
1575
+ classes: "bg-green-500 sr-only",
1576
+ message: e() ?? ""
1577
+ } : C.error || I.syncError ? {
1578
+ classes: "bg-red-500",
1579
+ message: $("account.error", "There has been an error connecting with your account.")
1580
+ } : !C.isLoggedIn() || I.dirty || !I.ready ? {
1581
+ classes: "bg-yellow-500",
1582
+ message: $(
1583
+ "account.dirty",
1584
+ "There are local changes that haven't been synchronized yet."
1585
+ )
1586
+ } : {
1587
+ classes: "bg-green-500",
1588
+ message: e() ?? ""
1589
+ });
1590
+ function e() {
1591
+ switch (I.status) {
1592
+ case v.Syncing:
1593
+ return $("cloud.status.syncing", "Synchronization in progress");
1594
+ case v.Migrating:
1595
+ return $("cloud.status.migrating", "Migration in progress");
1596
+ case v.Online:
1597
+ return $("cloud.status.online", "Online");
1598
+ case v.Disconnected:
1599
+ return $("cloud.status.disconnected", "Disconnected");
1600
+ }
1601
+ }
1602
+ return (t, n) => (f(), M("div", ns, [
1603
+ m("button", {
1604
+ class: "clickable focus-visible:outline-primary-600 flex size-full rounded-full focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",
1605
+ type: "button",
1606
+ "aria-label": t.$td("account.open", "Open account"),
1607
+ title: t.$td("account.open", "Open account"),
1608
+ onClick: n[0] || (n[0] = (i) => t.$ui.modal(ts))
1609
+ }, [
1610
+ u(d(xe), { class: "size-full" }),
1611
+ s.value.loading ? (f(), M("div", os)) : _("", !0)
1612
+ ], 8, ss),
1613
+ m("div", {
1614
+ class: Et(["pointer-events-none absolute right-0 bottom-0 size-3 rounded-full border-2 border-white", s.value.classes])
1615
+ }, [
1616
+ m("span", is, S(s.value.message), 1)
1617
+ ], 2)
1618
+ ]));
1619
+ }
1620
+ }), as = /* @__PURE__ */ j({
1621
+ __name: "AccountLoggedOut",
1622
+ setup(o) {
1623
+ return (s, e) => (f(), R(d(lt), {
1624
+ align: "start",
1625
+ options: [
1626
+ { label: s.$td("user.logIn", "Connect account"), click: () => s.$ui.modal(Ke) },
1627
+ { label: s.$td("user.settings", "Settings"), click: () => s.$ui.modal(d(Te)) }
1628
+ ]
1629
+ }, {
1630
+ default: b(() => [
1631
+ u(d(q), {
1632
+ size: "icon",
1633
+ variant: "ghost",
1634
+ "aria-label": s.$td("user.menu", "Configuration"),
1635
+ title: s.$td("user.menu", "Configuration")
1636
+ }, {
1637
+ default: b(() => [
1638
+ u(d(Ye), { class: "size-5" })
1639
+ ]),
1640
+ _: 1
1641
+ }, 8, ["aria-label", "title"])
1664
1642
  ]),
1665
1643
  _: 1
1666
- }));
1644
+ }, 8, ["options"]));
1645
+ }
1646
+ }), Ms = /* @__PURE__ */ j({
1647
+ __name: "Account",
1648
+ setup(o) {
1649
+ return (s, e) => s.$solid.hasLoggedIn() ? (f(), R(rs, { key: 0 })) : (f(), R(as, { key: 1 }));
1667
1650
  }
1668
- }), Ni = { $cloud: _i };
1669
- function Qi() {
1651
+ }), ls = { $cloud: I };
1652
+ function bs() {
1670
1653
  return {
1671
1654
  name: "@aerogel/local-first",
1672
- async install(n) {
1673
- await Mt(n, {
1674
- ...Ni,
1675
- $_documentsCache: G
1655
+ async install(o) {
1656
+ Mn.forEach((s) => oe.addSetting(s)), await ct(o, {
1657
+ ...ls,
1658
+ $_documentsCache: P
1676
1659
  });
1677
1660
  }
1678
1661
  };
1679
1662
  }
1680
1663
  export {
1681
- Yi as AGCloudStatus,
1682
- _i as Cloud,
1683
- Fi as CloudService,
1684
- Qi as default
1664
+ Ms as Account,
1665
+ rs as AccountLoggedIn,
1666
+ as as AccountLoggedOut,
1667
+ Ke as AccountLoginModal,
1668
+ ts as AccountModal,
1669
+ I as Cloud,
1670
+ un as CloudService,
1671
+ bs as default
1685
1672
  };
1686
1673
  //# sourceMappingURL=aerogel-plugin-local-first.js.map