@aiao/rxdb-plugin-sync 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SyncManager.d.ts +16 -2
- package/dist/SyncManager.d.ts.map +1 -1
- package/dist/branch-materialization-source.d.ts +22 -0
- package/dist/branch-materialization-source.d.ts.map +1 -0
- package/dist/branch-utils.d.ts +32 -0
- package/dist/branch-utils.d.ts.map +1 -1
- package/dist/bulk-sync.d.ts.map +1 -1
- package/dist/cleanup-expired.d.ts.map +1 -1
- package/dist/get-repository-sync-status.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1972 -1472
- package/dist/plugin.d.ts +5 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/pull-batch.d.ts.map +1 -1
- package/dist/pull-conflict-utils.d.ts.map +1 -1
- package/dist/pull-repository.d.ts +20 -1
- package/dist/pull-repository.d.ts.map +1 -1
- package/dist/pull-round.d.ts +41 -0
- package/dist/pull-round.d.ts.map +1 -0
- package/dist/push-branch.d.ts +1 -1
- package/dist/push-branch.d.ts.map +1 -1
- package/dist/push-repository.d.ts +18 -2
- package/dist/push-repository.d.ts.map +1 -1
- package/dist/push.d.ts.map +1 -1
- package/dist/query-cache-outbox.d.ts.map +1 -1
- package/dist/sync-branches.d.ts +51 -5
- package/dist/sync-branches.d.ts.map +1 -1
- package/dist/sync-listeners.d.ts.map +1 -1
- package/dist/sync-repository.d.ts +3 -2
- package/dist/sync-repository.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/SyncManager.ts +28 -0
- package/src/branch-materialization-source.ts +445 -0
- package/src/branch-utils.ts +42 -5
- package/src/bulk-sync.ts +22 -11
- package/src/check-repository-updates.ts +1 -1
- package/src/cleanup-expired.ts +17 -3
- package/src/get-repository-sync-status.ts +7 -7
- package/src/index.ts +7 -2
- package/src/plugin.ts +9 -1
- package/src/pull-batch.ts +16 -40
- package/src/pull-conflict-utils.ts +4 -0
- package/src/pull-repository.ts +43 -44
- package/src/pull-round.ts +103 -0
- package/src/pull.ts +1 -1
- package/src/push-branch.ts +4 -3
- package/src/push-repository.ts +674 -135
- package/src/push.ts +3 -1
- package/src/query-cache-outbox.ts +82 -9
- package/src/sync-branches.ts +130 -10
- package/src/sync-listeners.ts +30 -10
- package/src/sync-repository.ts +11 -6
- package/dist/version.utils.d.ts +0 -3
- package/dist/version.utils.d.ts.map +0 -1
- package/src/version.utils.ts +0 -20
package/dist/index.js
CHANGED
|
@@ -1,164 +1,153 @@
|
|
|
1
|
-
import { ConflictDetectedEvent as e, ConflictPendingEvent as t, ENTITY_REMOTE_CREATE_EVENT as n, ENTITY_REMOTE_REMOVE_EVENT as r, ENTITY_REMOTE_UPDATE_EVENT as i,
|
|
2
|
-
import { combineLatest as
|
|
3
|
-
import { isIgnorableDetachedVersionEventError as
|
|
4
|
-
//#region src/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
UPDATE: {
|
|
11
|
-
kind: "discard",
|
|
12
|
-
repair: "drop"
|
|
13
|
-
},
|
|
14
|
-
DELETE: { kind: "noop" }
|
|
15
|
-
}, le = {
|
|
16
|
-
INSERT: "update",
|
|
17
|
-
UPDATE: "update",
|
|
18
|
-
DELETE: "delete"
|
|
19
|
-
}, ue = [/* @__PURE__ */ new Set(["DELETE"]), /* @__PURE__ */ new Set(["INSERT", "UPDATE"])], de = /* @__PURE__ */ new WeakMap();
|
|
20
|
-
function fe(e, t, n, r) {
|
|
21
|
-
let i = de.get(e) ?? /* @__PURE__ */ new Map();
|
|
22
|
-
de.set(e, i);
|
|
23
|
-
let o = `${t}:${n}`, s = i.get(o);
|
|
24
|
-
if (s) return s;
|
|
25
|
-
let c = me(e, t, n, r?.conflictResolver ?? new a()).finally(() => {
|
|
26
|
-
i.delete(o);
|
|
27
|
-
});
|
|
28
|
-
return i.set(o, c), c;
|
|
1
|
+
import { ConflictDetectedEvent as e, ConflictPendingEvent as t, ENTITY_REMOTE_CREATE_EVENT as n, ENTITY_REMOTE_REMOVE_EVENT as r, ENTITY_REMOTE_UPDATE_EVENT as i, InvalidBranchIdError as a, LWWConflictResolver as o, MAIN_BRANCH_ID as s, RelationKind as c, RepositorySyncBeginEvent as l, RepositorySyncCompleteEvent as u, RepositorySyncErrorEvent as d, RxDBBranch as f, RxDBChange as p, RxDBDependencyFailedError as m, RxDBError as h, RxDBPartialSyncError as g, RxDBPluginBase as _, RxDBSync as v, SWITCH_BRANCH_BEGIN as y, SWITCH_BRANCH_COMMIT as b, SYNC_DISABLED_REASON as x, SyncBeginEvent as S, SyncCompleteEvent as C, SyncErrorEvent as w, TrustedWriteIntent as T, assertSingleActiveBranch as E, assertUsableBranchId as D, branchMaterializationPageFingerprint as ee, buildOfflineWriteRepositoryRules as te, canonicalMaterializationJson as O, compactChanges as k, declareTrustedWrite as ne, findCurrentSyncRecord as re, getCurrentBranch as ie, getEntityMetadata as A, getLocalSystemRepositories as j, getOrCreateSyncRecord as M, getRemoteSystemRepositories as ae, getRxDBChangeEntityIdQueryValues as oe, getRxDBChangeKey as N, getRxDBEntityIdentityKey as se, getSyncCapability as P, getSyncConfig as ce, getSyncType as F, isRepositorySyncEnabled as I, isSystemEntity as le, needsPull as ue, repositoryKey as L, resolvePullIneligibility as de, resolvePushIneligibility as fe } from "@aiao/rxdb";
|
|
2
|
+
import { combineLatest as pe, firstValueFrom as R, merge as me } from "rxjs";
|
|
3
|
+
import { isIgnorableDetachedVersionEventError as he } from "@aiao/rxdb-plugin-history";
|
|
4
|
+
//#region src/branch-utils.ts
|
|
5
|
+
async function ge(e, t) {
|
|
6
|
+
if (t === s) return [t];
|
|
7
|
+
let { adapter: n } = await e.getLocalRepositories();
|
|
8
|
+
return _e(n.getRepository(f), t);
|
|
29
9
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
branchId: a.id,
|
|
49
|
-
syncType: i
|
|
50
|
-
}, () => e.entityManager.instantiate(g));
|
|
51
|
-
if (!P(l)) return {
|
|
52
|
-
...pe(t, n),
|
|
53
|
-
skipped: _
|
|
54
|
-
};
|
|
55
|
-
let u = await ye(s.getRepository(d), t, n, a.id, l.lastPushedChangeId);
|
|
56
|
-
if (u.length === 0) return pe(t, n);
|
|
57
|
-
let f = u.reduce((e, t) => t.id > e ? t.id : e, u[0].id), p = be(u), m = {
|
|
58
|
-
...pe(t, n),
|
|
59
|
-
originalCount: u.length
|
|
60
|
-
};
|
|
61
|
-
if (p.length === 0) return await c.update(l, {
|
|
62
|
-
lastPushedChangeId: f,
|
|
63
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
64
|
-
}), {
|
|
65
|
-
...m,
|
|
66
|
-
compacted: u.length,
|
|
67
|
-
watermark: f
|
|
68
|
-
};
|
|
69
|
-
let h = await I(e.remoteAdapter$), v = {
|
|
70
|
-
...m,
|
|
71
|
-
compacted: u.length - p.length,
|
|
72
|
-
restoreIds: [],
|
|
73
|
-
dropIds: [],
|
|
74
|
-
settled: /* @__PURE__ */ new Set()
|
|
75
|
-
}, y = await Ce(h, n, p, e, v);
|
|
76
|
-
if (y && await we(p, y, {
|
|
77
|
-
rxdb: e,
|
|
78
|
-
entity: n,
|
|
79
|
-
remoteAdapter: h,
|
|
80
|
-
conflictResolver: r,
|
|
81
|
-
run: v
|
|
82
|
-
}), await je(s, h, n, v), v.failures.length > 0) {
|
|
83
|
-
let e = Te(p, v.settled, f);
|
|
84
|
-
return e <= (l.lastPushedChangeId ?? 0) ? he(v) : (await c.update(l, {
|
|
85
|
-
lastPushedChangeId: e,
|
|
86
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
87
|
-
}), {
|
|
88
|
-
...he(v),
|
|
89
|
-
watermark: e
|
|
90
|
-
});
|
|
10
|
+
async function _e(e, t) {
|
|
11
|
+
let n = [t];
|
|
12
|
+
if (t === s) return n;
|
|
13
|
+
let r = t, i = /* @__PURE__ */ new Set([r]);
|
|
14
|
+
for (; r;) {
|
|
15
|
+
let t = (await e.find({
|
|
16
|
+
where: {
|
|
17
|
+
combinator: "and",
|
|
18
|
+
rules: [{
|
|
19
|
+
field: "id",
|
|
20
|
+
operator: "=",
|
|
21
|
+
value: r
|
|
22
|
+
}]
|
|
23
|
+
},
|
|
24
|
+
limit: 1
|
|
25
|
+
}))[0];
|
|
26
|
+
if (!t?.parentId || i.has(t.parentId)) break;
|
|
27
|
+
n.push(t.parentId), i.add(t.parentId), r = t.parentId;
|
|
91
28
|
}
|
|
92
|
-
return
|
|
93
|
-
lastPushedChangeId: f,
|
|
94
|
-
lastPushedAt: /* @__PURE__ */ new Date(),
|
|
95
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
96
|
-
}), {
|
|
97
|
-
...he(v),
|
|
98
|
-
watermark: f
|
|
99
|
-
};
|
|
29
|
+
return n;
|
|
100
30
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
failures: e.failures
|
|
111
|
-
});
|
|
112
|
-
async function ge(e) {
|
|
113
|
-
let t = await w(e), { adapter: n } = await E(e), r = await n.getRepository(g).find({ where: {
|
|
114
|
-
combinator: "and",
|
|
115
|
-
rules: [{
|
|
116
|
-
field: "branchId",
|
|
117
|
-
operator: "=",
|
|
118
|
-
value: t.id
|
|
119
|
-
}]
|
|
120
|
-
} }), i = x(e.config.entities, e.config.sync, r);
|
|
121
|
-
return i.length === 0 ? 0 : I(e.entityManager.getRepository(d).count({ where: {
|
|
122
|
-
combinator: "and",
|
|
123
|
-
rules: [
|
|
124
|
-
{
|
|
125
|
-
field: "branchId",
|
|
126
|
-
operator: "=",
|
|
127
|
-
value: t.id
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
field: "revertChangeId",
|
|
131
|
-
operator: "=",
|
|
132
|
-
value: null
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
field: "remoteId",
|
|
136
|
-
operator: "=",
|
|
137
|
-
value: null
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/dependency-graph.ts
|
|
33
|
+
function z(e) {
|
|
34
|
+
let t = /* @__PURE__ */ new Map();
|
|
35
|
+
for (let n of e) {
|
|
36
|
+
let e = `${n.namespace}:${n.name}`, r = {
|
|
37
|
+
repository: {
|
|
38
|
+
namespace: n.namespace,
|
|
39
|
+
entity: n.name
|
|
138
40
|
},
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
41
|
+
dependsOn: [],
|
|
42
|
+
requiredBy: []
|
|
43
|
+
};
|
|
44
|
+
if (n.relations) {
|
|
45
|
+
for (let e of n.relations) if (e.kind === c.MANY_TO_ONE || e.kind === c.ONE_TO_ONE) {
|
|
46
|
+
let t = e.mappedEntity, i = e.mappedNamespace || n.namespace;
|
|
47
|
+
r.dependsOn.push({
|
|
48
|
+
namespace: i,
|
|
49
|
+
entity: t
|
|
50
|
+
});
|
|
142
51
|
}
|
|
143
|
-
|
|
144
|
-
|
|
52
|
+
}
|
|
53
|
+
t.set(e, r);
|
|
54
|
+
}
|
|
55
|
+
for (let e of t.values()) for (let n of e.dependsOn) {
|
|
56
|
+
let r = t.get(`${n.namespace}:${n.entity}`);
|
|
57
|
+
r && r.requiredBy.push(e.repository);
|
|
58
|
+
}
|
|
59
|
+
return ve(t), t;
|
|
145
60
|
}
|
|
146
|
-
|
|
147
|
-
let
|
|
148
|
-
|
|
61
|
+
function ve(e) {
|
|
62
|
+
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = [];
|
|
63
|
+
function i(a) {
|
|
64
|
+
t.add(a), n.add(a), r.push(a);
|
|
65
|
+
let o = e.get(a);
|
|
66
|
+
if (!o) return n.delete(a), r.pop(), !1;
|
|
67
|
+
for (let e of o.dependsOn) {
|
|
68
|
+
let o = `${e.namespace}:${e.entity}`;
|
|
69
|
+
if (o !== a) {
|
|
70
|
+
if (!t.has(o)) {
|
|
71
|
+
if (i(o)) return !0;
|
|
72
|
+
} else if (n.has(o)) {
|
|
73
|
+
let e = r.indexOf(o), t = [...r.slice(e), o];
|
|
74
|
+
throw new h(`Circular dependency detected: ${t.join(" -> ")}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return n.delete(a), r.pop(), !1;
|
|
79
|
+
}
|
|
80
|
+
for (let n of e.keys()) t.has(n) || i(n);
|
|
149
81
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (!r) throw new p(`Entity not found for QueryCache outbox flush: ${t}/${n}`);
|
|
156
|
-
let i = N(T(r), e.config.sync);
|
|
157
|
-
if (i !== "querycache") throw new p(`flushQueryCacheOutbox only handles syncType 'querycache'; ${t}/${n} is '${i}'. Repositories with a changelog endpoint push through syncManager.push().`);
|
|
158
|
-
return i;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/pull-ancestor-changes.ts
|
|
84
|
+
async function ye(e, t, n) {
|
|
85
|
+
let { namespace: r, entity: i, sinceId: a, limit: o, filter: s } = t, c = [`${r}:${i}`];
|
|
86
|
+
return (await Promise.all(n.map((t) => e.pullChanges(a, o, c, s, t)))).flat().sort((e, t) => e.id - t.id).slice(0, o);
|
|
159
87
|
}
|
|
160
|
-
|
|
161
|
-
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/cascade-blocking.ts
|
|
90
|
+
function be(e, t, n, r) {
|
|
91
|
+
let i = e.get(t);
|
|
92
|
+
if (i) for (let e of i[r]) {
|
|
93
|
+
let t = n.get(L(e));
|
|
94
|
+
if (t) return {
|
|
95
|
+
dependency: e,
|
|
96
|
+
cause: t
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/pull-conflict-utils.ts
|
|
102
|
+
function B() {
|
|
103
|
+
return {
|
|
104
|
+
deletes: /* @__PURE__ */ new Map(),
|
|
105
|
+
updates: /* @__PURE__ */ new Map(),
|
|
106
|
+
inserts: /* @__PURE__ */ new Map()
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function V(e) {
|
|
110
|
+
return e.inserts.size + e.updates.size + e.deletes.size;
|
|
111
|
+
}
|
|
112
|
+
function xe(e, t) {
|
|
113
|
+
if (t.type === "INSERT") {
|
|
114
|
+
e.inserts.set(t.key, t.change);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (t.type === "UPDATE") {
|
|
118
|
+
e.updates.set(t.key, t.change);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
e.deletes.set(t.key, t.change);
|
|
122
|
+
}
|
|
123
|
+
function Se(e, t) {
|
|
124
|
+
let n = /* @__PURE__ */ new Map();
|
|
125
|
+
for (let t of e) {
|
|
126
|
+
let e = N(t), r = n.get(e);
|
|
127
|
+
(!r || t.id > r.id) && n.set(e, t);
|
|
128
|
+
}
|
|
129
|
+
let r = [], i = (e, t) => {
|
|
130
|
+
for (let [i, a] of e) {
|
|
131
|
+
let e = n.get(i);
|
|
132
|
+
e && r.push({
|
|
133
|
+
key: i,
|
|
134
|
+
entityId: e.entityId,
|
|
135
|
+
type: t,
|
|
136
|
+
change: a,
|
|
137
|
+
remote: {
|
|
138
|
+
...e,
|
|
139
|
+
type: t,
|
|
140
|
+
patch: a.patch ?? null,
|
|
141
|
+
inversePatch: a.inversePatch ?? null
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return i(t.inserts, "INSERT"), i(t.updates, "UPDATE"), i(t.deletes, "DELETE"), r;
|
|
147
|
+
}
|
|
148
|
+
async function Ce(e, t, n, r, i, a) {
|
|
149
|
+
if (a.length === 0) return /* @__PURE__ */ new Map();
|
|
150
|
+
let o = [
|
|
162
151
|
{
|
|
163
152
|
field: "namespace",
|
|
164
153
|
operator: "=",
|
|
@@ -179,835 +168,1080 @@ async function ye(e, t, n, r, i) {
|
|
|
179
168
|
operator: "=",
|
|
180
169
|
value: null
|
|
181
170
|
},
|
|
171
|
+
{
|
|
172
|
+
field: "rejectedAt",
|
|
173
|
+
operator: "=",
|
|
174
|
+
value: null
|
|
175
|
+
},
|
|
182
176
|
{
|
|
183
177
|
field: "revertChangeId",
|
|
184
178
|
operator: "=",
|
|
185
179
|
value: null
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
field: "entityId",
|
|
183
|
+
operator: "in",
|
|
184
|
+
value: oe(a)
|
|
186
185
|
}
|
|
187
186
|
];
|
|
188
|
-
|
|
187
|
+
i !== null && o.push({
|
|
189
188
|
field: "id",
|
|
190
189
|
operator: ">",
|
|
191
190
|
value: i
|
|
192
|
-
})
|
|
191
|
+
});
|
|
192
|
+
let s = await e.find({
|
|
193
193
|
where: {
|
|
194
194
|
combinator: "and",
|
|
195
|
-
rules:
|
|
195
|
+
rules: o
|
|
196
196
|
},
|
|
197
197
|
orderBy: [{
|
|
198
198
|
field: "id",
|
|
199
199
|
sort: "asc"
|
|
200
200
|
}]
|
|
201
|
+
}), c = /* @__PURE__ */ new Map();
|
|
202
|
+
for (let e of s) {
|
|
203
|
+
let t = N(e);
|
|
204
|
+
c.has(t) || c.set(t, []), c.get(t).push(e);
|
|
205
|
+
}
|
|
206
|
+
return c;
|
|
207
|
+
}
|
|
208
|
+
async function we(e, t, n) {
|
|
209
|
+
for (let r of t) await e.update(r, {
|
|
210
|
+
remoteId: n,
|
|
211
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
201
212
|
});
|
|
202
213
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
214
|
+
var Te = (e, t) => t ? Object.assign(Object.create(Object.getPrototypeOf(e)), e, { clientId: t }) : e;
|
|
215
|
+
async function Ee(n, r, i) {
|
|
216
|
+
let a = B(), o = [], s = new Map(n.map((e) => [e.key, e])), c = [];
|
|
217
|
+
for (let e of n) {
|
|
218
|
+
let t = r.get(e.key);
|
|
219
|
+
if (!t || t.length === 0) {
|
|
220
|
+
xe(a, e);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
o.push({
|
|
224
|
+
entityKey: e.key,
|
|
225
|
+
local: Te(t[t.length - 1], i.localClientId),
|
|
226
|
+
remote: e.remote
|
|
227
|
+
});
|
|
208
228
|
}
|
|
209
|
-
let
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
let
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
229
|
+
let l = 0;
|
|
230
|
+
if (o.length > 0) {
|
|
231
|
+
let { conflictResolver: n, changeRepo: u, dispatchEvent: d, repoLabel: f } = i, p = n.resolveAll ? await n.resolveAll(o) : await Promise.all(o.map((e) => n.resolve(e))), m = [];
|
|
232
|
+
for (let e = 0; e < o.length; e += 1) {
|
|
233
|
+
let t = o[e], n = p[e], i = s.get(t.entityKey), u = r.get(t.entityKey) ?? [];
|
|
234
|
+
if (i) {
|
|
235
|
+
if (n.type === "KEEP_LOCAL") {
|
|
236
|
+
l += 1;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (n.type === "KEEP_REMOTE") {
|
|
240
|
+
l += 1, c.push({
|
|
241
|
+
localChanges: u,
|
|
242
|
+
remoteId: i.remote.id
|
|
243
|
+
}), xe(a, i);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
m.push(t);
|
|
247
|
+
}
|
|
222
248
|
}
|
|
249
|
+
if (m.length > 0) throw d(new e(o, 0, m.length)), d(new t(m)), new h(`Unsupported conflict resolution returned during pull for ${f}. Only KEEP_LOCAL and KEEP_REMOTE can be applied automatically at runtime.`);
|
|
250
|
+
if (d(new e(o, o.length, 0)), !i.deferLocalChangeSupersession) for (let e of c) await we(u, e.localChanges, e.remoteId);
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
applyActions: a,
|
|
254
|
+
conflictsResolved: l,
|
|
255
|
+
localChangeSupersessions: c
|
|
223
256
|
};
|
|
224
|
-
return i(n.deletes, "DELETE"), i(n.updates, "UPDATE"), i(n.inserts, "INSERT"), r;
|
|
225
|
-
}
|
|
226
|
-
var xe = 100;
|
|
227
|
-
function Se(e, t) {
|
|
228
|
-
let n = [];
|
|
229
|
-
for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
|
|
230
|
-
return n;
|
|
231
257
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/pull-round.ts
|
|
260
|
+
var De = (e, t) => {
|
|
261
|
+
let n = [], r = [];
|
|
262
|
+
for (let i of e) i.clientId != null && i.clientId === t ? n.push(i) : r.push(i);
|
|
263
|
+
return {
|
|
264
|
+
ownChanges: n,
|
|
265
|
+
otherChanges: r
|
|
266
|
+
};
|
|
267
|
+
}, Oe = async (e, t) => {
|
|
268
|
+
let n = t.filter((e) => e.localId != null);
|
|
269
|
+
if (n.length === 0) return;
|
|
270
|
+
let r = await e.find({ where: {
|
|
271
|
+
combinator: "and",
|
|
272
|
+
rules: [
|
|
273
|
+
{
|
|
238
274
|
field: "id",
|
|
239
275
|
operator: "in",
|
|
240
|
-
value: n
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
276
|
+
value: n.map((e) => e.localId)
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
field: "remoteId",
|
|
280
|
+
operator: "=",
|
|
281
|
+
value: null
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
field: "rejectedAt",
|
|
285
|
+
operator: "=",
|
|
286
|
+
value: null
|
|
287
|
+
}
|
|
288
|
+
]
|
|
289
|
+
} });
|
|
290
|
+
if (r.length === 0) return;
|
|
291
|
+
let i = new Map(n.map((e) => [e.localId, e.id]));
|
|
292
|
+
for (let t of r) {
|
|
293
|
+
let n = i.get(t.id);
|
|
294
|
+
n != null && await e.update(t, { remoteId: n });
|
|
249
295
|
}
|
|
250
|
-
|
|
296
|
+
};
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/topological-sort.ts
|
|
299
|
+
function ke(e) {
|
|
300
|
+
return e === "pull" ? "dependsOn" : "requiredBy";
|
|
251
301
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (n.run.failures.length > 0) return;
|
|
255
|
-
let e = n.run.failures.length;
|
|
256
|
-
await Ee(i, t.get(i.entityId), n), n.run.failures.length === e && n.run.settled.add(i);
|
|
257
|
-
}
|
|
302
|
+
function Ae(e) {
|
|
303
|
+
return e === "DELETE" ? "push" : "pull";
|
|
258
304
|
}
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
for (let n of e) t.has(n) || (r === void 0 || n.minChangeId < r) && (r = n.minChangeId);
|
|
262
|
-
return r === void 0 ? n : r - 1;
|
|
305
|
+
function je(e) {
|
|
306
|
+
return ke(Ae(e));
|
|
263
307
|
}
|
|
264
|
-
|
|
265
|
-
let r =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
});
|
|
279
|
-
return;
|
|
308
|
+
function Me(e, t) {
|
|
309
|
+
let n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
|
|
310
|
+
function a(o) {
|
|
311
|
+
if (r.has(o)) return;
|
|
312
|
+
if (i.has(o)) throw new h(`Circular dependency detected at ${o}`);
|
|
313
|
+
i.add(o);
|
|
314
|
+
let s = e.get(o);
|
|
315
|
+
if (!s) throw new h(`Repository ${o} not found in dependency graph`);
|
|
316
|
+
let c = s[ke(t)];
|
|
317
|
+
for (let t of c) {
|
|
318
|
+
let n = `${t.namespace}:${t.entity}`;
|
|
319
|
+
n !== o && e.has(n) && a(n);
|
|
320
|
+
}
|
|
321
|
+
i.delete(o), r.add(o), n.push(s.repository);
|
|
280
322
|
}
|
|
281
|
-
|
|
323
|
+
for (let t of e.keys()) a(t);
|
|
324
|
+
return n;
|
|
282
325
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
let r = await n.resolve({
|
|
286
|
-
entityKey: e.key,
|
|
287
|
-
local: e.lastChange,
|
|
288
|
-
remote: Oe(e, t)
|
|
289
|
-
});
|
|
290
|
-
return r.type === "KEEP_LOCAL" ? {
|
|
291
|
-
kind: "replay",
|
|
292
|
-
verb: le[e.kind]
|
|
293
|
-
} : r.type === "KEEP_REMOTE" ? {
|
|
294
|
-
kind: "discard",
|
|
295
|
-
repair: "restore"
|
|
296
|
-
} : {
|
|
297
|
-
kind: "unresolved",
|
|
298
|
-
resolution: r.type
|
|
299
|
-
};
|
|
326
|
+
function Ne(e) {
|
|
327
|
+
return Me(e, "pull");
|
|
300
328
|
}
|
|
301
|
-
function
|
|
302
|
-
|
|
329
|
+
function Pe(e, t) {
|
|
330
|
+
return Me(e, Ae(t));
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/pull-repository.ts
|
|
334
|
+
function Fe(e) {
|
|
335
|
+
if (!e || typeof e != "object") return !1;
|
|
336
|
+
let t = e;
|
|
337
|
+
return (t.combinator === "and" || t.combinator === "or") && Array.isArray(t.rules);
|
|
338
|
+
}
|
|
339
|
+
function Ie() {
|
|
303
340
|
return {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
updatedAt: n
|
|
341
|
+
pulled: 0,
|
|
342
|
+
compacted: 0,
|
|
343
|
+
applied: 0,
|
|
344
|
+
hasMore: !1,
|
|
345
|
+
conflictsResolved: 0,
|
|
346
|
+
conflictsDeferred: 0,
|
|
347
|
+
persistedProgress: !1,
|
|
348
|
+
historyInvalidated: !1,
|
|
349
|
+
failures: []
|
|
314
350
|
};
|
|
315
351
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
352
|
+
function Le(e) {
|
|
353
|
+
if (!(e instanceof g)) return;
|
|
354
|
+
let t = e.result;
|
|
355
|
+
if (!t || typeof t != "object") return;
|
|
356
|
+
let n = t;
|
|
357
|
+
return typeof n.applied == "number" && typeof n.persistedProgress == "boolean" ? n : void 0;
|
|
358
|
+
}
|
|
359
|
+
var Re = {
|
|
360
|
+
limit: 1e3,
|
|
361
|
+
fetchAll: !1,
|
|
362
|
+
includeRelated: !0,
|
|
363
|
+
filter: void 0,
|
|
364
|
+
conflictResolver: void 0
|
|
365
|
+
};
|
|
366
|
+
async function ze(e, t, n, r) {
|
|
367
|
+
let i = {
|
|
368
|
+
...Re,
|
|
369
|
+
...r
|
|
370
|
+
}, a = e.rxdb;
|
|
371
|
+
a.dispatchEvent(new l("pull", t, n, i.includeRelated));
|
|
325
372
|
try {
|
|
326
|
-
await
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
373
|
+
let r = await Be(e, t, n, i);
|
|
374
|
+
return a.dispatchEvent(new u("pull", t, n, {
|
|
375
|
+
pulled: r.pulled,
|
|
376
|
+
compacted: r.compacted,
|
|
377
|
+
conflictsResolved: r.conflictsResolved,
|
|
378
|
+
conflictsDeferred: r.conflictsDeferred
|
|
379
|
+
})), r;
|
|
380
|
+
} catch (e) {
|
|
381
|
+
throw a.dispatchEvent(new d("pull", t, n, e)), e;
|
|
332
382
|
}
|
|
333
383
|
}
|
|
334
|
-
function
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
384
|
+
async function Be(e, t, n, r) {
|
|
385
|
+
let i = e.rxdb.config.entities.find((e) => {
|
|
386
|
+
let r = A(e);
|
|
387
|
+
return r.namespace === t && r.name === n;
|
|
388
|
+
});
|
|
389
|
+
if (!i) throw new h(`Entity not found: ${t}:${n}`);
|
|
390
|
+
let a = A(i), o = F(a, e.rxdb.entitySync), s = await de(e.rxdb, t, n, o);
|
|
391
|
+
if (s) throw new h(`Cannot pull repository ${t}:${n}: ${s}.`);
|
|
392
|
+
let c = r.filter;
|
|
393
|
+
if (o === "filter" && !c) {
|
|
394
|
+
let r = ce(a, e.rxdb.entitySync);
|
|
395
|
+
if (r?.remote?.filter) {
|
|
396
|
+
try {
|
|
397
|
+
c = r.remote.filter();
|
|
398
|
+
} catch (e) {
|
|
399
|
+
throw new h(`Filter function failed for ${t}:${n}: ${e instanceof Error ? e.message : String(e)}`);
|
|
400
|
+
}
|
|
401
|
+
if (c && !Fe(c)) throw new h(`Invalid RuleGroup returned by filter function for ${t}:${n}: RuleGroup must have 'combinator' ('and' | 'or') and 'rules' array properties.`);
|
|
402
|
+
}
|
|
343
403
|
}
|
|
344
|
-
|
|
404
|
+
let l = {
|
|
405
|
+
...r,
|
|
406
|
+
filter: c
|
|
407
|
+
};
|
|
408
|
+
return r.includeRelated ? await Ve(e, t, n, l) : await We(e, t, n, l);
|
|
345
409
|
}
|
|
346
|
-
async function
|
|
347
|
-
|
|
348
|
-
let
|
|
349
|
-
|
|
410
|
+
async function Ve(e, t, n, r) {
|
|
411
|
+
let i = z(e.rxdb.config.entities.map((e) => A(e))), a = new Map(e.rxdb.config.entities.map((e) => {
|
|
412
|
+
let t = A(e);
|
|
413
|
+
return [`${t.namespace}:${t.name}`, e];
|
|
414
|
+
})), o = Ne(i), s = `${t}:${n}`;
|
|
415
|
+
if (!i.get(s)) throw new h(`Repository ${t}:${n} not found in dependency graph`);
|
|
416
|
+
let c = /* @__PURE__ */ new Set([s]), l = (e) => {
|
|
417
|
+
let t = i.get(e);
|
|
418
|
+
if (t) for (let e of t.dependsOn) {
|
|
419
|
+
let t = `${e.namespace}:${e.entity}`;
|
|
420
|
+
c.has(t) || (c.add(t), l(t));
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
l(s);
|
|
424
|
+
let u = o.filter((e) => {
|
|
425
|
+
let t = `${e.namespace}:${e.entity}`;
|
|
426
|
+
return c.has(t);
|
|
427
|
+
}), d = [], f = [], p = /* @__PURE__ */ new Map();
|
|
428
|
+
for (let t of u) {
|
|
429
|
+
let n = await He(e, i, a, t, r, p);
|
|
430
|
+
d.push(n), n.error && (p.set(L(t), n.error), f.push({
|
|
431
|
+
repository: t,
|
|
432
|
+
error: n.error
|
|
433
|
+
}));
|
|
350
434
|
}
|
|
351
|
-
|
|
435
|
+
let m = d.find((e) => e.repository.namespace === t && e.repository.entity === n);
|
|
436
|
+
if (!m) throw new h("Internal error: target repository result not found");
|
|
437
|
+
m.relatedResults = d.filter((e) => e !== m), m.failures = f;
|
|
438
|
+
for (let e of m.relatedResults) m.persistedProgress ||= e.persistedProgress, m.historyInvalidated ||= e.historyInvalidated;
|
|
439
|
+
let [_] = f;
|
|
440
|
+
if (!m.success && _) throw !m.persistedProgress && f.length === 1 ? _.error : new g(m, _.error);
|
|
441
|
+
return m;
|
|
352
442
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
443
|
+
async function He(e, t, n, r, i, a) {
|
|
444
|
+
let o = L(r), s = be(t, o, a, "dependsOn");
|
|
445
|
+
if (s) return {
|
|
446
|
+
...Ie(),
|
|
447
|
+
repository: r,
|
|
448
|
+
success: !1,
|
|
449
|
+
skipped: `dependency ${L(s.dependency)} failed`,
|
|
450
|
+
error: new m(r, s.dependency, s.cause)
|
|
451
|
+
};
|
|
452
|
+
let c = n.get(o);
|
|
453
|
+
if (!c) throw new h(`Internal error: entity not found for cascade node ${o}`);
|
|
454
|
+
let l = A(c), u = F(l, e.rxdb.entitySync), d = await de(e.rxdb, r.namespace, r.entity, u);
|
|
455
|
+
if (d) return {
|
|
456
|
+
...Ie(),
|
|
457
|
+
repository: r,
|
|
458
|
+
success: !0,
|
|
459
|
+
skipped: d
|
|
460
|
+
};
|
|
461
|
+
try {
|
|
462
|
+
let t = await We(e, r.namespace, r.entity, {
|
|
463
|
+
...i,
|
|
464
|
+
filter: Ue(o, ce(l, e.rxdb.entitySync), u, i.filter),
|
|
465
|
+
includeRelated: !1
|
|
466
|
+
});
|
|
467
|
+
return t.success = !0, t;
|
|
468
|
+
} catch (e) {
|
|
469
|
+
let t = e instanceof Error ? e : Error(String(e)), n = t instanceof g ? t.cause : t;
|
|
470
|
+
return {
|
|
471
|
+
...Le(t) ?? Ie(),
|
|
472
|
+
repository: r,
|
|
473
|
+
success: !1,
|
|
474
|
+
error: n,
|
|
475
|
+
failures: [{
|
|
476
|
+
repository: r,
|
|
477
|
+
error: n
|
|
478
|
+
}]
|
|
479
|
+
};
|
|
373
480
|
}
|
|
374
|
-
return n;
|
|
375
481
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
let i =
|
|
380
|
-
if (i)
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
};
|
|
482
|
+
function Ue(e, t, n, r) {
|
|
483
|
+
if (n === "full") return;
|
|
484
|
+
if (n !== "filter") return r;
|
|
485
|
+
let i = t?.remote?.filter;
|
|
486
|
+
if (!i) return r;
|
|
487
|
+
let a;
|
|
488
|
+
try {
|
|
489
|
+
a = i();
|
|
490
|
+
} catch (t) {
|
|
491
|
+
throw new h(`Filter function failed for ${e}: ${t instanceof Error ? t.message : String(t)}`);
|
|
386
492
|
}
|
|
493
|
+
if (!Fe(a)) throw new h(`Invalid RuleGroup returned by filter function for ${e}: RuleGroup must have 'combinator' ('and' | 'or') and 'rules' array properties.`);
|
|
494
|
+
return a;
|
|
387
495
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
let
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
496
|
+
async function We(e, t, n, r) {
|
|
497
|
+
let i = e.rxdb;
|
|
498
|
+
if (!i.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
499
|
+
let { adapter: a } = await e.getRemoteRepositories(), { adapter: s } = await e.getLocalRepositories(), c = await e.getCurrentBranch(), l = await ge(e, c.id), u = s.getRepository(v), d = e.rxdb.config.entities.find((e) => {
|
|
500
|
+
let r = A(e);
|
|
501
|
+
return r.namespace === t && r.name === n;
|
|
502
|
+
}), f = A(d), m = F(f, e.rxdb.entitySync), _ = await M(u, {
|
|
503
|
+
namespace: t,
|
|
504
|
+
entity: n,
|
|
505
|
+
branchId: c.id,
|
|
506
|
+
syncType: m
|
|
507
|
+
}, () => i.entityManager.instantiate(v)), y = _.lastPullRemoteChangeId, b = 0, x = 0, S = 0, C = 0, w = !1, E, D, ee = r.conflictResolver ?? new o(), te = y ?? 0, O = B();
|
|
508
|
+
try {
|
|
509
|
+
do {
|
|
510
|
+
let e = await ye(a, {
|
|
511
|
+
namespace: t,
|
|
512
|
+
entity: n,
|
|
513
|
+
sinceId: te,
|
|
514
|
+
limit: r.limit,
|
|
515
|
+
filter: r.filter
|
|
516
|
+
}, l);
|
|
517
|
+
if (b += e.length, E = e.length >= r.limit, e.length === 0) {
|
|
518
|
+
await u.update(_, {
|
|
519
|
+
lastPulledAt: /* @__PURE__ */ new Date(),
|
|
520
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
407
521
|
});
|
|
522
|
+
break;
|
|
408
523
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
524
|
+
D = e[e.length - 1], te = D.id;
|
|
525
|
+
let { ownChanges: o, otherChanges: d } = De(e, i.context.clientId), f = 0;
|
|
526
|
+
await s.transaction(async (e) => {
|
|
527
|
+
let r = e.getRepository(p), a = e.getRepository(v);
|
|
528
|
+
if (await Oe(r, o), d.length > 0) {
|
|
529
|
+
k(d, O);
|
|
530
|
+
let a = V(O);
|
|
531
|
+
x += d.length - a;
|
|
532
|
+
let o = Se(d, O), { applyActions: s, conflictsResolved: l, localChangeSupersessions: u } = await Ee(o, await Ce(r, t, n, c.id, _.lastPushedChangeId, [...new Set(o.map((e) => e.entityId))]), {
|
|
533
|
+
changeRepo: r,
|
|
534
|
+
conflictResolver: ee,
|
|
535
|
+
dispatchEvent: (e) => i.dispatchEvent(e),
|
|
536
|
+
repoLabel: `${t}:${n}`,
|
|
537
|
+
deferLocalChangeSupersession: !0,
|
|
538
|
+
localClientId: i.context.clientId
|
|
539
|
+
});
|
|
540
|
+
C += l;
|
|
541
|
+
let p = V(s);
|
|
542
|
+
if (p > 0) {
|
|
543
|
+
ne(e, {
|
|
544
|
+
file: "pull-repository.ts",
|
|
545
|
+
symbol: "pullSingleRepository",
|
|
546
|
+
intent: T.remote_sync
|
|
547
|
+
}), await e.mergeChanges(s, void 0, !0);
|
|
548
|
+
for (let e of u) await we(r, e.localChanges, e.remoteId);
|
|
549
|
+
f = p;
|
|
550
|
+
}
|
|
551
|
+
O = B();
|
|
432
552
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
553
|
+
let s = D.id;
|
|
554
|
+
_ = await a.update(_, {
|
|
555
|
+
lastPullRemoteChangeId: s,
|
|
556
|
+
lastPulledAt: /* @__PURE__ */ new Date(),
|
|
557
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
558
|
+
});
|
|
559
|
+
}), w = !0, S += f;
|
|
560
|
+
} while (E && r.fetchAll);
|
|
561
|
+
} catch (e) {
|
|
562
|
+
throw w ? new g({
|
|
563
|
+
repository: {
|
|
564
|
+
namespace: t,
|
|
565
|
+
entity: n
|
|
566
|
+
},
|
|
567
|
+
pulled: b,
|
|
568
|
+
compacted: x,
|
|
569
|
+
applied: S,
|
|
570
|
+
hasMore: !0,
|
|
571
|
+
conflictsResolved: C,
|
|
572
|
+
conflictsDeferred: 0,
|
|
573
|
+
persistedProgress: !0,
|
|
574
|
+
historyInvalidated: S > 0,
|
|
575
|
+
failures: [{
|
|
576
|
+
repository: {
|
|
577
|
+
namespace: t,
|
|
578
|
+
entity: n
|
|
579
|
+
},
|
|
580
|
+
error: e instanceof Error ? e : Error(String(e))
|
|
581
|
+
}]
|
|
582
|
+
}, e instanceof Error ? e : Error(String(e))) : e;
|
|
436
583
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
584
|
+
return {
|
|
585
|
+
repository: {
|
|
586
|
+
namespace: t,
|
|
587
|
+
entity: n
|
|
588
|
+
},
|
|
589
|
+
pulled: b,
|
|
590
|
+
compacted: x,
|
|
591
|
+
applied: S,
|
|
592
|
+
hasMore: E,
|
|
593
|
+
conflictsResolved: C,
|
|
594
|
+
conflictsDeferred: 0,
|
|
595
|
+
persistedProgress: w,
|
|
596
|
+
historyInvalidated: S > 0,
|
|
597
|
+
failures: []
|
|
598
|
+
};
|
|
444
599
|
}
|
|
445
600
|
//#endregion
|
|
446
|
-
//#region src/
|
|
447
|
-
|
|
601
|
+
//#region src/branch-materialization-source.ts
|
|
602
|
+
var Ge = 1e3, Ke = (e) => typeof e == "object" && !!e && !Array.isArray(e), qe = (e) => Array.isArray(e) && e.every((e) => typeof e == "string"), Je = (e) => {
|
|
603
|
+
let t = e.frozenRemoteWatermark, { lineage: n, cutoffs: r, filters: i } = t;
|
|
604
|
+
if (!(qe(n) && Ke(r) && Ke(i) && e.syncScope.every((e) => typeof r[e] == "number" && e in i))) throw new h(`分支物化意图不是同步插件冻结的形状:${O(t)}`);
|
|
448
605
|
return {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
606
|
+
syncScope: e.syncScope,
|
|
607
|
+
lineage: n,
|
|
608
|
+
cutoffs: r,
|
|
609
|
+
filters: i
|
|
452
610
|
};
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
if (t.type === "UPDATE") {
|
|
463
|
-
e.updates.set(t.key, t.change);
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
e.deletes.set(t.key, t.change);
|
|
467
|
-
}
|
|
468
|
-
function Ie(e, t) {
|
|
469
|
-
let n = /* @__PURE__ */ new Map();
|
|
470
|
-
for (let t of e) {
|
|
471
|
-
let e = A(t), r = n.get(e);
|
|
472
|
-
(!r || t.id > r.id) && n.set(e, t);
|
|
473
|
-
}
|
|
474
|
-
let r = [], i = (e, t) => {
|
|
475
|
-
for (let [i, a] of e) {
|
|
476
|
-
let e = n.get(i);
|
|
477
|
-
e && r.push({
|
|
478
|
-
key: i,
|
|
479
|
-
entityId: e.entityId,
|
|
480
|
-
type: t,
|
|
481
|
-
change: a,
|
|
482
|
-
remote: {
|
|
483
|
-
...e,
|
|
484
|
-
type: t,
|
|
485
|
-
patch: a.patch ?? null,
|
|
486
|
-
inversePatch: a.inversePatch ?? null
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
}
|
|
611
|
+
}, Ye = (e) => {
|
|
612
|
+
let { repository: t, sinceId: n, lastId: r, done: i, changes: a } = e;
|
|
613
|
+
if (!(typeof t == "string" && typeof n == "number" && typeof r == "number" && typeof i == "boolean" && Array.isArray(a))) throw new h(`分支物化分页不是同步插件交出的形状:${O(e)}`);
|
|
614
|
+
return {
|
|
615
|
+
repository: t,
|
|
616
|
+
sinceId: n,
|
|
617
|
+
lastId: r,
|
|
618
|
+
done: i,
|
|
619
|
+
changes: a
|
|
490
620
|
};
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
621
|
+
}, Xe = (e, t) => {
|
|
622
|
+
for (let n of e.config.entities) {
|
|
623
|
+
let e = A(n);
|
|
624
|
+
if (L({
|
|
625
|
+
namespace: e.namespace,
|
|
626
|
+
entity: e.name
|
|
627
|
+
}) === t) return e;
|
|
628
|
+
}
|
|
629
|
+
throw new h(`分支物化范围里的仓库 ${t} 不在当前实体配置里`);
|
|
630
|
+
}, Ze = async (e, t) => (await e.find({
|
|
631
|
+
where: {
|
|
632
|
+
combinator: "and",
|
|
633
|
+
rules: [{
|
|
634
|
+
field: "id",
|
|
498
635
|
operator: "=",
|
|
499
636
|
value: t
|
|
637
|
+
}]
|
|
638
|
+
},
|
|
639
|
+
limit: 1
|
|
640
|
+
}))[0], Qe = async (e, t, n) => {
|
|
641
|
+
let r = await _e(t.branchRepository, n), i = Ne(z(e.config.entities.map((e) => A(e)))), a = [], o = {};
|
|
642
|
+
for (let r of i) {
|
|
643
|
+
let i = L(r), s = Xe(e, i), c = F(s, e.entitySync);
|
|
644
|
+
if (!P(c).pull) continue;
|
|
645
|
+
let l = await Ze(t.syncRepository, `${i}:${n}`);
|
|
646
|
+
I(l) && (a.push(i), o[i] = Ue(i, ce(s, e.entitySync), c, void 0) ?? null);
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
lineage: r,
|
|
650
|
+
syncScope: a,
|
|
651
|
+
filters: o
|
|
652
|
+
};
|
|
653
|
+
}, $e = (e) => ({
|
|
654
|
+
branchRepository: e.getRepository(f),
|
|
655
|
+
syncRepository: e.getRepository(v)
|
|
656
|
+
}), et = async (e) => {
|
|
657
|
+
if (!e.rxdb.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
658
|
+
let { adapter: t } = await e.getRemoteRepositories();
|
|
659
|
+
return t;
|
|
660
|
+
}, tt = async (e, t, n) => {
|
|
661
|
+
let r = await Promise.all(n.map((n) => e.getChangeCount(0, [t], n)));
|
|
662
|
+
return Math.max(0, ...r.map((e) => e.latestChangeId));
|
|
663
|
+
}, nt = (e, t) => {
|
|
664
|
+
if (!t) return {
|
|
665
|
+
index: 0,
|
|
666
|
+
sinceId: 0
|
|
667
|
+
};
|
|
668
|
+
let n = Ye(t.payload), r = e.syncScope.indexOf(n.repository);
|
|
669
|
+
if (r < 0) throw new h(`续拉游标指向的仓库 ${n.repository} 不在冻结范围里`);
|
|
670
|
+
return n.done ? {
|
|
671
|
+
index: r + 1,
|
|
672
|
+
sinceId: 0
|
|
673
|
+
} : {
|
|
674
|
+
index: r,
|
|
675
|
+
sinceId: n.lastId
|
|
676
|
+
};
|
|
677
|
+
}, rt = async (e, t, n, r, i) => {
|
|
678
|
+
let a = Xe(e, r), o = n.cutoffs[r], s = await ye(t, {
|
|
679
|
+
namespace: a.namespace,
|
|
680
|
+
entity: a.name,
|
|
681
|
+
sinceId: i,
|
|
682
|
+
limit: Ge,
|
|
683
|
+
filter: n.filters[r] ?? void 0
|
|
684
|
+
}, n.lineage), c = s.filter((e) => e.id <= o), l = c.at(-1)?.id ?? i, u = {
|
|
685
|
+
repository: r,
|
|
686
|
+
sinceId: i,
|
|
687
|
+
lastId: l,
|
|
688
|
+
done: s.length < Ge || c.length < s.length || l >= o,
|
|
689
|
+
changes: c.map(it)
|
|
690
|
+
};
|
|
691
|
+
return {
|
|
692
|
+
payload: u,
|
|
693
|
+
fingerprint: ee(u)
|
|
694
|
+
};
|
|
695
|
+
}, it = (e) => ({
|
|
696
|
+
id: e.id,
|
|
697
|
+
namespace: e.namespace,
|
|
698
|
+
entity: e.entity,
|
|
699
|
+
entityId: e.entityId,
|
|
700
|
+
branchId: e.branchId,
|
|
701
|
+
type: e.type,
|
|
702
|
+
patch: e.patch ?? null,
|
|
703
|
+
inversePatch: e.inversePatch ?? null,
|
|
704
|
+
createdAt: e.createdAt,
|
|
705
|
+
updatedAt: e.updatedAt
|
|
706
|
+
}), at = (e, t) => {
|
|
707
|
+
if (O(e.syncScope) !== O(t.syncScope)) return `同步范围变了:冻结时 ${e.syncScope.join(", ")},现在 ${t.syncScope.join(", ")}`;
|
|
708
|
+
if (O(e.lineage) !== O(t.lineage)) return `分支血缘变了:冻结时 ${e.lineage.join(" → ")},现在 ${t.lineage.join(" → ")}`;
|
|
709
|
+
let n = e.syncScope.filter((n) => O(e.filters[n]) !== O(t.filters[n]));
|
|
710
|
+
if (n.length > 0) return `行级过滤条件变了:${n.join(", ")}`;
|
|
711
|
+
}, ot = (e) => {
|
|
712
|
+
let t = e.rxdb;
|
|
713
|
+
return {
|
|
714
|
+
async freezeIntent(n) {
|
|
715
|
+
let { adapter: r } = await e.getLocalRepositories(), i = await Qe(t, {
|
|
716
|
+
branchRepository: r.getRepository(f),
|
|
717
|
+
syncRepository: r.getRepository(v)
|
|
718
|
+
}, n), a = await et(e), o = {};
|
|
719
|
+
for (let e of i.syncScope) o[e] = await tt(a, e, i.lineage);
|
|
720
|
+
let s = {
|
|
721
|
+
lineage: i.lineage,
|
|
722
|
+
cutoffs: o,
|
|
723
|
+
filters: i.filters
|
|
724
|
+
};
|
|
725
|
+
return {
|
|
726
|
+
syncScope: i.syncScope,
|
|
727
|
+
frozenRemoteWatermark: { ...s }
|
|
728
|
+
};
|
|
500
729
|
},
|
|
501
|
-
{
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
730
|
+
async *pages(n) {
|
|
731
|
+
let r = Je(n.intent), i = nt(r, n.previousPage), a = await et(e), o = i.sinceId;
|
|
732
|
+
for (let e = i.index; e < r.syncScope.length; e++, o = 0) {
|
|
733
|
+
let n = r.syncScope[e], i = o >= r.cutoffs[n];
|
|
734
|
+
for (; !i;) {
|
|
735
|
+
let e = await rt(t, a, r, n, o);
|
|
736
|
+
yield e, i = e.payload.done === !0, o = e.payload.lastId;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
510
739
|
},
|
|
511
|
-
{
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
740
|
+
async resolveIntentDrift(e) {
|
|
741
|
+
let n;
|
|
742
|
+
try {
|
|
743
|
+
n = Je(e.intent);
|
|
744
|
+
} catch (e) {
|
|
745
|
+
return e instanceof Error ? e.message : String(e);
|
|
746
|
+
}
|
|
747
|
+
let r = await Qe(t, $e(e.executor), e.targetBranchId);
|
|
748
|
+
return at(n, r);
|
|
515
749
|
},
|
|
516
|
-
{
|
|
517
|
-
|
|
518
|
-
operator: "=",
|
|
519
|
-
value: null
|
|
750
|
+
async projectPage(e) {
|
|
751
|
+
return k(Ye(e.page.payload).changes);
|
|
520
752
|
},
|
|
521
|
-
{
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
753
|
+
async settle(e) {
|
|
754
|
+
let n = Je(e.intent), r = e.executor.getRepository(v), i = /* @__PURE__ */ new Date();
|
|
755
|
+
for (let a of n.syncScope) {
|
|
756
|
+
let o = Xe(t, a), s = await M(r, {
|
|
757
|
+
namespace: o.namespace,
|
|
758
|
+
entity: o.name,
|
|
759
|
+
branchId: e.targetBranchId,
|
|
760
|
+
syncType: F(o, t.entitySync)
|
|
761
|
+
}, () => t.entityManager.instantiate(v));
|
|
762
|
+
await r.update(s, {
|
|
763
|
+
lastPullRemoteChangeId: n.cutoffs[a],
|
|
764
|
+
lastPulledAt: i,
|
|
765
|
+
updatedAt: i
|
|
766
|
+
});
|
|
767
|
+
}
|
|
525
768
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
return
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
for (let r of t) await e.update(r, {
|
|
550
|
-
remoteId: n,
|
|
551
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
769
|
+
};
|
|
770
|
+
}, st = {
|
|
771
|
+
INSERT: {
|
|
772
|
+
kind: "replay",
|
|
773
|
+
verb: "create"
|
|
774
|
+
},
|
|
775
|
+
UPDATE: {
|
|
776
|
+
kind: "discard",
|
|
777
|
+
repair: "drop"
|
|
778
|
+
},
|
|
779
|
+
DELETE: { kind: "noop" }
|
|
780
|
+
}, ct = {
|
|
781
|
+
INSERT: "update",
|
|
782
|
+
UPDATE: "update",
|
|
783
|
+
DELETE: "delete"
|
|
784
|
+
}, lt = [/* @__PURE__ */ new Set(["DELETE"]), /* @__PURE__ */ new Set(["INSERT", "UPDATE"])], ut = /* @__PURE__ */ new WeakMap();
|
|
785
|
+
function dt(e, t, n, r) {
|
|
786
|
+
let i = ut.get(e) ?? /* @__PURE__ */ new Map();
|
|
787
|
+
ut.set(e, i);
|
|
788
|
+
let a = `${t}:${n}`, s = i.get(a);
|
|
789
|
+
if (s) return s;
|
|
790
|
+
let c = pt(e, t, n, r?.conflictResolver ?? new o()).finally(() => {
|
|
791
|
+
i.delete(a);
|
|
552
792
|
});
|
|
793
|
+
return i.set(a, c), c;
|
|
553
794
|
}
|
|
554
|
-
var
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
let l =
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
795
|
+
var ft = (e, t) => ({
|
|
796
|
+
repository: {
|
|
797
|
+
namespace: e,
|
|
798
|
+
entity: t
|
|
799
|
+
},
|
|
800
|
+
originalCount: 0,
|
|
801
|
+
compacted: 0,
|
|
802
|
+
replayed: 0,
|
|
803
|
+
discarded: 0,
|
|
804
|
+
noop: 0,
|
|
805
|
+
watermark: null,
|
|
806
|
+
conflicts: [],
|
|
807
|
+
failures: []
|
|
808
|
+
});
|
|
809
|
+
async function pt(e, t, n, r) {
|
|
810
|
+
let i = _t(e, t, n), a = await ie(e), { adapter: o } = await j(e), s = o, c = s.getRepository(v), l = await M(c, {
|
|
811
|
+
namespace: t,
|
|
812
|
+
entity: n,
|
|
813
|
+
branchId: a.id,
|
|
814
|
+
syncType: i
|
|
815
|
+
}, () => e.entityManager.instantiate(v));
|
|
816
|
+
if (!I(l)) return {
|
|
817
|
+
...ft(t, n),
|
|
818
|
+
skipped: x
|
|
819
|
+
};
|
|
820
|
+
let u = s.getRepository(p), d = await vt(u, t, n, a.id, l.lastPushedChangeId);
|
|
821
|
+
if (d.length === 0) return ft(t, n);
|
|
822
|
+
let f = d.reduce((e, t) => t.id > e ? t.id : e, d[0].id), m = yt(d), h = {
|
|
823
|
+
...ft(t, n),
|
|
824
|
+
originalCount: d.length
|
|
825
|
+
};
|
|
826
|
+
if (m.length === 0) return await c.update(l, {
|
|
827
|
+
lastPushedChangeId: f,
|
|
828
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
829
|
+
}), {
|
|
830
|
+
...h,
|
|
831
|
+
compacted: d.length,
|
|
832
|
+
watermark: f
|
|
833
|
+
};
|
|
834
|
+
let g = await R(e.remoteAdapter$), _ = {
|
|
835
|
+
...h,
|
|
836
|
+
compacted: d.length - m.length,
|
|
837
|
+
restoreIds: [],
|
|
838
|
+
dropIds: [],
|
|
839
|
+
settled: /* @__PURE__ */ new Set()
|
|
840
|
+
}, y = await St(g, n, m, e, _);
|
|
841
|
+
if (y && await Ct(m, y, {
|
|
842
|
+
rxdb: e,
|
|
843
|
+
entity: n,
|
|
844
|
+
remoteAdapter: g,
|
|
845
|
+
conflictResolver: r,
|
|
846
|
+
run: _
|
|
847
|
+
}), await jt(s, g, n, _, {
|
|
848
|
+
changeRepo: u,
|
|
849
|
+
namespace: t,
|
|
850
|
+
branchId: a.id,
|
|
851
|
+
maxChangeId: f
|
|
852
|
+
}), _.failures.length > 0) {
|
|
853
|
+
let e = wt(m, _.settled, f);
|
|
854
|
+
return e <= (l.lastPushedChangeId ?? 0) ? mt(_) : (await c.update(l, {
|
|
855
|
+
lastPushedChangeId: e,
|
|
856
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
857
|
+
}), {
|
|
858
|
+
...mt(_),
|
|
859
|
+
watermark: e
|
|
860
|
+
});
|
|
591
861
|
}
|
|
592
|
-
return {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
862
|
+
return await c.update(l, {
|
|
863
|
+
lastPushedChangeId: f,
|
|
864
|
+
lastPushedAt: /* @__PURE__ */ new Date(),
|
|
865
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
866
|
+
}), {
|
|
867
|
+
...mt(_),
|
|
868
|
+
watermark: f
|
|
596
869
|
};
|
|
597
870
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
871
|
+
var mt = (e) => ({
|
|
872
|
+
repository: e.repository,
|
|
873
|
+
originalCount: e.originalCount,
|
|
874
|
+
compacted: e.compacted,
|
|
875
|
+
replayed: e.replayed,
|
|
876
|
+
discarded: e.discarded,
|
|
877
|
+
noop: e.noop,
|
|
878
|
+
watermark: e.watermark,
|
|
879
|
+
conflicts: e.restoreIds,
|
|
880
|
+
failures: e.failures
|
|
881
|
+
});
|
|
882
|
+
async function ht(e) {
|
|
883
|
+
let t = await ie(e), { adapter: n } = await j(e), r = await n.getRepository(v).find({ where: {
|
|
884
|
+
combinator: "and",
|
|
885
|
+
rules: [{
|
|
886
|
+
field: "branchId",
|
|
887
|
+
operator: "=",
|
|
888
|
+
value: t.id
|
|
889
|
+
}]
|
|
890
|
+
} }), i = te(e.config.entities, e.entitySync, r);
|
|
891
|
+
return i.length === 0 ? 0 : R(e.entityManager.getRepository(p).count({ where: {
|
|
892
|
+
combinator: "and",
|
|
893
|
+
rules: [
|
|
894
|
+
{
|
|
895
|
+
field: "branchId",
|
|
896
|
+
operator: "=",
|
|
897
|
+
value: t.id
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
field: "revertChangeId",
|
|
901
|
+
operator: "=",
|
|
902
|
+
value: null
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
field: "remoteId",
|
|
906
|
+
operator: "=",
|
|
907
|
+
value: null
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
field: "rejectedAt",
|
|
911
|
+
operator: "=",
|
|
912
|
+
value: null
|
|
913
|
+
},
|
|
914
|
+
{
|
|
915
|
+
combinator: "or",
|
|
916
|
+
rules: i
|
|
917
|
+
}
|
|
918
|
+
]
|
|
919
|
+
} }));
|
|
602
920
|
}
|
|
603
|
-
function
|
|
604
|
-
|
|
921
|
+
async function gt(e, t, n) {
|
|
922
|
+
let r = await ie(e), { adapter: i } = await j(e), a = i, o = await re(e, t, n), s = await vt(a.getRepository(p), t, n, r.id, o?.lastPushedChangeId ?? null);
|
|
923
|
+
return new Set(s.map((e) => String(e.entityId)));
|
|
605
924
|
}
|
|
606
|
-
function
|
|
607
|
-
|
|
925
|
+
function _t(e, t, n) {
|
|
926
|
+
let r = e.config.entities.find((e) => {
|
|
927
|
+
let r = A(e);
|
|
928
|
+
return r.namespace === t && r.name === n;
|
|
929
|
+
});
|
|
930
|
+
if (!r) throw new h(`Entity not found for QueryCache outbox flush: ${t}/${n}`);
|
|
931
|
+
let i = F(A(r), e.entitySync);
|
|
932
|
+
if (i !== "querycache") throw new h(`flushQueryCacheOutbox only handles syncType 'querycache'; ${t}/${n} is '${i}'. Repositories with a changelog endpoint push through syncManager.push().`);
|
|
933
|
+
return i;
|
|
608
934
|
}
|
|
609
|
-
function
|
|
610
|
-
let
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
935
|
+
async function vt(e, t, n, r, i) {
|
|
936
|
+
let a = [
|
|
937
|
+
{
|
|
938
|
+
field: "namespace",
|
|
939
|
+
operator: "=",
|
|
940
|
+
value: t
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
field: "entity",
|
|
944
|
+
operator: "=",
|
|
945
|
+
value: n
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
field: "branchId",
|
|
949
|
+
operator: "=",
|
|
950
|
+
value: r
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
field: "remoteId",
|
|
954
|
+
operator: "=",
|
|
955
|
+
value: null
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
field: "rejectedAt",
|
|
959
|
+
operator: "=",
|
|
960
|
+
value: null
|
|
961
|
+
},
|
|
962
|
+
{
|
|
963
|
+
field: "revertChangeId",
|
|
964
|
+
operator: "=",
|
|
965
|
+
value: null
|
|
621
966
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
let t = e;
|
|
638
|
-
return (t.combinator === "and" || t.combinator === "or") && Array.isArray(t.rules);
|
|
967
|
+
];
|
|
968
|
+
return i !== null && a.push({
|
|
969
|
+
field: "id",
|
|
970
|
+
operator: ">",
|
|
971
|
+
value: i
|
|
972
|
+
}), e.find({
|
|
973
|
+
where: {
|
|
974
|
+
combinator: "and",
|
|
975
|
+
rules: a
|
|
976
|
+
},
|
|
977
|
+
orderBy: [{
|
|
978
|
+
field: "id",
|
|
979
|
+
sort: "asc"
|
|
980
|
+
}]
|
|
981
|
+
});
|
|
639
982
|
}
|
|
640
|
-
function
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
983
|
+
function yt(e) {
|
|
984
|
+
let t = /* @__PURE__ */ new Map();
|
|
985
|
+
for (let n of e) {
|
|
986
|
+
let e = N(n), r = t.get(e) ?? [];
|
|
987
|
+
r.push(n), t.set(e, r);
|
|
988
|
+
}
|
|
989
|
+
let n = k(e), r = [], i = (e, n) => {
|
|
990
|
+
for (let [i, a] of e) {
|
|
991
|
+
let e = t.get(i);
|
|
992
|
+
if (!e?.length) throw new h(`Missing source changes for compacted QueryCache action: ${i}`);
|
|
993
|
+
let o = e[e.length - 1], s = e.reduce((e, t) => t.id < e ? t.id : e, e[0].id);
|
|
994
|
+
r.push({
|
|
995
|
+
key: i,
|
|
996
|
+
entityId: String(o.entityId),
|
|
997
|
+
kind: n,
|
|
998
|
+
action: a,
|
|
999
|
+
lastChange: o,
|
|
1000
|
+
minChangeId: s
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
651
1003
|
};
|
|
1004
|
+
return i(n.deletes, "DELETE"), i(n.updates, "UPDATE"), i(n.inserts, "INSERT"), r;
|
|
652
1005
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
let
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
return typeof n.applied == "number" && typeof n.persistedProgress == "boolean" ? n : void 0;
|
|
1006
|
+
var bt = 100;
|
|
1007
|
+
function xt(e, t) {
|
|
1008
|
+
let n = [];
|
|
1009
|
+
for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
|
|
1010
|
+
return n;
|
|
659
1011
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
a.dispatchEvent(new s("pull", t, n, i.includeRelated));
|
|
673
|
-
try {
|
|
674
|
-
let r = await Qe(e, t, n, i);
|
|
675
|
-
return a.dispatchEvent(new c("pull", t, n, {
|
|
676
|
-
pulled: r.pulled,
|
|
677
|
-
compacted: r.compacted,
|
|
678
|
-
conflictsResolved: r.conflictsResolved,
|
|
679
|
-
conflictsDeferred: r.conflictsDeferred
|
|
680
|
-
})), r;
|
|
1012
|
+
async function St(e, t, n, r, i) {
|
|
1013
|
+
let a = n.map((e) => e.entityId), o = /* @__PURE__ */ new Map();
|
|
1014
|
+
for (let n of xt(a, bt)) try {
|
|
1015
|
+
let r = await R(e.fetchMetadata(t, {
|
|
1016
|
+
combinator: "and",
|
|
1017
|
+
rules: [{
|
|
1018
|
+
field: "id",
|
|
1019
|
+
operator: "in",
|
|
1020
|
+
value: n
|
|
1021
|
+
}]
|
|
1022
|
+
}));
|
|
1023
|
+
for (let e of r) o.set(e.id, e.updatedAt);
|
|
681
1024
|
} catch (e) {
|
|
682
|
-
|
|
1025
|
+
return r.reachability.report(e), i.failures.push({
|
|
1026
|
+
entityId: null,
|
|
1027
|
+
error: e instanceof Error ? e : Error(String(e))
|
|
1028
|
+
}), null;
|
|
683
1029
|
}
|
|
1030
|
+
return r.reachability.report(null), o;
|
|
684
1031
|
}
|
|
685
|
-
async function
|
|
686
|
-
let i
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
if (!i) throw new p(`Entity not found: ${t}:${n}`);
|
|
691
|
-
let a = T(i), o = N(a, e.rxdb.config.sync), s = await re(e.rxdb, t, n, o);
|
|
692
|
-
if (s) throw new p(`Cannot pull repository ${t}:${n}: ${s}.`);
|
|
693
|
-
let c = r.filter;
|
|
694
|
-
if (o === "filter" && !c) {
|
|
695
|
-
let e = a.sync;
|
|
696
|
-
if (e?.remote?.filter) {
|
|
697
|
-
try {
|
|
698
|
-
c = e.remote.filter();
|
|
699
|
-
} catch (e) {
|
|
700
|
-
throw new p(`Filter function failed for ${t}:${n}: ${e instanceof Error ? e.message : String(e)}`);
|
|
701
|
-
}
|
|
702
|
-
if (c && !qe(c)) throw new p(`Invalid RuleGroup returned by filter function for ${t}:${n}: RuleGroup must have 'combinator' ('and' | 'or') and 'rules' array properties.`);
|
|
703
|
-
}
|
|
1032
|
+
async function Ct(e, t, n) {
|
|
1033
|
+
for (let r of lt) for (let i of e.filter((e) => r.has(e.kind))) {
|
|
1034
|
+
if (n.run.failures.length > 0) return;
|
|
1035
|
+
let e = n.run.failures.length;
|
|
1036
|
+
await Tt(i, t.get(i.entityId), n), n.run.failures.length === e && n.run.settled.add(i);
|
|
704
1037
|
}
|
|
705
|
-
let l = {
|
|
706
|
-
...r,
|
|
707
|
-
filter: c
|
|
708
|
-
};
|
|
709
|
-
return r.includeRelated ? await $e(e, t, n, l) : await nt(e, t, n, l);
|
|
710
1038
|
}
|
|
711
|
-
|
|
712
|
-
let
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
})), o = Ge(i), s = `${t}:${n}`;
|
|
716
|
-
if (!i.get(s)) throw new p(`Repository ${t}:${n} not found in dependency graph`);
|
|
717
|
-
let c = /* @__PURE__ */ new Set([s]), l = (e) => {
|
|
718
|
-
let t = i.get(e);
|
|
719
|
-
if (t) for (let e of t.dependsOn) {
|
|
720
|
-
let t = `${e.namespace}:${e.entity}`;
|
|
721
|
-
c.has(t) || (c.add(t), l(t));
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
l(s);
|
|
725
|
-
let u = o.filter((e) => {
|
|
726
|
-
let t = `${e.namespace}:${e.entity}`;
|
|
727
|
-
return c.has(t);
|
|
728
|
-
}), d = [], f = [], h = /* @__PURE__ */ new Map();
|
|
729
|
-
for (let t of u) {
|
|
730
|
-
let n = await et(e, i, a, t, r, h);
|
|
731
|
-
d.push(n), n.error && (h.set(F(t), n.error), f.push({
|
|
732
|
-
repository: t,
|
|
733
|
-
error: n.error
|
|
734
|
-
}));
|
|
735
|
-
}
|
|
736
|
-
let g = d.find((e) => e.repository.namespace === t && e.repository.entity === n);
|
|
737
|
-
if (!g) throw new p("Internal error: target repository result not found");
|
|
738
|
-
g.relatedResults = d.filter((e) => e !== g), g.failures = f;
|
|
739
|
-
for (let e of g.relatedResults) g.persistedProgress ||= e.persistedProgress, g.historyInvalidated ||= e.historyInvalidated;
|
|
740
|
-
let [_] = f;
|
|
741
|
-
if (!g.success && _) throw !g.persistedProgress && f.length === 1 ? _.error : new m(g, _.error);
|
|
742
|
-
return g;
|
|
1039
|
+
function wt(e, t, n) {
|
|
1040
|
+
let r;
|
|
1041
|
+
for (let n of e) t.has(n) || (r === void 0 || n.minChangeId < r) && (r = n.minChangeId);
|
|
1042
|
+
return r === void 0 ? n : r - 1;
|
|
743
1043
|
}
|
|
744
|
-
async function
|
|
745
|
-
let
|
|
746
|
-
if (
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
if (
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
repository: r,
|
|
759
|
-
success: !0,
|
|
760
|
-
skipped: d
|
|
761
|
-
};
|
|
762
|
-
try {
|
|
763
|
-
let t = await nt(e, r.namespace, r.entity, {
|
|
764
|
-
...i,
|
|
765
|
-
filter: tt(o, l, u, i.filter),
|
|
766
|
-
includeRelated: !1
|
|
1044
|
+
async function Tt(e, t, n) {
|
|
1045
|
+
let r = await Et(e, t, n.conflictResolver), { run: i } = n;
|
|
1046
|
+
if (r.kind === "noop") {
|
|
1047
|
+
i.noop += 1;
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
if (r.kind === "discard") {
|
|
1051
|
+
i.discarded += 1, (r.repair === "restore" ? i.restoreIds : i.dropIds).push(e.entityId);
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
if (r.kind === "unresolved") {
|
|
1055
|
+
i.failures.push({
|
|
1056
|
+
entityId: e.entityId,
|
|
1057
|
+
error: new h(`Unsupported conflict resolution '${r.resolution}' during QueryCache outbox replay for ${e.key}. Only KEEP_LOCAL and KEEP_REMOTE can be applied over REST verbs.`)
|
|
767
1058
|
});
|
|
768
|
-
return
|
|
769
|
-
} catch (e) {
|
|
770
|
-
let t = e instanceof Error ? e : Error(String(e)), n = t instanceof m ? t.cause : t;
|
|
771
|
-
return {
|
|
772
|
-
...Ye(t) ?? Je(),
|
|
773
|
-
repository: r,
|
|
774
|
-
success: !1,
|
|
775
|
-
error: n,
|
|
776
|
-
failures: [{
|
|
777
|
-
repository: r,
|
|
778
|
-
error: n
|
|
779
|
-
}]
|
|
780
|
-
};
|
|
1059
|
+
return;
|
|
781
1060
|
}
|
|
1061
|
+
await Ot(e, r.verb, n);
|
|
782
1062
|
}
|
|
783
|
-
function
|
|
784
|
-
if (
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
|
|
1063
|
+
async function Et(e, t, n) {
|
|
1064
|
+
if (t === void 0) return st[e.kind];
|
|
1065
|
+
let r = await n.resolve({
|
|
1066
|
+
entityKey: e.key,
|
|
1067
|
+
local: e.lastChange,
|
|
1068
|
+
remote: Dt(e, t)
|
|
1069
|
+
});
|
|
1070
|
+
return r.type === "KEEP_LOCAL" ? {
|
|
1071
|
+
kind: "replay",
|
|
1072
|
+
verb: ct[e.kind]
|
|
1073
|
+
} : r.type === "KEEP_REMOTE" ? {
|
|
1074
|
+
kind: "discard",
|
|
1075
|
+
repair: "restore"
|
|
1076
|
+
} : {
|
|
1077
|
+
kind: "unresolved",
|
|
1078
|
+
resolution: r.type
|
|
1079
|
+
};
|
|
796
1080
|
}
|
|
797
|
-
|
|
798
|
-
let
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
do {
|
|
811
|
-
let e = await Pe(o, {
|
|
812
|
-
namespace: t,
|
|
813
|
-
entity: n,
|
|
814
|
-
sinceId: j,
|
|
815
|
-
limit: r.limit,
|
|
816
|
-
filter: r.filter
|
|
817
|
-
}, l);
|
|
818
|
-
if (b += e.length, O = e.length >= r.limit, e.length === 0) {
|
|
819
|
-
await u.update(v, {
|
|
820
|
-
lastPulledAt: /* @__PURE__ */ new Date(),
|
|
821
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
822
|
-
});
|
|
823
|
-
break;
|
|
824
|
-
}
|
|
825
|
-
k = e[e.length - 1], j = k.id;
|
|
826
|
-
let a = i.context.clientId, f = [], p = [];
|
|
827
|
-
for (let t of e) t.clientId != null && t.clientId === a ? f.push(t) : p.push(t);
|
|
828
|
-
let m = 0;
|
|
829
|
-
await s.transaction(async (e) => {
|
|
830
|
-
let r = e.getRepository(d), a = e.getRepository(g), o = f.filter((e) => e.localId != null);
|
|
831
|
-
if (o.length > 0) {
|
|
832
|
-
let e = o.map((e) => e.localId), t = await r.find({ where: {
|
|
833
|
-
combinator: "and",
|
|
834
|
-
rules: [{
|
|
835
|
-
field: "id",
|
|
836
|
-
operator: "in",
|
|
837
|
-
value: e
|
|
838
|
-
}]
|
|
839
|
-
} }), n = new Map(t.map((e) => [e.id, e]));
|
|
840
|
-
for (let e of o) {
|
|
841
|
-
let t = n.get(e.localId);
|
|
842
|
-
t && t.remoteId == null && await r.update(t, { remoteId: e.id });
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
if (p.length > 0) {
|
|
846
|
-
S(p, M);
|
|
847
|
-
let a = B(M);
|
|
848
|
-
x += p.length - a;
|
|
849
|
-
let o = Ie(p, M), { applyActions: s, conflictsResolved: l, localChangeSupersessions: u } = await Be(o, await Le(r, t, n, c.id, v.lastPushedChangeId, [...new Set(o.map((e) => e.entityId))]), {
|
|
850
|
-
changeRepo: r,
|
|
851
|
-
conflictResolver: A,
|
|
852
|
-
dispatchEvent: (e) => i.dispatchEvent(e),
|
|
853
|
-
repoLabel: `${t}:${n}`,
|
|
854
|
-
deferLocalChangeSupersession: !0,
|
|
855
|
-
localClientId: i.context.clientId
|
|
856
|
-
});
|
|
857
|
-
w += l;
|
|
858
|
-
let d = B(s);
|
|
859
|
-
if (d > 0) {
|
|
860
|
-
await e.mergeChanges(s, void 0, !0);
|
|
861
|
-
for (let e of u) await Re(r, e.localChanges, e.remoteId);
|
|
862
|
-
m = d;
|
|
863
|
-
}
|
|
864
|
-
M = z();
|
|
865
|
-
}
|
|
866
|
-
let s = k.id;
|
|
867
|
-
v = await a.update(v, {
|
|
868
|
-
lastPullRemoteChangeId: s,
|
|
869
|
-
lastPulledAt: /* @__PURE__ */ new Date(),
|
|
870
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
871
|
-
});
|
|
872
|
-
}), E = !0, C += m;
|
|
873
|
-
} while (O && r.fetchAll);
|
|
874
|
-
} catch (e) {
|
|
875
|
-
throw E ? new m({
|
|
876
|
-
repository: {
|
|
877
|
-
namespace: t,
|
|
878
|
-
entity: n
|
|
879
|
-
},
|
|
880
|
-
pulled: b,
|
|
881
|
-
compacted: x,
|
|
882
|
-
applied: C,
|
|
883
|
-
hasMore: !0,
|
|
884
|
-
conflictsResolved: w,
|
|
885
|
-
conflictsDeferred: 0,
|
|
886
|
-
persistedProgress: !0,
|
|
887
|
-
historyInvalidated: C > 0,
|
|
888
|
-
failures: [{
|
|
889
|
-
repository: {
|
|
890
|
-
namespace: t,
|
|
891
|
-
entity: n
|
|
892
|
-
},
|
|
893
|
-
error: e instanceof Error ? e : Error(String(e))
|
|
894
|
-
}]
|
|
895
|
-
}, e instanceof Error ? e : Error(String(e))) : e;
|
|
896
|
-
}
|
|
897
|
-
return {
|
|
898
|
-
repository: {
|
|
899
|
-
namespace: t,
|
|
900
|
-
entity: n
|
|
901
|
-
},
|
|
902
|
-
pulled: b,
|
|
903
|
-
compacted: x,
|
|
904
|
-
applied: C,
|
|
905
|
-
hasMore: O,
|
|
906
|
-
conflictsResolved: w,
|
|
907
|
-
conflictsDeferred: 0,
|
|
908
|
-
persistedProgress: E,
|
|
909
|
-
historyInvalidated: C > 0,
|
|
910
|
-
failures: []
|
|
1081
|
+
function Dt(e, t) {
|
|
1082
|
+
let n = new Date(t);
|
|
1083
|
+
return {
|
|
1084
|
+
id: 0,
|
|
1085
|
+
namespace: e.lastChange.namespace,
|
|
1086
|
+
entity: e.lastChange.entity,
|
|
1087
|
+
entityId: e.lastChange.entityId,
|
|
1088
|
+
branchId: e.lastChange.branchId,
|
|
1089
|
+
type: e.kind,
|
|
1090
|
+
patch: null,
|
|
1091
|
+
inversePatch: null,
|
|
1092
|
+
createdAt: n,
|
|
1093
|
+
updatedAt: n
|
|
911
1094
|
};
|
|
912
1095
|
}
|
|
1096
|
+
async function Ot(e, t, n) {
|
|
1097
|
+
let { entity: r, remoteAdapter: i, run: a, rxdb: o } = n, s = kt(i, r, e, t);
|
|
1098
|
+
if (!s) {
|
|
1099
|
+
a.failures.push({
|
|
1100
|
+
entityId: e.entityId,
|
|
1101
|
+
error: new h(`Remote adapter does not support ${t} operation for ${r}`)
|
|
1102
|
+
});
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
try {
|
|
1106
|
+
await R(s), o.reachability.report(null), a.replayed += 1;
|
|
1107
|
+
} catch (t) {
|
|
1108
|
+
o.reachability.report(t), a.failures.push({
|
|
1109
|
+
entityId: e.entityId,
|
|
1110
|
+
error: t instanceof Error ? t : Error(String(t))
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
function kt(e, t, n, r) {
|
|
1115
|
+
if (r === "delete") return e.delete ? e.delete(t, [n.entityId]) : null;
|
|
1116
|
+
let i = n.action.patch ?? {};
|
|
1117
|
+
if (r === "create") {
|
|
1118
|
+
let r = {
|
|
1119
|
+
id: n.entityId,
|
|
1120
|
+
...i
|
|
1121
|
+
};
|
|
1122
|
+
return e.create ? e.create(t, r) : null;
|
|
1123
|
+
}
|
|
1124
|
+
return e.update ? e.update(t, n.entityId, i) : null;
|
|
1125
|
+
}
|
|
1126
|
+
async function At(e, t) {
|
|
1127
|
+
let n = await vt(e.changeRepo, e.namespace, t, e.branchId, e.maxChangeId);
|
|
1128
|
+
return new Set(n.map((e) => String(e.entityId)));
|
|
1129
|
+
}
|
|
1130
|
+
async function jt(e, t, n, r, i) {
|
|
1131
|
+
if (r.restoreIds.length === 0 && r.dropIds.length === 0) return;
|
|
1132
|
+
let a = r.restoreIds.length > 0 ? await R(t.findByIds(n, r.restoreIds)) : [], o = await At(i, n), s = a.filter((e) => !o.has(e.id));
|
|
1133
|
+
s.length > 0 && await R(e.upsertMany(n, s));
|
|
1134
|
+
let c = r.dropIds.filter((e) => !o.has(e));
|
|
1135
|
+
c.length > 0 && await R(e.deleteByIds(n, c));
|
|
1136
|
+
}
|
|
913
1137
|
//#endregion
|
|
914
1138
|
//#region src/push-repository.ts
|
|
915
|
-
var
|
|
1139
|
+
var Mt = {
|
|
916
1140
|
batchSize: 1e3,
|
|
917
1141
|
includeRelated: !0
|
|
918
1142
|
};
|
|
919
|
-
function
|
|
1143
|
+
function Nt(e) {
|
|
920
1144
|
if (!Number.isSafeInteger(e) || e <= 0) throw RangeError("batchSize must be a positive safe integer");
|
|
921
1145
|
}
|
|
922
|
-
function
|
|
923
|
-
if (!(e instanceof
|
|
1146
|
+
function Pt(e) {
|
|
1147
|
+
if (!(e instanceof g)) return;
|
|
924
1148
|
let t = e.result;
|
|
925
1149
|
if (!t || typeof t != "object") return;
|
|
926
1150
|
let n = t;
|
|
927
1151
|
return typeof n.pushed == "number" && typeof n.originalCount == "number" ? n : void 0;
|
|
928
1152
|
}
|
|
929
|
-
function
|
|
1153
|
+
function Ft(e) {
|
|
930
1154
|
let { error: t } = e;
|
|
931
|
-
throw t ? e.pushed === 0 ? t : new
|
|
932
|
-
}
|
|
933
|
-
async function
|
|
934
|
-
let
|
|
935
|
-
batchSize: r?.batchSize === void 0 ?
|
|
936
|
-
includeRelated: r?.includeRelated === void 0 ?
|
|
937
|
-
},
|
|
938
|
-
|
|
939
|
-
let
|
|
1155
|
+
throw t ? e.pushed === 0 ? t : new g(e, t) : new h(`Internal error: repository ${L(e.repository)} failed without an error`);
|
|
1156
|
+
}
|
|
1157
|
+
async function It(e, t, n, r, i) {
|
|
1158
|
+
let a = {
|
|
1159
|
+
batchSize: r?.batchSize === void 0 ? Mt.batchSize : r.batchSize,
|
|
1160
|
+
includeRelated: r?.includeRelated === void 0 ? Mt.includeRelated : r.includeRelated
|
|
1161
|
+
}, o = e.rxdb;
|
|
1162
|
+
o.dispatchEvent(new l("push", t, n, a.includeRelated));
|
|
1163
|
+
let s = e.pushInFlight.session(), c = [], f = () => {
|
|
1164
|
+
i ? i.push(...c) : gn(e, c);
|
|
1165
|
+
};
|
|
940
1166
|
try {
|
|
941
|
-
|
|
942
|
-
let r
|
|
943
|
-
|
|
1167
|
+
Nt(a.batchSize);
|
|
1168
|
+
let r;
|
|
1169
|
+
try {
|
|
1170
|
+
r = await Lt(e, t, n, a, s, c);
|
|
1171
|
+
} finally {
|
|
1172
|
+
f();
|
|
1173
|
+
}
|
|
1174
|
+
return o.dispatchEvent(new u("push", t, n, {
|
|
944
1175
|
pushed: r.pushed,
|
|
945
1176
|
compacted: r.compacted,
|
|
946
1177
|
failed: r.failed
|
|
947
1178
|
})), r;
|
|
948
1179
|
} catch (e) {
|
|
949
|
-
throw
|
|
1180
|
+
throw o.dispatchEvent(new d("push", t, n, e)), e;
|
|
950
1181
|
} finally {
|
|
951
|
-
|
|
1182
|
+
s.release();
|
|
952
1183
|
}
|
|
953
1184
|
}
|
|
954
|
-
async function
|
|
955
|
-
let
|
|
956
|
-
let r =
|
|
1185
|
+
async function Lt(e, t, n, r, i, a) {
|
|
1186
|
+
let o = e.rxdb.config.entities.find((e) => {
|
|
1187
|
+
let r = A(e);
|
|
957
1188
|
return r.namespace === t && r.name === n;
|
|
958
1189
|
});
|
|
959
|
-
if (!
|
|
960
|
-
let
|
|
961
|
-
if (
|
|
962
|
-
return r.includeRelated ? await
|
|
963
|
-
}
|
|
964
|
-
async function
|
|
965
|
-
let
|
|
966
|
-
if (!
|
|
967
|
-
let
|
|
968
|
-
let t =
|
|
1190
|
+
if (!o) throw new h(`Entity not found: ${t}:${n}`);
|
|
1191
|
+
let s = A(o), c = await fe(e.rxdb, t, n, F(s, e.rxdb.entitySync));
|
|
1192
|
+
if (c) throw new h(`Cannot push repository ${t}:${n}: ${c}.`);
|
|
1193
|
+
return r.includeRelated ? await Rt(e, t, n, r, i, a) : await _n(e, t, n, r, i, a);
|
|
1194
|
+
}
|
|
1195
|
+
async function Rt(e, t, n, r, i, a) {
|
|
1196
|
+
let o = z(e.rxdb.config.entities.map((e) => A(e))), s = `${t}:${n}`;
|
|
1197
|
+
if (!o.get(s)) throw new h(`Repository ${t}:${n} not found in dependency graph`);
|
|
1198
|
+
let c = /* @__PURE__ */ new Set([s]), l = (e) => {
|
|
1199
|
+
let t = o.get(e);
|
|
969
1200
|
if (t) for (let e of t.requiredBy) {
|
|
970
1201
|
let t = `${e.namespace}:${e.entity}`;
|
|
971
|
-
|
|
1202
|
+
c.has(t) || (c.add(t), l(t));
|
|
972
1203
|
}
|
|
973
1204
|
};
|
|
974
|
-
|
|
975
|
-
let
|
|
976
|
-
for (let t of
|
|
977
|
-
let
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1205
|
+
l(s);
|
|
1206
|
+
let u = (e) => Pe(o, e).filter((e) => c.has(L(e))), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
|
|
1207
|
+
for (let t of Ht) for (let n of u(t.action)) await zt(e, o, n, t, r, d, f, i);
|
|
1208
|
+
let p = u("INSERT").map((e) => {
|
|
1209
|
+
let t = d.get(L(e));
|
|
1210
|
+
if (!t) throw new h(`Internal error: cascade node missing for ${L(e)}`);
|
|
1211
|
+
return t;
|
|
1212
|
+
}), m = await en(e, p.flatMap((e) => e.result ? [] : [e.plan]), a), g = [], _ = [];
|
|
1213
|
+
for (let e of p) {
|
|
1214
|
+
let t = e.repo, n = e.result ?? m.get(e.plan);
|
|
1215
|
+
if (!n) throw new h(`Internal error: push result missing for ${L(t)}`);
|
|
1216
|
+
g.push(n), n.error && _.push({
|
|
1217
|
+
repository: t,
|
|
984
1218
|
error: n.error
|
|
985
1219
|
});
|
|
986
1220
|
}
|
|
987
|
-
let
|
|
988
|
-
if (!
|
|
989
|
-
return
|
|
1221
|
+
let v = g.find((e) => e.repository.namespace === t && e.repository.entity === n);
|
|
1222
|
+
if (!v) throw new h("Internal error: target repository result not found");
|
|
1223
|
+
return v.relatedResults = g.filter((e) => e !== v), v.failures = _, v.success || Ft(v), v;
|
|
990
1224
|
}
|
|
991
|
-
async function
|
|
992
|
-
let c =
|
|
1225
|
+
async function zt(e, t, n, r, i, a, o, s) {
|
|
1226
|
+
let c = L(n), l = a.get(c);
|
|
993
1227
|
if (l || (l = { repo: n }, a.set(c, l)), l.result) return;
|
|
994
|
-
let u =
|
|
1228
|
+
let u = be(t, c, o, je(r.action));
|
|
995
1229
|
if (u) {
|
|
996
|
-
let e = new
|
|
1230
|
+
let e = new m(n, u.dependency, u.cause);
|
|
997
1231
|
l.result = {
|
|
998
|
-
...
|
|
1232
|
+
...Vt(l.plan),
|
|
999
1233
|
repository: n,
|
|
1000
1234
|
success: !1,
|
|
1001
|
-
skipped: `dependency ${
|
|
1235
|
+
skipped: `dependency ${L(u.dependency)} failed`,
|
|
1002
1236
|
error: e
|
|
1003
1237
|
}, o.set(c, e);
|
|
1004
1238
|
return;
|
|
1005
1239
|
}
|
|
1006
1240
|
if (!l.plan) {
|
|
1007
|
-
let t = await
|
|
1241
|
+
let t = await Bt(e, n);
|
|
1008
1242
|
if (t) {
|
|
1009
1243
|
l.result = {
|
|
1010
|
-
...
|
|
1244
|
+
...H(),
|
|
1011
1245
|
repository: n,
|
|
1012
1246
|
success: !0,
|
|
1013
1247
|
skipped: t
|
|
@@ -1015,7 +1249,7 @@ async function ut(e, t, n, r, i, a, o, s) {
|
|
|
1015
1249
|
return;
|
|
1016
1250
|
}
|
|
1017
1251
|
try {
|
|
1018
|
-
let t = await
|
|
1252
|
+
let t = await Zt(e, n.namespace, n.entity, s);
|
|
1019
1253
|
if ("emptyResult" in t) {
|
|
1020
1254
|
l.result = {
|
|
1021
1255
|
...t.emptyResult,
|
|
@@ -1027,7 +1261,7 @@ async function ut(e, t, n, r, i, a, o, s) {
|
|
|
1027
1261
|
} catch (e) {
|
|
1028
1262
|
let t = e instanceof Error ? e : Error(String(e));
|
|
1029
1263
|
l.result = {
|
|
1030
|
-
...
|
|
1264
|
+
...H(),
|
|
1031
1265
|
repository: n,
|
|
1032
1266
|
success: !1,
|
|
1033
1267
|
error: t,
|
|
@@ -1039,120 +1273,183 @@ async function ut(e, t, n, r, i, a, o, s) {
|
|
|
1039
1273
|
return;
|
|
1040
1274
|
}
|
|
1041
1275
|
}
|
|
1042
|
-
await
|
|
1276
|
+
await Qt(l.plan, r.kinds, i.batchSize), l.plan.error && (l.result = U(l.plan, l.plan.pushed, 0, l.plan.error), o.set(c, l.plan.error));
|
|
1043
1277
|
}
|
|
1044
|
-
async function
|
|
1278
|
+
async function Bt(e, t) {
|
|
1045
1279
|
let n = e.rxdb.config.entities.find((e) => {
|
|
1046
|
-
let n =
|
|
1280
|
+
let n = A(e);
|
|
1047
1281
|
return n.namespace === t.namespace && n.name === t.entity;
|
|
1048
1282
|
});
|
|
1049
|
-
if (!n) throw new
|
|
1050
|
-
return
|
|
1283
|
+
if (!n) throw new h(`Internal error: entity not found for cascade node ${L(t)}`);
|
|
1284
|
+
return fe(e.rxdb, t.namespace, t.entity, F(A(n), e.rxdb.entitySync));
|
|
1051
1285
|
}
|
|
1052
|
-
function
|
|
1286
|
+
function H() {
|
|
1053
1287
|
return {
|
|
1054
1288
|
pushed: 0,
|
|
1289
|
+
rejected: 0,
|
|
1055
1290
|
failed: 0,
|
|
1056
1291
|
compacted: 0,
|
|
1057
1292
|
originalCount: 0,
|
|
1058
1293
|
failures: []
|
|
1059
1294
|
};
|
|
1060
1295
|
}
|
|
1061
|
-
function
|
|
1296
|
+
function Vt(e) {
|
|
1062
1297
|
return e ? {
|
|
1063
1298
|
pushed: e.pushed,
|
|
1299
|
+
rejected: 0,
|
|
1064
1300
|
failed: e.effectiveCount - e.pushed,
|
|
1065
1301
|
compacted: e.compacted,
|
|
1066
1302
|
originalCount: e.originalCount,
|
|
1067
1303
|
failures: []
|
|
1068
|
-
} :
|
|
1304
|
+
} : H();
|
|
1069
1305
|
}
|
|
1070
|
-
var
|
|
1306
|
+
var Ht = [{
|
|
1071
1307
|
action: "DELETE",
|
|
1072
1308
|
kinds: /* @__PURE__ */ new Set(["deletes"])
|
|
1073
1309
|
}, {
|
|
1074
1310
|
action: "INSERT",
|
|
1075
1311
|
kinds: /* @__PURE__ */ new Set(["updates", "inserts"])
|
|
1076
|
-
}],
|
|
1312
|
+
}], Ut = /* @__PURE__ */ new Set([
|
|
1077
1313
|
"deletes",
|
|
1078
1314
|
"updates",
|
|
1079
1315
|
"inserts"
|
|
1080
1316
|
]);
|
|
1081
|
-
function
|
|
1317
|
+
function Wt(e, t) {
|
|
1082
1318
|
let n = /* @__PURE__ */ new Map();
|
|
1083
1319
|
for (let t of e) {
|
|
1084
|
-
let
|
|
1320
|
+
let { branchId: e } = t;
|
|
1321
|
+
if (e === void 0) throw new h(`Internal error: unpushed change ${t.id} has no branchId`);
|
|
1322
|
+
let r = n.get(e) ?? [];
|
|
1085
1323
|
r.push(t), n.set(e, r);
|
|
1086
1324
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1325
|
+
return [...t].reverse().flatMap((e) => {
|
|
1326
|
+
let t = n.get(e);
|
|
1327
|
+
return t ? Gt(e, t) : [];
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
function Gt(e, t) {
|
|
1331
|
+
let n = {
|
|
1332
|
+
deletes: /* @__PURE__ */ new Map(),
|
|
1333
|
+
updates: /* @__PURE__ */ new Map(),
|
|
1334
|
+
inserts: /* @__PURE__ */ new Map()
|
|
1335
|
+
};
|
|
1336
|
+
return k(t.map((e) => ({
|
|
1337
|
+
id: e.id,
|
|
1338
|
+
namespace: e.namespace,
|
|
1339
|
+
entity: e.entity,
|
|
1340
|
+
entityId: e.entityId,
|
|
1341
|
+
type: e.type,
|
|
1342
|
+
branchId: e.branchId,
|
|
1343
|
+
patch: e.patch,
|
|
1344
|
+
inversePatch: e.inversePatch,
|
|
1345
|
+
createdAt: e.createdAt,
|
|
1346
|
+
updatedAt: e.updatedAt
|
|
1347
|
+
})), n), Kt(e, t, n);
|
|
1348
|
+
}
|
|
1349
|
+
function Kt(e, t, n) {
|
|
1350
|
+
let r = /* @__PURE__ */ new Map();
|
|
1351
|
+
for (let e of t) {
|
|
1352
|
+
let t = N(e), n = r.get(t) ?? [];
|
|
1353
|
+
n.push(e), r.set(t, n);
|
|
1354
|
+
}
|
|
1355
|
+
let i = [], a = (t, n) => {
|
|
1356
|
+
for (let [a, o] of n) {
|
|
1357
|
+
let n = r.get(a);
|
|
1358
|
+
if (!n?.length) throw new h(`Missing source changes for compacted action: ${a}`);
|
|
1359
|
+
i.push({
|
|
1360
|
+
branchId: e,
|
|
1361
|
+
actionKind: t,
|
|
1362
|
+
key: a,
|
|
1363
|
+
action: o,
|
|
1364
|
+
sourceChanges: n
|
|
1096
1365
|
});
|
|
1097
1366
|
}
|
|
1098
1367
|
};
|
|
1099
|
-
return
|
|
1368
|
+
return a("deletes", n.deletes), a("updates", n.updates), a("inserts", n.inserts), i;
|
|
1100
1369
|
}
|
|
1101
|
-
function
|
|
1370
|
+
function qt(e) {
|
|
1102
1371
|
let t = {
|
|
1103
1372
|
deletes: /* @__PURE__ */ new Map(),
|
|
1104
1373
|
updates: /* @__PURE__ */ new Map(),
|
|
1105
1374
|
inserts: /* @__PURE__ */ new Map()
|
|
1106
|
-
}, n = []
|
|
1107
|
-
for (let
|
|
1108
|
-
t[
|
|
1109
|
-
for (let e of
|
|
1375
|
+
}, n = [];
|
|
1376
|
+
for (let r of e) {
|
|
1377
|
+
t[r.actionKind].set(r.key, r.action);
|
|
1378
|
+
for (let e of r.sourceChanges) n.push(e);
|
|
1110
1379
|
}
|
|
1111
1380
|
return n.sort((e, t) => e.id - t.id), {
|
|
1112
1381
|
actions: t,
|
|
1113
|
-
sourceChanges: n
|
|
1114
|
-
sourceChangesByLocalId: r
|
|
1382
|
+
sourceChanges: n
|
|
1115
1383
|
};
|
|
1116
1384
|
}
|
|
1117
|
-
function
|
|
1118
|
-
|
|
1385
|
+
function Jt(e, t) {
|
|
1386
|
+
let n = new Set(t.map((e) => e.id)), r = /* @__PURE__ */ new Set();
|
|
1387
|
+
for (let t of e) {
|
|
1388
|
+
if (!n.has(t.localId)) throw new h(`Remote merge result references unknown local change: ${t.localId}`);
|
|
1389
|
+
if (r.has(t.localId)) throw new h(`Remote merge result duplicates local change: ${t.localId}`);
|
|
1390
|
+
r.add(t.localId);
|
|
1391
|
+
}
|
|
1392
|
+
if (r.size !== n.size) {
|
|
1393
|
+
let e = [...n].filter((e) => !r.has(e));
|
|
1394
|
+
throw new h(`Remote merge result missing local changes: ${e.join(", ")}`);
|
|
1395
|
+
}
|
|
1119
1396
|
}
|
|
1120
|
-
function
|
|
1121
|
-
let n = e.map((
|
|
1122
|
-
let
|
|
1123
|
-
if (!
|
|
1124
|
-
return
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
return [...r].map(([e, t]) => ({
|
|
1131
|
-
change: e,
|
|
1132
|
-
remoteId: t
|
|
1133
|
-
}));
|
|
1397
|
+
function Yt(e, t) {
|
|
1398
|
+
let n = e.sourceChanges.map((e) => {
|
|
1399
|
+
let n = t.get(e.id);
|
|
1400
|
+
if (!n) throw new h(`Remote merge result missing local changes: ${e.id}`);
|
|
1401
|
+
return n;
|
|
1402
|
+
}), r = n.find((e) => e.status === "rejected");
|
|
1403
|
+
if (r) {
|
|
1404
|
+
if (n.some((e) => e.status === "applied")) throw new h(`Remote merge result splits entity ${e.key}: some source changes applied, some rejected`);
|
|
1405
|
+
return r.rejection;
|
|
1406
|
+
}
|
|
1134
1407
|
}
|
|
1135
|
-
async function
|
|
1136
|
-
|
|
1408
|
+
async function Xt(e, t, n) {
|
|
1409
|
+
let r = qt(n), i = await e.mergeChanges(r.actions, t, r.sourceChanges);
|
|
1410
|
+
Jt(i.results, r.sourceChanges);
|
|
1411
|
+
let a = new Map(i.results.map((e) => [e.localId, e])), o = new Map(r.sourceChanges.map((e) => [e.id, e])), s = {
|
|
1412
|
+
applied: [],
|
|
1413
|
+
rejected: []
|
|
1414
|
+
};
|
|
1415
|
+
for (let e of n) {
|
|
1416
|
+
let t = Yt(e, a);
|
|
1417
|
+
t && s.rejected.push({
|
|
1418
|
+
entry: e,
|
|
1419
|
+
rejection: t
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
for (let e of i.results) {
|
|
1423
|
+
if (e.status !== "applied") continue;
|
|
1424
|
+
let t = o.get(e.localId);
|
|
1425
|
+
if (!t) throw new h(`Remote merge result references unknown local change: ${e.localId}`);
|
|
1426
|
+
s.applied.push({
|
|
1427
|
+
change: t,
|
|
1428
|
+
remoteId: e.remoteId
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
return s;
|
|
1137
1432
|
}
|
|
1138
|
-
async function
|
|
1433
|
+
async function Zt(e, t, n, r) {
|
|
1139
1434
|
let i = e.rxdb;
|
|
1140
|
-
if (!i.config.sync?.remote?.adapter) throw new
|
|
1435
|
+
if (!i.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
1141
1436
|
await e.getRemoteRepositories();
|
|
1142
|
-
let { adapter: a } = await e.getLocalRepositories(), o = await e.getCurrentBranch(),
|
|
1143
|
-
let r =
|
|
1437
|
+
let { adapter: a } = await e.getLocalRepositories(), o = e.branchSwitchGeneration, s = await e.getCurrentBranch(), c = a.getRepository(v), l = e.rxdb.config.entities.find((e) => {
|
|
1438
|
+
let r = A(e);
|
|
1144
1439
|
return r.namespace === t && r.name === n;
|
|
1145
|
-
})
|
|
1440
|
+
});
|
|
1441
|
+
if (!l) throw new h(`Entity not found: ${t}:${n}`);
|
|
1442
|
+
let u = A(l), d = F(u, e.rxdb.entitySync), f = await M(c, {
|
|
1146
1443
|
namespace: t,
|
|
1147
1444
|
entity: n,
|
|
1148
|
-
branchId:
|
|
1149
|
-
syncType:
|
|
1150
|
-
}, () => i.entityManager.instantiate(
|
|
1151
|
-
if (
|
|
1445
|
+
branchId: s.id,
|
|
1446
|
+
syncType: d
|
|
1447
|
+
}, () => i.entityManager.instantiate(v)), m = f.lastPushedChangeId, g = await ge(e, s.id), _ = a.getRepository(p), y;
|
|
1448
|
+
if (g.length === 1) y = await vn(_, g, m, t, [n]);
|
|
1152
1449
|
else {
|
|
1153
1450
|
let e = m;
|
|
1154
|
-
for (let r of
|
|
1155
|
-
let i = `${t}:${n}:${r}`, a = (await
|
|
1451
|
+
for (let r of g.slice(1)) {
|
|
1452
|
+
let i = `${t}:${n}:${r}`, a = (await c.find({
|
|
1156
1453
|
where: {
|
|
1157
1454
|
combinator: "and",
|
|
1158
1455
|
rules: [{
|
|
@@ -1169,129 +1466,294 @@ async function bt(e, t, n, r) {
|
|
|
1169
1466
|
}
|
|
1170
1467
|
(e === null || a < e) && (e = a);
|
|
1171
1468
|
}
|
|
1172
|
-
|
|
1469
|
+
y = await vn(_, g, e, t, [n]);
|
|
1173
1470
|
}
|
|
1174
|
-
let
|
|
1175
|
-
if (
|
|
1176
|
-
...
|
|
1471
|
+
let b = y.length;
|
|
1472
|
+
if (b === 0) return { emptyResult: {
|
|
1473
|
+
...H(),
|
|
1177
1474
|
repository: {
|
|
1178
1475
|
namespace: t,
|
|
1179
1476
|
entity: n
|
|
1180
1477
|
}
|
|
1181
1478
|
} };
|
|
1182
|
-
let
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
};
|
|
1187
|
-
S(v.map((e) => ({
|
|
1188
|
-
id: e.id,
|
|
1189
|
-
namespace: e.namespace,
|
|
1190
|
-
entity: e.entity,
|
|
1191
|
-
entityId: e.entityId,
|
|
1192
|
-
type: e.type,
|
|
1193
|
-
branchId: e.branchId,
|
|
1194
|
-
patch: e.patch,
|
|
1195
|
-
inversePatch: e.inversePatch,
|
|
1196
|
-
createdAt: e.createdAt,
|
|
1197
|
-
updatedAt: e.updatedAt
|
|
1198
|
-
})), b);
|
|
1199
|
-
let x = b.inserts.size + b.updates.size + b.deletes.size, C = y - x;
|
|
1200
|
-
if (x === 0) {
|
|
1201
|
-
let e = v.reduce((e, t) => t.id > e ? t.id : e, v[0].id);
|
|
1202
|
-
return await s.update(f, {
|
|
1479
|
+
let x = Wt(y, g), S = x.length, C = b - S;
|
|
1480
|
+
if (S === 0) {
|
|
1481
|
+
let e = y.reduce((e, t) => t.id > e ? t.id : e, y[0].id);
|
|
1482
|
+
return await c.update(f, {
|
|
1203
1483
|
lastPushedChangeId: e,
|
|
1204
1484
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1205
1485
|
}), { emptyResult: {
|
|
1206
|
-
...
|
|
1486
|
+
...H(),
|
|
1207
1487
|
repository: {
|
|
1208
1488
|
namespace: t,
|
|
1209
1489
|
entity: n
|
|
1210
1490
|
},
|
|
1211
|
-
compacted:
|
|
1212
|
-
originalCount:
|
|
1491
|
+
compacted: b,
|
|
1492
|
+
originalCount: b
|
|
1213
1493
|
} };
|
|
1214
1494
|
}
|
|
1215
1495
|
let { adapter: w } = await e.getRemoteRepositories();
|
|
1216
|
-
return r.claim(`${t}:${n}`,
|
|
1496
|
+
return r.claim(`${t}:${n}`, y.reduce((e, t) => t.id > e ? t.id : e, y[0].id)), {
|
|
1217
1497
|
repository: {
|
|
1218
1498
|
namespace: t,
|
|
1219
1499
|
entity: n
|
|
1220
1500
|
},
|
|
1221
|
-
|
|
1222
|
-
|
|
1501
|
+
entityType: l,
|
|
1502
|
+
entries: x,
|
|
1503
|
+
localChanges: y,
|
|
1223
1504
|
repoSync: f,
|
|
1224
1505
|
localAdapter: a,
|
|
1225
1506
|
remoteAdapter: w,
|
|
1226
|
-
branchId:
|
|
1227
|
-
|
|
1228
|
-
|
|
1507
|
+
branchId: s.id,
|
|
1508
|
+
branchGeneration: o,
|
|
1509
|
+
originalCount: b,
|
|
1510
|
+
effectiveCount: S,
|
|
1229
1511
|
compacted: C,
|
|
1230
1512
|
pushed: 0,
|
|
1231
|
-
remoteIdsByChange: /* @__PURE__ */ new Map()
|
|
1513
|
+
remoteIdsByChange: /* @__PURE__ */ new Map(),
|
|
1514
|
+
rejectedEntries: []
|
|
1232
1515
|
};
|
|
1233
1516
|
}
|
|
1234
|
-
async function
|
|
1517
|
+
async function Qt(e, t, n) {
|
|
1235
1518
|
if (e.error) return;
|
|
1236
1519
|
let r = e.entries.filter((e) => t.has(e.actionKind));
|
|
1237
1520
|
if (r.length === 0) return;
|
|
1238
1521
|
let { namespace: i, entity: a } = e.repository;
|
|
1239
|
-
for (let t
|
|
1240
|
-
let
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
return;
|
|
1248
|
-
}
|
|
1522
|
+
for (let { branchId: t, entries: o } of $t(r, n)) try {
|
|
1523
|
+
let n = await Xt(e.remoteAdapter, t, o);
|
|
1524
|
+
for (let { change: t, remoteId: r } of n.applied) e.remoteIdsByChange.set(t, r);
|
|
1525
|
+
for (let t of n.rejected) e.rejectedEntries.push(t);
|
|
1526
|
+
e.pushed += o.length - n.rejected.length;
|
|
1527
|
+
} catch (t) {
|
|
1528
|
+
console.error(`Error pushing changes to remote for repository [${i}/${a}]:`, t), e.error = t instanceof Error ? t : Error(String(t));
|
|
1529
|
+
return;
|
|
1249
1530
|
}
|
|
1250
1531
|
}
|
|
1251
|
-
|
|
1252
|
-
let
|
|
1253
|
-
|
|
1254
|
-
let e = n.
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1532
|
+
function $t(e, t) {
|
|
1533
|
+
let n = [];
|
|
1534
|
+
for (let r of e) {
|
|
1535
|
+
let e = n.at(-1);
|
|
1536
|
+
e?.branchId === r.branchId && e.entries.length < t ? e.entries.push(r) : n.push({
|
|
1537
|
+
branchId: r.branchId,
|
|
1538
|
+
entries: [r]
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
return n;
|
|
1542
|
+
}
|
|
1543
|
+
async function en(e, t, n) {
|
|
1544
|
+
let r = /* @__PURE__ */ new Map(), i = [];
|
|
1545
|
+
for (let e of t) e.effectiveCount - e.pushed - e.rejectedEntries.length > 0 ? r.set(e, U(e, e.pushed, 0, e.error)) : i.push(e);
|
|
1546
|
+
if (i.length === 0) return r;
|
|
1547
|
+
try {
|
|
1548
|
+
let t = await tn(e, i);
|
|
1549
|
+
for (let e of t) n.push(e);
|
|
1550
|
+
for (let e of i) r.set(e, U(e, e.pushed, e.rejectedEntries.length, void 0));
|
|
1551
|
+
} catch (e) {
|
|
1552
|
+
let t = i.map((e) => L(e.repository)).join(", ");
|
|
1553
|
+
console.error(`Error saving push state for repositories [${t}]:`, e);
|
|
1554
|
+
let n = e instanceof Error ? e : Error(String(e));
|
|
1555
|
+
for (let e of i) r.set(e, U(e, 0, 0, n));
|
|
1272
1556
|
}
|
|
1557
|
+
return r;
|
|
1558
|
+
}
|
|
1559
|
+
function U(e, t, n, r) {
|
|
1560
|
+
let { repository: i } = e, a = e.effectiveCount - t - n;
|
|
1273
1561
|
return {
|
|
1274
|
-
repository:
|
|
1275
|
-
success:
|
|
1276
|
-
error:
|
|
1277
|
-
pushed:
|
|
1278
|
-
|
|
1562
|
+
repository: i,
|
|
1563
|
+
success: a === 0,
|
|
1564
|
+
error: r,
|
|
1565
|
+
pushed: t,
|
|
1566
|
+
rejected: n,
|
|
1567
|
+
failed: a,
|
|
1279
1568
|
compacted: e.compacted,
|
|
1280
1569
|
originalCount: e.originalCount,
|
|
1281
|
-
failures:
|
|
1282
|
-
repository:
|
|
1283
|
-
error:
|
|
1570
|
+
failures: r ? [{
|
|
1571
|
+
repository: i,
|
|
1572
|
+
error: r
|
|
1284
1573
|
}] : []
|
|
1285
1574
|
};
|
|
1286
1575
|
}
|
|
1287
|
-
async function
|
|
1288
|
-
let
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1576
|
+
async function tn(e, t) {
|
|
1577
|
+
let n = [];
|
|
1578
|
+
for (let e of t) n.push({
|
|
1579
|
+
plan: e,
|
|
1580
|
+
remoteRows: await cn(e)
|
|
1581
|
+
});
|
|
1582
|
+
let r = /* @__PURE__ */ new Date(), i = t.map(an);
|
|
1583
|
+
try {
|
|
1584
|
+
await t[0].localAdapter.transaction(async (i) => {
|
|
1585
|
+
await sn(e, i, t);
|
|
1586
|
+
let a = [];
|
|
1587
|
+
for (let { plan: e, remoteRows: t } of n) await on(i, e, r), a.push(await dn(i, e, t));
|
|
1588
|
+
for (let { removals: e } of [...a].reverse()) await fn(i, e);
|
|
1589
|
+
for (let { restores: e } of a) await fn(i, e);
|
|
1590
|
+
for (let e of t) await i.getRepository(v).update(e.repoSync, {
|
|
1591
|
+
lastPushedChangeId: rn(e),
|
|
1592
|
+
lastPushedAt: r,
|
|
1593
|
+
updatedAt: r
|
|
1594
|
+
});
|
|
1595
|
+
});
|
|
1596
|
+
} catch (e) {
|
|
1597
|
+
for (let e of i) e();
|
|
1598
|
+
throw e;
|
|
1599
|
+
}
|
|
1600
|
+
return t.flatMap((e) => hn(e.rejectedEntries, r));
|
|
1601
|
+
}
|
|
1602
|
+
function nn(e) {
|
|
1603
|
+
return [...e.remoteIdsByChange.keys(), ...e.rejectedEntries.flatMap(({ entry: e }) => e.sourceChanges)];
|
|
1604
|
+
}
|
|
1605
|
+
function rn(e) {
|
|
1606
|
+
return e.localChanges.reduce((e, t) => t.id > e ? t.id : e, e.localChanges[0].id);
|
|
1607
|
+
}
|
|
1608
|
+
function an(e) {
|
|
1609
|
+
let { repoSync: t } = e, n = nn(e).map((e) => ({
|
|
1610
|
+
change: e,
|
|
1611
|
+
remoteId: e.remoteId,
|
|
1612
|
+
rejectedAt: e.rejectedAt,
|
|
1613
|
+
rejection: e.rejection
|
|
1614
|
+
})), r = {
|
|
1615
|
+
lastPushedChangeId: t.lastPushedChangeId,
|
|
1616
|
+
lastPushedAt: t.lastPushedAt,
|
|
1617
|
+
updatedAt: t.updatedAt
|
|
1618
|
+
};
|
|
1619
|
+
return () => {
|
|
1620
|
+
for (let e of n) e.change.remoteId = e.remoteId, e.change.rejectedAt = e.rejectedAt, e.change.rejection = e.rejection;
|
|
1621
|
+
Object.assign(t, r);
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
async function on(e, t, n) {
|
|
1625
|
+
for (let [e, n] of t.remoteIdsByChange) e.remoteId = n;
|
|
1626
|
+
for (let { entry: e, rejection: r } of t.rejectedEntries) for (let t of e.sourceChanges) t.rejectedAt = n, t.rejection = r;
|
|
1627
|
+
let r = nn(t);
|
|
1628
|
+
r.length > 0 && await e.saveMany(r);
|
|
1629
|
+
}
|
|
1630
|
+
async function sn(e, t, n) {
|
|
1631
|
+
if (!n.some((e) => e.rejectedEntries.length > 0)) return;
|
|
1632
|
+
let r = await E(t), i = e.branchSwitchGeneration, a = n.find((e) => e.branchId !== r.id || e.branchGeneration !== i);
|
|
1633
|
+
if (a) throw new h(`Branch switched while pushing ${L(a.repository)} from branch ${a.branchId}; rejected receipts are not applied to active branch ${r.id}.`);
|
|
1634
|
+
}
|
|
1635
|
+
async function cn(e) {
|
|
1636
|
+
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
1637
|
+
for (let { rejection: t } of e.rejectedEntries) {
|
|
1638
|
+
let e = `${t.entity.namespace}:${t.entity.entity}`, r = n.get(e) ?? [];
|
|
1639
|
+
r.push(t.entity.entityId), n.set(e, r);
|
|
1640
|
+
}
|
|
1641
|
+
for (let [r, i] of n) {
|
|
1642
|
+
let n = await R(e.remoteAdapter.findByIds(r, i));
|
|
1643
|
+
for (let e of n) t.set(`${r}:${String(e.id)}`, e);
|
|
1644
|
+
}
|
|
1645
|
+
return t;
|
|
1646
|
+
}
|
|
1647
|
+
function ln(e) {
|
|
1648
|
+
let { namespace: t, entity: n, entityId: r } = e.entity;
|
|
1649
|
+
return `${t}:${n}:${r}`;
|
|
1650
|
+
}
|
|
1651
|
+
var un = () => ({
|
|
1652
|
+
deletes: /* @__PURE__ */ new Map(),
|
|
1653
|
+
updates: /* @__PURE__ */ new Map(),
|
|
1654
|
+
inserts: /* @__PURE__ */ new Map()
|
|
1655
|
+
});
|
|
1656
|
+
async function dn(e, t, n) {
|
|
1657
|
+
let r = {
|
|
1658
|
+
removals: un(),
|
|
1659
|
+
restores: un()
|
|
1660
|
+
};
|
|
1661
|
+
if (t.rejectedEntries.length === 0) return r;
|
|
1662
|
+
let { namespace: i, entity: a } = t.repository, o = await e.getRepository(p).find({ where: {
|
|
1663
|
+
combinator: "and",
|
|
1664
|
+
rules: [
|
|
1665
|
+
{
|
|
1666
|
+
field: "namespace",
|
|
1667
|
+
operator: "=",
|
|
1668
|
+
value: i
|
|
1669
|
+
},
|
|
1670
|
+
{
|
|
1671
|
+
field: "entity",
|
|
1672
|
+
operator: "=",
|
|
1673
|
+
value: a
|
|
1674
|
+
},
|
|
1675
|
+
{
|
|
1676
|
+
field: "entityId",
|
|
1677
|
+
operator: "in",
|
|
1678
|
+
value: oe(t.rejectedEntries.map(({ rejection: e }) => e.entity.entityId))
|
|
1679
|
+
},
|
|
1680
|
+
{
|
|
1681
|
+
field: "id",
|
|
1682
|
+
operator: ">",
|
|
1683
|
+
value: rn(t)
|
|
1684
|
+
},
|
|
1685
|
+
{
|
|
1686
|
+
field: "revertChangeId",
|
|
1687
|
+
operator: "=",
|
|
1688
|
+
value: null
|
|
1689
|
+
},
|
|
1690
|
+
{
|
|
1691
|
+
field: "remoteId",
|
|
1692
|
+
operator: "=",
|
|
1693
|
+
value: null
|
|
1694
|
+
},
|
|
1695
|
+
{
|
|
1696
|
+
field: "rejectedAt",
|
|
1697
|
+
operator: "=",
|
|
1698
|
+
value: null
|
|
1699
|
+
}
|
|
1700
|
+
]
|
|
1701
|
+
} }), s = new Set(o.map((e) => N(e)));
|
|
1702
|
+
for (let { entry: e, rejection: i } of t.rejectedEntries) s.has(e.key) || pn(r, e, n.get(ln(i)));
|
|
1703
|
+
return r;
|
|
1704
|
+
}
|
|
1705
|
+
async function fn(e, t) {
|
|
1706
|
+
t.inserts.size + t.updates.size + t.deletes.size !== 0 && (ne(e, {
|
|
1707
|
+
file: "push-repository.ts",
|
|
1708
|
+
symbol: "alignRejectedEntities",
|
|
1709
|
+
intent: T.remote_sync
|
|
1710
|
+
}), await e.mergeChanges(t, void 0, !0));
|
|
1711
|
+
}
|
|
1712
|
+
function pn(e, t, n) {
|
|
1713
|
+
if (n) {
|
|
1714
|
+
let { restores: r } = e;
|
|
1715
|
+
(t.actionKind === "deletes" ? r.inserts : r.updates).set(t.key, {
|
|
1716
|
+
patch: n,
|
|
1717
|
+
inversePatch: null
|
|
1718
|
+
});
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1721
|
+
t.actionKind !== "deletes" && e.removals.deletes.set(t.key, {
|
|
1722
|
+
patch: null,
|
|
1723
|
+
inversePatch: null
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
var mn = {
|
|
1727
|
+
deletes: "DELETE",
|
|
1728
|
+
updates: "UPDATE",
|
|
1729
|
+
inserts: "INSERT"
|
|
1730
|
+
};
|
|
1731
|
+
function hn(e, t) {
|
|
1732
|
+
return e.map(({ entry: e, rejection: n }) => ({
|
|
1733
|
+
namespace: n.entity.namespace,
|
|
1734
|
+
entity: n.entity.entity,
|
|
1735
|
+
entityId: n.entity.entityId,
|
|
1736
|
+
op: mn[e.actionKind],
|
|
1737
|
+
code: n.code,
|
|
1738
|
+
reason: n.reason,
|
|
1739
|
+
message: n.message,
|
|
1740
|
+
...n.dependsOn ? { dependsOn: n.dependsOn } : {},
|
|
1741
|
+
at: t,
|
|
1742
|
+
changeIds: e.sourceChanges.map((e) => e.id)
|
|
1743
|
+
}));
|
|
1744
|
+
}
|
|
1745
|
+
function gn(e, t) {
|
|
1746
|
+
t.length > 0 && e.rxdb.syncState.reportRejections(t);
|
|
1293
1747
|
}
|
|
1294
|
-
async function
|
|
1748
|
+
async function _n(e, t, n, r, i, a) {
|
|
1749
|
+
let o = await Zt(e, t, n, i);
|
|
1750
|
+
if ("emptyResult" in o) return o.emptyResult;
|
|
1751
|
+
await Qt(o, Ut, r.batchSize);
|
|
1752
|
+
let s = (await en(e, [o], a)).get(o);
|
|
1753
|
+
if (!s) throw new h(`Internal error: push result missing for ${t}:${n}`);
|
|
1754
|
+
return s.success || Ft(s), s;
|
|
1755
|
+
}
|
|
1756
|
+
async function vn(e, t, n, r, i) {
|
|
1295
1757
|
let a = [
|
|
1296
1758
|
{
|
|
1297
1759
|
field: "revertChangeId",
|
|
@@ -1303,6 +1765,11 @@ async function wt(e, t, n, r, i) {
|
|
|
1303
1765
|
operator: "=",
|
|
1304
1766
|
value: null
|
|
1305
1767
|
},
|
|
1768
|
+
{
|
|
1769
|
+
field: "rejectedAt",
|
|
1770
|
+
operator: "=",
|
|
1771
|
+
value: null
|
|
1772
|
+
},
|
|
1306
1773
|
{
|
|
1307
1774
|
field: "namespace",
|
|
1308
1775
|
operator: "=",
|
|
@@ -1338,7 +1805,7 @@ async function wt(e, t, n, r, i) {
|
|
|
1338
1805
|
}
|
|
1339
1806
|
//#endregion
|
|
1340
1807
|
//#region src/sync-repository.ts
|
|
1341
|
-
function
|
|
1808
|
+
function yn(e, t) {
|
|
1342
1809
|
return {
|
|
1343
1810
|
repository: {
|
|
1344
1811
|
namespace: e,
|
|
@@ -1355,33 +1822,34 @@ function Tt(e, t) {
|
|
|
1355
1822
|
failures: []
|
|
1356
1823
|
};
|
|
1357
1824
|
}
|
|
1358
|
-
function
|
|
1825
|
+
function bn(e, t) {
|
|
1359
1826
|
return {
|
|
1360
1827
|
repository: {
|
|
1361
1828
|
namespace: e,
|
|
1362
1829
|
entity: t
|
|
1363
1830
|
},
|
|
1364
1831
|
pushed: 0,
|
|
1832
|
+
rejected: 0,
|
|
1365
1833
|
failed: 0,
|
|
1366
1834
|
compacted: 0,
|
|
1367
1835
|
originalCount: 0,
|
|
1368
1836
|
failures: []
|
|
1369
1837
|
};
|
|
1370
1838
|
}
|
|
1371
|
-
function
|
|
1372
|
-
if (!(e instanceof
|
|
1373
|
-
let r =
|
|
1839
|
+
function xn(e, t, n) {
|
|
1840
|
+
if (!(e instanceof g)) return e;
|
|
1841
|
+
let r = Le(e);
|
|
1374
1842
|
if (!r) return e;
|
|
1375
1843
|
let i = {
|
|
1376
1844
|
pullResult: r,
|
|
1377
|
-
pushResult:
|
|
1845
|
+
pushResult: bn(t, n),
|
|
1378
1846
|
persistedProgress: r.persistedProgress,
|
|
1379
1847
|
historyInvalidated: r.historyInvalidated
|
|
1380
1848
|
};
|
|
1381
|
-
return new
|
|
1849
|
+
return new g(i, e.cause);
|
|
1382
1850
|
}
|
|
1383
|
-
function
|
|
1384
|
-
let i = e instanceof Error ? e : Error(String(e)), a =
|
|
1851
|
+
function Sn(e, t, n, r) {
|
|
1852
|
+
let i = e instanceof Error ? e : Error(String(e)), a = Pt(i), o = a === void 0 ? bn(n, r) : a, s = t.persistedProgress || o.pushed > 0;
|
|
1385
1853
|
if (!s) return i;
|
|
1386
1854
|
let c = {
|
|
1387
1855
|
pullResult: t,
|
|
@@ -1389,140 +1857,140 @@ function Ot(e, t, n, r) {
|
|
|
1389
1857
|
persistedProgress: s,
|
|
1390
1858
|
historyInvalidated: t.historyInvalidated
|
|
1391
1859
|
};
|
|
1392
|
-
return new
|
|
1860
|
+
return new g(c, i instanceof g ? i.cause : i);
|
|
1393
1861
|
}
|
|
1394
|
-
async function
|
|
1395
|
-
let
|
|
1396
|
-
|
|
1862
|
+
async function Cn(e, t, n, r, i) {
|
|
1863
|
+
let a = e.rxdb, o = r?.pull?.includeRelated ?? r?.push?.includeRelated ?? !0;
|
|
1864
|
+
a.dispatchEvent(new l("sync", t, n, o));
|
|
1397
1865
|
try {
|
|
1398
|
-
let
|
|
1399
|
-
pulled:
|
|
1400
|
-
pushed:
|
|
1401
|
-
compacted:
|
|
1402
|
-
failed:
|
|
1403
|
-
conflictsResolved:
|
|
1404
|
-
conflictsDeferred:
|
|
1866
|
+
let o = await wn(e, t, n, r, i), { pullResult: s, pushResult: c } = o, l = {
|
|
1867
|
+
pulled: s.pulled,
|
|
1868
|
+
pushed: c.pushed,
|
|
1869
|
+
compacted: s.compacted + c.compacted,
|
|
1870
|
+
failed: c.failed,
|
|
1871
|
+
conflictsResolved: s.conflictsResolved,
|
|
1872
|
+
conflictsDeferred: s.conflictsDeferred
|
|
1405
1873
|
};
|
|
1406
|
-
return
|
|
1874
|
+
return a.dispatchEvent(new u("sync", t, n, l)), o;
|
|
1407
1875
|
} catch (e) {
|
|
1408
|
-
throw
|
|
1876
|
+
throw a.dispatchEvent(new d("sync", t, n, e)), e;
|
|
1409
1877
|
}
|
|
1410
1878
|
}
|
|
1411
|
-
async function
|
|
1412
|
-
let
|
|
1413
|
-
let r =
|
|
1879
|
+
async function wn(e, t, n, r, i) {
|
|
1880
|
+
let a = e.rxdb.config.entities.find((e) => {
|
|
1881
|
+
let r = A(e);
|
|
1414
1882
|
return r.namespace === t && r.name === n;
|
|
1415
1883
|
});
|
|
1416
|
-
if (!
|
|
1417
|
-
let
|
|
1418
|
-
if (
|
|
1419
|
-
let
|
|
1420
|
-
if ((r?.direction === "pull" || r?.direction === "sync" || !r?.direction) &&
|
|
1421
|
-
|
|
1884
|
+
if (!a) throw new h(`Entity not found: ${t}:${n}`);
|
|
1885
|
+
let o = A(a), s = F(o, e.rxdb.entitySync);
|
|
1886
|
+
if (s === "none") throw new h(`Cannot sync repository ${t}:${n}: syncType is 'none'. This entity is not configured for remote synchronization.`);
|
|
1887
|
+
let c;
|
|
1888
|
+
if ((r?.direction === "pull" || r?.direction === "sync" || !r?.direction) && P(s).pull) try {
|
|
1889
|
+
c = await ze(e, t, n, r?.pull);
|
|
1422
1890
|
} catch (e) {
|
|
1423
|
-
throw
|
|
1891
|
+
throw xn(e, t, n);
|
|
1424
1892
|
}
|
|
1425
|
-
else
|
|
1426
|
-
let
|
|
1427
|
-
if ((r?.direction === "push" || r?.direction === "sync" || !r?.direction) &&
|
|
1428
|
-
|
|
1893
|
+
else c = yn(t, n);
|
|
1894
|
+
let l;
|
|
1895
|
+
if ((r?.direction === "push" || r?.direction === "sync" || !r?.direction) && P(s).push) try {
|
|
1896
|
+
l = await It(e, t, n, r?.push, i);
|
|
1429
1897
|
} catch (e) {
|
|
1430
|
-
throw
|
|
1898
|
+
throw Sn(e, c, t, n);
|
|
1431
1899
|
}
|
|
1432
|
-
else
|
|
1900
|
+
else l = bn(t, n);
|
|
1433
1901
|
return {
|
|
1434
|
-
pullResult:
|
|
1435
|
-
pushResult:
|
|
1436
|
-
persistedProgress:
|
|
1437
|
-
historyInvalidated:
|
|
1902
|
+
pullResult: c,
|
|
1903
|
+
pushResult: l,
|
|
1904
|
+
persistedProgress: c.persistedProgress || l.pushed > 0,
|
|
1905
|
+
historyInvalidated: c.historyInvalidated
|
|
1438
1906
|
};
|
|
1439
1907
|
}
|
|
1440
1908
|
//#endregion
|
|
1441
1909
|
//#region src/bulk-sync.ts
|
|
1442
|
-
async function
|
|
1910
|
+
async function Tn(e, t) {
|
|
1443
1911
|
if (t.repositories && t.repositories.length > 0) return t.repositories;
|
|
1444
1912
|
let n = [];
|
|
1445
1913
|
for (let t of e.config.entities) {
|
|
1446
|
-
let r =
|
|
1914
|
+
let r = A(t), i = P(F(r, e.entitySync));
|
|
1447
1915
|
if (!i.pull && !i.push) continue;
|
|
1448
|
-
let a = await
|
|
1449
|
-
|
|
1916
|
+
let a = await re(e, r.namespace, r.name);
|
|
1917
|
+
I(a) && n.push({
|
|
1450
1918
|
namespace: r.namespace,
|
|
1451
1919
|
entity: r.name
|
|
1452
1920
|
});
|
|
1453
1921
|
}
|
|
1454
1922
|
return n;
|
|
1455
1923
|
}
|
|
1456
|
-
async function
|
|
1924
|
+
async function En(e, t, n, r) {
|
|
1457
1925
|
try {
|
|
1458
1926
|
return {
|
|
1459
1927
|
repository: t,
|
|
1460
1928
|
success: !0,
|
|
1461
|
-
result: await
|
|
1929
|
+
result: await Cn(e, t.namespace, t.entity, n, r)
|
|
1462
1930
|
};
|
|
1463
1931
|
} catch (e) {
|
|
1464
1932
|
let n = e instanceof Error ? e : Error(String(e));
|
|
1465
1933
|
return {
|
|
1466
1934
|
repository: t,
|
|
1467
1935
|
success: !1,
|
|
1468
|
-
result: n instanceof
|
|
1936
|
+
result: n instanceof g ? n.result : void 0,
|
|
1469
1937
|
error: n
|
|
1470
1938
|
};
|
|
1471
1939
|
}
|
|
1472
1940
|
}
|
|
1473
|
-
async function
|
|
1474
|
-
let r = [];
|
|
1475
|
-
for (let i of t) {
|
|
1476
|
-
let t = await Mt(e, i, n);
|
|
1477
|
-
r.push(t);
|
|
1478
|
-
}
|
|
1479
|
-
return r;
|
|
1480
|
-
}
|
|
1481
|
-
async function Pt(e, t, n, r) {
|
|
1941
|
+
async function Dn(e, t, n, r) {
|
|
1482
1942
|
let i = [];
|
|
1483
|
-
for (let a
|
|
1484
|
-
let
|
|
1485
|
-
i.push(
|
|
1943
|
+
for (let a of t) {
|
|
1944
|
+
let t = await En(e, a, n, r);
|
|
1945
|
+
i.push(t);
|
|
1486
1946
|
}
|
|
1487
1947
|
return i;
|
|
1488
1948
|
}
|
|
1489
|
-
async function
|
|
1490
|
-
let
|
|
1949
|
+
async function On(e, t, n, r, i) {
|
|
1950
|
+
let a = [];
|
|
1951
|
+
for (let o = 0; o < t.length; o += r) {
|
|
1952
|
+
let s = t.slice(o, o + r).map((t) => En(e, t, n, i)), c = await Promise.all(s);
|
|
1953
|
+
a.push(...c);
|
|
1954
|
+
}
|
|
1955
|
+
return a;
|
|
1956
|
+
}
|
|
1957
|
+
async function kn(e, t = {}) {
|
|
1958
|
+
let n = Date.now(), r = e.syncManager, i = await Tn(e, t), a = {
|
|
1491
1959
|
direction: t.operation,
|
|
1492
1960
|
pull: t.pull,
|
|
1493
1961
|
push: t.push
|
|
1494
1962
|
}, o = t.concurrent ?? !1, s = t.concurrency ?? 3;
|
|
1495
|
-
if (o && (!Number.isSafeInteger(s) || s < 1)) throw new
|
|
1496
|
-
let c;
|
|
1497
|
-
c = o ? await
|
|
1498
|
-
let
|
|
1963
|
+
if (o && (!Number.isSafeInteger(s) || s < 1)) throw new h(`bulkSync: concurrency 必须是不小于 1 的安全整数,收到 ${String(s)}`);
|
|
1964
|
+
let c, l = [];
|
|
1965
|
+
c = o ? await On(r, i, a, s, l) : await Dn(r, i, a, l), gn(r, l);
|
|
1966
|
+
let u = c.filter((e) => e.success).length, d = c.filter((e) => !e.success).length, f = Date.now() - n;
|
|
1499
1967
|
return {
|
|
1500
|
-
succeeded:
|
|
1501
|
-
failed:
|
|
1968
|
+
succeeded: u,
|
|
1969
|
+
failed: d,
|
|
1502
1970
|
results: c,
|
|
1503
|
-
durationMs:
|
|
1971
|
+
durationMs: f
|
|
1504
1972
|
};
|
|
1505
1973
|
}
|
|
1506
1974
|
//#endregion
|
|
1507
1975
|
//#region src/check-repository-updates.ts
|
|
1508
|
-
async function
|
|
1976
|
+
async function An(e, t, n) {
|
|
1509
1977
|
let r = {
|
|
1510
1978
|
namespace: t,
|
|
1511
1979
|
entity: n
|
|
1512
1980
|
}, i = e.config.entities.find((e) => {
|
|
1513
|
-
let r =
|
|
1981
|
+
let r = A(e);
|
|
1514
1982
|
return r.namespace === t && r.name === n;
|
|
1515
1983
|
});
|
|
1516
1984
|
if (!i) throw Error(`Entity not found: ${t}.${n}`);
|
|
1517
|
-
let a =
|
|
1518
|
-
if (!
|
|
1985
|
+
let a = A(i);
|
|
1986
|
+
if (!ue(a, e.entitySync)) return {
|
|
1519
1987
|
repository: r,
|
|
1520
1988
|
remoteLatestChangeId: 0,
|
|
1521
1989
|
localLastPullRemoteChangeId: null,
|
|
1522
1990
|
pendingCount: 0,
|
|
1523
1991
|
hasUpdates: !1
|
|
1524
1992
|
};
|
|
1525
|
-
let o = e.syncManager, s = (await o.getCurrentBranch()).id, { adapter: c } = await o.getLocalRepositories(), l = c.getRepository(
|
|
1993
|
+
let o = e.syncManager, s = (await o.getCurrentBranch()).id, { adapter: c } = await o.getLocalRepositories(), l = c.getRepository(v), u = `${t}:${n}:${s}`, d = (await l.find({
|
|
1526
1994
|
where: {
|
|
1527
1995
|
combinator: "and",
|
|
1528
1996
|
rules: [{
|
|
@@ -1534,36 +2002,36 @@ async function It(e, t, n) {
|
|
|
1534
2002
|
limit: 1
|
|
1535
2003
|
}))[0]?.lastPullRemoteChangeId ?? null, { adapter: f } = await o.getRemoteRepositories();
|
|
1536
2004
|
if (!f) throw Error("Remote adapter not configured");
|
|
1537
|
-
let p = d ?? 0, m = await
|
|
2005
|
+
let p = d ?? 0, m = await ge(o, s), h = await Promise.all(m.map((e) => f.getChangeCount(p, [`${t}:${a.name}`], e))), g = h.reduce((e, t) => e + t.count, 0);
|
|
1538
2006
|
return {
|
|
1539
2007
|
repository: r,
|
|
1540
2008
|
remoteLatestChangeId: h.reduce((e, t) => t.latestChangeId > e ? t.latestChangeId : e, 0),
|
|
1541
2009
|
localLastPullRemoteChangeId: d,
|
|
1542
|
-
pendingCount:
|
|
1543
|
-
hasUpdates:
|
|
2010
|
+
pendingCount: g,
|
|
2011
|
+
hasUpdates: g > 0
|
|
1544
2012
|
};
|
|
1545
2013
|
}
|
|
1546
2014
|
//#endregion
|
|
1547
2015
|
//#region src/cleanup-expired.ts
|
|
1548
|
-
async function
|
|
2016
|
+
async function jn(e, t, n, r) {
|
|
1549
2017
|
let i = e.rxdb, { adapter: a } = await e.getLocalRepositories(), o = i.config.entities.find((e) => {
|
|
1550
|
-
let r =
|
|
2018
|
+
let r = A(e);
|
|
1551
2019
|
return r.namespace === t && r.name === n;
|
|
1552
2020
|
});
|
|
1553
|
-
if (!o) throw new
|
|
1554
|
-
let s =
|
|
2021
|
+
if (!o) throw new h(`Entity not found: ${t}:${n}`);
|
|
2022
|
+
let s = A(o), c = F(s, i.entitySync), l = r?.filter;
|
|
1555
2023
|
if (!l && c === "filter") {
|
|
1556
|
-
let e = s.
|
|
2024
|
+
let e = ce(s, i.entitySync);
|
|
1557
2025
|
if (e?.remote?.filter) try {
|
|
1558
2026
|
l = e.remote.filter();
|
|
1559
2027
|
} catch (e) {
|
|
1560
|
-
throw new
|
|
2028
|
+
throw new h(`Filter function failed for ${t}:${n}: ${e instanceof Error ? e.message : String(e)}`);
|
|
1561
2029
|
}
|
|
1562
2030
|
}
|
|
1563
|
-
if (!l) throw new
|
|
1564
|
-
let u =
|
|
2031
|
+
if (!l) throw new h(`No filter provided and entity ${t}:${n} does not have a Filter sync configuration.`);
|
|
2032
|
+
let u = Mn(l), d = async (e, r) => {
|
|
1565
2033
|
if (e.length === 0) return e;
|
|
1566
|
-
let i = await r.getRepository(
|
|
2034
|
+
let i = await r.getRepository(p).find({ where: {
|
|
1567
2035
|
combinator: "and",
|
|
1568
2036
|
rules: [
|
|
1569
2037
|
{
|
|
@@ -1581,6 +2049,11 @@ async function Lt(e, t, n, r) {
|
|
|
1581
2049
|
operator: "=",
|
|
1582
2050
|
value: null
|
|
1583
2051
|
},
|
|
2052
|
+
{
|
|
2053
|
+
field: "rejectedAt",
|
|
2054
|
+
operator: "=",
|
|
2055
|
+
value: null
|
|
2056
|
+
},
|
|
1584
2057
|
{
|
|
1585
2058
|
field: "revertChangeId",
|
|
1586
2059
|
operator: "=",
|
|
@@ -1589,24 +2062,24 @@ async function Lt(e, t, n, r) {
|
|
|
1589
2062
|
{
|
|
1590
2063
|
field: "entityId",
|
|
1591
2064
|
operator: "in",
|
|
1592
|
-
value:
|
|
2065
|
+
value: oe(e.map((e) => e.id))
|
|
1593
2066
|
}
|
|
1594
2067
|
]
|
|
1595
|
-
} }), a = new Set(i.map((e) =>
|
|
1596
|
-
return a.size === 0 ? e : e.filter((e) => !a.has(
|
|
2068
|
+
} }), a = new Set(i.map((e) => se(e.entityId)));
|
|
2069
|
+
return a.size === 0 ? e : e.filter((e) => !a.has(se(e.id)));
|
|
1597
2070
|
};
|
|
1598
2071
|
if (r?.dryRun) {
|
|
1599
|
-
let e = await
|
|
2072
|
+
let e = await d(await a.getRepository(o).find({ where: u }), a);
|
|
1600
2073
|
return {
|
|
1601
2074
|
removed: e.length,
|
|
1602
2075
|
removedIds: e.map((e) => e.id)
|
|
1603
2076
|
};
|
|
1604
2077
|
}
|
|
1605
2078
|
return a.transaction(async (e) => {
|
|
1606
|
-
let r = e.getRepository(o), i = await
|
|
2079
|
+
let r = e.getRepository(o), i = await d(await r.find({ where: u }), e), a = i.map((e) => e.id);
|
|
1607
2080
|
if (a.length > 0) {
|
|
1608
2081
|
let r = /* @__PURE__ */ new Map();
|
|
1609
|
-
for (let e of i) r.set(`${t}:${n}:${
|
|
2082
|
+
for (let e of i) r.set(`${t}:${n}:${se(e.id)}`, {
|
|
1610
2083
|
patch: null,
|
|
1611
2084
|
inversePatch: null
|
|
1612
2085
|
});
|
|
@@ -1615,7 +2088,11 @@ async function Lt(e, t, n, r) {
|
|
|
1615
2088
|
updates: /* @__PURE__ */ new Map(),
|
|
1616
2089
|
inserts: /* @__PURE__ */ new Map()
|
|
1617
2090
|
};
|
|
1618
|
-
|
|
2091
|
+
ne(e, {
|
|
2092
|
+
file: "cleanup-expired.ts",
|
|
2093
|
+
symbol: "cleanupExpired",
|
|
2094
|
+
intent: T.remote_sync
|
|
2095
|
+
}), await e.mergeChanges(a, void 0, !0);
|
|
1619
2096
|
}
|
|
1620
2097
|
return {
|
|
1621
2098
|
removed: a.length,
|
|
@@ -1623,13 +2100,13 @@ async function Lt(e, t, n, r) {
|
|
|
1623
2100
|
};
|
|
1624
2101
|
});
|
|
1625
2102
|
}
|
|
1626
|
-
function
|
|
2103
|
+
function Mn(e) {
|
|
1627
2104
|
return {
|
|
1628
2105
|
combinator: e.combinator === "and" ? "or" : "and",
|
|
1629
|
-
rules: e.rules.map((e) => "combinator" in e ?
|
|
2106
|
+
rules: e.rules.map((e) => "combinator" in e ? Mn(e) : Nn(e))
|
|
1630
2107
|
};
|
|
1631
2108
|
}
|
|
1632
|
-
function
|
|
2109
|
+
function Nn(e) {
|
|
1633
2110
|
let t = {
|
|
1634
2111
|
"=": "!=",
|
|
1635
2112
|
"!=": "=",
|
|
@@ -1652,7 +2129,7 @@ function zt(e) {
|
|
|
1652
2129
|
exists: "notExists",
|
|
1653
2130
|
notExists: "exists"
|
|
1654
2131
|
}[e.operator];
|
|
1655
|
-
if (!t) throw new
|
|
2132
|
+
if (!t) throw new h(`Cannot invert operator: ${e.operator}`);
|
|
1656
2133
|
return {
|
|
1657
2134
|
...e,
|
|
1658
2135
|
operator: t
|
|
@@ -1660,8 +2137,8 @@ function zt(e) {
|
|
|
1660
2137
|
}
|
|
1661
2138
|
//#endregion
|
|
1662
2139
|
//#region src/get-repository-sync-status.ts
|
|
1663
|
-
async function
|
|
1664
|
-
let { adapter: a } = await e.getLocalRepositories(), o = a.getRepository(
|
|
2140
|
+
async function Pn(e, t, n, r, i) {
|
|
2141
|
+
let { adapter: a } = await e.getLocalRepositories(), o = a.getRepository(p), s = [
|
|
1665
2142
|
{
|
|
1666
2143
|
field: "namespace",
|
|
1667
2144
|
operator: "=",
|
|
@@ -1682,6 +2159,11 @@ async function Bt(e, t, n, r, i) {
|
|
|
1682
2159
|
operator: "=",
|
|
1683
2160
|
value: null
|
|
1684
2161
|
},
|
|
2162
|
+
{
|
|
2163
|
+
field: "rejectedAt",
|
|
2164
|
+
operator: "=",
|
|
2165
|
+
value: null
|
|
2166
|
+
},
|
|
1685
2167
|
{
|
|
1686
2168
|
field: "revertChangeId",
|
|
1687
2169
|
operator: "=",
|
|
@@ -1697,16 +2179,16 @@ async function Bt(e, t, n, r, i) {
|
|
|
1697
2179
|
rules: s
|
|
1698
2180
|
} })).length;
|
|
1699
2181
|
}
|
|
1700
|
-
async function
|
|
1701
|
-
return (await
|
|
2182
|
+
async function Fn(e, t, n) {
|
|
2183
|
+
return (await An(e, t, n)).pendingCount;
|
|
1702
2184
|
}
|
|
1703
|
-
async function
|
|
2185
|
+
async function In(e, t, n) {
|
|
1704
2186
|
let r = e.config.entities.find((e) => {
|
|
1705
|
-
let r =
|
|
2187
|
+
let r = A(e);
|
|
1706
2188
|
return r.namespace === t && r.name === n;
|
|
1707
2189
|
});
|
|
1708
2190
|
if (!r) throw Error(`Entity not found: ${t}.${n}`);
|
|
1709
|
-
let i =
|
|
2191
|
+
let i = A(r), a = F(i, e.entitySync), o = P(a), s = e.syncManager, c = (await s.getCurrentBranch()).id, { adapter: l } = await s.getLocalRepositories(), u = l.getRepository(v), d = {
|
|
1710
2192
|
combinator: "and",
|
|
1711
2193
|
rules: [{
|
|
1712
2194
|
field: "id",
|
|
@@ -1717,14 +2199,14 @@ async function Ht(e, t, n) {
|
|
|
1717
2199
|
where: d,
|
|
1718
2200
|
limit: 1
|
|
1719
2201
|
}), p = f.length > 0 ? f[0] : null, m = 0, h = 0;
|
|
1720
|
-
return
|
|
2202
|
+
return o.push && (m = await Pn(s, t, n, c, p?.lastPushedChangeId ?? null)), o.pull && (h = await Fn(e, t, n)), {
|
|
1721
2203
|
repository: {
|
|
1722
2204
|
namespace: t,
|
|
1723
2205
|
entity: n
|
|
1724
2206
|
},
|
|
1725
2207
|
branchId: c,
|
|
1726
2208
|
syncType: a,
|
|
1727
|
-
enabled: o.pull || o.push ?
|
|
2209
|
+
enabled: o.pull || o.push ? I(p) : !1,
|
|
1728
2210
|
lastPushedChangeId: p?.lastPushedChangeId ?? null,
|
|
1729
2211
|
lastPushedAt: p?.lastPushedAt ?? null,
|
|
1730
2212
|
lastPulledAt: p?.lastPulledAt ?? null,
|
|
@@ -1735,10 +2217,10 @@ async function Ht(e, t, n) {
|
|
|
1735
2217
|
}
|
|
1736
2218
|
//#endregion
|
|
1737
2219
|
//#region src/get-all-repository-sync-status.ts
|
|
1738
|
-
async function
|
|
2220
|
+
async function Ln(e, t) {
|
|
1739
2221
|
let n = e.config.entities, r = [];
|
|
1740
2222
|
for (let t of n) {
|
|
1741
|
-
let n =
|
|
2223
|
+
let n = A(t), i = n.namespace, a = n.name, o = await In(e, i, a);
|
|
1742
2224
|
r.push(o);
|
|
1743
2225
|
}
|
|
1744
2226
|
let i = r;
|
|
@@ -1746,9 +2228,9 @@ async function Ut(e, t) {
|
|
|
1746
2228
|
}
|
|
1747
2229
|
//#endregion
|
|
1748
2230
|
//#region src/pull-batch.ts
|
|
1749
|
-
var
|
|
1750
|
-
async function
|
|
1751
|
-
if (t?.fetchAll !== !0) return await
|
|
2231
|
+
var Rn = 1e3;
|
|
2232
|
+
async function zn(e, t) {
|
|
2233
|
+
if (t?.fetchAll !== !0) return await Hn(e, t?.limit, t?.conflictResolver);
|
|
1752
2234
|
let n = {
|
|
1753
2235
|
pulled: 0,
|
|
1754
2236
|
compacted: 0,
|
|
@@ -1762,36 +2244,36 @@ async function Gt(e, t) {
|
|
|
1762
2244
|
}, r = (e) => {
|
|
1763
2245
|
n.pulled += e.pulled, n.compacted += e.compacted, n.applied += e.applied, n.conflictsResolved += e.conflictsResolved, n.conflictsDeferred += e.conflictsDeferred, n.hasMore = e.hasMore, n.persistedProgress ||= e.persistedProgress, n.historyInvalidated ||= e.historyInvalidated, n.failures.push(...e.failures);
|
|
1764
2246
|
};
|
|
1765
|
-
for (let i = 0; i <
|
|
2247
|
+
for (let i = 0; i < Rn; i++) {
|
|
1766
2248
|
let i;
|
|
1767
2249
|
try {
|
|
1768
|
-
i = await
|
|
2250
|
+
i = await Hn(e, t.limit, t.conflictResolver);
|
|
1769
2251
|
} catch (e) {
|
|
1770
|
-
throw
|
|
2252
|
+
throw Vn(e, n);
|
|
1771
2253
|
}
|
|
1772
2254
|
if (r(i), !i.hasMore || i.pulled === 0) break;
|
|
1773
2255
|
}
|
|
1774
2256
|
return n;
|
|
1775
2257
|
}
|
|
1776
|
-
var
|
|
1777
|
-
function
|
|
2258
|
+
var Bn = (e) => !e.persistedProgress;
|
|
2259
|
+
function Vn(e, t) {
|
|
1778
2260
|
let n = e instanceof Error ? e : Error(String(e));
|
|
1779
|
-
return
|
|
2261
|
+
return Bn(t) ? n : new g(t, n);
|
|
1780
2262
|
}
|
|
1781
|
-
async function
|
|
2263
|
+
async function Hn(e, t, n) {
|
|
1782
2264
|
let r = e.rxdb, i = t ?? 1e3;
|
|
1783
|
-
if (!r.config.sync?.remote?.adapter) throw new
|
|
1784
|
-
let { adapter:
|
|
2265
|
+
if (!r.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
2266
|
+
let { adapter: a } = await e.getRemoteRepositories(), { adapter: s } = await e.getLocalRepositories(), c = (await e.getCurrentBranch()).id, l = await ge(e, c), u = s.getRepository(v), d = [];
|
|
1785
2267
|
for (let e of r.config.entities) {
|
|
1786
|
-
let t =
|
|
1787
|
-
if (!
|
|
1788
|
-
let i = await
|
|
2268
|
+
let t = A(e), n = F(t, r.entitySync);
|
|
2269
|
+
if (!P(n).pull || n === "filter") continue;
|
|
2270
|
+
let i = await M(u, {
|
|
1789
2271
|
namespace: t.namespace,
|
|
1790
2272
|
entity: t.name,
|
|
1791
2273
|
branchId: c,
|
|
1792
2274
|
syncType: n
|
|
1793
|
-
}, () => r.entityManager.instantiate(
|
|
1794
|
-
|
|
2275
|
+
}, () => r.entityManager.instantiate(v));
|
|
2276
|
+
I(i) && d.push({
|
|
1795
2277
|
namespace: t.namespace,
|
|
1796
2278
|
entity: t.name,
|
|
1797
2279
|
syncId: i.id,
|
|
@@ -1800,7 +2282,7 @@ async function Jt(e, t, n) {
|
|
|
1800
2282
|
syncType: n
|
|
1801
2283
|
});
|
|
1802
2284
|
}
|
|
1803
|
-
if (
|
|
2285
|
+
if (d.length === 0) return {
|
|
1804
2286
|
pulled: 0,
|
|
1805
2287
|
compacted: 0,
|
|
1806
2288
|
applied: 0,
|
|
@@ -1811,12 +2293,12 @@ async function Jt(e, t, n) {
|
|
|
1811
2293
|
historyInvalidated: !1,
|
|
1812
2294
|
failures: []
|
|
1813
2295
|
};
|
|
1814
|
-
let
|
|
2296
|
+
let f = Ne(z(r.config.entities.map((e) => A(e)))), m = new Map(d.map((e) => [`${e.namespace}:${e.entity}`, e])), g = f.map((e) => m.get(`${e.namespace}:${e.entity}`)).filter((e) => e != null), _ = i * g.length, y, b = g.map((e) => ({
|
|
1815
2297
|
namespace: e.namespace,
|
|
1816
2298
|
entity: e.entity,
|
|
1817
2299
|
sinceId: e.lastPullRemoteChangeId
|
|
1818
2300
|
}));
|
|
1819
|
-
y =
|
|
2301
|
+
y = a.pullChangesBatch ? await a.pullChangesBatch(b, _, l) : (await Promise.all(g.map((e) => ye(a, {
|
|
1820
2302
|
namespace: e.namespace,
|
|
1821
2303
|
entity: e.entity,
|
|
1822
2304
|
sinceId: e.lastPullRemoteChangeId,
|
|
@@ -1827,99 +2309,80 @@ async function Jt(e, t, n) {
|
|
|
1827
2309
|
let t = `${e.namespace}:${e.entity}`;
|
|
1828
2310
|
x.has(t) || x.set(t, []), x.get(t).push(e);
|
|
1829
2311
|
}
|
|
1830
|
-
let
|
|
2312
|
+
let S = 0, C = 0, w = 0, E = 0, D = !1, ee = r.context.clientId, te = n === void 0 ? new o() : n;
|
|
1831
2313
|
return await s.transaction(async (e) => {
|
|
1832
|
-
let t = e.getRepository(
|
|
1833
|
-
for (let a of
|
|
2314
|
+
let t = e.getRepository(p), n = e.getRepository(v);
|
|
2315
|
+
for (let a of g) {
|
|
1834
2316
|
let o = (x.get(`${a.namespace}:${a.entity}`) ?? []).filter((e) => e.id > a.lastPullRemoteChangeId);
|
|
1835
2317
|
if (o.length === 0) continue;
|
|
1836
|
-
|
|
1837
|
-
let
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
let
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
field: "id",
|
|
1845
|
-
operator: "in",
|
|
1846
|
-
value: e
|
|
1847
|
-
}, {
|
|
1848
|
-
field: "remoteId",
|
|
1849
|
-
operator: "=",
|
|
1850
|
-
value: null
|
|
1851
|
-
}]
|
|
1852
|
-
} });
|
|
1853
|
-
if (n.length > 0) {
|
|
1854
|
-
let e = new Map(u.map((e) => [e.localId, e.id]));
|
|
1855
|
-
for (let r of n) {
|
|
1856
|
-
let n = e.get(r.id);
|
|
1857
|
-
n != null && await t.update(r, { remoteId: n });
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
if (l.length > 0) {
|
|
1862
|
-
let n = z();
|
|
1863
|
-
S(l, n);
|
|
1864
|
-
let i = B(n);
|
|
1865
|
-
w += l.length - i;
|
|
1866
|
-
let o = Ie(l, n), { applyActions: s, conflictsResolved: u } = await Be(o, await Le(t, a.namespace, a.entity, c, a.repoSync.lastPushedChangeId ?? null, [...new Set(o.map((e) => e.entityId))]), {
|
|
2318
|
+
S += o.length;
|
|
2319
|
+
let { ownChanges: s, otherChanges: l } = De(o, ee);
|
|
2320
|
+
if (await Oe(t, s), l.length > 0) {
|
|
2321
|
+
let n = B();
|
|
2322
|
+
k(l, n);
|
|
2323
|
+
let i = V(n);
|
|
2324
|
+
C += l.length - i;
|
|
2325
|
+
let o = Se(l, n), { applyActions: s, conflictsResolved: u } = await Ee(o, await Ce(t, a.namespace, a.entity, c, a.repoSync.lastPushedChangeId ?? null, [...new Set(o.map((e) => e.entityId))]), {
|
|
1867
2326
|
changeRepo: t,
|
|
1868
|
-
conflictResolver:
|
|
2327
|
+
conflictResolver: te,
|
|
1869
2328
|
dispatchEvent: (e) => r.dispatchEvent(e),
|
|
1870
2329
|
repoLabel: `${a.namespace}:${a.entity}`,
|
|
1871
2330
|
localClientId: r.context.clientId
|
|
1872
2331
|
});
|
|
1873
|
-
|
|
1874
|
-
let d =
|
|
1875
|
-
d > 0 && (
|
|
2332
|
+
E += u;
|
|
2333
|
+
let d = V(s);
|
|
2334
|
+
d > 0 && (ne(e, {
|
|
2335
|
+
file: "pull-batch.ts",
|
|
2336
|
+
symbol: "pullBatchOnce",
|
|
2337
|
+
intent: T.remote_sync
|
|
2338
|
+
}), await e.mergeChanges(s, void 0, !0), w += d);
|
|
1876
2339
|
}
|
|
1877
|
-
let
|
|
2340
|
+
let u = o.reduce((e, t) => t.id > e ? t.id : e, o[0].id);
|
|
1878
2341
|
a.repoSync = await n.update(a.repoSync, {
|
|
1879
|
-
lastPullRemoteChangeId:
|
|
2342
|
+
lastPullRemoteChangeId: u,
|
|
1880
2343
|
lastPulledAt: /* @__PURE__ */ new Date(),
|
|
1881
2344
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1882
|
-
}), o.length >= i && (
|
|
2345
|
+
}), o.length >= i && (D = !0);
|
|
1883
2346
|
}
|
|
1884
2347
|
}), {
|
|
1885
|
-
pulled:
|
|
1886
|
-
compacted:
|
|
1887
|
-
applied:
|
|
1888
|
-
hasMore:
|
|
1889
|
-
conflictsResolved:
|
|
2348
|
+
pulled: S,
|
|
2349
|
+
compacted: C,
|
|
2350
|
+
applied: w,
|
|
2351
|
+
hasMore: D,
|
|
2352
|
+
conflictsResolved: E,
|
|
1890
2353
|
conflictsDeferred: 0,
|
|
1891
|
-
persistedProgress:
|
|
1892
|
-
historyInvalidated:
|
|
2354
|
+
persistedProgress: S > 0,
|
|
2355
|
+
historyInvalidated: w > 0,
|
|
1893
2356
|
failures: []
|
|
1894
2357
|
};
|
|
1895
2358
|
}
|
|
1896
2359
|
//#endregion
|
|
1897
2360
|
//#region src/pull.ts
|
|
1898
|
-
async function
|
|
2361
|
+
async function Un(e, t) {
|
|
1899
2362
|
let n = e.rxdb;
|
|
1900
|
-
if (!n.config.sync?.remote?.adapter) throw new
|
|
1901
|
-
n.dispatchEvent(new
|
|
2363
|
+
if (!n.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
2364
|
+
n.dispatchEvent(new S("pull"));
|
|
1902
2365
|
try {
|
|
1903
2366
|
let r;
|
|
1904
|
-
return t?.repositoryFilter?.length ? r = await
|
|
2367
|
+
return t?.repositoryFilter?.length ? r = await Kn(e, t) : (r = await zn(e, {
|
|
1905
2368
|
limit: t?.limit,
|
|
1906
2369
|
fetchAll: t?.fetchAll,
|
|
1907
2370
|
conflictResolver: t?.conflictResolver
|
|
1908
|
-
}), await
|
|
2371
|
+
}), await Wn(e, t, r)), n.dispatchEvent(new C("pull", r)), r;
|
|
1909
2372
|
} catch (e) {
|
|
1910
|
-
throw n.dispatchEvent(new
|
|
2373
|
+
throw n.dispatchEvent(new w("pull", e)), e;
|
|
1911
2374
|
}
|
|
1912
2375
|
}
|
|
1913
|
-
async function
|
|
2376
|
+
async function Wn(e, t, n) {
|
|
1914
2377
|
let r = e.rxdb;
|
|
1915
2378
|
for (let i of r.config.entities) {
|
|
1916
|
-
let a =
|
|
1917
|
-
if (o !== "filter" || !
|
|
1918
|
-
let s = await
|
|
1919
|
-
if (!
|
|
2379
|
+
let a = A(i), o = F(a, r.entitySync);
|
|
2380
|
+
if (o !== "filter" || !P(o).pull) continue;
|
|
2381
|
+
let s = await re(e.rxdb, a.namespace, a.name);
|
|
2382
|
+
if (!I(s)) continue;
|
|
1920
2383
|
let c;
|
|
1921
2384
|
try {
|
|
1922
|
-
c = await
|
|
2385
|
+
c = await ze(e, a.namespace, a.name, {
|
|
1923
2386
|
limit: t?.limit,
|
|
1924
2387
|
fetchAll: t?.fetchAll,
|
|
1925
2388
|
conflictResolver: t?.conflictResolver,
|
|
@@ -1927,22 +2390,22 @@ async function Xt(e, t, n) {
|
|
|
1927
2390
|
});
|
|
1928
2391
|
} catch (e) {
|
|
1929
2392
|
let t = e instanceof Error ? e : Error(String(e));
|
|
1930
|
-
t instanceof
|
|
2393
|
+
t instanceof g && Gn(n, t.result), n.failures.push({
|
|
1931
2394
|
repository: {
|
|
1932
2395
|
namespace: a.namespace,
|
|
1933
2396
|
entity: a.name
|
|
1934
2397
|
},
|
|
1935
|
-
error: t instanceof
|
|
2398
|
+
error: t instanceof g ? t.cause : t
|
|
1936
2399
|
});
|
|
1937
2400
|
continue;
|
|
1938
2401
|
}
|
|
1939
|
-
|
|
2402
|
+
Gn(n, c), n.failures.push(...c.failures);
|
|
1940
2403
|
}
|
|
1941
2404
|
}
|
|
1942
|
-
function
|
|
2405
|
+
function Gn(e, t) {
|
|
1943
2406
|
e.pulled += t.pulled, e.compacted += t.compacted, e.applied += t.applied, e.conflictsResolved += t.conflictsResolved, e.conflictsDeferred += t.conflictsDeferred, e.hasMore ||= t.hasMore, e.persistedProgress ||= t.persistedProgress, e.historyInvalidated ||= t.historyInvalidated;
|
|
1944
2407
|
}
|
|
1945
|
-
async function
|
|
2408
|
+
async function Kn(e, t) {
|
|
1946
2409
|
let n = {
|
|
1947
2410
|
operation: "pull",
|
|
1948
2411
|
repositories: t.repositoryFilter?.map((e) => typeof e == "string" ? {
|
|
@@ -1968,19 +2431,19 @@ async function Qt(e, t) {
|
|
|
1968
2431
|
for (let e of r.results) {
|
|
1969
2432
|
let t = e.result?.pullResult;
|
|
1970
2433
|
if (t && (i.pulled += t.pulled, i.compacted += t.compacted, i.applied += t.applied, i.conflictsResolved += t.conflictsResolved, i.conflictsDeferred += t.conflictsDeferred, i.hasMore ||= t.hasMore, i.persistedProgress ||= t.persistedProgress, i.historyInvalidated ||= t.historyInvalidated), e.success) continue;
|
|
1971
|
-
let n = e.error ?? new
|
|
2434
|
+
let n = e.error ?? new h(`Repository pull failed: ${e.repository.namespace}:${e.repository.entity}`);
|
|
1972
2435
|
i.failures.push({
|
|
1973
2436
|
repository: e.repository,
|
|
1974
|
-
error: n instanceof
|
|
2437
|
+
error: n instanceof g ? n.cause : n
|
|
1975
2438
|
});
|
|
1976
2439
|
}
|
|
1977
2440
|
let [a] = i.failures;
|
|
1978
|
-
if (a) throw !i.persistedProgress && i.failures.length === 1 ? a.error : new
|
|
2441
|
+
if (a) throw !i.persistedProgress && i.failures.length === 1 ? a.error : new g(i, a.error);
|
|
1979
2442
|
return i;
|
|
1980
2443
|
}
|
|
1981
2444
|
//#endregion
|
|
1982
2445
|
//#region src/branch-change-id.ts
|
|
1983
|
-
var
|
|
2446
|
+
var qn = async (e, t, n) => (await e.find({
|
|
1984
2447
|
where: {
|
|
1985
2448
|
combinator: "and",
|
|
1986
2449
|
rules: [{
|
|
@@ -1990,18 +2453,18 @@ var $t = async (e, t, n) => (await e.find({
|
|
|
1990
2453
|
}]
|
|
1991
2454
|
},
|
|
1992
2455
|
limit: 1
|
|
1993
|
-
}))[0],
|
|
1994
|
-
let n = await
|
|
1995
|
-
if (!n) throw new
|
|
2456
|
+
}))[0], Jn = async (e, t) => {
|
|
2457
|
+
let n = await qn(e, "id", t);
|
|
2458
|
+
if (!n) throw new h(`分支分叉点翻译失败:本地不存在 RxDBChange id=${t},分支表与变更表已不一致`);
|
|
1996
2459
|
return n.remoteId ?? null;
|
|
1997
|
-
},
|
|
2460
|
+
}, Yn = async (e, t) => (await qn(e, "remoteId", t))?.id ?? null;
|
|
1998
2461
|
//#endregion
|
|
1999
2462
|
//#region src/push-branch.ts
|
|
2000
|
-
async function
|
|
2463
|
+
async function Xn(e) {
|
|
2001
2464
|
let t = await e.getCurrentBranch();
|
|
2002
|
-
if (!t || t.id ===
|
|
2465
|
+
if (!t || t.id === s) return {
|
|
2003
2466
|
synced: 0,
|
|
2004
|
-
skipped: t ? [
|
|
2467
|
+
skipped: t ? [s] : [],
|
|
2005
2468
|
forkPointPending: !1
|
|
2006
2469
|
};
|
|
2007
2470
|
let { adapter: n } = await e.getRemoteRepositories();
|
|
@@ -2010,29 +2473,29 @@ async function nn(e) {
|
|
|
2010
2473
|
skipped: [],
|
|
2011
2474
|
forkPointPending: !1
|
|
2012
2475
|
};
|
|
2013
|
-
let { branchRepository: r, changeRepository: i } = await e.getLocalRepositories(), a = t.fromChangeId ?? null, o = a === null ? null : await
|
|
2476
|
+
let { branchRepository: r, changeRepository: i } = await e.getLocalRepositories(), a = t.fromChangeId ?? null, o = a === null ? null : await Jn(i, a), c = a !== null && o === null, l = {
|
|
2014
2477
|
id: t.id,
|
|
2015
2478
|
fromChangeId: o,
|
|
2016
2479
|
local: t.local,
|
|
2017
2480
|
remote: !0,
|
|
2018
2481
|
parentId: t.parentId
|
|
2019
|
-
},
|
|
2020
|
-
return
|
|
2482
|
+
}, u = await n.pushBranches([l]);
|
|
2483
|
+
return u.synced > 0 && !t.remote && await r.update(t, {
|
|
2021
2484
|
remote: !0,
|
|
2022
2485
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2023
2486
|
}), {
|
|
2024
|
-
...
|
|
2025
|
-
forkPointPending:
|
|
2487
|
+
...u,
|
|
2488
|
+
forkPointPending: c
|
|
2026
2489
|
};
|
|
2027
2490
|
}
|
|
2028
2491
|
//#endregion
|
|
2029
2492
|
//#region src/push.ts
|
|
2030
|
-
async function
|
|
2493
|
+
async function Zn(e, t) {
|
|
2031
2494
|
let n = e.rxdb;
|
|
2032
|
-
if (!n.config.sync?.remote?.adapter) throw new
|
|
2033
|
-
n.dispatchEvent(new
|
|
2495
|
+
if (!n.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
2496
|
+
n.dispatchEvent(new S("push"));
|
|
2034
2497
|
try {
|
|
2035
|
-
let r = await
|
|
2498
|
+
let r = await Xn(e), i = {
|
|
2036
2499
|
operation: "push",
|
|
2037
2500
|
repositories: t?.repositoryFilter?.map((e) => typeof e == "string" ? {
|
|
2038
2501
|
namespace: "public",
|
|
@@ -2041,6 +2504,7 @@ async function rn(e, t) {
|
|
|
2041
2504
|
...t?.batchSize === void 0 ? {} : { push: { batchSize: t.batchSize } }
|
|
2042
2505
|
}, a = await e.bulkSync(i), o = {
|
|
2043
2506
|
pushed: 0,
|
|
2507
|
+
rejected: 0,
|
|
2044
2508
|
failed: 0,
|
|
2045
2509
|
compacted: 0,
|
|
2046
2510
|
originalCount: 0,
|
|
@@ -2048,21 +2512,29 @@ async function rn(e, t) {
|
|
|
2048
2512
|
};
|
|
2049
2513
|
for (let e of a.results) {
|
|
2050
2514
|
let t = e.result?.pushResult;
|
|
2051
|
-
if (t && (o.pushed += t.pushed, o.failed += t.failed, o.compacted += t.compacted, o.originalCount += t.originalCount), e.success) continue;
|
|
2052
|
-
let n = e.error ?? new
|
|
2515
|
+
if (t && (o.pushed += t.pushed, o.rejected += t.rejected, o.failed += t.failed, o.compacted += t.compacted, o.originalCount += t.originalCount), e.success) continue;
|
|
2516
|
+
let n = e.error ?? new h(`Repository push failed: ${e.repository.namespace}:${e.repository.entity}`);
|
|
2053
2517
|
o.failures.push({
|
|
2054
2518
|
repository: e.repository,
|
|
2055
|
-
error: n instanceof
|
|
2519
|
+
error: n instanceof g ? n.cause : n
|
|
2056
2520
|
});
|
|
2057
2521
|
}
|
|
2058
|
-
return r.forkPointPending && o.pushed > 0 && await
|
|
2522
|
+
return r.forkPointPending && o.pushed > 0 && await Xn(e), n.dispatchEvent(new C("push", o)), o;
|
|
2059
2523
|
} catch (e) {
|
|
2060
|
-
throw n.dispatchEvent(new
|
|
2524
|
+
throw n.dispatchEvent(new w("push", e)), e;
|
|
2061
2525
|
}
|
|
2062
2526
|
}
|
|
2063
2527
|
//#endregion
|
|
2064
2528
|
//#region src/sync-branches.ts
|
|
2065
|
-
function
|
|
2529
|
+
function Qn(e) {
|
|
2530
|
+
try {
|
|
2531
|
+
return D(e), !0;
|
|
2532
|
+
} catch (e) {
|
|
2533
|
+
if (e instanceof a) return !1;
|
|
2534
|
+
throw e;
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
function $n(e, t) {
|
|
2066
2538
|
let n = new Set(t), r = new Set(e.map((e) => e.id)), i = [], a = e;
|
|
2067
2539
|
for (; a.length > 0;) {
|
|
2068
2540
|
let e = a.filter((e) => {
|
|
@@ -2078,51 +2550,68 @@ function an(e, t) {
|
|
|
2078
2550
|
let t = e.parentId ?? null, n = t !== null && r.has(t) ? "cycle" : "missing parent";
|
|
2079
2551
|
return `'${e.id}' -> '${String(t)}' (${n})`;
|
|
2080
2552
|
}).join(", ");
|
|
2081
|
-
throw new
|
|
2553
|
+
throw new h(`syncBranches: 远端分支拓扑无法解析,整批放弃:${e}`);
|
|
2082
2554
|
}
|
|
2083
2555
|
return i;
|
|
2084
2556
|
}
|
|
2085
|
-
async function
|
|
2557
|
+
async function er(e) {
|
|
2086
2558
|
let { adapter: t } = await e.getRemoteRepositories();
|
|
2087
2559
|
if (!t.pullBranches) return {
|
|
2088
2560
|
created: 0,
|
|
2089
2561
|
updated: 0,
|
|
2090
2562
|
total: 0,
|
|
2091
|
-
skipped: []
|
|
2563
|
+
skipped: [],
|
|
2564
|
+
skipReasons: {}
|
|
2092
2565
|
};
|
|
2093
2566
|
let n = await t.pullBranches();
|
|
2094
2567
|
if (n.length === 0) return {
|
|
2095
2568
|
created: 0,
|
|
2096
2569
|
updated: 0,
|
|
2097
2570
|
total: 0,
|
|
2098
|
-
skipped: []
|
|
2571
|
+
skipped: [],
|
|
2572
|
+
skipReasons: {}
|
|
2099
2573
|
};
|
|
2100
2574
|
let { adapter: r } = await e.getLocalRepositories();
|
|
2101
2575
|
return r.transaction(async (e) => {
|
|
2102
|
-
let t = e.getRepository(
|
|
2576
|
+
let t = e.getRepository(f), r = e.getRepository(p), i = await t.find({ where: {
|
|
2103
2577
|
combinator: "and",
|
|
2104
2578
|
rules: []
|
|
2105
|
-
} }), a = new Map(i.map((e) => [e.id, e])), o = 0, s = 0, c = []
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2579
|
+
} }), a = new Map(i.map((e) => [e.id, e])), o = 0, s = 0, c = [], l = /* @__PURE__ */ new Map(), u = (e, t) => {
|
|
2580
|
+
c.push(e), l.set(e, t);
|
|
2581
|
+
};
|
|
2582
|
+
for (let e of $n(n, new Set(a.keys()))) {
|
|
2583
|
+
let n = e.parentId ?? null;
|
|
2584
|
+
if (n !== null && l.has(n)) {
|
|
2585
|
+
u(e.id, {
|
|
2586
|
+
cause: "ancestor-skipped",
|
|
2587
|
+
ancestorId: n
|
|
2588
|
+
});
|
|
2589
|
+
continue;
|
|
2590
|
+
}
|
|
2591
|
+
if (!Qn(e.id)) {
|
|
2592
|
+
u(e.id, { cause: "invalid-id" });
|
|
2593
|
+
continue;
|
|
2594
|
+
}
|
|
2595
|
+
let i = a.get(e.id);
|
|
2596
|
+
if (i) {
|
|
2597
|
+
i.remote || (await t.update(i, {
|
|
2110
2598
|
remote: !0,
|
|
2111
2599
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2112
2600
|
}), s++);
|
|
2113
2601
|
continue;
|
|
2114
2602
|
}
|
|
2115
|
-
let
|
|
2116
|
-
if (
|
|
2117
|
-
|
|
2603
|
+
let c = e.fromChangeId ?? null, d = c === null ? null : await Yn(r, c);
|
|
2604
|
+
if (c !== null && d === null) {
|
|
2605
|
+
u(e.id, { cause: "unresolved-from-change-id" });
|
|
2118
2606
|
continue;
|
|
2119
2607
|
}
|
|
2120
2608
|
await t.create({
|
|
2121
2609
|
id: e.id,
|
|
2122
2610
|
activated: !1,
|
|
2611
|
+
activeKey: null,
|
|
2123
2612
|
local: !1,
|
|
2124
2613
|
remote: !0,
|
|
2125
|
-
fromChangeId:
|
|
2614
|
+
fromChangeId: d,
|
|
2126
2615
|
parentId: e.parentId ?? null
|
|
2127
2616
|
}), o++;
|
|
2128
2617
|
}
|
|
@@ -2130,23 +2619,24 @@ async function on(e) {
|
|
|
2130
2619
|
created: o,
|
|
2131
2620
|
updated: s,
|
|
2132
2621
|
total: n.length,
|
|
2133
|
-
skipped: c
|
|
2622
|
+
skipped: c,
|
|
2623
|
+
skipReasons: Object.fromEntries(l)
|
|
2134
2624
|
};
|
|
2135
2625
|
});
|
|
2136
2626
|
}
|
|
2137
2627
|
//#endregion
|
|
2138
2628
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isFunction.js
|
|
2139
|
-
function
|
|
2629
|
+
function W(e) {
|
|
2140
2630
|
return typeof e == "function";
|
|
2141
2631
|
}
|
|
2142
2632
|
//#endregion
|
|
2143
2633
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/lift.js
|
|
2144
|
-
function
|
|
2145
|
-
return
|
|
2634
|
+
function tr(e) {
|
|
2635
|
+
return W(e?.lift);
|
|
2146
2636
|
}
|
|
2147
|
-
function
|
|
2637
|
+
function G(e) {
|
|
2148
2638
|
return function(t) {
|
|
2149
|
-
if (
|
|
2639
|
+
if (tr(t)) return t.lift(function(t) {
|
|
2150
2640
|
try {
|
|
2151
2641
|
return e(t, this);
|
|
2152
2642
|
} catch (e) {
|
|
@@ -2158,22 +2648,22 @@ function U(e) {
|
|
|
2158
2648
|
}
|
|
2159
2649
|
//#endregion
|
|
2160
2650
|
//#region ../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
|
|
2161
|
-
var
|
|
2162
|
-
return
|
|
2651
|
+
var nr = function(e, t) {
|
|
2652
|
+
return nr = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, t) {
|
|
2163
2653
|
e.__proto__ = t;
|
|
2164
2654
|
} || function(e, t) {
|
|
2165
2655
|
for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
|
|
2166
|
-
},
|
|
2656
|
+
}, nr(e, t);
|
|
2167
2657
|
};
|
|
2168
|
-
function
|
|
2658
|
+
function rr(e, t) {
|
|
2169
2659
|
if (typeof t != "function" && t !== null) throw TypeError("Class extends value " + String(t) + " is not a constructor or null");
|
|
2170
|
-
|
|
2660
|
+
nr(e, t);
|
|
2171
2661
|
function n() {
|
|
2172
2662
|
this.constructor = e;
|
|
2173
2663
|
}
|
|
2174
2664
|
e.prototype = t === null ? Object.create(t) : (n.prototype = t.prototype, new n());
|
|
2175
2665
|
}
|
|
2176
|
-
function
|
|
2666
|
+
function ir(e, t, n, r) {
|
|
2177
2667
|
function i(e) {
|
|
2178
2668
|
return e instanceof n ? e : new n(function(t) {
|
|
2179
2669
|
t(e);
|
|
@@ -2200,7 +2690,7 @@ function un(e, t, n, r) {
|
|
|
2200
2690
|
c((r = r.apply(e, t || [])).next());
|
|
2201
2691
|
});
|
|
2202
2692
|
}
|
|
2203
|
-
function
|
|
2693
|
+
function ar(e, t) {
|
|
2204
2694
|
var n = {
|
|
2205
2695
|
label: 0,
|
|
2206
2696
|
sent: function() {
|
|
@@ -2270,7 +2760,7 @@ function dn(e, t) {
|
|
|
2270
2760
|
};
|
|
2271
2761
|
}
|
|
2272
2762
|
}
|
|
2273
|
-
function
|
|
2763
|
+
function K(e) {
|
|
2274
2764
|
var t = typeof Symbol == "function" && Symbol.iterator, n = t && e[t], r = 0;
|
|
2275
2765
|
if (n) return n.call(e);
|
|
2276
2766
|
if (e && typeof e.length == "number") return { next: function() {
|
|
@@ -2281,7 +2771,7 @@ function W(e) {
|
|
|
2281
2771
|
} };
|
|
2282
2772
|
throw TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
2283
2773
|
}
|
|
2284
|
-
function
|
|
2774
|
+
function q(e, t) {
|
|
2285
2775
|
var n = typeof Symbol == "function" && e[Symbol.iterator];
|
|
2286
2776
|
if (!n) return e;
|
|
2287
2777
|
var r = n.call(e), i, a = [], o;
|
|
@@ -2298,14 +2788,14 @@ function G(e, t) {
|
|
|
2298
2788
|
}
|
|
2299
2789
|
return a;
|
|
2300
2790
|
}
|
|
2301
|
-
function
|
|
2791
|
+
function J(e, t, n) {
|
|
2302
2792
|
if (n || arguments.length === 2) for (var r = 0, i = t.length, a; r < i; r++) (a || !(r in t)) && (a ||= Array.prototype.slice.call(t, 0, r), a[r] = t[r]);
|
|
2303
2793
|
return e.concat(a || Array.prototype.slice.call(t));
|
|
2304
2794
|
}
|
|
2305
|
-
function
|
|
2306
|
-
return this instanceof
|
|
2795
|
+
function Y(e) {
|
|
2796
|
+
return this instanceof Y ? (this.v = e, this) : new Y(e);
|
|
2307
2797
|
}
|
|
2308
|
-
function
|
|
2798
|
+
function or(e, t, n) {
|
|
2309
2799
|
if (!Symbol.asyncIterator) throw TypeError("Symbol.asyncIterator is not defined.");
|
|
2310
2800
|
var r = n.apply(e, t || []), i, a = [];
|
|
2311
2801
|
return i = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), s("next"), s("throw"), s("return", o), i[Symbol.asyncIterator] = function() {
|
|
@@ -2336,7 +2826,7 @@ function fn(e, t, n) {
|
|
|
2336
2826
|
}
|
|
2337
2827
|
}
|
|
2338
2828
|
function l(e) {
|
|
2339
|
-
e.value instanceof
|
|
2829
|
+
e.value instanceof Y ? Promise.resolve(e.value.v).then(u, d) : f(a[0][2], e);
|
|
2340
2830
|
}
|
|
2341
2831
|
function u(e) {
|
|
2342
2832
|
c("next", e);
|
|
@@ -2348,10 +2838,10 @@ function fn(e, t, n) {
|
|
|
2348
2838
|
e(t), a.shift(), a.length && c(a[0][0], a[0][1]);
|
|
2349
2839
|
}
|
|
2350
2840
|
}
|
|
2351
|
-
function
|
|
2841
|
+
function sr(e) {
|
|
2352
2842
|
if (!Symbol.asyncIterator) throw TypeError("Symbol.asyncIterator is not defined.");
|
|
2353
2843
|
var t = e[Symbol.asyncIterator], n;
|
|
2354
|
-
return t ? t.call(e) : (e = typeof
|
|
2844
|
+
return t ? t.call(e) : (e = typeof K == "function" ? K(e) : e[Symbol.iterator](), n = {}, r("next"), r("throw"), r("return"), n[Symbol.asyncIterator] = function() {
|
|
2355
2845
|
return this;
|
|
2356
2846
|
}, n);
|
|
2357
2847
|
function r(t) {
|
|
@@ -2372,17 +2862,17 @@ function pn(e) {
|
|
|
2372
2862
|
}
|
|
2373
2863
|
//#endregion
|
|
2374
2864
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isArrayLike.js
|
|
2375
|
-
var
|
|
2865
|
+
var cr = (function(e) {
|
|
2376
2866
|
return e && typeof e.length == "number" && typeof e != "function";
|
|
2377
2867
|
});
|
|
2378
2868
|
//#endregion
|
|
2379
2869
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isPromise.js
|
|
2380
|
-
function
|
|
2381
|
-
return
|
|
2870
|
+
function lr(e) {
|
|
2871
|
+
return W(e?.then);
|
|
2382
2872
|
}
|
|
2383
2873
|
//#endregion
|
|
2384
2874
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js
|
|
2385
|
-
function
|
|
2875
|
+
function ur(e) {
|
|
2386
2876
|
var t = e(function(e) {
|
|
2387
2877
|
Error.call(e), e.stack = (/* @__PURE__ */ Error()).stack;
|
|
2388
2878
|
});
|
|
@@ -2390,7 +2880,7 @@ function gn(e) {
|
|
|
2390
2880
|
}
|
|
2391
2881
|
//#endregion
|
|
2392
2882
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js
|
|
2393
|
-
var
|
|
2883
|
+
var dr = ur(function(e) {
|
|
2394
2884
|
return function(t) {
|
|
2395
2885
|
e(this), this.message = t ? t.length + " errors occurred during unsubscription:\n" + t.map(function(e, t) {
|
|
2396
2886
|
return t + 1 + ") " + e.toString();
|
|
@@ -2399,7 +2889,7 @@ var _n = gn(function(e) {
|
|
|
2399
2889
|
});
|
|
2400
2890
|
//#endregion
|
|
2401
2891
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js
|
|
2402
|
-
function
|
|
2892
|
+
function fr(e, t) {
|
|
2403
2893
|
if (e) {
|
|
2404
2894
|
var n = e.indexOf(t);
|
|
2405
2895
|
0 <= n && e.splice(n, 1);
|
|
@@ -2407,7 +2897,7 @@ function vn(e, t) {
|
|
|
2407
2897
|
}
|
|
2408
2898
|
//#endregion
|
|
2409
2899
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/Subscription.js
|
|
2410
|
-
var
|
|
2900
|
+
var pr = function() {
|
|
2411
2901
|
function e(e) {
|
|
2412
2902
|
this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
|
|
2413
2903
|
}
|
|
@@ -2418,7 +2908,7 @@ var yn = function() {
|
|
|
2418
2908
|
var a = this._parentage;
|
|
2419
2909
|
if (a) {
|
|
2420
2910
|
if (this._parentage = null, Array.isArray(a)) try {
|
|
2421
|
-
for (var o =
|
|
2911
|
+
for (var o = K(a), s = o.next(); !s.done; s = o.next()) s.value.remove(this);
|
|
2422
2912
|
} catch (t) {
|
|
2423
2913
|
e = { error: t };
|
|
2424
2914
|
} finally {
|
|
@@ -2431,21 +2921,21 @@ var yn = function() {
|
|
|
2431
2921
|
else a.remove(this);
|
|
2432
2922
|
}
|
|
2433
2923
|
var c = this.initialTeardown;
|
|
2434
|
-
if (
|
|
2924
|
+
if (W(c)) try {
|
|
2435
2925
|
c();
|
|
2436
2926
|
} catch (e) {
|
|
2437
|
-
i = e instanceof
|
|
2927
|
+
i = e instanceof dr ? e.errors : [e];
|
|
2438
2928
|
}
|
|
2439
2929
|
var l = this._finalizers;
|
|
2440
2930
|
if (l) {
|
|
2441
2931
|
this._finalizers = null;
|
|
2442
2932
|
try {
|
|
2443
|
-
for (var u =
|
|
2933
|
+
for (var u = K(l), d = u.next(); !d.done; d = u.next()) {
|
|
2444
2934
|
var f = d.value;
|
|
2445
2935
|
try {
|
|
2446
|
-
|
|
2936
|
+
hr(f);
|
|
2447
2937
|
} catch (e) {
|
|
2448
|
-
i ??= [], e instanceof
|
|
2938
|
+
i ??= [], e instanceof dr ? i = J(J([], q(i)), q(e.errors)) : i.push(e);
|
|
2449
2939
|
}
|
|
2450
2940
|
}
|
|
2451
2941
|
} catch (e) {
|
|
@@ -2458,11 +2948,11 @@ var yn = function() {
|
|
|
2458
2948
|
}
|
|
2459
2949
|
}
|
|
2460
2950
|
}
|
|
2461
|
-
if (i) throw new
|
|
2951
|
+
if (i) throw new dr(i);
|
|
2462
2952
|
}
|
|
2463
2953
|
}, e.prototype.add = function(t) {
|
|
2464
2954
|
if (t && t !== this) {
|
|
2465
|
-
if (this.closed)
|
|
2955
|
+
if (this.closed) hr(t);
|
|
2466
2956
|
else {
|
|
2467
2957
|
if (t instanceof e) {
|
|
2468
2958
|
if (t.closed || t._hasParent(this)) return;
|
|
@@ -2479,64 +2969,64 @@ var yn = function() {
|
|
|
2479
2969
|
this._parentage = Array.isArray(t) ? (t.push(e), t) : t ? [t, e] : e;
|
|
2480
2970
|
}, e.prototype._removeParent = function(e) {
|
|
2481
2971
|
var t = this._parentage;
|
|
2482
|
-
t === e ? this._parentage = null : Array.isArray(t) &&
|
|
2972
|
+
t === e ? this._parentage = null : Array.isArray(t) && fr(t, e);
|
|
2483
2973
|
}, e.prototype.remove = function(t) {
|
|
2484
2974
|
var n = this._finalizers;
|
|
2485
|
-
n &&
|
|
2975
|
+
n && fr(n, t), t instanceof e && t._removeParent(this);
|
|
2486
2976
|
}, e.EMPTY = (function() {
|
|
2487
2977
|
var t = new e();
|
|
2488
2978
|
return t.closed = !0, t;
|
|
2489
2979
|
})(), e;
|
|
2490
2980
|
}();
|
|
2491
|
-
|
|
2492
|
-
function
|
|
2493
|
-
return e instanceof
|
|
2981
|
+
pr.EMPTY;
|
|
2982
|
+
function mr(e) {
|
|
2983
|
+
return e instanceof pr || e && "closed" in e && W(e.remove) && W(e.add) && W(e.unsubscribe);
|
|
2494
2984
|
}
|
|
2495
|
-
function
|
|
2496
|
-
|
|
2985
|
+
function hr(e) {
|
|
2986
|
+
W(e) ? e() : e.unsubscribe();
|
|
2497
2987
|
}
|
|
2498
2988
|
//#endregion
|
|
2499
2989
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/config.js
|
|
2500
|
-
var
|
|
2990
|
+
var X = {
|
|
2501
2991
|
onUnhandledError: null,
|
|
2502
2992
|
onStoppedNotification: null,
|
|
2503
2993
|
Promise: void 0,
|
|
2504
2994
|
useDeprecatedSynchronousErrorHandling: !1,
|
|
2505
2995
|
useDeprecatedNextContext: !1
|
|
2506
|
-
},
|
|
2996
|
+
}, gr = {
|
|
2507
2997
|
setTimeout: function(e, t) {
|
|
2508
|
-
var n = [...arguments].slice(2), r =
|
|
2509
|
-
return r?.setTimeout ? r.setTimeout.apply(r,
|
|
2998
|
+
var n = [...arguments].slice(2), r = gr.delegate;
|
|
2999
|
+
return r?.setTimeout ? r.setTimeout.apply(r, J([e, t], q(n))) : setTimeout.apply(void 0, J([e, t], q(n)));
|
|
2510
3000
|
},
|
|
2511
3001
|
clearTimeout: function(e) {
|
|
2512
|
-
return (
|
|
3002
|
+
return (gr.delegate?.clearTimeout || clearTimeout)(e);
|
|
2513
3003
|
},
|
|
2514
3004
|
delegate: void 0
|
|
2515
3005
|
};
|
|
2516
3006
|
//#endregion
|
|
2517
3007
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js
|
|
2518
|
-
function
|
|
2519
|
-
|
|
2520
|
-
var t =
|
|
3008
|
+
function _r(e) {
|
|
3009
|
+
gr.setTimeout(function() {
|
|
3010
|
+
var t = X.onUnhandledError;
|
|
2521
3011
|
if (t) t(e);
|
|
2522
3012
|
else throw e;
|
|
2523
3013
|
});
|
|
2524
3014
|
}
|
|
2525
3015
|
//#endregion
|
|
2526
3016
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/noop.js
|
|
2527
|
-
function
|
|
3017
|
+
function vr() {}
|
|
2528
3018
|
//#endregion
|
|
2529
3019
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/NotificationFactories.js
|
|
2530
|
-
var
|
|
2531
|
-
return
|
|
3020
|
+
var yr = (function() {
|
|
3021
|
+
return Sr("C", void 0, void 0);
|
|
2532
3022
|
})();
|
|
2533
|
-
function
|
|
2534
|
-
return
|
|
3023
|
+
function br(e) {
|
|
3024
|
+
return Sr("E", void 0, e);
|
|
2535
3025
|
}
|
|
2536
|
-
function
|
|
2537
|
-
return
|
|
3026
|
+
function xr(e) {
|
|
3027
|
+
return Sr("N", e, void 0);
|
|
2538
3028
|
}
|
|
2539
|
-
function
|
|
3029
|
+
function Sr(e, t, n) {
|
|
2540
3030
|
return {
|
|
2541
3031
|
kind: e,
|
|
2542
3032
|
value: t,
|
|
@@ -2545,38 +3035,38 @@ function Dn(e, t, n) {
|
|
|
2545
3035
|
}
|
|
2546
3036
|
//#endregion
|
|
2547
3037
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/errorContext.js
|
|
2548
|
-
var
|
|
2549
|
-
function
|
|
2550
|
-
if (
|
|
2551
|
-
var t = !
|
|
2552
|
-
if (t && (
|
|
3038
|
+
var Z = null;
|
|
3039
|
+
function Cr(e) {
|
|
3040
|
+
if (X.useDeprecatedSynchronousErrorHandling) {
|
|
3041
|
+
var t = !Z;
|
|
3042
|
+
if (t && (Z = {
|
|
2553
3043
|
errorThrown: !1,
|
|
2554
3044
|
error: null
|
|
2555
3045
|
}), e(), t) {
|
|
2556
|
-
var n =
|
|
2557
|
-
if (
|
|
3046
|
+
var n = Z, r = n.errorThrown, i = n.error;
|
|
3047
|
+
if (Z = null, r) throw i;
|
|
2558
3048
|
}
|
|
2559
3049
|
} else e();
|
|
2560
3050
|
}
|
|
2561
|
-
function
|
|
2562
|
-
|
|
3051
|
+
function wr(e) {
|
|
3052
|
+
X.useDeprecatedSynchronousErrorHandling && Z && (Z.errorThrown = !0, Z.error = e);
|
|
2563
3053
|
}
|
|
2564
3054
|
//#endregion
|
|
2565
3055
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/Subscriber.js
|
|
2566
|
-
var
|
|
2567
|
-
|
|
3056
|
+
var Tr = function(e) {
|
|
3057
|
+
rr(t, e);
|
|
2568
3058
|
function t(t) {
|
|
2569
3059
|
var n = e.call(this) || this;
|
|
2570
|
-
return n.isStopped = !1, t ? (n.destination = t,
|
|
3060
|
+
return n.isStopped = !1, t ? (n.destination = t, mr(t) && t.add(n)) : n.destination = Nr, n;
|
|
2571
3061
|
}
|
|
2572
3062
|
return t.create = function(e, t, n) {
|
|
2573
|
-
return new
|
|
3063
|
+
return new kr(e, t, n);
|
|
2574
3064
|
}, t.prototype.next = function(e) {
|
|
2575
|
-
this.isStopped ?
|
|
3065
|
+
this.isStopped ? Mr(xr(e), this) : this._next(e);
|
|
2576
3066
|
}, t.prototype.error = function(e) {
|
|
2577
|
-
this.isStopped ?
|
|
3067
|
+
this.isStopped ? Mr(br(e), this) : (this.isStopped = !0, this._error(e));
|
|
2578
3068
|
}, t.prototype.complete = function() {
|
|
2579
|
-
this.isStopped ?
|
|
3069
|
+
this.isStopped ? Mr(yr, this) : (this.isStopped = !0, this._complete());
|
|
2580
3070
|
}, t.prototype.unsubscribe = function() {
|
|
2581
3071
|
this.closed || (this.isStopped = !0, e.prototype.unsubscribe.call(this), this.destination = null);
|
|
2582
3072
|
}, t.prototype._next = function(e) {
|
|
@@ -2594,11 +3084,11 @@ var An = function(e) {
|
|
|
2594
3084
|
this.unsubscribe();
|
|
2595
3085
|
}
|
|
2596
3086
|
}, t;
|
|
2597
|
-
}(
|
|
2598
|
-
function
|
|
2599
|
-
return
|
|
3087
|
+
}(pr), Er = Function.prototype.bind;
|
|
3088
|
+
function Dr(e, t) {
|
|
3089
|
+
return Er.call(e, t);
|
|
2600
3090
|
}
|
|
2601
|
-
var
|
|
3091
|
+
var Or = function() {
|
|
2602
3092
|
function e(e) {
|
|
2603
3093
|
this.partialObserver = e;
|
|
2604
3094
|
}
|
|
@@ -2607,76 +3097,76 @@ var Nn = function() {
|
|
|
2607
3097
|
if (t.next) try {
|
|
2608
3098
|
t.next(e);
|
|
2609
3099
|
} catch (e) {
|
|
2610
|
-
|
|
3100
|
+
Ar(e);
|
|
2611
3101
|
}
|
|
2612
3102
|
}, e.prototype.error = function(e) {
|
|
2613
3103
|
var t = this.partialObserver;
|
|
2614
3104
|
if (t.error) try {
|
|
2615
3105
|
t.error(e);
|
|
2616
3106
|
} catch (e) {
|
|
2617
|
-
|
|
3107
|
+
Ar(e);
|
|
2618
3108
|
}
|
|
2619
|
-
else
|
|
3109
|
+
else Ar(e);
|
|
2620
3110
|
}, e.prototype.complete = function() {
|
|
2621
3111
|
var e = this.partialObserver;
|
|
2622
3112
|
if (e.complete) try {
|
|
2623
3113
|
e.complete();
|
|
2624
3114
|
} catch (e) {
|
|
2625
|
-
|
|
3115
|
+
Ar(e);
|
|
2626
3116
|
}
|
|
2627
3117
|
}, e;
|
|
2628
|
-
}(),
|
|
2629
|
-
|
|
3118
|
+
}(), kr = function(e) {
|
|
3119
|
+
rr(t, e);
|
|
2630
3120
|
function t(t, n, r) {
|
|
2631
3121
|
var i = e.call(this) || this, a;
|
|
2632
|
-
if (
|
|
3122
|
+
if (W(t) || !t) a = {
|
|
2633
3123
|
next: t ?? void 0,
|
|
2634
3124
|
error: n ?? void 0,
|
|
2635
3125
|
complete: r ?? void 0
|
|
2636
3126
|
};
|
|
2637
3127
|
else {
|
|
2638
3128
|
var o;
|
|
2639
|
-
i &&
|
|
3129
|
+
i && X.useDeprecatedNextContext ? (o = Object.create(t), o.unsubscribe = function() {
|
|
2640
3130
|
return i.unsubscribe();
|
|
2641
3131
|
}, a = {
|
|
2642
|
-
next: t.next &&
|
|
2643
|
-
error: t.error &&
|
|
2644
|
-
complete: t.complete &&
|
|
3132
|
+
next: t.next && Dr(t.next, o),
|
|
3133
|
+
error: t.error && Dr(t.error, o),
|
|
3134
|
+
complete: t.complete && Dr(t.complete, o)
|
|
2645
3135
|
}) : a = t;
|
|
2646
3136
|
}
|
|
2647
|
-
return i.destination = new
|
|
3137
|
+
return i.destination = new Or(a), i;
|
|
2648
3138
|
}
|
|
2649
3139
|
return t;
|
|
2650
|
-
}(
|
|
2651
|
-
function
|
|
2652
|
-
|
|
3140
|
+
}(Tr);
|
|
3141
|
+
function Ar(e) {
|
|
3142
|
+
X.useDeprecatedSynchronousErrorHandling ? wr(e) : _r(e);
|
|
2653
3143
|
}
|
|
2654
|
-
function
|
|
3144
|
+
function jr(e) {
|
|
2655
3145
|
throw e;
|
|
2656
3146
|
}
|
|
2657
|
-
function
|
|
2658
|
-
var n =
|
|
2659
|
-
n &&
|
|
3147
|
+
function Mr(e, t) {
|
|
3148
|
+
var n = X.onStoppedNotification;
|
|
3149
|
+
n && gr.setTimeout(function() {
|
|
2660
3150
|
return n(e, t);
|
|
2661
3151
|
});
|
|
2662
3152
|
}
|
|
2663
|
-
var
|
|
3153
|
+
var Nr = {
|
|
2664
3154
|
closed: !0,
|
|
2665
|
-
next:
|
|
2666
|
-
error:
|
|
2667
|
-
complete:
|
|
2668
|
-
},
|
|
3155
|
+
next: vr,
|
|
3156
|
+
error: jr,
|
|
3157
|
+
complete: vr
|
|
3158
|
+
}, Pr = (function() {
|
|
2669
3159
|
return typeof Symbol == "function" && Symbol.observable || "@@observable";
|
|
2670
3160
|
})();
|
|
2671
3161
|
//#endregion
|
|
2672
3162
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/identity.js
|
|
2673
|
-
function
|
|
3163
|
+
function Fr(e) {
|
|
2674
3164
|
return e;
|
|
2675
3165
|
}
|
|
2676
3166
|
//#endregion
|
|
2677
3167
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/pipe.js
|
|
2678
|
-
function
|
|
2679
|
-
return e.length === 0 ?
|
|
3168
|
+
function Ir(e) {
|
|
3169
|
+
return e.length === 0 ? Fr : e.length === 1 ? e[0] : function(t) {
|
|
2680
3170
|
return e.reduce(function(e, t) {
|
|
2681
3171
|
return t(e);
|
|
2682
3172
|
}, t);
|
|
@@ -2692,8 +3182,8 @@ var Q = function() {
|
|
|
2692
3182
|
var n = new e();
|
|
2693
3183
|
return n.source = this, n.operator = t, n;
|
|
2694
3184
|
}, e.prototype.subscribe = function(e, t, n) {
|
|
2695
|
-
var r = this, i =
|
|
2696
|
-
return
|
|
3185
|
+
var r = this, i = zr(e) ? e : new kr(e, t, n);
|
|
3186
|
+
return Cr(function() {
|
|
2697
3187
|
var e = r, t = e.operator, n = e.source;
|
|
2698
3188
|
i.add(t ? t.call(i, n) : n ? r._subscribe(i) : r._trySubscribe(i));
|
|
2699
3189
|
}), i;
|
|
@@ -2705,8 +3195,8 @@ var Q = function() {
|
|
|
2705
3195
|
}
|
|
2706
3196
|
}, e.prototype.forEach = function(e, t) {
|
|
2707
3197
|
var n = this;
|
|
2708
|
-
return t =
|
|
2709
|
-
var i = new
|
|
3198
|
+
return t = Lr(t), new t(function(t, r) {
|
|
3199
|
+
var i = new kr({
|
|
2710
3200
|
next: function(t) {
|
|
2711
3201
|
try {
|
|
2712
3202
|
e(t);
|
|
@@ -2721,13 +3211,13 @@ var Q = function() {
|
|
|
2721
3211
|
});
|
|
2722
3212
|
}, e.prototype._subscribe = function(e) {
|
|
2723
3213
|
return this.source?.subscribe(e);
|
|
2724
|
-
}, e.prototype[
|
|
3214
|
+
}, e.prototype[Pr] = function() {
|
|
2725
3215
|
return this;
|
|
2726
3216
|
}, e.prototype.pipe = function() {
|
|
2727
|
-
return
|
|
3217
|
+
return Ir([...arguments])(this);
|
|
2728
3218
|
}, e.prototype.toPromise = function(e) {
|
|
2729
3219
|
var t = this;
|
|
2730
|
-
return e =
|
|
3220
|
+
return e = Lr(e), new e(function(e, n) {
|
|
2731
3221
|
var r;
|
|
2732
3222
|
t.subscribe(function(e) {
|
|
2733
3223
|
return r = e;
|
|
@@ -2741,47 +3231,47 @@ var Q = function() {
|
|
|
2741
3231
|
return new e(t);
|
|
2742
3232
|
}, e;
|
|
2743
3233
|
}();
|
|
2744
|
-
function
|
|
2745
|
-
return e ??
|
|
3234
|
+
function Lr(e) {
|
|
3235
|
+
return e ?? X.Promise ?? Promise;
|
|
2746
3236
|
}
|
|
2747
|
-
function
|
|
2748
|
-
return e &&
|
|
3237
|
+
function Rr(e) {
|
|
3238
|
+
return e && W(e.next) && W(e.error) && W(e.complete);
|
|
2749
3239
|
}
|
|
2750
|
-
function
|
|
2751
|
-
return e && e instanceof
|
|
3240
|
+
function zr(e) {
|
|
3241
|
+
return e && e instanceof Tr || Rr(e) && mr(e);
|
|
2752
3242
|
}
|
|
2753
3243
|
//#endregion
|
|
2754
3244
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isInteropObservable.js
|
|
2755
|
-
function
|
|
2756
|
-
return
|
|
3245
|
+
function Br(e) {
|
|
3246
|
+
return W(e[Pr]);
|
|
2757
3247
|
}
|
|
2758
3248
|
//#endregion
|
|
2759
3249
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isAsyncIterable.js
|
|
2760
|
-
function
|
|
2761
|
-
return Symbol.asyncIterator &&
|
|
3250
|
+
function Vr(e) {
|
|
3251
|
+
return Symbol.asyncIterator && W(e?.[Symbol.asyncIterator]);
|
|
2762
3252
|
}
|
|
2763
3253
|
//#endregion
|
|
2764
3254
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/throwUnobservableError.js
|
|
2765
|
-
function
|
|
3255
|
+
function Hr(e) {
|
|
2766
3256
|
return /* @__PURE__ */ TypeError("You provided " + (typeof e == "object" && e ? "an invalid object" : "'" + e + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
|
|
2767
3257
|
}
|
|
2768
3258
|
//#endregion
|
|
2769
3259
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/symbol/iterator.js
|
|
2770
|
-
function
|
|
3260
|
+
function Ur() {
|
|
2771
3261
|
return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
|
|
2772
3262
|
}
|
|
2773
|
-
var
|
|
3263
|
+
var Wr = Ur();
|
|
2774
3264
|
//#endregion
|
|
2775
3265
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isIterable.js
|
|
2776
|
-
function
|
|
2777
|
-
return
|
|
3266
|
+
function Gr(e) {
|
|
3267
|
+
return W(e?.[Wr]);
|
|
2778
3268
|
}
|
|
2779
3269
|
//#endregion
|
|
2780
3270
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isReadableStreamLike.js
|
|
2781
|
-
function
|
|
2782
|
-
return
|
|
3271
|
+
function Kr(e) {
|
|
3272
|
+
return or(this, arguments, function() {
|
|
2783
3273
|
var t, n, r, i;
|
|
2784
|
-
return
|
|
3274
|
+
return ar(this, function(a) {
|
|
2785
3275
|
switch (a.label) {
|
|
2786
3276
|
case 0: t = e.getReader(), a.label = 1;
|
|
2787
3277
|
case 1: a.trys.push([
|
|
@@ -2790,10 +3280,10 @@ function Xn(e) {
|
|
|
2790
3280
|
9,
|
|
2791
3281
|
10
|
|
2792
3282
|
]), a.label = 2;
|
|
2793
|
-
case 2: return [4,
|
|
2794
|
-
case 3: return n = a.sent(), r = n.value, i = n.done, i ? [4,
|
|
3283
|
+
case 2: return [4, Y(t.read())];
|
|
3284
|
+
case 3: return n = a.sent(), r = n.value, i = n.done, i ? [4, Y(void 0)] : [3, 5];
|
|
2795
3285
|
case 4: return [2, a.sent()];
|
|
2796
|
-
case 5: return [4,
|
|
3286
|
+
case 5: return [4, Y(r)];
|
|
2797
3287
|
case 6: return [4, a.sent()];
|
|
2798
3288
|
case 7: return a.sent(), [3, 2];
|
|
2799
3289
|
case 8: return [3, 10];
|
|
@@ -2803,50 +3293,50 @@ function Xn(e) {
|
|
|
2803
3293
|
});
|
|
2804
3294
|
});
|
|
2805
3295
|
}
|
|
2806
|
-
function
|
|
2807
|
-
return
|
|
3296
|
+
function qr(e) {
|
|
3297
|
+
return W(e?.getReader);
|
|
2808
3298
|
}
|
|
2809
3299
|
//#endregion
|
|
2810
3300
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/observable/innerFrom.js
|
|
2811
|
-
function
|
|
3301
|
+
function Jr(e) {
|
|
2812
3302
|
if (e instanceof Q) return e;
|
|
2813
3303
|
if (e != null) {
|
|
2814
|
-
if (
|
|
2815
|
-
if (
|
|
2816
|
-
if (
|
|
2817
|
-
if (
|
|
2818
|
-
if (
|
|
2819
|
-
if (
|
|
3304
|
+
if (Br(e)) return Yr(e);
|
|
3305
|
+
if (cr(e)) return Xr(e);
|
|
3306
|
+
if (lr(e)) return Zr(e);
|
|
3307
|
+
if (Vr(e)) return $r(e);
|
|
3308
|
+
if (Gr(e)) return Qr(e);
|
|
3309
|
+
if (qr(e)) return ei(e);
|
|
2820
3310
|
}
|
|
2821
|
-
throw
|
|
3311
|
+
throw Hr(e);
|
|
2822
3312
|
}
|
|
2823
|
-
function
|
|
3313
|
+
function Yr(e) {
|
|
2824
3314
|
return new Q(function(t) {
|
|
2825
|
-
var n = e[
|
|
2826
|
-
if (
|
|
3315
|
+
var n = e[Pr]();
|
|
3316
|
+
if (W(n.subscribe)) return n.subscribe(t);
|
|
2827
3317
|
throw TypeError("Provided object does not correctly implement Symbol.observable");
|
|
2828
3318
|
});
|
|
2829
3319
|
}
|
|
2830
|
-
function
|
|
3320
|
+
function Xr(e) {
|
|
2831
3321
|
return new Q(function(t) {
|
|
2832
3322
|
for (var n = 0; n < e.length && !t.closed; n++) t.next(e[n]);
|
|
2833
3323
|
t.complete();
|
|
2834
3324
|
});
|
|
2835
3325
|
}
|
|
2836
|
-
function
|
|
3326
|
+
function Zr(e) {
|
|
2837
3327
|
return new Q(function(t) {
|
|
2838
3328
|
e.then(function(e) {
|
|
2839
3329
|
t.closed || (t.next(e), t.complete());
|
|
2840
3330
|
}, function(e) {
|
|
2841
3331
|
return t.error(e);
|
|
2842
|
-
}).then(null,
|
|
3332
|
+
}).then(null, _r);
|
|
2843
3333
|
});
|
|
2844
3334
|
}
|
|
2845
|
-
function
|
|
3335
|
+
function Qr(e) {
|
|
2846
3336
|
return new Q(function(t) {
|
|
2847
3337
|
var n, r;
|
|
2848
3338
|
try {
|
|
2849
|
-
for (var i =
|
|
3339
|
+
for (var i = K(e), a = i.next(); !a.done; a = i.next()) {
|
|
2850
3340
|
var o = a.value;
|
|
2851
3341
|
if (t.next(o), t.closed) return;
|
|
2852
3342
|
}
|
|
@@ -2862,28 +3352,28 @@ function nr(e) {
|
|
|
2862
3352
|
t.complete();
|
|
2863
3353
|
});
|
|
2864
3354
|
}
|
|
2865
|
-
function
|
|
3355
|
+
function $r(e) {
|
|
2866
3356
|
return new Q(function(t) {
|
|
2867
|
-
|
|
3357
|
+
ti(e, t).catch(function(e) {
|
|
2868
3358
|
return t.error(e);
|
|
2869
3359
|
});
|
|
2870
3360
|
});
|
|
2871
3361
|
}
|
|
2872
|
-
function
|
|
2873
|
-
return
|
|
3362
|
+
function ei(e) {
|
|
3363
|
+
return $r(Kr(e));
|
|
2874
3364
|
}
|
|
2875
|
-
function
|
|
3365
|
+
function ti(e, t) {
|
|
2876
3366
|
var n, r, i, a;
|
|
2877
|
-
return
|
|
3367
|
+
return ir(this, void 0, void 0, function() {
|
|
2878
3368
|
var o, s;
|
|
2879
|
-
return
|
|
3369
|
+
return ar(this, function(c) {
|
|
2880
3370
|
switch (c.label) {
|
|
2881
3371
|
case 0: c.trys.push([
|
|
2882
3372
|
0,
|
|
2883
3373
|
5,
|
|
2884
3374
|
6,
|
|
2885
3375
|
11
|
|
2886
|
-
]), n =
|
|
3376
|
+
]), n = sr(e), c.label = 1;
|
|
2887
3377
|
case 1: return [4, n.next()];
|
|
2888
3378
|
case 2:
|
|
2889
3379
|
if (r = c.sent(), r.done) return [3, 4];
|
|
@@ -2912,10 +3402,10 @@ function ar(e, t) {
|
|
|
2912
3402
|
//#endregion
|
|
2913
3403
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/OperatorSubscriber.js
|
|
2914
3404
|
function $(e, t, n, r, i) {
|
|
2915
|
-
return new
|
|
3405
|
+
return new ni(e, t, n, r, i);
|
|
2916
3406
|
}
|
|
2917
|
-
var
|
|
2918
|
-
|
|
3407
|
+
var ni = function(e) {
|
|
3408
|
+
rr(t, e);
|
|
2919
3409
|
function t(t, n, r, i, a, o) {
|
|
2920
3410
|
var s = e.call(this, t) || this;
|
|
2921
3411
|
return s.onFinalize = a, s.shouldUnsubscribe = o, s._next = n ? function(e) {
|
|
@@ -2949,19 +3439,19 @@ var or = function(e) {
|
|
|
2949
3439
|
e.prototype.unsubscribe.call(this), !n && ((t = this.onFinalize) == null || t.call(this));
|
|
2950
3440
|
}
|
|
2951
3441
|
}, t;
|
|
2952
|
-
}(
|
|
3442
|
+
}(Tr);
|
|
2953
3443
|
//#endregion
|
|
2954
3444
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/args.js
|
|
2955
|
-
function
|
|
3445
|
+
function ri(e) {
|
|
2956
3446
|
return e[e.length - 1];
|
|
2957
3447
|
}
|
|
2958
|
-
function
|
|
2959
|
-
return
|
|
3448
|
+
function ii(e) {
|
|
3449
|
+
return W(ri(e)) ? e.pop() : void 0;
|
|
2960
3450
|
}
|
|
2961
3451
|
//#endregion
|
|
2962
3452
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/map.js
|
|
2963
|
-
function
|
|
2964
|
-
return
|
|
3453
|
+
function ai(e, t) {
|
|
3454
|
+
return G(function(n, r) {
|
|
2965
3455
|
var i = 0;
|
|
2966
3456
|
n.subscribe($(r, function(n) {
|
|
2967
3457
|
r.next(e.call(t, n, i++));
|
|
@@ -2970,8 +3460,8 @@ function lr(e, t) {
|
|
|
2970
3460
|
}
|
|
2971
3461
|
//#endregion
|
|
2972
3462
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/distinctUntilChanged.js
|
|
2973
|
-
function
|
|
2974
|
-
return t === void 0 && (t =
|
|
3463
|
+
function oi(e, t) {
|
|
3464
|
+
return t === void 0 && (t = Fr), e ??= si, G(function(n, r) {
|
|
2975
3465
|
var i, a = !0;
|
|
2976
3466
|
n.subscribe($(r, function(n) {
|
|
2977
3467
|
var o = t(n);
|
|
@@ -2979,13 +3469,13 @@ function ur(e, t) {
|
|
|
2979
3469
|
}));
|
|
2980
3470
|
});
|
|
2981
3471
|
}
|
|
2982
|
-
function
|
|
3472
|
+
function si(e, t) {
|
|
2983
3473
|
return e === t;
|
|
2984
3474
|
}
|
|
2985
3475
|
//#endregion
|
|
2986
3476
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/filter.js
|
|
2987
|
-
function
|
|
2988
|
-
return
|
|
3477
|
+
function ci(e, t) {
|
|
3478
|
+
return G(function(n, r) {
|
|
2989
3479
|
var i = 0;
|
|
2990
3480
|
n.subscribe($(r, function(n) {
|
|
2991
3481
|
return e.call(t, n, i++) && r.next(n);
|
|
@@ -2994,19 +3484,19 @@ function fr(e, t) {
|
|
|
2994
3484
|
}
|
|
2995
3485
|
//#endregion
|
|
2996
3486
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/exhaustMap.js
|
|
2997
|
-
function
|
|
3487
|
+
function li(e, t) {
|
|
2998
3488
|
return t ? function(n) {
|
|
2999
|
-
return n.pipe(
|
|
3000
|
-
return
|
|
3489
|
+
return n.pipe(li(function(n, r) {
|
|
3490
|
+
return Jr(e(n, r)).pipe(ai(function(e, i) {
|
|
3001
3491
|
return t(n, e, r, i);
|
|
3002
3492
|
}));
|
|
3003
3493
|
}));
|
|
3004
|
-
} :
|
|
3494
|
+
} : G(function(t, n) {
|
|
3005
3495
|
var r = 0, i = null, a = !1;
|
|
3006
3496
|
t.subscribe($(n, function(t) {
|
|
3007
3497
|
i || (i = $(n, void 0, function() {
|
|
3008
3498
|
i = null, a && n.complete();
|
|
3009
|
-
}),
|
|
3499
|
+
}), Jr(e(t, r++)).subscribe(i));
|
|
3010
3500
|
}, function() {
|
|
3011
3501
|
a = !0, !i && n.complete();
|
|
3012
3502
|
}));
|
|
@@ -3014,40 +3504,40 @@ function pr(e, t) {
|
|
|
3014
3504
|
}
|
|
3015
3505
|
//#endregion
|
|
3016
3506
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/withLatestFrom.js
|
|
3017
|
-
function
|
|
3018
|
-
var e = [...arguments], t =
|
|
3019
|
-
return
|
|
3507
|
+
function ui() {
|
|
3508
|
+
var e = [...arguments], t = ii(e);
|
|
3509
|
+
return G(function(n, r) {
|
|
3020
3510
|
for (var i = e.length, a = Array(i), o = e.map(function() {
|
|
3021
3511
|
return !1;
|
|
3022
3512
|
}), s = !1, c = function(t) {
|
|
3023
|
-
|
|
3024
|
-
a[t] = e, !s && !o[t] && (o[t] = !0, (s = o.every(
|
|
3025
|
-
},
|
|
3513
|
+
Jr(e[t]).subscribe($(r, function(e) {
|
|
3514
|
+
a[t] = e, !s && !o[t] && (o[t] = !0, (s = o.every(Fr)) && (o = null));
|
|
3515
|
+
}, vr));
|
|
3026
3516
|
}, l = 0; l < i; l++) c(l);
|
|
3027
3517
|
n.subscribe($(r, function(e) {
|
|
3028
3518
|
if (s) {
|
|
3029
|
-
var n =
|
|
3030
|
-
r.next(t ? t.apply(void 0,
|
|
3519
|
+
var n = J([e], q(a));
|
|
3520
|
+
r.next(t ? t.apply(void 0, J([], q(n))) : n);
|
|
3031
3521
|
}
|
|
3032
3522
|
}));
|
|
3033
3523
|
});
|
|
3034
3524
|
}
|
|
3035
3525
|
//#endregion
|
|
3036
3526
|
//#region src/sync-listeners.ts
|
|
3037
|
-
async function
|
|
3527
|
+
async function di(e, t) {
|
|
3038
3528
|
try {
|
|
3039
|
-
return await t()
|
|
3529
|
+
return await t();
|
|
3040
3530
|
} catch (t) {
|
|
3041
3531
|
return e.reportError(t), !1;
|
|
3042
3532
|
}
|
|
3043
3533
|
}
|
|
3044
|
-
function
|
|
3045
|
-
return e.rxdb.config.entities.filter((e) => !
|
|
3534
|
+
function fi(e) {
|
|
3535
|
+
return e.rxdb.config.entities.filter((e) => !le(e));
|
|
3046
3536
|
}
|
|
3047
|
-
function
|
|
3537
|
+
function pi(e) {
|
|
3048
3538
|
let t = [];
|
|
3049
|
-
for (let n of
|
|
3050
|
-
let r =
|
|
3539
|
+
for (let n of fi(e)) {
|
|
3540
|
+
let r = A(n), i = P(F(r, e.rxdb.entitySync));
|
|
3051
3541
|
i.offlineWrite && !i.push && t.push({
|
|
3052
3542
|
namespace: r.namespace,
|
|
3053
3543
|
entity: r.name
|
|
@@ -3055,44 +3545,46 @@ function _r(e) {
|
|
|
3055
3545
|
}
|
|
3056
3546
|
return t;
|
|
3057
3547
|
}
|
|
3058
|
-
async function
|
|
3059
|
-
let { syncState: r } = e.rxdb, i = await
|
|
3548
|
+
async function mi(e, t, n) {
|
|
3549
|
+
let { syncState: r } = e.rxdb, i = await dt(e.rxdb, t, n);
|
|
3060
3550
|
for (let e of i.conflicts) r.reportConflict({
|
|
3061
3551
|
namespace: t,
|
|
3062
3552
|
entity: n,
|
|
3063
3553
|
entityId: e,
|
|
3064
3554
|
winner: "remote"
|
|
3065
3555
|
});
|
|
3556
|
+
for (let e of i.failures) r.reportError(e.error);
|
|
3557
|
+
return i.failures.length === 0;
|
|
3066
3558
|
}
|
|
3067
|
-
async function
|
|
3559
|
+
async function hi(e, t) {
|
|
3068
3560
|
let { syncState: n } = e.rxdb, r = !0;
|
|
3069
|
-
for (let { namespace: i, entity: a } of t) r = await
|
|
3561
|
+
for (let { namespace: i, entity: a } of t) r = await di(n, () => mi(e, i, a)) && r;
|
|
3070
3562
|
return r;
|
|
3071
3563
|
}
|
|
3072
|
-
async function
|
|
3564
|
+
async function gi(e) {
|
|
3073
3565
|
try {
|
|
3074
|
-
e.rxdb.syncState.reportOutboxCount(await
|
|
3566
|
+
e.rxdb.syncState.reportOutboxCount(await ht(e.rxdb));
|
|
3075
3567
|
} catch {}
|
|
3076
3568
|
}
|
|
3077
|
-
async function
|
|
3078
|
-
let t =
|
|
3569
|
+
async function _i(e) {
|
|
3570
|
+
let t = pi(e);
|
|
3079
3571
|
if (t.length === 0) return;
|
|
3080
3572
|
let { syncState: n } = e.rxdb;
|
|
3081
3573
|
n.beginRound();
|
|
3082
3574
|
try {
|
|
3083
|
-
await
|
|
3575
|
+
await hi(e, t) && n.reportSuccess(), await gi(e);
|
|
3084
3576
|
} finally {
|
|
3085
3577
|
n.endRound();
|
|
3086
3578
|
}
|
|
3087
3579
|
}
|
|
3088
|
-
function
|
|
3089
|
-
let t = e.rxdb.connected$, n =
|
|
3090
|
-
return
|
|
3580
|
+
function vi(e) {
|
|
3581
|
+
let t = e.rxdb.connected$, n = pe([t, e.rxdb.reachability.online$]).pipe(ai(([e, t]) => e && t), oi());
|
|
3582
|
+
return me(n.pipe(ci((e) => e)), e.rxdb.reachability.wakeup$.pipe(ui(t), ci(([, e]) => e)));
|
|
3091
3583
|
}
|
|
3092
|
-
function
|
|
3584
|
+
function yi(e) {
|
|
3093
3585
|
let t = [], a = [];
|
|
3094
3586
|
if (e.rxdb.config.sync?.remote?.adapter) {
|
|
3095
|
-
let n =
|
|
3587
|
+
let n = vi(e).pipe(li(() => _i(e).catch((t) => {
|
|
3096
3588
|
e.rxdb.syncState.reportError(t);
|
|
3097
3589
|
}))).subscribe();
|
|
3098
3590
|
t.push(n);
|
|
@@ -3106,7 +3598,7 @@ function Cr(e) {
|
|
|
3106
3598
|
let t = await o(n.entities);
|
|
3107
3599
|
t > 0 && e.history.incrementPullableCount(t);
|
|
3108
3600
|
} catch (e) {
|
|
3109
|
-
|
|
3601
|
+
he(e) || console.error(`[SyncManager] ${t} failed:`, e);
|
|
3110
3602
|
}
|
|
3111
3603
|
})();
|
|
3112
3604
|
}, c = [
|
|
@@ -3131,20 +3623,28 @@ function Cr(e) {
|
|
|
3131
3623
|
}
|
|
3132
3624
|
//#endregion
|
|
3133
3625
|
//#region src/sync-manager.utils.ts
|
|
3134
|
-
var
|
|
3626
|
+
var bi = (e) => e?.historyInvalidated === !0 || (e?.pushResult?.pushed ?? 0) > 0, xi = (e) => e instanceof g && bi(e.result), Si = (e) => e instanceof g ? e.result : void 0, Ci = class {
|
|
3135
3627
|
rxdb;
|
|
3136
3628
|
history;
|
|
3137
3629
|
#e = [];
|
|
3138
3630
|
#t = [];
|
|
3631
|
+
#n = 0;
|
|
3139
3632
|
get pushInFlight() {
|
|
3140
3633
|
return this.history.pushInFlight;
|
|
3141
3634
|
}
|
|
3635
|
+
get branchSwitchGeneration() {
|
|
3636
|
+
return this.#n;
|
|
3637
|
+
}
|
|
3142
3638
|
constructor(e, t) {
|
|
3143
3639
|
this.rxdb = e, this.history = t;
|
|
3144
3640
|
}
|
|
3145
3641
|
init() {
|
|
3146
|
-
let { subscriptions: e, removers: t } =
|
|
3642
|
+
let { subscriptions: e, removers: t } = yi(this);
|
|
3147
3643
|
this.#t.push(...e), this.#e.push(...t);
|
|
3644
|
+
let n = () => {
|
|
3645
|
+
this.#n += 1;
|
|
3646
|
+
};
|
|
3647
|
+
for (let e of [y, b]) this.rxdb.addEventListener(e, n), this.#e.push(() => this.rxdb.removeEventListener(e, n));
|
|
3148
3648
|
}
|
|
3149
3649
|
destroy() {
|
|
3150
3650
|
for (let e of this.#e) e();
|
|
@@ -3153,121 +3653,121 @@ var wr = (e) => e?.historyInvalidated === !0 || (e?.pushResult?.pushed ?? 0) > 0
|
|
|
3153
3653
|
this.#t.length = 0;
|
|
3154
3654
|
}
|
|
3155
3655
|
async getLocalRepositories() {
|
|
3156
|
-
return
|
|
3656
|
+
return j(this.rxdb);
|
|
3157
3657
|
}
|
|
3158
3658
|
async getRemoteRepositories() {
|
|
3159
|
-
return
|
|
3659
|
+
return ae(this.rxdb);
|
|
3160
3660
|
}
|
|
3161
3661
|
async getCurrentBranch() {
|
|
3162
|
-
return
|
|
3662
|
+
return ie(this.rxdb);
|
|
3163
3663
|
}
|
|
3164
3664
|
async syncBranches() {
|
|
3165
|
-
return
|
|
3665
|
+
return er(this);
|
|
3166
3666
|
}
|
|
3167
3667
|
async pull(e) {
|
|
3168
3668
|
let t;
|
|
3169
3669
|
try {
|
|
3170
|
-
t = await this.history.syncing(() => this.#
|
|
3670
|
+
t = await this.history.syncing(() => this.#r(e));
|
|
3171
3671
|
} catch (e) {
|
|
3172
|
-
throw
|
|
3672
|
+
throw xi(e) && this.history.clearUndoHistory(), e;
|
|
3173
3673
|
}
|
|
3174
3674
|
return t.historyInvalidated && this.history.clearUndoHistory(), t;
|
|
3175
3675
|
}
|
|
3176
3676
|
async push(e) {
|
|
3177
|
-
let t = await this.history.syncing(() =>
|
|
3677
|
+
let t = await this.history.syncing(() => Zn(this, e));
|
|
3178
3678
|
return t.pushed > 0 && this.history.clearUndoHistory(), t;
|
|
3179
3679
|
}
|
|
3180
3680
|
async sync(e) {
|
|
3181
3681
|
let t, n;
|
|
3182
3682
|
try {
|
|
3183
3683
|
n = await this.history.syncing(async () => {
|
|
3184
|
-
t = await this.#
|
|
3185
|
-
let n = await
|
|
3684
|
+
t = await this.#r(e?.pull);
|
|
3685
|
+
let n = await Zn(this, e?.push);
|
|
3186
3686
|
return {
|
|
3187
3687
|
pullResult: t,
|
|
3188
3688
|
pushResult: n
|
|
3189
3689
|
};
|
|
3190
3690
|
});
|
|
3191
3691
|
} catch (e) {
|
|
3192
|
-
throw (t?.historyInvalidated === !0 ||
|
|
3692
|
+
throw (t?.historyInvalidated === !0 || xi(e)) && this.history.clearUndoHistory(), e;
|
|
3193
3693
|
}
|
|
3194
3694
|
return (n.pullResult.historyInvalidated || n.pushResult.pushed > 0) && this.history.clearUndoHistory(), n;
|
|
3195
3695
|
}
|
|
3196
3696
|
async pullRepository(e, t, n) {
|
|
3197
3697
|
let r;
|
|
3198
3698
|
try {
|
|
3199
|
-
r = await this.history.syncing(() =>
|
|
3699
|
+
r = await this.history.syncing(() => ze(this, e, t, n));
|
|
3200
3700
|
} catch (e) {
|
|
3201
|
-
throw
|
|
3701
|
+
throw xi(e) && this.history.clearUndoHistory(), e;
|
|
3202
3702
|
}
|
|
3203
3703
|
return r.historyInvalidated && this.history.clearUndoHistory(), r;
|
|
3204
3704
|
}
|
|
3205
3705
|
async pushRepository(e, t, n) {
|
|
3206
|
-
let r = await this.history.syncing(() =>
|
|
3706
|
+
let r = await this.history.syncing(() => It(this, e, t, n));
|
|
3207
3707
|
return r.pushed > 0 && this.history.clearUndoHistory(), r;
|
|
3208
3708
|
}
|
|
3209
3709
|
async syncRepository(e, t, n) {
|
|
3210
3710
|
let r;
|
|
3211
3711
|
try {
|
|
3212
|
-
r = await this.history.syncing(() =>
|
|
3712
|
+
r = await this.history.syncing(() => Cn(this, e, t, n));
|
|
3213
3713
|
} catch (e) {
|
|
3214
|
-
throw
|
|
3714
|
+
throw xi(e) && this.history.clearUndoHistory(), e;
|
|
3215
3715
|
}
|
|
3216
3716
|
return (r.pullResult.historyInvalidated || r.pushResult.pushed > 0) && this.history.clearUndoHistory(), r;
|
|
3217
3717
|
}
|
|
3218
3718
|
async cleanupExpired(e, t, n) {
|
|
3219
|
-
return
|
|
3719
|
+
return jn(this, e, t, n);
|
|
3220
3720
|
}
|
|
3221
3721
|
async checkRepositoryUpdates(e, t) {
|
|
3222
|
-
return
|
|
3722
|
+
return An(this.rxdb, e, t);
|
|
3223
3723
|
}
|
|
3224
3724
|
async getRepositorySyncStatus(e, t) {
|
|
3225
|
-
return
|
|
3725
|
+
return In(this.rxdb, e, t);
|
|
3226
3726
|
}
|
|
3227
3727
|
async getAllRepositorySyncStatus(e) {
|
|
3228
|
-
return
|
|
3728
|
+
return Ln(this.rxdb, e);
|
|
3229
3729
|
}
|
|
3230
3730
|
async refreshPullableCount() {
|
|
3231
|
-
let e = this.history.beginPullableSettlement(), t = (await
|
|
3731
|
+
let e = this.history.beginPullableSettlement(), t = (await Ln(this.rxdb)).reduce((e, t) => e + (t.enabled ? t.pullableCount : 0), 0);
|
|
3232
3732
|
return this.history.reconcilePullableCount(e, t), t;
|
|
3233
3733
|
}
|
|
3234
3734
|
async bulkSync(e) {
|
|
3235
|
-
let t = await this.history.syncing(() =>
|
|
3236
|
-
return t.results.some((e) =>
|
|
3735
|
+
let t = await this.history.syncing(() => kn(this.rxdb, e));
|
|
3736
|
+
return t.results.some((e) => bi(e.result) || bi(Si(e.error))) && this.history.clearUndoHistory(), t;
|
|
3237
3737
|
}
|
|
3238
3738
|
getRepositoryDependencyGraph() {
|
|
3239
|
-
return
|
|
3739
|
+
return z(this.rxdb.config.entities.map((e) => A(e)));
|
|
3240
3740
|
}
|
|
3241
3741
|
getRepositorySyncOrder(e) {
|
|
3242
|
-
return
|
|
3742
|
+
return Me(this.getRepositoryDependencyGraph(), e);
|
|
3243
3743
|
}
|
|
3244
|
-
async #
|
|
3744
|
+
async #r(e) {
|
|
3245
3745
|
let t = this.history.beginPullableSettlement(), n;
|
|
3246
3746
|
try {
|
|
3247
|
-
n = await
|
|
3747
|
+
n = await Un(this, e);
|
|
3248
3748
|
} catch (e) {
|
|
3249
|
-
let n = e instanceof
|
|
3749
|
+
let n = e instanceof g ? e.result : void 0;
|
|
3250
3750
|
throw this.history.settleAbortedPull(t, n ? n.pulled : 0), e;
|
|
3251
3751
|
}
|
|
3252
3752
|
return this.history.settlePull(t, e, n), n;
|
|
3253
3753
|
}
|
|
3254
|
-
},
|
|
3754
|
+
}, wi = class extends _ {
|
|
3255
3755
|
lifecycle = "scoped";
|
|
3256
3756
|
inject = ["plugin:history"];
|
|
3257
3757
|
name = "sync";
|
|
3258
3758
|
install(e) {
|
|
3259
|
-
let t = new
|
|
3759
|
+
let t = new Ci(this.rxdb, this.rxdb.versionManager.syncBridge);
|
|
3260
3760
|
e.acquire(() => () => t.destroy(), "sync:syncManager"), e.acquire(() => (Object.defineProperty(this.rxdb, "syncManager", {
|
|
3261
3761
|
value: t,
|
|
3262
3762
|
configurable: !0,
|
|
3263
3763
|
enumerable: !0
|
|
3264
|
-
}), () => void Reflect.deleteProperty(this.rxdb, "syncManager")), "sync:slot"), this.rxdb.queryCacheOutbox({ pendingWriteIds: (e, t) =>
|
|
3764
|
+
}), () => void Reflect.deleteProperty(this.rxdb, "syncManager")), "sync:slot"), this.rxdb.queryCacheOutbox({ pendingWriteIds: (e, t) => gt(this.rxdb, e, t) }, e), this.rxdb.branchMaterializationSource(ot(t), e), e.acquire(() => this.rxdb.reachability.watch(), "sync:reachability"), t.init(), e.acquire(() => this.rxdb.syncState.bindPullableRefresh(() => {
|
|
3265
3765
|
t.refreshPullableCount().catch((e) => {
|
|
3266
3766
|
let t = e instanceof Error ? e.message : String(e);
|
|
3267
3767
|
console.warn(`[RxDB Sync] 重算待拉数失败:${t}。`);
|
|
3268
3768
|
});
|
|
3269
3769
|
}), "sync:pullableRefresh");
|
|
3270
3770
|
}
|
|
3271
|
-
},
|
|
3771
|
+
}, Ti = (e) => new wi(e);
|
|
3272
3772
|
//#endregion
|
|
3273
|
-
export {
|
|
3773
|
+
export { wi as RxDBPluginSync, ht as countQueryCacheOutbox, dt as flushQueryCacheOutbox, gt as pendingQueryCacheWriteIds, Ti as rxDBPluginSync };
|