@aiao/rxdb-plugin-sync 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +81 -2
- package/dist/SyncManager.d.ts +426 -0
- package/dist/SyncManager.d.ts.map +1 -0
- package/dist/branch-change-id.d.ts +31 -0
- package/dist/branch-change-id.d.ts.map +1 -0
- 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 +40 -0
- package/dist/branch-utils.d.ts.map +1 -0
- package/dist/bulk-sync.d.ts +117 -0
- package/dist/bulk-sync.d.ts.map +1 -0
- package/dist/cascade-blocking.d.ts +38 -0
- package/dist/cascade-blocking.d.ts.map +1 -0
- package/dist/check-repository-updates.d.ts +47 -0
- package/dist/check-repository-updates.d.ts.map +1 -0
- package/dist/cleanup-expired.d.ts +56 -0
- package/dist/cleanup-expired.d.ts.map +1 -0
- package/dist/dependency-graph.d.ts +128 -0
- package/dist/dependency-graph.d.ts.map +1 -0
- package/dist/get-all-repository-sync-status.d.ts +58 -0
- package/dist/get-all-repository-sync-status.d.ts.map +1 -0
- package/dist/get-repository-sync-status.d.ts +68 -0
- package/dist/get-repository-sync-status.d.ts.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3773 -0
- package/dist/plugin.d.ts +74 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/pull-ancestor-changes.d.ts +41 -0
- package/dist/pull-ancestor-changes.d.ts.map +1 -0
- package/dist/pull-batch.d.ts +16 -0
- package/dist/pull-batch.d.ts.map +1 -0
- package/dist/pull-conflict-utils.d.ts +43 -0
- package/dist/pull-conflict-utils.d.ts.map +1 -0
- package/dist/pull-repository.d.ts +55 -0
- package/dist/pull-repository.d.ts.map +1 -0
- package/dist/pull-round.d.ts +41 -0
- package/dist/pull-round.d.ts.map +1 -0
- package/dist/pull.d.ts +16 -0
- package/dist/pull.d.ts.map +1 -0
- package/dist/push-branch.d.ts +22 -0
- package/dist/push-branch.d.ts.map +1 -0
- package/dist/push-repository.d.ts +79 -0
- package/dist/push-repository.d.ts.map +1 -0
- package/dist/push.d.ts +14 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/query-cache-outbox.d.ts +120 -0
- package/dist/query-cache-outbox.d.ts.map +1 -0
- package/dist/sync-branches.d.ts +81 -0
- package/dist/sync-branches.d.ts.map +1 -0
- package/dist/sync-listeners.d.ts +20 -0
- package/dist/sync-listeners.d.ts.map +1 -0
- package/dist/sync-manager.utils.d.ts +36 -0
- package/dist/sync-manager.utils.d.ts.map +1 -0
- package/dist/sync-repository.d.ts +64 -0
- package/dist/sync-repository.d.ts.map +1 -0
- package/dist/topological-sort.d.ts +126 -0
- package/dist/topological-sort.d.ts.map +1 -0
- package/package.json +60 -3
- package/src/SyncManager.ts +690 -0
- package/src/branch-change-id.ts +70 -0
- package/src/branch-materialization-source.ts +445 -0
- package/src/branch-utils.ts +74 -0
- package/src/bulk-sync.ts +349 -0
- package/src/cascade-blocking.ts +61 -0
- package/src/check-repository-updates.ts +143 -0
- package/src/cleanup-expired.ts +285 -0
- package/src/dependency-graph.ts +324 -0
- package/src/get-all-repository-sync-status.ts +115 -0
- package/src/get-repository-sync-status.ts +237 -0
- package/src/index.ts +58 -0
- package/src/plugin.ts +132 -0
- package/src/pull-ancestor-changes.ts +61 -0
- package/src/pull-batch.ts +386 -0
- package/src/pull-conflict-utils.ts +284 -0
- package/src/pull-repository.ts +700 -0
- package/src/pull-round.ts +103 -0
- package/src/pull.ts +204 -0
- package/src/push-branch.ts +62 -0
- package/src/push-repository.ts +1541 -0
- package/src/push.ts +106 -0
- package/src/query-cache-outbox.ts +939 -0
- package/src/sync-branches.ts +276 -0
- package/src/sync-listeners.ts +309 -0
- package/src/sync-manager.utils.ts +48 -0
- package/src/sync-repository.ts +307 -0
- package/src/topological-sort.ts +246 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3773 @@
|
|
|
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);
|
|
9
|
+
}
|
|
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;
|
|
28
|
+
}
|
|
29
|
+
return n;
|
|
30
|
+
}
|
|
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
|
|
40
|
+
},
|
|
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
|
+
});
|
|
51
|
+
}
|
|
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;
|
|
60
|
+
}
|
|
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);
|
|
81
|
+
}
|
|
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);
|
|
87
|
+
}
|
|
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 = [
|
|
151
|
+
{
|
|
152
|
+
field: "namespace",
|
|
153
|
+
operator: "=",
|
|
154
|
+
value: t
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
field: "entity",
|
|
158
|
+
operator: "=",
|
|
159
|
+
value: n
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
field: "branchId",
|
|
163
|
+
operator: "=",
|
|
164
|
+
value: r
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
field: "remoteId",
|
|
168
|
+
operator: "=",
|
|
169
|
+
value: null
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
field: "rejectedAt",
|
|
173
|
+
operator: "=",
|
|
174
|
+
value: null
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
field: "revertChangeId",
|
|
178
|
+
operator: "=",
|
|
179
|
+
value: null
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
field: "entityId",
|
|
183
|
+
operator: "in",
|
|
184
|
+
value: oe(a)
|
|
185
|
+
}
|
|
186
|
+
];
|
|
187
|
+
i !== null && o.push({
|
|
188
|
+
field: "id",
|
|
189
|
+
operator: ">",
|
|
190
|
+
value: i
|
|
191
|
+
});
|
|
192
|
+
let s = await e.find({
|
|
193
|
+
where: {
|
|
194
|
+
combinator: "and",
|
|
195
|
+
rules: o
|
|
196
|
+
},
|
|
197
|
+
orderBy: [{
|
|
198
|
+
field: "id",
|
|
199
|
+
sort: "asc"
|
|
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()
|
|
212
|
+
});
|
|
213
|
+
}
|
|
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
|
+
});
|
|
228
|
+
}
|
|
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
|
+
}
|
|
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
|
|
256
|
+
};
|
|
257
|
+
}
|
|
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
|
+
{
|
|
274
|
+
field: "id",
|
|
275
|
+
operator: "in",
|
|
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 });
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/topological-sort.ts
|
|
299
|
+
function ke(e) {
|
|
300
|
+
return e === "pull" ? "dependsOn" : "requiredBy";
|
|
301
|
+
}
|
|
302
|
+
function Ae(e) {
|
|
303
|
+
return e === "DELETE" ? "push" : "pull";
|
|
304
|
+
}
|
|
305
|
+
function je(e) {
|
|
306
|
+
return ke(Ae(e));
|
|
307
|
+
}
|
|
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);
|
|
322
|
+
}
|
|
323
|
+
for (let t of e.keys()) a(t);
|
|
324
|
+
return n;
|
|
325
|
+
}
|
|
326
|
+
function Ne(e) {
|
|
327
|
+
return Me(e, "pull");
|
|
328
|
+
}
|
|
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() {
|
|
340
|
+
return {
|
|
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: []
|
|
350
|
+
};
|
|
351
|
+
}
|
|
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));
|
|
372
|
+
try {
|
|
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;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
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
|
+
}
|
|
403
|
+
}
|
|
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);
|
|
409
|
+
}
|
|
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
|
+
}));
|
|
434
|
+
}
|
|
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;
|
|
442
|
+
}
|
|
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
|
+
};
|
|
480
|
+
}
|
|
481
|
+
}
|
|
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)}`);
|
|
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;
|
|
495
|
+
}
|
|
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()
|
|
521
|
+
});
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
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();
|
|
552
|
+
}
|
|
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;
|
|
583
|
+
}
|
|
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
|
+
};
|
|
599
|
+
}
|
|
600
|
+
//#endregion
|
|
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)}`);
|
|
605
|
+
return {
|
|
606
|
+
syncScope: e.syncScope,
|
|
607
|
+
lineage: n,
|
|
608
|
+
cutoffs: r,
|
|
609
|
+
filters: i
|
|
610
|
+
};
|
|
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
|
|
620
|
+
};
|
|
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",
|
|
635
|
+
operator: "=",
|
|
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
|
+
};
|
|
729
|
+
},
|
|
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
|
+
}
|
|
739
|
+
},
|
|
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);
|
|
749
|
+
},
|
|
750
|
+
async projectPage(e) {
|
|
751
|
+
return k(Ye(e.page.payload).changes);
|
|
752
|
+
},
|
|
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
|
+
}
|
|
768
|
+
}
|
|
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);
|
|
792
|
+
});
|
|
793
|
+
return i.set(a, c), c;
|
|
794
|
+
}
|
|
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
|
+
});
|
|
861
|
+
}
|
|
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
|
|
869
|
+
};
|
|
870
|
+
}
|
|
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
|
+
} }));
|
|
920
|
+
}
|
|
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)));
|
|
924
|
+
}
|
|
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;
|
|
934
|
+
}
|
|
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
|
|
966
|
+
}
|
|
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
|
+
});
|
|
982
|
+
}
|
|
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
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
return i(n.deletes, "DELETE"), i(n.updates, "UPDATE"), i(n.inserts, "INSERT"), r;
|
|
1005
|
+
}
|
|
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;
|
|
1011
|
+
}
|
|
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);
|
|
1024
|
+
} catch (e) {
|
|
1025
|
+
return r.reachability.report(e), i.failures.push({
|
|
1026
|
+
entityId: null,
|
|
1027
|
+
error: e instanceof Error ? e : Error(String(e))
|
|
1028
|
+
}), null;
|
|
1029
|
+
}
|
|
1030
|
+
return r.reachability.report(null), o;
|
|
1031
|
+
}
|
|
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);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
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;
|
|
1043
|
+
}
|
|
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.`)
|
|
1058
|
+
});
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
await Ot(e, r.verb, n);
|
|
1062
|
+
}
|
|
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
|
+
};
|
|
1080
|
+
}
|
|
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
|
|
1094
|
+
};
|
|
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
|
+
}
|
|
1137
|
+
//#endregion
|
|
1138
|
+
//#region src/push-repository.ts
|
|
1139
|
+
var Mt = {
|
|
1140
|
+
batchSize: 1e3,
|
|
1141
|
+
includeRelated: !0
|
|
1142
|
+
};
|
|
1143
|
+
function Nt(e) {
|
|
1144
|
+
if (!Number.isSafeInteger(e) || e <= 0) throw RangeError("batchSize must be a positive safe integer");
|
|
1145
|
+
}
|
|
1146
|
+
function Pt(e) {
|
|
1147
|
+
if (!(e instanceof g)) return;
|
|
1148
|
+
let t = e.result;
|
|
1149
|
+
if (!t || typeof t != "object") return;
|
|
1150
|
+
let n = t;
|
|
1151
|
+
return typeof n.pushed == "number" && typeof n.originalCount == "number" ? n : void 0;
|
|
1152
|
+
}
|
|
1153
|
+
function Ft(e) {
|
|
1154
|
+
let { error: t } = e;
|
|
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
|
+
};
|
|
1166
|
+
try {
|
|
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, {
|
|
1175
|
+
pushed: r.pushed,
|
|
1176
|
+
compacted: r.compacted,
|
|
1177
|
+
failed: r.failed
|
|
1178
|
+
})), r;
|
|
1179
|
+
} catch (e) {
|
|
1180
|
+
throw o.dispatchEvent(new d("push", t, n, e)), e;
|
|
1181
|
+
} finally {
|
|
1182
|
+
s.release();
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
async function Lt(e, t, n, r, i, a) {
|
|
1186
|
+
let o = e.rxdb.config.entities.find((e) => {
|
|
1187
|
+
let r = A(e);
|
|
1188
|
+
return r.namespace === t && r.name === n;
|
|
1189
|
+
});
|
|
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);
|
|
1200
|
+
if (t) for (let e of t.requiredBy) {
|
|
1201
|
+
let t = `${e.namespace}:${e.entity}`;
|
|
1202
|
+
c.has(t) || (c.add(t), l(t));
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
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,
|
|
1218
|
+
error: n.error
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
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;
|
|
1224
|
+
}
|
|
1225
|
+
async function zt(e, t, n, r, i, a, o, s) {
|
|
1226
|
+
let c = L(n), l = a.get(c);
|
|
1227
|
+
if (l || (l = { repo: n }, a.set(c, l)), l.result) return;
|
|
1228
|
+
let u = be(t, c, o, je(r.action));
|
|
1229
|
+
if (u) {
|
|
1230
|
+
let e = new m(n, u.dependency, u.cause);
|
|
1231
|
+
l.result = {
|
|
1232
|
+
...Vt(l.plan),
|
|
1233
|
+
repository: n,
|
|
1234
|
+
success: !1,
|
|
1235
|
+
skipped: `dependency ${L(u.dependency)} failed`,
|
|
1236
|
+
error: e
|
|
1237
|
+
}, o.set(c, e);
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
if (!l.plan) {
|
|
1241
|
+
let t = await Bt(e, n);
|
|
1242
|
+
if (t) {
|
|
1243
|
+
l.result = {
|
|
1244
|
+
...H(),
|
|
1245
|
+
repository: n,
|
|
1246
|
+
success: !0,
|
|
1247
|
+
skipped: t
|
|
1248
|
+
};
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
try {
|
|
1252
|
+
let t = await Zt(e, n.namespace, n.entity, s);
|
|
1253
|
+
if ("emptyResult" in t) {
|
|
1254
|
+
l.result = {
|
|
1255
|
+
...t.emptyResult,
|
|
1256
|
+
success: t.emptyResult.success ?? !0
|
|
1257
|
+
};
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
l.plan = t;
|
|
1261
|
+
} catch (e) {
|
|
1262
|
+
let t = e instanceof Error ? e : Error(String(e));
|
|
1263
|
+
l.result = {
|
|
1264
|
+
...H(),
|
|
1265
|
+
repository: n,
|
|
1266
|
+
success: !1,
|
|
1267
|
+
error: t,
|
|
1268
|
+
failures: [{
|
|
1269
|
+
repository: n,
|
|
1270
|
+
error: t
|
|
1271
|
+
}]
|
|
1272
|
+
}, o.set(c, t);
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
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));
|
|
1277
|
+
}
|
|
1278
|
+
async function Bt(e, t) {
|
|
1279
|
+
let n = e.rxdb.config.entities.find((e) => {
|
|
1280
|
+
let n = A(e);
|
|
1281
|
+
return n.namespace === t.namespace && n.name === t.entity;
|
|
1282
|
+
});
|
|
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));
|
|
1285
|
+
}
|
|
1286
|
+
function H() {
|
|
1287
|
+
return {
|
|
1288
|
+
pushed: 0,
|
|
1289
|
+
rejected: 0,
|
|
1290
|
+
failed: 0,
|
|
1291
|
+
compacted: 0,
|
|
1292
|
+
originalCount: 0,
|
|
1293
|
+
failures: []
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
function Vt(e) {
|
|
1297
|
+
return e ? {
|
|
1298
|
+
pushed: e.pushed,
|
|
1299
|
+
rejected: 0,
|
|
1300
|
+
failed: e.effectiveCount - e.pushed,
|
|
1301
|
+
compacted: e.compacted,
|
|
1302
|
+
originalCount: e.originalCount,
|
|
1303
|
+
failures: []
|
|
1304
|
+
} : H();
|
|
1305
|
+
}
|
|
1306
|
+
var Ht = [{
|
|
1307
|
+
action: "DELETE",
|
|
1308
|
+
kinds: /* @__PURE__ */ new Set(["deletes"])
|
|
1309
|
+
}, {
|
|
1310
|
+
action: "INSERT",
|
|
1311
|
+
kinds: /* @__PURE__ */ new Set(["updates", "inserts"])
|
|
1312
|
+
}], Ut = /* @__PURE__ */ new Set([
|
|
1313
|
+
"deletes",
|
|
1314
|
+
"updates",
|
|
1315
|
+
"inserts"
|
|
1316
|
+
]);
|
|
1317
|
+
function Wt(e, t) {
|
|
1318
|
+
let n = /* @__PURE__ */ new Map();
|
|
1319
|
+
for (let t of e) {
|
|
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) ?? [];
|
|
1323
|
+
r.push(t), n.set(e, r);
|
|
1324
|
+
}
|
|
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
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
return a("deletes", n.deletes), a("updates", n.updates), a("inserts", n.inserts), i;
|
|
1369
|
+
}
|
|
1370
|
+
function qt(e) {
|
|
1371
|
+
let t = {
|
|
1372
|
+
deletes: /* @__PURE__ */ new Map(),
|
|
1373
|
+
updates: /* @__PURE__ */ new Map(),
|
|
1374
|
+
inserts: /* @__PURE__ */ new Map()
|
|
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);
|
|
1379
|
+
}
|
|
1380
|
+
return n.sort((e, t) => e.id - t.id), {
|
|
1381
|
+
actions: t,
|
|
1382
|
+
sourceChanges: n
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
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
|
+
}
|
|
1396
|
+
}
|
|
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
|
+
}
|
|
1407
|
+
}
|
|
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;
|
|
1432
|
+
}
|
|
1433
|
+
async function Zt(e, t, n, r) {
|
|
1434
|
+
let i = e.rxdb;
|
|
1435
|
+
if (!i.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
1436
|
+
await e.getRemoteRepositories();
|
|
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);
|
|
1439
|
+
return r.namespace === t && r.name === n;
|
|
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, {
|
|
1443
|
+
namespace: t,
|
|
1444
|
+
entity: n,
|
|
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]);
|
|
1449
|
+
else {
|
|
1450
|
+
let e = m;
|
|
1451
|
+
for (let r of g.slice(1)) {
|
|
1452
|
+
let i = `${t}:${n}:${r}`, a = (await c.find({
|
|
1453
|
+
where: {
|
|
1454
|
+
combinator: "and",
|
|
1455
|
+
rules: [{
|
|
1456
|
+
field: "id",
|
|
1457
|
+
operator: "=",
|
|
1458
|
+
value: i
|
|
1459
|
+
}]
|
|
1460
|
+
},
|
|
1461
|
+
limit: 1
|
|
1462
|
+
}))[0]?.lastPushedChangeId ?? null;
|
|
1463
|
+
if (a === null) {
|
|
1464
|
+
e = null;
|
|
1465
|
+
break;
|
|
1466
|
+
}
|
|
1467
|
+
(e === null || a < e) && (e = a);
|
|
1468
|
+
}
|
|
1469
|
+
y = await vn(_, g, e, t, [n]);
|
|
1470
|
+
}
|
|
1471
|
+
let b = y.length;
|
|
1472
|
+
if (b === 0) return { emptyResult: {
|
|
1473
|
+
...H(),
|
|
1474
|
+
repository: {
|
|
1475
|
+
namespace: t,
|
|
1476
|
+
entity: n
|
|
1477
|
+
}
|
|
1478
|
+
} };
|
|
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, {
|
|
1483
|
+
lastPushedChangeId: e,
|
|
1484
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1485
|
+
}), { emptyResult: {
|
|
1486
|
+
...H(),
|
|
1487
|
+
repository: {
|
|
1488
|
+
namespace: t,
|
|
1489
|
+
entity: n
|
|
1490
|
+
},
|
|
1491
|
+
compacted: b,
|
|
1492
|
+
originalCount: b
|
|
1493
|
+
} };
|
|
1494
|
+
}
|
|
1495
|
+
let { adapter: w } = await e.getRemoteRepositories();
|
|
1496
|
+
return r.claim(`${t}:${n}`, y.reduce((e, t) => t.id > e ? t.id : e, y[0].id)), {
|
|
1497
|
+
repository: {
|
|
1498
|
+
namespace: t,
|
|
1499
|
+
entity: n
|
|
1500
|
+
},
|
|
1501
|
+
entityType: l,
|
|
1502
|
+
entries: x,
|
|
1503
|
+
localChanges: y,
|
|
1504
|
+
repoSync: f,
|
|
1505
|
+
localAdapter: a,
|
|
1506
|
+
remoteAdapter: w,
|
|
1507
|
+
branchId: s.id,
|
|
1508
|
+
branchGeneration: o,
|
|
1509
|
+
originalCount: b,
|
|
1510
|
+
effectiveCount: S,
|
|
1511
|
+
compacted: C,
|
|
1512
|
+
pushed: 0,
|
|
1513
|
+
remoteIdsByChange: /* @__PURE__ */ new Map(),
|
|
1514
|
+
rejectedEntries: []
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
async function Qt(e, t, n) {
|
|
1518
|
+
if (e.error) return;
|
|
1519
|
+
let r = e.entries.filter((e) => t.has(e.actionKind));
|
|
1520
|
+
if (r.length === 0) return;
|
|
1521
|
+
let { namespace: i, entity: a } = e.repository;
|
|
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;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
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));
|
|
1556
|
+
}
|
|
1557
|
+
return r;
|
|
1558
|
+
}
|
|
1559
|
+
function U(e, t, n, r) {
|
|
1560
|
+
let { repository: i } = e, a = e.effectiveCount - t - n;
|
|
1561
|
+
return {
|
|
1562
|
+
repository: i,
|
|
1563
|
+
success: a === 0,
|
|
1564
|
+
error: r,
|
|
1565
|
+
pushed: t,
|
|
1566
|
+
rejected: n,
|
|
1567
|
+
failed: a,
|
|
1568
|
+
compacted: e.compacted,
|
|
1569
|
+
originalCount: e.originalCount,
|
|
1570
|
+
failures: r ? [{
|
|
1571
|
+
repository: i,
|
|
1572
|
+
error: r
|
|
1573
|
+
}] : []
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
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);
|
|
1747
|
+
}
|
|
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) {
|
|
1757
|
+
let a = [
|
|
1758
|
+
{
|
|
1759
|
+
field: "revertChangeId",
|
|
1760
|
+
operator: "=",
|
|
1761
|
+
value: null
|
|
1762
|
+
},
|
|
1763
|
+
{
|
|
1764
|
+
field: "remoteId",
|
|
1765
|
+
operator: "=",
|
|
1766
|
+
value: null
|
|
1767
|
+
},
|
|
1768
|
+
{
|
|
1769
|
+
field: "rejectedAt",
|
|
1770
|
+
operator: "=",
|
|
1771
|
+
value: null
|
|
1772
|
+
},
|
|
1773
|
+
{
|
|
1774
|
+
field: "namespace",
|
|
1775
|
+
operator: "=",
|
|
1776
|
+
value: r
|
|
1777
|
+
}
|
|
1778
|
+
];
|
|
1779
|
+
return t.length === 1 ? a.push({
|
|
1780
|
+
field: "branchId",
|
|
1781
|
+
operator: "=",
|
|
1782
|
+
value: t[0]
|
|
1783
|
+
}) : a.push({
|
|
1784
|
+
field: "branchId",
|
|
1785
|
+
operator: "in",
|
|
1786
|
+
value: t
|
|
1787
|
+
}), i && i.length > 0 && a.push({
|
|
1788
|
+
field: "entity",
|
|
1789
|
+
operator: "in",
|
|
1790
|
+
value: i
|
|
1791
|
+
}), n !== null && a.push({
|
|
1792
|
+
field: "id",
|
|
1793
|
+
operator: ">",
|
|
1794
|
+
value: n
|
|
1795
|
+
}), await e.find({
|
|
1796
|
+
where: {
|
|
1797
|
+
combinator: "and",
|
|
1798
|
+
rules: a
|
|
1799
|
+
},
|
|
1800
|
+
orderBy: [{
|
|
1801
|
+
field: "id",
|
|
1802
|
+
sort: "asc"
|
|
1803
|
+
}]
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
//#endregion
|
|
1807
|
+
//#region src/sync-repository.ts
|
|
1808
|
+
function yn(e, t) {
|
|
1809
|
+
return {
|
|
1810
|
+
repository: {
|
|
1811
|
+
namespace: e,
|
|
1812
|
+
entity: t
|
|
1813
|
+
},
|
|
1814
|
+
pulled: 0,
|
|
1815
|
+
compacted: 0,
|
|
1816
|
+
applied: 0,
|
|
1817
|
+
hasMore: !1,
|
|
1818
|
+
conflictsResolved: 0,
|
|
1819
|
+
conflictsDeferred: 0,
|
|
1820
|
+
persistedProgress: !1,
|
|
1821
|
+
historyInvalidated: !1,
|
|
1822
|
+
failures: []
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
function bn(e, t) {
|
|
1826
|
+
return {
|
|
1827
|
+
repository: {
|
|
1828
|
+
namespace: e,
|
|
1829
|
+
entity: t
|
|
1830
|
+
},
|
|
1831
|
+
pushed: 0,
|
|
1832
|
+
rejected: 0,
|
|
1833
|
+
failed: 0,
|
|
1834
|
+
compacted: 0,
|
|
1835
|
+
originalCount: 0,
|
|
1836
|
+
failures: []
|
|
1837
|
+
};
|
|
1838
|
+
}
|
|
1839
|
+
function xn(e, t, n) {
|
|
1840
|
+
if (!(e instanceof g)) return e;
|
|
1841
|
+
let r = Le(e);
|
|
1842
|
+
if (!r) return e;
|
|
1843
|
+
let i = {
|
|
1844
|
+
pullResult: r,
|
|
1845
|
+
pushResult: bn(t, n),
|
|
1846
|
+
persistedProgress: r.persistedProgress,
|
|
1847
|
+
historyInvalidated: r.historyInvalidated
|
|
1848
|
+
};
|
|
1849
|
+
return new g(i, e.cause);
|
|
1850
|
+
}
|
|
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;
|
|
1853
|
+
if (!s) return i;
|
|
1854
|
+
let c = {
|
|
1855
|
+
pullResult: t,
|
|
1856
|
+
pushResult: o,
|
|
1857
|
+
persistedProgress: s,
|
|
1858
|
+
historyInvalidated: t.historyInvalidated
|
|
1859
|
+
};
|
|
1860
|
+
return new g(c, i instanceof g ? i.cause : i);
|
|
1861
|
+
}
|
|
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));
|
|
1865
|
+
try {
|
|
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
|
|
1873
|
+
};
|
|
1874
|
+
return a.dispatchEvent(new u("sync", t, n, l)), o;
|
|
1875
|
+
} catch (e) {
|
|
1876
|
+
throw a.dispatchEvent(new d("sync", t, n, e)), e;
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
async function wn(e, t, n, r, i) {
|
|
1880
|
+
let a = e.rxdb.config.entities.find((e) => {
|
|
1881
|
+
let r = A(e);
|
|
1882
|
+
return r.namespace === t && r.name === n;
|
|
1883
|
+
});
|
|
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);
|
|
1890
|
+
} catch (e) {
|
|
1891
|
+
throw xn(e, t, n);
|
|
1892
|
+
}
|
|
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);
|
|
1897
|
+
} catch (e) {
|
|
1898
|
+
throw Sn(e, c, t, n);
|
|
1899
|
+
}
|
|
1900
|
+
else l = bn(t, n);
|
|
1901
|
+
return {
|
|
1902
|
+
pullResult: c,
|
|
1903
|
+
pushResult: l,
|
|
1904
|
+
persistedProgress: c.persistedProgress || l.pushed > 0,
|
|
1905
|
+
historyInvalidated: c.historyInvalidated
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
//#endregion
|
|
1909
|
+
//#region src/bulk-sync.ts
|
|
1910
|
+
async function Tn(e, t) {
|
|
1911
|
+
if (t.repositories && t.repositories.length > 0) return t.repositories;
|
|
1912
|
+
let n = [];
|
|
1913
|
+
for (let t of e.config.entities) {
|
|
1914
|
+
let r = A(t), i = P(F(r, e.entitySync));
|
|
1915
|
+
if (!i.pull && !i.push) continue;
|
|
1916
|
+
let a = await re(e, r.namespace, r.name);
|
|
1917
|
+
I(a) && n.push({
|
|
1918
|
+
namespace: r.namespace,
|
|
1919
|
+
entity: r.name
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
return n;
|
|
1923
|
+
}
|
|
1924
|
+
async function En(e, t, n, r) {
|
|
1925
|
+
try {
|
|
1926
|
+
return {
|
|
1927
|
+
repository: t,
|
|
1928
|
+
success: !0,
|
|
1929
|
+
result: await Cn(e, t.namespace, t.entity, n, r)
|
|
1930
|
+
};
|
|
1931
|
+
} catch (e) {
|
|
1932
|
+
let n = e instanceof Error ? e : Error(String(e));
|
|
1933
|
+
return {
|
|
1934
|
+
repository: t,
|
|
1935
|
+
success: !1,
|
|
1936
|
+
result: n instanceof g ? n.result : void 0,
|
|
1937
|
+
error: n
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
async function Dn(e, t, n, r) {
|
|
1942
|
+
let i = [];
|
|
1943
|
+
for (let a of t) {
|
|
1944
|
+
let t = await En(e, a, n, r);
|
|
1945
|
+
i.push(t);
|
|
1946
|
+
}
|
|
1947
|
+
return i;
|
|
1948
|
+
}
|
|
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 = {
|
|
1959
|
+
direction: t.operation,
|
|
1960
|
+
pull: t.pull,
|
|
1961
|
+
push: t.push
|
|
1962
|
+
}, o = t.concurrent ?? !1, s = t.concurrency ?? 3;
|
|
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;
|
|
1967
|
+
return {
|
|
1968
|
+
succeeded: u,
|
|
1969
|
+
failed: d,
|
|
1970
|
+
results: c,
|
|
1971
|
+
durationMs: f
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1974
|
+
//#endregion
|
|
1975
|
+
//#region src/check-repository-updates.ts
|
|
1976
|
+
async function An(e, t, n) {
|
|
1977
|
+
let r = {
|
|
1978
|
+
namespace: t,
|
|
1979
|
+
entity: n
|
|
1980
|
+
}, i = e.config.entities.find((e) => {
|
|
1981
|
+
let r = A(e);
|
|
1982
|
+
return r.namespace === t && r.name === n;
|
|
1983
|
+
});
|
|
1984
|
+
if (!i) throw Error(`Entity not found: ${t}.${n}`);
|
|
1985
|
+
let a = A(i);
|
|
1986
|
+
if (!ue(a, e.entitySync)) return {
|
|
1987
|
+
repository: r,
|
|
1988
|
+
remoteLatestChangeId: 0,
|
|
1989
|
+
localLastPullRemoteChangeId: null,
|
|
1990
|
+
pendingCount: 0,
|
|
1991
|
+
hasUpdates: !1
|
|
1992
|
+
};
|
|
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({
|
|
1994
|
+
where: {
|
|
1995
|
+
combinator: "and",
|
|
1996
|
+
rules: [{
|
|
1997
|
+
field: "id",
|
|
1998
|
+
operator: "=",
|
|
1999
|
+
value: u
|
|
2000
|
+
}]
|
|
2001
|
+
},
|
|
2002
|
+
limit: 1
|
|
2003
|
+
}))[0]?.lastPullRemoteChangeId ?? null, { adapter: f } = await o.getRemoteRepositories();
|
|
2004
|
+
if (!f) throw Error("Remote adapter not configured");
|
|
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);
|
|
2006
|
+
return {
|
|
2007
|
+
repository: r,
|
|
2008
|
+
remoteLatestChangeId: h.reduce((e, t) => t.latestChangeId > e ? t.latestChangeId : e, 0),
|
|
2009
|
+
localLastPullRemoteChangeId: d,
|
|
2010
|
+
pendingCount: g,
|
|
2011
|
+
hasUpdates: g > 0
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
//#endregion
|
|
2015
|
+
//#region src/cleanup-expired.ts
|
|
2016
|
+
async function jn(e, t, n, r) {
|
|
2017
|
+
let i = e.rxdb, { adapter: a } = await e.getLocalRepositories(), o = i.config.entities.find((e) => {
|
|
2018
|
+
let r = A(e);
|
|
2019
|
+
return r.namespace === t && r.name === n;
|
|
2020
|
+
});
|
|
2021
|
+
if (!o) throw new h(`Entity not found: ${t}:${n}`);
|
|
2022
|
+
let s = A(o), c = F(s, i.entitySync), l = r?.filter;
|
|
2023
|
+
if (!l && c === "filter") {
|
|
2024
|
+
let e = ce(s, i.entitySync);
|
|
2025
|
+
if (e?.remote?.filter) try {
|
|
2026
|
+
l = e.remote.filter();
|
|
2027
|
+
} catch (e) {
|
|
2028
|
+
throw new h(`Filter function failed for ${t}:${n}: ${e instanceof Error ? e.message : String(e)}`);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
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) => {
|
|
2033
|
+
if (e.length === 0) return e;
|
|
2034
|
+
let i = await r.getRepository(p).find({ where: {
|
|
2035
|
+
combinator: "and",
|
|
2036
|
+
rules: [
|
|
2037
|
+
{
|
|
2038
|
+
field: "namespace",
|
|
2039
|
+
operator: "=",
|
|
2040
|
+
value: t
|
|
2041
|
+
},
|
|
2042
|
+
{
|
|
2043
|
+
field: "entity",
|
|
2044
|
+
operator: "=",
|
|
2045
|
+
value: n
|
|
2046
|
+
},
|
|
2047
|
+
{
|
|
2048
|
+
field: "remoteId",
|
|
2049
|
+
operator: "=",
|
|
2050
|
+
value: null
|
|
2051
|
+
},
|
|
2052
|
+
{
|
|
2053
|
+
field: "rejectedAt",
|
|
2054
|
+
operator: "=",
|
|
2055
|
+
value: null
|
|
2056
|
+
},
|
|
2057
|
+
{
|
|
2058
|
+
field: "revertChangeId",
|
|
2059
|
+
operator: "=",
|
|
2060
|
+
value: null
|
|
2061
|
+
},
|
|
2062
|
+
{
|
|
2063
|
+
field: "entityId",
|
|
2064
|
+
operator: "in",
|
|
2065
|
+
value: oe(e.map((e) => e.id))
|
|
2066
|
+
}
|
|
2067
|
+
]
|
|
2068
|
+
} }), a = new Set(i.map((e) => se(e.entityId)));
|
|
2069
|
+
return a.size === 0 ? e : e.filter((e) => !a.has(se(e.id)));
|
|
2070
|
+
};
|
|
2071
|
+
if (r?.dryRun) {
|
|
2072
|
+
let e = await d(await a.getRepository(o).find({ where: u }), a);
|
|
2073
|
+
return {
|
|
2074
|
+
removed: e.length,
|
|
2075
|
+
removedIds: e.map((e) => e.id)
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
return a.transaction(async (e) => {
|
|
2079
|
+
let r = e.getRepository(o), i = await d(await r.find({ where: u }), e), a = i.map((e) => e.id);
|
|
2080
|
+
if (a.length > 0) {
|
|
2081
|
+
let r = /* @__PURE__ */ new Map();
|
|
2082
|
+
for (let e of i) r.set(`${t}:${n}:${se(e.id)}`, {
|
|
2083
|
+
patch: null,
|
|
2084
|
+
inversePatch: null
|
|
2085
|
+
});
|
|
2086
|
+
let a = {
|
|
2087
|
+
deletes: r,
|
|
2088
|
+
updates: /* @__PURE__ */ new Map(),
|
|
2089
|
+
inserts: /* @__PURE__ */ new Map()
|
|
2090
|
+
};
|
|
2091
|
+
ne(e, {
|
|
2092
|
+
file: "cleanup-expired.ts",
|
|
2093
|
+
symbol: "cleanupExpired",
|
|
2094
|
+
intent: T.remote_sync
|
|
2095
|
+
}), await e.mergeChanges(a, void 0, !0);
|
|
2096
|
+
}
|
|
2097
|
+
return {
|
|
2098
|
+
removed: a.length,
|
|
2099
|
+
removedIds: a
|
|
2100
|
+
};
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
function Mn(e) {
|
|
2104
|
+
return {
|
|
2105
|
+
combinator: e.combinator === "and" ? "or" : "and",
|
|
2106
|
+
rules: e.rules.map((e) => "combinator" in e ? Mn(e) : Nn(e))
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2109
|
+
function Nn(e) {
|
|
2110
|
+
let t = {
|
|
2111
|
+
"=": "!=",
|
|
2112
|
+
"!=": "=",
|
|
2113
|
+
"<": ">=",
|
|
2114
|
+
"<=": ">",
|
|
2115
|
+
">": "<=",
|
|
2116
|
+
">=": "<",
|
|
2117
|
+
in: "notIn",
|
|
2118
|
+
notIn: "in",
|
|
2119
|
+
contains: "notContains",
|
|
2120
|
+
notContains: "contains",
|
|
2121
|
+
startsWith: "notStartsWith",
|
|
2122
|
+
notStartsWith: "startsWith",
|
|
2123
|
+
endsWith: "notEndsWith",
|
|
2124
|
+
notEndsWith: "endsWith",
|
|
2125
|
+
between: "notBetween",
|
|
2126
|
+
notBetween: "between",
|
|
2127
|
+
null: "notNull",
|
|
2128
|
+
notNull: "null",
|
|
2129
|
+
exists: "notExists",
|
|
2130
|
+
notExists: "exists"
|
|
2131
|
+
}[e.operator];
|
|
2132
|
+
if (!t) throw new h(`Cannot invert operator: ${e.operator}`);
|
|
2133
|
+
return {
|
|
2134
|
+
...e,
|
|
2135
|
+
operator: t
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
//#endregion
|
|
2139
|
+
//#region src/get-repository-sync-status.ts
|
|
2140
|
+
async function Pn(e, t, n, r, i) {
|
|
2141
|
+
let { adapter: a } = await e.getLocalRepositories(), o = a.getRepository(p), s = [
|
|
2142
|
+
{
|
|
2143
|
+
field: "namespace",
|
|
2144
|
+
operator: "=",
|
|
2145
|
+
value: t
|
|
2146
|
+
},
|
|
2147
|
+
{
|
|
2148
|
+
field: "entity",
|
|
2149
|
+
operator: "=",
|
|
2150
|
+
value: n
|
|
2151
|
+
},
|
|
2152
|
+
{
|
|
2153
|
+
field: "branchId",
|
|
2154
|
+
operator: "=",
|
|
2155
|
+
value: r
|
|
2156
|
+
},
|
|
2157
|
+
{
|
|
2158
|
+
field: "remoteId",
|
|
2159
|
+
operator: "=",
|
|
2160
|
+
value: null
|
|
2161
|
+
},
|
|
2162
|
+
{
|
|
2163
|
+
field: "rejectedAt",
|
|
2164
|
+
operator: "=",
|
|
2165
|
+
value: null
|
|
2166
|
+
},
|
|
2167
|
+
{
|
|
2168
|
+
field: "revertChangeId",
|
|
2169
|
+
operator: "=",
|
|
2170
|
+
value: null
|
|
2171
|
+
}
|
|
2172
|
+
];
|
|
2173
|
+
return i !== null && s.push({
|
|
2174
|
+
field: "id",
|
|
2175
|
+
operator: ">",
|
|
2176
|
+
value: i
|
|
2177
|
+
}), (await o.find({ where: {
|
|
2178
|
+
combinator: "and",
|
|
2179
|
+
rules: s
|
|
2180
|
+
} })).length;
|
|
2181
|
+
}
|
|
2182
|
+
async function Fn(e, t, n) {
|
|
2183
|
+
return (await An(e, t, n)).pendingCount;
|
|
2184
|
+
}
|
|
2185
|
+
async function In(e, t, n) {
|
|
2186
|
+
let r = e.config.entities.find((e) => {
|
|
2187
|
+
let r = A(e);
|
|
2188
|
+
return r.namespace === t && r.name === n;
|
|
2189
|
+
});
|
|
2190
|
+
if (!r) throw Error(`Entity not found: ${t}.${n}`);
|
|
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 = {
|
|
2192
|
+
combinator: "and",
|
|
2193
|
+
rules: [{
|
|
2194
|
+
field: "id",
|
|
2195
|
+
operator: "=",
|
|
2196
|
+
value: `${t}:${n}:${c}`
|
|
2197
|
+
}]
|
|
2198
|
+
}, f = await u.find({
|
|
2199
|
+
where: d,
|
|
2200
|
+
limit: 1
|
|
2201
|
+
}), p = f.length > 0 ? f[0] : null, m = 0, h = 0;
|
|
2202
|
+
return o.push && (m = await Pn(s, t, n, c, p?.lastPushedChangeId ?? null)), o.pull && (h = await Fn(e, t, n)), {
|
|
2203
|
+
repository: {
|
|
2204
|
+
namespace: t,
|
|
2205
|
+
entity: n
|
|
2206
|
+
},
|
|
2207
|
+
branchId: c,
|
|
2208
|
+
syncType: a,
|
|
2209
|
+
enabled: o.pull || o.push ? I(p) : !1,
|
|
2210
|
+
lastPushedChangeId: p?.lastPushedChangeId ?? null,
|
|
2211
|
+
lastPushedAt: p?.lastPushedAt ?? null,
|
|
2212
|
+
lastPulledAt: p?.lastPulledAt ?? null,
|
|
2213
|
+
lastPullRemoteChangeId: p?.lastPullRemoteChangeId ?? null,
|
|
2214
|
+
pushableCount: m,
|
|
2215
|
+
pullableCount: h
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2218
|
+
//#endregion
|
|
2219
|
+
//#region src/get-all-repository-sync-status.ts
|
|
2220
|
+
async function Ln(e, t) {
|
|
2221
|
+
let n = e.config.entities, r = [];
|
|
2222
|
+
for (let t of n) {
|
|
2223
|
+
let n = A(t), i = n.namespace, a = n.name, o = await In(e, i, a);
|
|
2224
|
+
r.push(o);
|
|
2225
|
+
}
|
|
2226
|
+
let i = r;
|
|
2227
|
+
return t?.syncType && t.syncType.length > 0 && (i = i.filter((e) => t.syncType.includes(e.syncType))), t?.enabled !== void 0 && (i = i.filter((e) => e.enabled === t.enabled)), t?.hasPendingChanges !== void 0 && (i = t.hasPendingChanges ? i.filter((e) => e.pushableCount > 0 || e.pullableCount > 0) : i.filter((e) => e.pushableCount === 0 && e.pullableCount === 0)), i;
|
|
2228
|
+
}
|
|
2229
|
+
//#endregion
|
|
2230
|
+
//#region src/pull-batch.ts
|
|
2231
|
+
var Rn = 1e3;
|
|
2232
|
+
async function zn(e, t) {
|
|
2233
|
+
if (t?.fetchAll !== !0) return await Hn(e, t?.limit, t?.conflictResolver);
|
|
2234
|
+
let n = {
|
|
2235
|
+
pulled: 0,
|
|
2236
|
+
compacted: 0,
|
|
2237
|
+
applied: 0,
|
|
2238
|
+
hasMore: !1,
|
|
2239
|
+
conflictsResolved: 0,
|
|
2240
|
+
conflictsDeferred: 0,
|
|
2241
|
+
persistedProgress: !1,
|
|
2242
|
+
historyInvalidated: !1,
|
|
2243
|
+
failures: []
|
|
2244
|
+
}, r = (e) => {
|
|
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);
|
|
2246
|
+
};
|
|
2247
|
+
for (let i = 0; i < Rn; i++) {
|
|
2248
|
+
let i;
|
|
2249
|
+
try {
|
|
2250
|
+
i = await Hn(e, t.limit, t.conflictResolver);
|
|
2251
|
+
} catch (e) {
|
|
2252
|
+
throw Vn(e, n);
|
|
2253
|
+
}
|
|
2254
|
+
if (r(i), !i.hasMore || i.pulled === 0) break;
|
|
2255
|
+
}
|
|
2256
|
+
return n;
|
|
2257
|
+
}
|
|
2258
|
+
var Bn = (e) => !e.persistedProgress;
|
|
2259
|
+
function Vn(e, t) {
|
|
2260
|
+
let n = e instanceof Error ? e : Error(String(e));
|
|
2261
|
+
return Bn(t) ? n : new g(t, n);
|
|
2262
|
+
}
|
|
2263
|
+
async function Hn(e, t, n) {
|
|
2264
|
+
let r = e.rxdb, i = t ?? 1e3;
|
|
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 = [];
|
|
2267
|
+
for (let e of r.config.entities) {
|
|
2268
|
+
let t = A(e), n = F(t, r.entitySync);
|
|
2269
|
+
if (!P(n).pull || n === "filter") continue;
|
|
2270
|
+
let i = await M(u, {
|
|
2271
|
+
namespace: t.namespace,
|
|
2272
|
+
entity: t.name,
|
|
2273
|
+
branchId: c,
|
|
2274
|
+
syncType: n
|
|
2275
|
+
}, () => r.entityManager.instantiate(v));
|
|
2276
|
+
I(i) && d.push({
|
|
2277
|
+
namespace: t.namespace,
|
|
2278
|
+
entity: t.name,
|
|
2279
|
+
syncId: i.id,
|
|
2280
|
+
repoSync: i,
|
|
2281
|
+
lastPullRemoteChangeId: i.lastPullRemoteChangeId ?? 0,
|
|
2282
|
+
syncType: n
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
if (d.length === 0) return {
|
|
2286
|
+
pulled: 0,
|
|
2287
|
+
compacted: 0,
|
|
2288
|
+
applied: 0,
|
|
2289
|
+
hasMore: !1,
|
|
2290
|
+
conflictsResolved: 0,
|
|
2291
|
+
conflictsDeferred: 0,
|
|
2292
|
+
persistedProgress: !1,
|
|
2293
|
+
historyInvalidated: !1,
|
|
2294
|
+
failures: []
|
|
2295
|
+
};
|
|
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) => ({
|
|
2297
|
+
namespace: e.namespace,
|
|
2298
|
+
entity: e.entity,
|
|
2299
|
+
sinceId: e.lastPullRemoteChangeId
|
|
2300
|
+
}));
|
|
2301
|
+
y = a.pullChangesBatch ? await a.pullChangesBatch(b, _, l) : (await Promise.all(g.map((e) => ye(a, {
|
|
2302
|
+
namespace: e.namespace,
|
|
2303
|
+
entity: e.entity,
|
|
2304
|
+
sinceId: e.lastPullRemoteChangeId,
|
|
2305
|
+
limit: i
|
|
2306
|
+
}, l)))).flat();
|
|
2307
|
+
let x = /* @__PURE__ */ new Map();
|
|
2308
|
+
for (let e of y) {
|
|
2309
|
+
let t = `${e.namespace}:${e.entity}`;
|
|
2310
|
+
x.has(t) || x.set(t, []), x.get(t).push(e);
|
|
2311
|
+
}
|
|
2312
|
+
let S = 0, C = 0, w = 0, E = 0, D = !1, ee = r.context.clientId, te = n === void 0 ? new o() : n;
|
|
2313
|
+
return await s.transaction(async (e) => {
|
|
2314
|
+
let t = e.getRepository(p), n = e.getRepository(v);
|
|
2315
|
+
for (let a of g) {
|
|
2316
|
+
let o = (x.get(`${a.namespace}:${a.entity}`) ?? []).filter((e) => e.id > a.lastPullRemoteChangeId);
|
|
2317
|
+
if (o.length === 0) continue;
|
|
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))]), {
|
|
2326
|
+
changeRepo: t,
|
|
2327
|
+
conflictResolver: te,
|
|
2328
|
+
dispatchEvent: (e) => r.dispatchEvent(e),
|
|
2329
|
+
repoLabel: `${a.namespace}:${a.entity}`,
|
|
2330
|
+
localClientId: r.context.clientId
|
|
2331
|
+
});
|
|
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);
|
|
2339
|
+
}
|
|
2340
|
+
let u = o.reduce((e, t) => t.id > e ? t.id : e, o[0].id);
|
|
2341
|
+
a.repoSync = await n.update(a.repoSync, {
|
|
2342
|
+
lastPullRemoteChangeId: u,
|
|
2343
|
+
lastPulledAt: /* @__PURE__ */ new Date(),
|
|
2344
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
2345
|
+
}), o.length >= i && (D = !0);
|
|
2346
|
+
}
|
|
2347
|
+
}), {
|
|
2348
|
+
pulled: S,
|
|
2349
|
+
compacted: C,
|
|
2350
|
+
applied: w,
|
|
2351
|
+
hasMore: D,
|
|
2352
|
+
conflictsResolved: E,
|
|
2353
|
+
conflictsDeferred: 0,
|
|
2354
|
+
persistedProgress: S > 0,
|
|
2355
|
+
historyInvalidated: w > 0,
|
|
2356
|
+
failures: []
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2359
|
+
//#endregion
|
|
2360
|
+
//#region src/pull.ts
|
|
2361
|
+
async function Un(e, t) {
|
|
2362
|
+
let n = e.rxdb;
|
|
2363
|
+
if (!n.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
2364
|
+
n.dispatchEvent(new S("pull"));
|
|
2365
|
+
try {
|
|
2366
|
+
let r;
|
|
2367
|
+
return t?.repositoryFilter?.length ? r = await Kn(e, t) : (r = await zn(e, {
|
|
2368
|
+
limit: t?.limit,
|
|
2369
|
+
fetchAll: t?.fetchAll,
|
|
2370
|
+
conflictResolver: t?.conflictResolver
|
|
2371
|
+
}), await Wn(e, t, r)), n.dispatchEvent(new C("pull", r)), r;
|
|
2372
|
+
} catch (e) {
|
|
2373
|
+
throw n.dispatchEvent(new w("pull", e)), e;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
async function Wn(e, t, n) {
|
|
2377
|
+
let r = e.rxdb;
|
|
2378
|
+
for (let i of r.config.entities) {
|
|
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;
|
|
2383
|
+
let c;
|
|
2384
|
+
try {
|
|
2385
|
+
c = await ze(e, a.namespace, a.name, {
|
|
2386
|
+
limit: t?.limit,
|
|
2387
|
+
fetchAll: t?.fetchAll,
|
|
2388
|
+
conflictResolver: t?.conflictResolver,
|
|
2389
|
+
includeRelated: !1
|
|
2390
|
+
});
|
|
2391
|
+
} catch (e) {
|
|
2392
|
+
let t = e instanceof Error ? e : Error(String(e));
|
|
2393
|
+
t instanceof g && Gn(n, t.result), n.failures.push({
|
|
2394
|
+
repository: {
|
|
2395
|
+
namespace: a.namespace,
|
|
2396
|
+
entity: a.name
|
|
2397
|
+
},
|
|
2398
|
+
error: t instanceof g ? t.cause : t
|
|
2399
|
+
});
|
|
2400
|
+
continue;
|
|
2401
|
+
}
|
|
2402
|
+
Gn(n, c), n.failures.push(...c.failures);
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
function Gn(e, t) {
|
|
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;
|
|
2407
|
+
}
|
|
2408
|
+
async function Kn(e, t) {
|
|
2409
|
+
let n = {
|
|
2410
|
+
operation: "pull",
|
|
2411
|
+
repositories: t.repositoryFilter?.map((e) => typeof e == "string" ? {
|
|
2412
|
+
namespace: "public",
|
|
2413
|
+
entity: e
|
|
2414
|
+
} : e),
|
|
2415
|
+
pull: {
|
|
2416
|
+
limit: t.limit,
|
|
2417
|
+
fetchAll: t.fetchAll,
|
|
2418
|
+
conflictResolver: t.conflictResolver
|
|
2419
|
+
}
|
|
2420
|
+
}, r = await e.bulkSync(n), i = {
|
|
2421
|
+
pulled: 0,
|
|
2422
|
+
compacted: 0,
|
|
2423
|
+
applied: 0,
|
|
2424
|
+
hasMore: !1,
|
|
2425
|
+
conflictsResolved: 0,
|
|
2426
|
+
conflictsDeferred: 0,
|
|
2427
|
+
persistedProgress: !1,
|
|
2428
|
+
historyInvalidated: !1,
|
|
2429
|
+
failures: []
|
|
2430
|
+
};
|
|
2431
|
+
for (let e of r.results) {
|
|
2432
|
+
let t = e.result?.pullResult;
|
|
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;
|
|
2434
|
+
let n = e.error ?? new h(`Repository pull failed: ${e.repository.namespace}:${e.repository.entity}`);
|
|
2435
|
+
i.failures.push({
|
|
2436
|
+
repository: e.repository,
|
|
2437
|
+
error: n instanceof g ? n.cause : n
|
|
2438
|
+
});
|
|
2439
|
+
}
|
|
2440
|
+
let [a] = i.failures;
|
|
2441
|
+
if (a) throw !i.persistedProgress && i.failures.length === 1 ? a.error : new g(i, a.error);
|
|
2442
|
+
return i;
|
|
2443
|
+
}
|
|
2444
|
+
//#endregion
|
|
2445
|
+
//#region src/branch-change-id.ts
|
|
2446
|
+
var qn = async (e, t, n) => (await e.find({
|
|
2447
|
+
where: {
|
|
2448
|
+
combinator: "and",
|
|
2449
|
+
rules: [{
|
|
2450
|
+
field: t,
|
|
2451
|
+
operator: "=",
|
|
2452
|
+
value: n
|
|
2453
|
+
}]
|
|
2454
|
+
},
|
|
2455
|
+
limit: 1
|
|
2456
|
+
}))[0], Jn = async (e, t) => {
|
|
2457
|
+
let n = await qn(e, "id", t);
|
|
2458
|
+
if (!n) throw new h(`分支分叉点翻译失败:本地不存在 RxDBChange id=${t},分支表与变更表已不一致`);
|
|
2459
|
+
return n.remoteId ?? null;
|
|
2460
|
+
}, Yn = async (e, t) => (await qn(e, "remoteId", t))?.id ?? null;
|
|
2461
|
+
//#endregion
|
|
2462
|
+
//#region src/push-branch.ts
|
|
2463
|
+
async function Xn(e) {
|
|
2464
|
+
let t = await e.getCurrentBranch();
|
|
2465
|
+
if (!t || t.id === s) return {
|
|
2466
|
+
synced: 0,
|
|
2467
|
+
skipped: t ? [s] : [],
|
|
2468
|
+
forkPointPending: !1
|
|
2469
|
+
};
|
|
2470
|
+
let { adapter: n } = await e.getRemoteRepositories();
|
|
2471
|
+
if (!n.pushBranches) return {
|
|
2472
|
+
synced: 0,
|
|
2473
|
+
skipped: [],
|
|
2474
|
+
forkPointPending: !1
|
|
2475
|
+
};
|
|
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 = {
|
|
2477
|
+
id: t.id,
|
|
2478
|
+
fromChangeId: o,
|
|
2479
|
+
local: t.local,
|
|
2480
|
+
remote: !0,
|
|
2481
|
+
parentId: t.parentId
|
|
2482
|
+
}, u = await n.pushBranches([l]);
|
|
2483
|
+
return u.synced > 0 && !t.remote && await r.update(t, {
|
|
2484
|
+
remote: !0,
|
|
2485
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
2486
|
+
}), {
|
|
2487
|
+
...u,
|
|
2488
|
+
forkPointPending: c
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
//#endregion
|
|
2492
|
+
//#region src/push.ts
|
|
2493
|
+
async function Zn(e, t) {
|
|
2494
|
+
let n = e.rxdb;
|
|
2495
|
+
if (!n.config.sync?.remote?.adapter) throw new h("Remote adapter not configured.");
|
|
2496
|
+
n.dispatchEvent(new S("push"));
|
|
2497
|
+
try {
|
|
2498
|
+
let r = await Xn(e), i = {
|
|
2499
|
+
operation: "push",
|
|
2500
|
+
repositories: t?.repositoryFilter?.map((e) => typeof e == "string" ? {
|
|
2501
|
+
namespace: "public",
|
|
2502
|
+
entity: e
|
|
2503
|
+
} : e),
|
|
2504
|
+
...t?.batchSize === void 0 ? {} : { push: { batchSize: t.batchSize } }
|
|
2505
|
+
}, a = await e.bulkSync(i), o = {
|
|
2506
|
+
pushed: 0,
|
|
2507
|
+
rejected: 0,
|
|
2508
|
+
failed: 0,
|
|
2509
|
+
compacted: 0,
|
|
2510
|
+
originalCount: 0,
|
|
2511
|
+
failures: []
|
|
2512
|
+
};
|
|
2513
|
+
for (let e of a.results) {
|
|
2514
|
+
let t = e.result?.pushResult;
|
|
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}`);
|
|
2517
|
+
o.failures.push({
|
|
2518
|
+
repository: e.repository,
|
|
2519
|
+
error: n instanceof g ? n.cause : n
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
return r.forkPointPending && o.pushed > 0 && await Xn(e), n.dispatchEvent(new C("push", o)), o;
|
|
2523
|
+
} catch (e) {
|
|
2524
|
+
throw n.dispatchEvent(new w("push", e)), e;
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
//#endregion
|
|
2528
|
+
//#region src/sync-branches.ts
|
|
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) {
|
|
2538
|
+
let n = new Set(t), r = new Set(e.map((e) => e.id)), i = [], a = e;
|
|
2539
|
+
for (; a.length > 0;) {
|
|
2540
|
+
let e = a.filter((e) => {
|
|
2541
|
+
let t = e.parentId ?? null;
|
|
2542
|
+
return t === null || n.has(t);
|
|
2543
|
+
});
|
|
2544
|
+
if (e.length === 0) break;
|
|
2545
|
+
for (let t of e) i.push(t), n.add(t.id);
|
|
2546
|
+
a = a.filter((e) => !n.has(e.id));
|
|
2547
|
+
}
|
|
2548
|
+
if (a.length > 0) {
|
|
2549
|
+
let e = a.map((e) => {
|
|
2550
|
+
let t = e.parentId ?? null, n = t !== null && r.has(t) ? "cycle" : "missing parent";
|
|
2551
|
+
return `'${e.id}' -> '${String(t)}' (${n})`;
|
|
2552
|
+
}).join(", ");
|
|
2553
|
+
throw new h(`syncBranches: 远端分支拓扑无法解析,整批放弃:${e}`);
|
|
2554
|
+
}
|
|
2555
|
+
return i;
|
|
2556
|
+
}
|
|
2557
|
+
async function er(e) {
|
|
2558
|
+
let { adapter: t } = await e.getRemoteRepositories();
|
|
2559
|
+
if (!t.pullBranches) return {
|
|
2560
|
+
created: 0,
|
|
2561
|
+
updated: 0,
|
|
2562
|
+
total: 0,
|
|
2563
|
+
skipped: [],
|
|
2564
|
+
skipReasons: {}
|
|
2565
|
+
};
|
|
2566
|
+
let n = await t.pullBranches();
|
|
2567
|
+
if (n.length === 0) return {
|
|
2568
|
+
created: 0,
|
|
2569
|
+
updated: 0,
|
|
2570
|
+
total: 0,
|
|
2571
|
+
skipped: [],
|
|
2572
|
+
skipReasons: {}
|
|
2573
|
+
};
|
|
2574
|
+
let { adapter: r } = await e.getLocalRepositories();
|
|
2575
|
+
return r.transaction(async (e) => {
|
|
2576
|
+
let t = e.getRepository(f), r = e.getRepository(p), i = await t.find({ where: {
|
|
2577
|
+
combinator: "and",
|
|
2578
|
+
rules: []
|
|
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, {
|
|
2598
|
+
remote: !0,
|
|
2599
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
2600
|
+
}), s++);
|
|
2601
|
+
continue;
|
|
2602
|
+
}
|
|
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" });
|
|
2606
|
+
continue;
|
|
2607
|
+
}
|
|
2608
|
+
await t.create({
|
|
2609
|
+
id: e.id,
|
|
2610
|
+
activated: !1,
|
|
2611
|
+
activeKey: null,
|
|
2612
|
+
local: !1,
|
|
2613
|
+
remote: !0,
|
|
2614
|
+
fromChangeId: d,
|
|
2615
|
+
parentId: e.parentId ?? null
|
|
2616
|
+
}), o++;
|
|
2617
|
+
}
|
|
2618
|
+
return {
|
|
2619
|
+
created: o,
|
|
2620
|
+
updated: s,
|
|
2621
|
+
total: n.length,
|
|
2622
|
+
skipped: c,
|
|
2623
|
+
skipReasons: Object.fromEntries(l)
|
|
2624
|
+
};
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
//#endregion
|
|
2628
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isFunction.js
|
|
2629
|
+
function W(e) {
|
|
2630
|
+
return typeof e == "function";
|
|
2631
|
+
}
|
|
2632
|
+
//#endregion
|
|
2633
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/lift.js
|
|
2634
|
+
function tr(e) {
|
|
2635
|
+
return W(e?.lift);
|
|
2636
|
+
}
|
|
2637
|
+
function G(e) {
|
|
2638
|
+
return function(t) {
|
|
2639
|
+
if (tr(t)) return t.lift(function(t) {
|
|
2640
|
+
try {
|
|
2641
|
+
return e(t, this);
|
|
2642
|
+
} catch (e) {
|
|
2643
|
+
this.error(e);
|
|
2644
|
+
}
|
|
2645
|
+
});
|
|
2646
|
+
throw TypeError("Unable to lift unknown Observable type");
|
|
2647
|
+
};
|
|
2648
|
+
}
|
|
2649
|
+
//#endregion
|
|
2650
|
+
//#region ../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
|
|
2651
|
+
var nr = function(e, t) {
|
|
2652
|
+
return nr = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, t) {
|
|
2653
|
+
e.__proto__ = t;
|
|
2654
|
+
} || function(e, t) {
|
|
2655
|
+
for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
|
|
2656
|
+
}, nr(e, t);
|
|
2657
|
+
};
|
|
2658
|
+
function rr(e, t) {
|
|
2659
|
+
if (typeof t != "function" && t !== null) throw TypeError("Class extends value " + String(t) + " is not a constructor or null");
|
|
2660
|
+
nr(e, t);
|
|
2661
|
+
function n() {
|
|
2662
|
+
this.constructor = e;
|
|
2663
|
+
}
|
|
2664
|
+
e.prototype = t === null ? Object.create(t) : (n.prototype = t.prototype, new n());
|
|
2665
|
+
}
|
|
2666
|
+
function ir(e, t, n, r) {
|
|
2667
|
+
function i(e) {
|
|
2668
|
+
return e instanceof n ? e : new n(function(t) {
|
|
2669
|
+
t(e);
|
|
2670
|
+
});
|
|
2671
|
+
}
|
|
2672
|
+
return new (n ||= Promise)(function(n, a) {
|
|
2673
|
+
function o(e) {
|
|
2674
|
+
try {
|
|
2675
|
+
c(r.next(e));
|
|
2676
|
+
} catch (e) {
|
|
2677
|
+
a(e);
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
function s(e) {
|
|
2681
|
+
try {
|
|
2682
|
+
c(r.throw(e));
|
|
2683
|
+
} catch (e) {
|
|
2684
|
+
a(e);
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
function c(e) {
|
|
2688
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
2689
|
+
}
|
|
2690
|
+
c((r = r.apply(e, t || [])).next());
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
function ar(e, t) {
|
|
2694
|
+
var n = {
|
|
2695
|
+
label: 0,
|
|
2696
|
+
sent: function() {
|
|
2697
|
+
if (a[0] & 1) throw a[1];
|
|
2698
|
+
return a[1];
|
|
2699
|
+
},
|
|
2700
|
+
trys: [],
|
|
2701
|
+
ops: []
|
|
2702
|
+
}, r, i, a, o = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
|
|
2703
|
+
return o.next = s(0), o.throw = s(1), o.return = s(2), typeof Symbol == "function" && (o[Symbol.iterator] = function() {
|
|
2704
|
+
return this;
|
|
2705
|
+
}), o;
|
|
2706
|
+
function s(e) {
|
|
2707
|
+
return function(t) {
|
|
2708
|
+
return c([e, t]);
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2711
|
+
function c(s) {
|
|
2712
|
+
if (r) throw TypeError("Generator is already executing.");
|
|
2713
|
+
for (; o && (o = 0, s[0] && (n = 0)), n;) try {
|
|
2714
|
+
if (r = 1, i && (a = s[0] & 2 ? i.return : s[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, s[1])).done) return a;
|
|
2715
|
+
switch (i = 0, a && (s = [s[0] & 2, a.value]), s[0]) {
|
|
2716
|
+
case 0:
|
|
2717
|
+
case 1:
|
|
2718
|
+
a = s;
|
|
2719
|
+
break;
|
|
2720
|
+
case 4: return n.label++, {
|
|
2721
|
+
value: s[1],
|
|
2722
|
+
done: !1
|
|
2723
|
+
};
|
|
2724
|
+
case 5:
|
|
2725
|
+
n.label++, i = s[1], s = [0];
|
|
2726
|
+
continue;
|
|
2727
|
+
case 7:
|
|
2728
|
+
s = n.ops.pop(), n.trys.pop();
|
|
2729
|
+
continue;
|
|
2730
|
+
default:
|
|
2731
|
+
if (a = n.trys, !(a = a.length > 0 && a[a.length - 1]) && (s[0] === 6 || s[0] === 2)) {
|
|
2732
|
+
n = 0;
|
|
2733
|
+
continue;
|
|
2734
|
+
}
|
|
2735
|
+
if (s[0] === 3 && (!a || s[1] > a[0] && s[1] < a[3])) {
|
|
2736
|
+
n.label = s[1];
|
|
2737
|
+
break;
|
|
2738
|
+
}
|
|
2739
|
+
if (s[0] === 6 && n.label < a[1]) {
|
|
2740
|
+
n.label = a[1], a = s;
|
|
2741
|
+
break;
|
|
2742
|
+
}
|
|
2743
|
+
if (a && n.label < a[2]) {
|
|
2744
|
+
n.label = a[2], n.ops.push(s);
|
|
2745
|
+
break;
|
|
2746
|
+
}
|
|
2747
|
+
a[2] && n.ops.pop(), n.trys.pop();
|
|
2748
|
+
continue;
|
|
2749
|
+
}
|
|
2750
|
+
s = t.call(e, n);
|
|
2751
|
+
} catch (e) {
|
|
2752
|
+
s = [6, e], i = 0;
|
|
2753
|
+
} finally {
|
|
2754
|
+
r = a = 0;
|
|
2755
|
+
}
|
|
2756
|
+
if (s[0] & 5) throw s[1];
|
|
2757
|
+
return {
|
|
2758
|
+
value: s[0] ? s[1] : void 0,
|
|
2759
|
+
done: !0
|
|
2760
|
+
};
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
function K(e) {
|
|
2764
|
+
var t = typeof Symbol == "function" && Symbol.iterator, n = t && e[t], r = 0;
|
|
2765
|
+
if (n) return n.call(e);
|
|
2766
|
+
if (e && typeof e.length == "number") return { next: function() {
|
|
2767
|
+
return e && r >= e.length && (e = void 0), {
|
|
2768
|
+
value: e && e[r++],
|
|
2769
|
+
done: !e
|
|
2770
|
+
};
|
|
2771
|
+
} };
|
|
2772
|
+
throw TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
2773
|
+
}
|
|
2774
|
+
function q(e, t) {
|
|
2775
|
+
var n = typeof Symbol == "function" && e[Symbol.iterator];
|
|
2776
|
+
if (!n) return e;
|
|
2777
|
+
var r = n.call(e), i, a = [], o;
|
|
2778
|
+
try {
|
|
2779
|
+
for (; (t === void 0 || t-- > 0) && !(i = r.next()).done;) a.push(i.value);
|
|
2780
|
+
} catch (e) {
|
|
2781
|
+
o = { error: e };
|
|
2782
|
+
} finally {
|
|
2783
|
+
try {
|
|
2784
|
+
i && !i.done && (n = r.return) && n.call(r);
|
|
2785
|
+
} finally {
|
|
2786
|
+
if (o) throw o.error;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
return a;
|
|
2790
|
+
}
|
|
2791
|
+
function J(e, t, n) {
|
|
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]);
|
|
2793
|
+
return e.concat(a || Array.prototype.slice.call(t));
|
|
2794
|
+
}
|
|
2795
|
+
function Y(e) {
|
|
2796
|
+
return this instanceof Y ? (this.v = e, this) : new Y(e);
|
|
2797
|
+
}
|
|
2798
|
+
function or(e, t, n) {
|
|
2799
|
+
if (!Symbol.asyncIterator) throw TypeError("Symbol.asyncIterator is not defined.");
|
|
2800
|
+
var r = n.apply(e, t || []), i, a = [];
|
|
2801
|
+
return i = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), s("next"), s("throw"), s("return", o), i[Symbol.asyncIterator] = function() {
|
|
2802
|
+
return this;
|
|
2803
|
+
}, i;
|
|
2804
|
+
function o(e) {
|
|
2805
|
+
return function(t) {
|
|
2806
|
+
return Promise.resolve(t).then(e, d);
|
|
2807
|
+
};
|
|
2808
|
+
}
|
|
2809
|
+
function s(e, t) {
|
|
2810
|
+
r[e] && (i[e] = function(t) {
|
|
2811
|
+
return new Promise(function(n, r) {
|
|
2812
|
+
a.push([
|
|
2813
|
+
e,
|
|
2814
|
+
t,
|
|
2815
|
+
n,
|
|
2816
|
+
r
|
|
2817
|
+
]) > 1 || c(e, t);
|
|
2818
|
+
});
|
|
2819
|
+
}, t && (i[e] = t(i[e])));
|
|
2820
|
+
}
|
|
2821
|
+
function c(e, t) {
|
|
2822
|
+
try {
|
|
2823
|
+
l(r[e](t));
|
|
2824
|
+
} catch (e) {
|
|
2825
|
+
f(a[0][3], e);
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
function l(e) {
|
|
2829
|
+
e.value instanceof Y ? Promise.resolve(e.value.v).then(u, d) : f(a[0][2], e);
|
|
2830
|
+
}
|
|
2831
|
+
function u(e) {
|
|
2832
|
+
c("next", e);
|
|
2833
|
+
}
|
|
2834
|
+
function d(e) {
|
|
2835
|
+
c("throw", e);
|
|
2836
|
+
}
|
|
2837
|
+
function f(e, t) {
|
|
2838
|
+
e(t), a.shift(), a.length && c(a[0][0], a[0][1]);
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
function sr(e) {
|
|
2842
|
+
if (!Symbol.asyncIterator) throw TypeError("Symbol.asyncIterator is not defined.");
|
|
2843
|
+
var t = e[Symbol.asyncIterator], n;
|
|
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() {
|
|
2845
|
+
return this;
|
|
2846
|
+
}, n);
|
|
2847
|
+
function r(t) {
|
|
2848
|
+
n[t] = e[t] && function(n) {
|
|
2849
|
+
return new Promise(function(r, a) {
|
|
2850
|
+
n = e[t](n), i(r, a, n.done, n.value);
|
|
2851
|
+
});
|
|
2852
|
+
};
|
|
2853
|
+
}
|
|
2854
|
+
function i(e, t, n, r) {
|
|
2855
|
+
Promise.resolve(r).then(function(t) {
|
|
2856
|
+
e({
|
|
2857
|
+
value: t,
|
|
2858
|
+
done: n
|
|
2859
|
+
});
|
|
2860
|
+
}, t);
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
//#endregion
|
|
2864
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isArrayLike.js
|
|
2865
|
+
var cr = (function(e) {
|
|
2866
|
+
return e && typeof e.length == "number" && typeof e != "function";
|
|
2867
|
+
});
|
|
2868
|
+
//#endregion
|
|
2869
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isPromise.js
|
|
2870
|
+
function lr(e) {
|
|
2871
|
+
return W(e?.then);
|
|
2872
|
+
}
|
|
2873
|
+
//#endregion
|
|
2874
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js
|
|
2875
|
+
function ur(e) {
|
|
2876
|
+
var t = e(function(e) {
|
|
2877
|
+
Error.call(e), e.stack = (/* @__PURE__ */ Error()).stack;
|
|
2878
|
+
});
|
|
2879
|
+
return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
|
|
2880
|
+
}
|
|
2881
|
+
//#endregion
|
|
2882
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js
|
|
2883
|
+
var dr = ur(function(e) {
|
|
2884
|
+
return function(t) {
|
|
2885
|
+
e(this), this.message = t ? t.length + " errors occurred during unsubscription:\n" + t.map(function(e, t) {
|
|
2886
|
+
return t + 1 + ") " + e.toString();
|
|
2887
|
+
}).join("\n ") : "", this.name = "UnsubscriptionError", this.errors = t;
|
|
2888
|
+
};
|
|
2889
|
+
});
|
|
2890
|
+
//#endregion
|
|
2891
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js
|
|
2892
|
+
function fr(e, t) {
|
|
2893
|
+
if (e) {
|
|
2894
|
+
var n = e.indexOf(t);
|
|
2895
|
+
0 <= n && e.splice(n, 1);
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
//#endregion
|
|
2899
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/Subscription.js
|
|
2900
|
+
var pr = function() {
|
|
2901
|
+
function e(e) {
|
|
2902
|
+
this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
|
|
2903
|
+
}
|
|
2904
|
+
return e.prototype.unsubscribe = function() {
|
|
2905
|
+
var e, t, n, r, i;
|
|
2906
|
+
if (!this.closed) {
|
|
2907
|
+
this.closed = !0;
|
|
2908
|
+
var a = this._parentage;
|
|
2909
|
+
if (a) {
|
|
2910
|
+
if (this._parentage = null, Array.isArray(a)) try {
|
|
2911
|
+
for (var o = K(a), s = o.next(); !s.done; s = o.next()) s.value.remove(this);
|
|
2912
|
+
} catch (t) {
|
|
2913
|
+
e = { error: t };
|
|
2914
|
+
} finally {
|
|
2915
|
+
try {
|
|
2916
|
+
s && !s.done && (t = o.return) && t.call(o);
|
|
2917
|
+
} finally {
|
|
2918
|
+
if (e) throw e.error;
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
else a.remove(this);
|
|
2922
|
+
}
|
|
2923
|
+
var c = this.initialTeardown;
|
|
2924
|
+
if (W(c)) try {
|
|
2925
|
+
c();
|
|
2926
|
+
} catch (e) {
|
|
2927
|
+
i = e instanceof dr ? e.errors : [e];
|
|
2928
|
+
}
|
|
2929
|
+
var l = this._finalizers;
|
|
2930
|
+
if (l) {
|
|
2931
|
+
this._finalizers = null;
|
|
2932
|
+
try {
|
|
2933
|
+
for (var u = K(l), d = u.next(); !d.done; d = u.next()) {
|
|
2934
|
+
var f = d.value;
|
|
2935
|
+
try {
|
|
2936
|
+
hr(f);
|
|
2937
|
+
} catch (e) {
|
|
2938
|
+
i ??= [], e instanceof dr ? i = J(J([], q(i)), q(e.errors)) : i.push(e);
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
} catch (e) {
|
|
2942
|
+
n = { error: e };
|
|
2943
|
+
} finally {
|
|
2944
|
+
try {
|
|
2945
|
+
d && !d.done && (r = u.return) && r.call(u);
|
|
2946
|
+
} finally {
|
|
2947
|
+
if (n) throw n.error;
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
if (i) throw new dr(i);
|
|
2952
|
+
}
|
|
2953
|
+
}, e.prototype.add = function(t) {
|
|
2954
|
+
if (t && t !== this) {
|
|
2955
|
+
if (this.closed) hr(t);
|
|
2956
|
+
else {
|
|
2957
|
+
if (t instanceof e) {
|
|
2958
|
+
if (t.closed || t._hasParent(this)) return;
|
|
2959
|
+
t._addParent(this);
|
|
2960
|
+
}
|
|
2961
|
+
(this._finalizers = this._finalizers ?? []).push(t);
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
}, e.prototype._hasParent = function(e) {
|
|
2965
|
+
var t = this._parentage;
|
|
2966
|
+
return t === e || Array.isArray(t) && t.includes(e);
|
|
2967
|
+
}, e.prototype._addParent = function(e) {
|
|
2968
|
+
var t = this._parentage;
|
|
2969
|
+
this._parentage = Array.isArray(t) ? (t.push(e), t) : t ? [t, e] : e;
|
|
2970
|
+
}, e.prototype._removeParent = function(e) {
|
|
2971
|
+
var t = this._parentage;
|
|
2972
|
+
t === e ? this._parentage = null : Array.isArray(t) && fr(t, e);
|
|
2973
|
+
}, e.prototype.remove = function(t) {
|
|
2974
|
+
var n = this._finalizers;
|
|
2975
|
+
n && fr(n, t), t instanceof e && t._removeParent(this);
|
|
2976
|
+
}, e.EMPTY = (function() {
|
|
2977
|
+
var t = new e();
|
|
2978
|
+
return t.closed = !0, t;
|
|
2979
|
+
})(), e;
|
|
2980
|
+
}();
|
|
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);
|
|
2984
|
+
}
|
|
2985
|
+
function hr(e) {
|
|
2986
|
+
W(e) ? e() : e.unsubscribe();
|
|
2987
|
+
}
|
|
2988
|
+
//#endregion
|
|
2989
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/config.js
|
|
2990
|
+
var X = {
|
|
2991
|
+
onUnhandledError: null,
|
|
2992
|
+
onStoppedNotification: null,
|
|
2993
|
+
Promise: void 0,
|
|
2994
|
+
useDeprecatedSynchronousErrorHandling: !1,
|
|
2995
|
+
useDeprecatedNextContext: !1
|
|
2996
|
+
}, gr = {
|
|
2997
|
+
setTimeout: function(e, t) {
|
|
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)));
|
|
3000
|
+
},
|
|
3001
|
+
clearTimeout: function(e) {
|
|
3002
|
+
return (gr.delegate?.clearTimeout || clearTimeout)(e);
|
|
3003
|
+
},
|
|
3004
|
+
delegate: void 0
|
|
3005
|
+
};
|
|
3006
|
+
//#endregion
|
|
3007
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js
|
|
3008
|
+
function _r(e) {
|
|
3009
|
+
gr.setTimeout(function() {
|
|
3010
|
+
var t = X.onUnhandledError;
|
|
3011
|
+
if (t) t(e);
|
|
3012
|
+
else throw e;
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
//#endregion
|
|
3016
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/noop.js
|
|
3017
|
+
function vr() {}
|
|
3018
|
+
//#endregion
|
|
3019
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/NotificationFactories.js
|
|
3020
|
+
var yr = (function() {
|
|
3021
|
+
return Sr("C", void 0, void 0);
|
|
3022
|
+
})();
|
|
3023
|
+
function br(e) {
|
|
3024
|
+
return Sr("E", void 0, e);
|
|
3025
|
+
}
|
|
3026
|
+
function xr(e) {
|
|
3027
|
+
return Sr("N", e, void 0);
|
|
3028
|
+
}
|
|
3029
|
+
function Sr(e, t, n) {
|
|
3030
|
+
return {
|
|
3031
|
+
kind: e,
|
|
3032
|
+
value: t,
|
|
3033
|
+
error: n
|
|
3034
|
+
};
|
|
3035
|
+
}
|
|
3036
|
+
//#endregion
|
|
3037
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/errorContext.js
|
|
3038
|
+
var Z = null;
|
|
3039
|
+
function Cr(e) {
|
|
3040
|
+
if (X.useDeprecatedSynchronousErrorHandling) {
|
|
3041
|
+
var t = !Z;
|
|
3042
|
+
if (t && (Z = {
|
|
3043
|
+
errorThrown: !1,
|
|
3044
|
+
error: null
|
|
3045
|
+
}), e(), t) {
|
|
3046
|
+
var n = Z, r = n.errorThrown, i = n.error;
|
|
3047
|
+
if (Z = null, r) throw i;
|
|
3048
|
+
}
|
|
3049
|
+
} else e();
|
|
3050
|
+
}
|
|
3051
|
+
function wr(e) {
|
|
3052
|
+
X.useDeprecatedSynchronousErrorHandling && Z && (Z.errorThrown = !0, Z.error = e);
|
|
3053
|
+
}
|
|
3054
|
+
//#endregion
|
|
3055
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/Subscriber.js
|
|
3056
|
+
var Tr = function(e) {
|
|
3057
|
+
rr(t, e);
|
|
3058
|
+
function t(t) {
|
|
3059
|
+
var n = e.call(this) || this;
|
|
3060
|
+
return n.isStopped = !1, t ? (n.destination = t, mr(t) && t.add(n)) : n.destination = Nr, n;
|
|
3061
|
+
}
|
|
3062
|
+
return t.create = function(e, t, n) {
|
|
3063
|
+
return new kr(e, t, n);
|
|
3064
|
+
}, t.prototype.next = function(e) {
|
|
3065
|
+
this.isStopped ? Mr(xr(e), this) : this._next(e);
|
|
3066
|
+
}, t.prototype.error = function(e) {
|
|
3067
|
+
this.isStopped ? Mr(br(e), this) : (this.isStopped = !0, this._error(e));
|
|
3068
|
+
}, t.prototype.complete = function() {
|
|
3069
|
+
this.isStopped ? Mr(yr, this) : (this.isStopped = !0, this._complete());
|
|
3070
|
+
}, t.prototype.unsubscribe = function() {
|
|
3071
|
+
this.closed || (this.isStopped = !0, e.prototype.unsubscribe.call(this), this.destination = null);
|
|
3072
|
+
}, t.prototype._next = function(e) {
|
|
3073
|
+
this.destination.next(e);
|
|
3074
|
+
}, t.prototype._error = function(e) {
|
|
3075
|
+
try {
|
|
3076
|
+
this.destination.error(e);
|
|
3077
|
+
} finally {
|
|
3078
|
+
this.unsubscribe();
|
|
3079
|
+
}
|
|
3080
|
+
}, t.prototype._complete = function() {
|
|
3081
|
+
try {
|
|
3082
|
+
this.destination.complete();
|
|
3083
|
+
} finally {
|
|
3084
|
+
this.unsubscribe();
|
|
3085
|
+
}
|
|
3086
|
+
}, t;
|
|
3087
|
+
}(pr), Er = Function.prototype.bind;
|
|
3088
|
+
function Dr(e, t) {
|
|
3089
|
+
return Er.call(e, t);
|
|
3090
|
+
}
|
|
3091
|
+
var Or = function() {
|
|
3092
|
+
function e(e) {
|
|
3093
|
+
this.partialObserver = e;
|
|
3094
|
+
}
|
|
3095
|
+
return e.prototype.next = function(e) {
|
|
3096
|
+
var t = this.partialObserver;
|
|
3097
|
+
if (t.next) try {
|
|
3098
|
+
t.next(e);
|
|
3099
|
+
} catch (e) {
|
|
3100
|
+
Ar(e);
|
|
3101
|
+
}
|
|
3102
|
+
}, e.prototype.error = function(e) {
|
|
3103
|
+
var t = this.partialObserver;
|
|
3104
|
+
if (t.error) try {
|
|
3105
|
+
t.error(e);
|
|
3106
|
+
} catch (e) {
|
|
3107
|
+
Ar(e);
|
|
3108
|
+
}
|
|
3109
|
+
else Ar(e);
|
|
3110
|
+
}, e.prototype.complete = function() {
|
|
3111
|
+
var e = this.partialObserver;
|
|
3112
|
+
if (e.complete) try {
|
|
3113
|
+
e.complete();
|
|
3114
|
+
} catch (e) {
|
|
3115
|
+
Ar(e);
|
|
3116
|
+
}
|
|
3117
|
+
}, e;
|
|
3118
|
+
}(), kr = function(e) {
|
|
3119
|
+
rr(t, e);
|
|
3120
|
+
function t(t, n, r) {
|
|
3121
|
+
var i = e.call(this) || this, a;
|
|
3122
|
+
if (W(t) || !t) a = {
|
|
3123
|
+
next: t ?? void 0,
|
|
3124
|
+
error: n ?? void 0,
|
|
3125
|
+
complete: r ?? void 0
|
|
3126
|
+
};
|
|
3127
|
+
else {
|
|
3128
|
+
var o;
|
|
3129
|
+
i && X.useDeprecatedNextContext ? (o = Object.create(t), o.unsubscribe = function() {
|
|
3130
|
+
return i.unsubscribe();
|
|
3131
|
+
}, a = {
|
|
3132
|
+
next: t.next && Dr(t.next, o),
|
|
3133
|
+
error: t.error && Dr(t.error, o),
|
|
3134
|
+
complete: t.complete && Dr(t.complete, o)
|
|
3135
|
+
}) : a = t;
|
|
3136
|
+
}
|
|
3137
|
+
return i.destination = new Or(a), i;
|
|
3138
|
+
}
|
|
3139
|
+
return t;
|
|
3140
|
+
}(Tr);
|
|
3141
|
+
function Ar(e) {
|
|
3142
|
+
X.useDeprecatedSynchronousErrorHandling ? wr(e) : _r(e);
|
|
3143
|
+
}
|
|
3144
|
+
function jr(e) {
|
|
3145
|
+
throw e;
|
|
3146
|
+
}
|
|
3147
|
+
function Mr(e, t) {
|
|
3148
|
+
var n = X.onStoppedNotification;
|
|
3149
|
+
n && gr.setTimeout(function() {
|
|
3150
|
+
return n(e, t);
|
|
3151
|
+
});
|
|
3152
|
+
}
|
|
3153
|
+
var Nr = {
|
|
3154
|
+
closed: !0,
|
|
3155
|
+
next: vr,
|
|
3156
|
+
error: jr,
|
|
3157
|
+
complete: vr
|
|
3158
|
+
}, Pr = (function() {
|
|
3159
|
+
return typeof Symbol == "function" && Symbol.observable || "@@observable";
|
|
3160
|
+
})();
|
|
3161
|
+
//#endregion
|
|
3162
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/identity.js
|
|
3163
|
+
function Fr(e) {
|
|
3164
|
+
return e;
|
|
3165
|
+
}
|
|
3166
|
+
//#endregion
|
|
3167
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/pipe.js
|
|
3168
|
+
function Ir(e) {
|
|
3169
|
+
return e.length === 0 ? Fr : e.length === 1 ? e[0] : function(t) {
|
|
3170
|
+
return e.reduce(function(e, t) {
|
|
3171
|
+
return t(e);
|
|
3172
|
+
}, t);
|
|
3173
|
+
};
|
|
3174
|
+
}
|
|
3175
|
+
//#endregion
|
|
3176
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/Observable.js
|
|
3177
|
+
var Q = function() {
|
|
3178
|
+
function e(e) {
|
|
3179
|
+
e && (this._subscribe = e);
|
|
3180
|
+
}
|
|
3181
|
+
return e.prototype.lift = function(t) {
|
|
3182
|
+
var n = new e();
|
|
3183
|
+
return n.source = this, n.operator = t, n;
|
|
3184
|
+
}, e.prototype.subscribe = function(e, t, n) {
|
|
3185
|
+
var r = this, i = zr(e) ? e : new kr(e, t, n);
|
|
3186
|
+
return Cr(function() {
|
|
3187
|
+
var e = r, t = e.operator, n = e.source;
|
|
3188
|
+
i.add(t ? t.call(i, n) : n ? r._subscribe(i) : r._trySubscribe(i));
|
|
3189
|
+
}), i;
|
|
3190
|
+
}, e.prototype._trySubscribe = function(e) {
|
|
3191
|
+
try {
|
|
3192
|
+
return this._subscribe(e);
|
|
3193
|
+
} catch (t) {
|
|
3194
|
+
e.error(t);
|
|
3195
|
+
}
|
|
3196
|
+
}, e.prototype.forEach = function(e, t) {
|
|
3197
|
+
var n = this;
|
|
3198
|
+
return t = Lr(t), new t(function(t, r) {
|
|
3199
|
+
var i = new kr({
|
|
3200
|
+
next: function(t) {
|
|
3201
|
+
try {
|
|
3202
|
+
e(t);
|
|
3203
|
+
} catch (e) {
|
|
3204
|
+
r(e), i.unsubscribe();
|
|
3205
|
+
}
|
|
3206
|
+
},
|
|
3207
|
+
error: r,
|
|
3208
|
+
complete: t
|
|
3209
|
+
});
|
|
3210
|
+
n.subscribe(i);
|
|
3211
|
+
});
|
|
3212
|
+
}, e.prototype._subscribe = function(e) {
|
|
3213
|
+
return this.source?.subscribe(e);
|
|
3214
|
+
}, e.prototype[Pr] = function() {
|
|
3215
|
+
return this;
|
|
3216
|
+
}, e.prototype.pipe = function() {
|
|
3217
|
+
return Ir([...arguments])(this);
|
|
3218
|
+
}, e.prototype.toPromise = function(e) {
|
|
3219
|
+
var t = this;
|
|
3220
|
+
return e = Lr(e), new e(function(e, n) {
|
|
3221
|
+
var r;
|
|
3222
|
+
t.subscribe(function(e) {
|
|
3223
|
+
return r = e;
|
|
3224
|
+
}, function(e) {
|
|
3225
|
+
return n(e);
|
|
3226
|
+
}, function() {
|
|
3227
|
+
return e(r);
|
|
3228
|
+
});
|
|
3229
|
+
});
|
|
3230
|
+
}, e.create = function(t) {
|
|
3231
|
+
return new e(t);
|
|
3232
|
+
}, e;
|
|
3233
|
+
}();
|
|
3234
|
+
function Lr(e) {
|
|
3235
|
+
return e ?? X.Promise ?? Promise;
|
|
3236
|
+
}
|
|
3237
|
+
function Rr(e) {
|
|
3238
|
+
return e && W(e.next) && W(e.error) && W(e.complete);
|
|
3239
|
+
}
|
|
3240
|
+
function zr(e) {
|
|
3241
|
+
return e && e instanceof Tr || Rr(e) && mr(e);
|
|
3242
|
+
}
|
|
3243
|
+
//#endregion
|
|
3244
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isInteropObservable.js
|
|
3245
|
+
function Br(e) {
|
|
3246
|
+
return W(e[Pr]);
|
|
3247
|
+
}
|
|
3248
|
+
//#endregion
|
|
3249
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isAsyncIterable.js
|
|
3250
|
+
function Vr(e) {
|
|
3251
|
+
return Symbol.asyncIterator && W(e?.[Symbol.asyncIterator]);
|
|
3252
|
+
}
|
|
3253
|
+
//#endregion
|
|
3254
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/throwUnobservableError.js
|
|
3255
|
+
function Hr(e) {
|
|
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.");
|
|
3257
|
+
}
|
|
3258
|
+
//#endregion
|
|
3259
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/symbol/iterator.js
|
|
3260
|
+
function Ur() {
|
|
3261
|
+
return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
|
|
3262
|
+
}
|
|
3263
|
+
var Wr = Ur();
|
|
3264
|
+
//#endregion
|
|
3265
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isIterable.js
|
|
3266
|
+
function Gr(e) {
|
|
3267
|
+
return W(e?.[Wr]);
|
|
3268
|
+
}
|
|
3269
|
+
//#endregion
|
|
3270
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/isReadableStreamLike.js
|
|
3271
|
+
function Kr(e) {
|
|
3272
|
+
return or(this, arguments, function() {
|
|
3273
|
+
var t, n, r, i;
|
|
3274
|
+
return ar(this, function(a) {
|
|
3275
|
+
switch (a.label) {
|
|
3276
|
+
case 0: t = e.getReader(), a.label = 1;
|
|
3277
|
+
case 1: a.trys.push([
|
|
3278
|
+
1,
|
|
3279
|
+
,
|
|
3280
|
+
9,
|
|
3281
|
+
10
|
|
3282
|
+
]), a.label = 2;
|
|
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];
|
|
3285
|
+
case 4: return [2, a.sent()];
|
|
3286
|
+
case 5: return [4, Y(r)];
|
|
3287
|
+
case 6: return [4, a.sent()];
|
|
3288
|
+
case 7: return a.sent(), [3, 2];
|
|
3289
|
+
case 8: return [3, 10];
|
|
3290
|
+
case 9: return t.releaseLock(), [7];
|
|
3291
|
+
case 10: return [2];
|
|
3292
|
+
}
|
|
3293
|
+
});
|
|
3294
|
+
});
|
|
3295
|
+
}
|
|
3296
|
+
function qr(e) {
|
|
3297
|
+
return W(e?.getReader);
|
|
3298
|
+
}
|
|
3299
|
+
//#endregion
|
|
3300
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/observable/innerFrom.js
|
|
3301
|
+
function Jr(e) {
|
|
3302
|
+
if (e instanceof Q) return e;
|
|
3303
|
+
if (e != null) {
|
|
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);
|
|
3310
|
+
}
|
|
3311
|
+
throw Hr(e);
|
|
3312
|
+
}
|
|
3313
|
+
function Yr(e) {
|
|
3314
|
+
return new Q(function(t) {
|
|
3315
|
+
var n = e[Pr]();
|
|
3316
|
+
if (W(n.subscribe)) return n.subscribe(t);
|
|
3317
|
+
throw TypeError("Provided object does not correctly implement Symbol.observable");
|
|
3318
|
+
});
|
|
3319
|
+
}
|
|
3320
|
+
function Xr(e) {
|
|
3321
|
+
return new Q(function(t) {
|
|
3322
|
+
for (var n = 0; n < e.length && !t.closed; n++) t.next(e[n]);
|
|
3323
|
+
t.complete();
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
function Zr(e) {
|
|
3327
|
+
return new Q(function(t) {
|
|
3328
|
+
e.then(function(e) {
|
|
3329
|
+
t.closed || (t.next(e), t.complete());
|
|
3330
|
+
}, function(e) {
|
|
3331
|
+
return t.error(e);
|
|
3332
|
+
}).then(null, _r);
|
|
3333
|
+
});
|
|
3334
|
+
}
|
|
3335
|
+
function Qr(e) {
|
|
3336
|
+
return new Q(function(t) {
|
|
3337
|
+
var n, r;
|
|
3338
|
+
try {
|
|
3339
|
+
for (var i = K(e), a = i.next(); !a.done; a = i.next()) {
|
|
3340
|
+
var o = a.value;
|
|
3341
|
+
if (t.next(o), t.closed) return;
|
|
3342
|
+
}
|
|
3343
|
+
} catch (e) {
|
|
3344
|
+
n = { error: e };
|
|
3345
|
+
} finally {
|
|
3346
|
+
try {
|
|
3347
|
+
a && !a.done && (r = i.return) && r.call(i);
|
|
3348
|
+
} finally {
|
|
3349
|
+
if (n) throw n.error;
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
t.complete();
|
|
3353
|
+
});
|
|
3354
|
+
}
|
|
3355
|
+
function $r(e) {
|
|
3356
|
+
return new Q(function(t) {
|
|
3357
|
+
ti(e, t).catch(function(e) {
|
|
3358
|
+
return t.error(e);
|
|
3359
|
+
});
|
|
3360
|
+
});
|
|
3361
|
+
}
|
|
3362
|
+
function ei(e) {
|
|
3363
|
+
return $r(Kr(e));
|
|
3364
|
+
}
|
|
3365
|
+
function ti(e, t) {
|
|
3366
|
+
var n, r, i, a;
|
|
3367
|
+
return ir(this, void 0, void 0, function() {
|
|
3368
|
+
var o, s;
|
|
3369
|
+
return ar(this, function(c) {
|
|
3370
|
+
switch (c.label) {
|
|
3371
|
+
case 0: c.trys.push([
|
|
3372
|
+
0,
|
|
3373
|
+
5,
|
|
3374
|
+
6,
|
|
3375
|
+
11
|
|
3376
|
+
]), n = sr(e), c.label = 1;
|
|
3377
|
+
case 1: return [4, n.next()];
|
|
3378
|
+
case 2:
|
|
3379
|
+
if (r = c.sent(), r.done) return [3, 4];
|
|
3380
|
+
if (o = r.value, t.next(o), t.closed) return [2];
|
|
3381
|
+
c.label = 3;
|
|
3382
|
+
case 3: return [3, 1];
|
|
3383
|
+
case 4: return [3, 11];
|
|
3384
|
+
case 5: return s = c.sent(), i = { error: s }, [3, 11];
|
|
3385
|
+
case 6: return c.trys.push([
|
|
3386
|
+
6,
|
|
3387
|
+
,
|
|
3388
|
+
9,
|
|
3389
|
+
10
|
|
3390
|
+
]), r && !r.done && (a = n.return) ? [4, a.call(n)] : [3, 8];
|
|
3391
|
+
case 7: c.sent(), c.label = 8;
|
|
3392
|
+
case 8: return [3, 10];
|
|
3393
|
+
case 9:
|
|
3394
|
+
if (i) throw i.error;
|
|
3395
|
+
return [7];
|
|
3396
|
+
case 10: return [7];
|
|
3397
|
+
case 11: return t.complete(), [2];
|
|
3398
|
+
}
|
|
3399
|
+
});
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
//#endregion
|
|
3403
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/OperatorSubscriber.js
|
|
3404
|
+
function $(e, t, n, r, i) {
|
|
3405
|
+
return new ni(e, t, n, r, i);
|
|
3406
|
+
}
|
|
3407
|
+
var ni = function(e) {
|
|
3408
|
+
rr(t, e);
|
|
3409
|
+
function t(t, n, r, i, a, o) {
|
|
3410
|
+
var s = e.call(this, t) || this;
|
|
3411
|
+
return s.onFinalize = a, s.shouldUnsubscribe = o, s._next = n ? function(e) {
|
|
3412
|
+
try {
|
|
3413
|
+
n(e);
|
|
3414
|
+
} catch (e) {
|
|
3415
|
+
t.error(e);
|
|
3416
|
+
}
|
|
3417
|
+
} : e.prototype._next, s._error = i ? function(e) {
|
|
3418
|
+
try {
|
|
3419
|
+
i(e);
|
|
3420
|
+
} catch (e) {
|
|
3421
|
+
t.error(e);
|
|
3422
|
+
} finally {
|
|
3423
|
+
this.unsubscribe();
|
|
3424
|
+
}
|
|
3425
|
+
} : e.prototype._error, s._complete = r ? function() {
|
|
3426
|
+
try {
|
|
3427
|
+
r();
|
|
3428
|
+
} catch (e) {
|
|
3429
|
+
t.error(e);
|
|
3430
|
+
} finally {
|
|
3431
|
+
this.unsubscribe();
|
|
3432
|
+
}
|
|
3433
|
+
} : e.prototype._complete, s;
|
|
3434
|
+
}
|
|
3435
|
+
return t.prototype.unsubscribe = function() {
|
|
3436
|
+
var t;
|
|
3437
|
+
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
3438
|
+
var n = this.closed;
|
|
3439
|
+
e.prototype.unsubscribe.call(this), !n && ((t = this.onFinalize) == null || t.call(this));
|
|
3440
|
+
}
|
|
3441
|
+
}, t;
|
|
3442
|
+
}(Tr);
|
|
3443
|
+
//#endregion
|
|
3444
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/util/args.js
|
|
3445
|
+
function ri(e) {
|
|
3446
|
+
return e[e.length - 1];
|
|
3447
|
+
}
|
|
3448
|
+
function ii(e) {
|
|
3449
|
+
return W(ri(e)) ? e.pop() : void 0;
|
|
3450
|
+
}
|
|
3451
|
+
//#endregion
|
|
3452
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/map.js
|
|
3453
|
+
function ai(e, t) {
|
|
3454
|
+
return G(function(n, r) {
|
|
3455
|
+
var i = 0;
|
|
3456
|
+
n.subscribe($(r, function(n) {
|
|
3457
|
+
r.next(e.call(t, n, i++));
|
|
3458
|
+
}));
|
|
3459
|
+
});
|
|
3460
|
+
}
|
|
3461
|
+
//#endregion
|
|
3462
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/distinctUntilChanged.js
|
|
3463
|
+
function oi(e, t) {
|
|
3464
|
+
return t === void 0 && (t = Fr), e ??= si, G(function(n, r) {
|
|
3465
|
+
var i, a = !0;
|
|
3466
|
+
n.subscribe($(r, function(n) {
|
|
3467
|
+
var o = t(n);
|
|
3468
|
+
(a || !e(i, o)) && (a = !1, i = o, r.next(n));
|
|
3469
|
+
}));
|
|
3470
|
+
});
|
|
3471
|
+
}
|
|
3472
|
+
function si(e, t) {
|
|
3473
|
+
return e === t;
|
|
3474
|
+
}
|
|
3475
|
+
//#endregion
|
|
3476
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/filter.js
|
|
3477
|
+
function ci(e, t) {
|
|
3478
|
+
return G(function(n, r) {
|
|
3479
|
+
var i = 0;
|
|
3480
|
+
n.subscribe($(r, function(n) {
|
|
3481
|
+
return e.call(t, n, i++) && r.next(n);
|
|
3482
|
+
}));
|
|
3483
|
+
});
|
|
3484
|
+
}
|
|
3485
|
+
//#endregion
|
|
3486
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/exhaustMap.js
|
|
3487
|
+
function li(e, t) {
|
|
3488
|
+
return t ? function(n) {
|
|
3489
|
+
return n.pipe(li(function(n, r) {
|
|
3490
|
+
return Jr(e(n, r)).pipe(ai(function(e, i) {
|
|
3491
|
+
return t(n, e, r, i);
|
|
3492
|
+
}));
|
|
3493
|
+
}));
|
|
3494
|
+
} : G(function(t, n) {
|
|
3495
|
+
var r = 0, i = null, a = !1;
|
|
3496
|
+
t.subscribe($(n, function(t) {
|
|
3497
|
+
i || (i = $(n, void 0, function() {
|
|
3498
|
+
i = null, a && n.complete();
|
|
3499
|
+
}), Jr(e(t, r++)).subscribe(i));
|
|
3500
|
+
}, function() {
|
|
3501
|
+
a = !0, !i && n.complete();
|
|
3502
|
+
}));
|
|
3503
|
+
});
|
|
3504
|
+
}
|
|
3505
|
+
//#endregion
|
|
3506
|
+
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/withLatestFrom.js
|
|
3507
|
+
function ui() {
|
|
3508
|
+
var e = [...arguments], t = ii(e);
|
|
3509
|
+
return G(function(n, r) {
|
|
3510
|
+
for (var i = e.length, a = Array(i), o = e.map(function() {
|
|
3511
|
+
return !1;
|
|
3512
|
+
}), s = !1, c = function(t) {
|
|
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));
|
|
3516
|
+
}, l = 0; l < i; l++) c(l);
|
|
3517
|
+
n.subscribe($(r, function(e) {
|
|
3518
|
+
if (s) {
|
|
3519
|
+
var n = J([e], q(a));
|
|
3520
|
+
r.next(t ? t.apply(void 0, J([], q(n))) : n);
|
|
3521
|
+
}
|
|
3522
|
+
}));
|
|
3523
|
+
});
|
|
3524
|
+
}
|
|
3525
|
+
//#endregion
|
|
3526
|
+
//#region src/sync-listeners.ts
|
|
3527
|
+
async function di(e, t) {
|
|
3528
|
+
try {
|
|
3529
|
+
return await t();
|
|
3530
|
+
} catch (t) {
|
|
3531
|
+
return e.reportError(t), !1;
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
function fi(e) {
|
|
3535
|
+
return e.rxdb.config.entities.filter((e) => !le(e));
|
|
3536
|
+
}
|
|
3537
|
+
function pi(e) {
|
|
3538
|
+
let t = [];
|
|
3539
|
+
for (let n of fi(e)) {
|
|
3540
|
+
let r = A(n), i = P(F(r, e.rxdb.entitySync));
|
|
3541
|
+
i.offlineWrite && !i.push && t.push({
|
|
3542
|
+
namespace: r.namespace,
|
|
3543
|
+
entity: r.name
|
|
3544
|
+
});
|
|
3545
|
+
}
|
|
3546
|
+
return t;
|
|
3547
|
+
}
|
|
3548
|
+
async function mi(e, t, n) {
|
|
3549
|
+
let { syncState: r } = e.rxdb, i = await dt(e.rxdb, t, n);
|
|
3550
|
+
for (let e of i.conflicts) r.reportConflict({
|
|
3551
|
+
namespace: t,
|
|
3552
|
+
entity: n,
|
|
3553
|
+
entityId: e,
|
|
3554
|
+
winner: "remote"
|
|
3555
|
+
});
|
|
3556
|
+
for (let e of i.failures) r.reportError(e.error);
|
|
3557
|
+
return i.failures.length === 0;
|
|
3558
|
+
}
|
|
3559
|
+
async function hi(e, t) {
|
|
3560
|
+
let { syncState: n } = e.rxdb, r = !0;
|
|
3561
|
+
for (let { namespace: i, entity: a } of t) r = await di(n, () => mi(e, i, a)) && r;
|
|
3562
|
+
return r;
|
|
3563
|
+
}
|
|
3564
|
+
async function gi(e) {
|
|
3565
|
+
try {
|
|
3566
|
+
e.rxdb.syncState.reportOutboxCount(await ht(e.rxdb));
|
|
3567
|
+
} catch {}
|
|
3568
|
+
}
|
|
3569
|
+
async function _i(e) {
|
|
3570
|
+
let t = pi(e);
|
|
3571
|
+
if (t.length === 0) return;
|
|
3572
|
+
let { syncState: n } = e.rxdb;
|
|
3573
|
+
n.beginRound();
|
|
3574
|
+
try {
|
|
3575
|
+
await hi(e, t) && n.reportSuccess(), await gi(e);
|
|
3576
|
+
} finally {
|
|
3577
|
+
n.endRound();
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
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)));
|
|
3583
|
+
}
|
|
3584
|
+
function yi(e) {
|
|
3585
|
+
let t = [], a = [];
|
|
3586
|
+
if (e.rxdb.config.sync?.remote?.adapter) {
|
|
3587
|
+
let n = vi(e).pipe(li(() => _i(e).catch((t) => {
|
|
3588
|
+
e.rxdb.syncState.reportError(t);
|
|
3589
|
+
}))).subscribe();
|
|
3590
|
+
t.push(n);
|
|
3591
|
+
}
|
|
3592
|
+
let o = async (t) => {
|
|
3593
|
+
let n = await e.getCurrentBranch();
|
|
3594
|
+
return t.filter((e) => !e.branchId || e.branchId === n.id).length;
|
|
3595
|
+
}, s = (t) => (n) => {
|
|
3596
|
+
(async () => {
|
|
3597
|
+
try {
|
|
3598
|
+
let t = await o(n.entities);
|
|
3599
|
+
t > 0 && e.history.incrementPullableCount(t);
|
|
3600
|
+
} catch (e) {
|
|
3601
|
+
he(e) || console.error(`[SyncManager] ${t} failed:`, e);
|
|
3602
|
+
}
|
|
3603
|
+
})();
|
|
3604
|
+
}, c = [
|
|
3605
|
+
{
|
|
3606
|
+
type: n,
|
|
3607
|
+
handler: s("onRemoteCreate")
|
|
3608
|
+
},
|
|
3609
|
+
{
|
|
3610
|
+
type: i,
|
|
3611
|
+
handler: s("onRemoteUpdate")
|
|
3612
|
+
},
|
|
3613
|
+
{
|
|
3614
|
+
type: r,
|
|
3615
|
+
handler: s("onRemoteRemove")
|
|
3616
|
+
}
|
|
3617
|
+
];
|
|
3618
|
+
for (let { type: t, handler: n } of c) e.rxdb.addEventListener(t, n), a.push(() => e.rxdb.removeEventListener(t, n));
|
|
3619
|
+
return {
|
|
3620
|
+
subscriptions: t,
|
|
3621
|
+
removers: a
|
|
3622
|
+
};
|
|
3623
|
+
}
|
|
3624
|
+
//#endregion
|
|
3625
|
+
//#region src/sync-manager.utils.ts
|
|
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 {
|
|
3627
|
+
rxdb;
|
|
3628
|
+
history;
|
|
3629
|
+
#e = [];
|
|
3630
|
+
#t = [];
|
|
3631
|
+
#n = 0;
|
|
3632
|
+
get pushInFlight() {
|
|
3633
|
+
return this.history.pushInFlight;
|
|
3634
|
+
}
|
|
3635
|
+
get branchSwitchGeneration() {
|
|
3636
|
+
return this.#n;
|
|
3637
|
+
}
|
|
3638
|
+
constructor(e, t) {
|
|
3639
|
+
this.rxdb = e, this.history = t;
|
|
3640
|
+
}
|
|
3641
|
+
init() {
|
|
3642
|
+
let { subscriptions: e, removers: t } = yi(this);
|
|
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));
|
|
3648
|
+
}
|
|
3649
|
+
destroy() {
|
|
3650
|
+
for (let e of this.#e) e();
|
|
3651
|
+
this.#e.length = 0;
|
|
3652
|
+
for (let e of this.#t) e.unsubscribe();
|
|
3653
|
+
this.#t.length = 0;
|
|
3654
|
+
}
|
|
3655
|
+
async getLocalRepositories() {
|
|
3656
|
+
return j(this.rxdb);
|
|
3657
|
+
}
|
|
3658
|
+
async getRemoteRepositories() {
|
|
3659
|
+
return ae(this.rxdb);
|
|
3660
|
+
}
|
|
3661
|
+
async getCurrentBranch() {
|
|
3662
|
+
return ie(this.rxdb);
|
|
3663
|
+
}
|
|
3664
|
+
async syncBranches() {
|
|
3665
|
+
return er(this);
|
|
3666
|
+
}
|
|
3667
|
+
async pull(e) {
|
|
3668
|
+
let t;
|
|
3669
|
+
try {
|
|
3670
|
+
t = await this.history.syncing(() => this.#r(e));
|
|
3671
|
+
} catch (e) {
|
|
3672
|
+
throw xi(e) && this.history.clearUndoHistory(), e;
|
|
3673
|
+
}
|
|
3674
|
+
return t.historyInvalidated && this.history.clearUndoHistory(), t;
|
|
3675
|
+
}
|
|
3676
|
+
async push(e) {
|
|
3677
|
+
let t = await this.history.syncing(() => Zn(this, e));
|
|
3678
|
+
return t.pushed > 0 && this.history.clearUndoHistory(), t;
|
|
3679
|
+
}
|
|
3680
|
+
async sync(e) {
|
|
3681
|
+
let t, n;
|
|
3682
|
+
try {
|
|
3683
|
+
n = await this.history.syncing(async () => {
|
|
3684
|
+
t = await this.#r(e?.pull);
|
|
3685
|
+
let n = await Zn(this, e?.push);
|
|
3686
|
+
return {
|
|
3687
|
+
pullResult: t,
|
|
3688
|
+
pushResult: n
|
|
3689
|
+
};
|
|
3690
|
+
});
|
|
3691
|
+
} catch (e) {
|
|
3692
|
+
throw (t?.historyInvalidated === !0 || xi(e)) && this.history.clearUndoHistory(), e;
|
|
3693
|
+
}
|
|
3694
|
+
return (n.pullResult.historyInvalidated || n.pushResult.pushed > 0) && this.history.clearUndoHistory(), n;
|
|
3695
|
+
}
|
|
3696
|
+
async pullRepository(e, t, n) {
|
|
3697
|
+
let r;
|
|
3698
|
+
try {
|
|
3699
|
+
r = await this.history.syncing(() => ze(this, e, t, n));
|
|
3700
|
+
} catch (e) {
|
|
3701
|
+
throw xi(e) && this.history.clearUndoHistory(), e;
|
|
3702
|
+
}
|
|
3703
|
+
return r.historyInvalidated && this.history.clearUndoHistory(), r;
|
|
3704
|
+
}
|
|
3705
|
+
async pushRepository(e, t, n) {
|
|
3706
|
+
let r = await this.history.syncing(() => It(this, e, t, n));
|
|
3707
|
+
return r.pushed > 0 && this.history.clearUndoHistory(), r;
|
|
3708
|
+
}
|
|
3709
|
+
async syncRepository(e, t, n) {
|
|
3710
|
+
let r;
|
|
3711
|
+
try {
|
|
3712
|
+
r = await this.history.syncing(() => Cn(this, e, t, n));
|
|
3713
|
+
} catch (e) {
|
|
3714
|
+
throw xi(e) && this.history.clearUndoHistory(), e;
|
|
3715
|
+
}
|
|
3716
|
+
return (r.pullResult.historyInvalidated || r.pushResult.pushed > 0) && this.history.clearUndoHistory(), r;
|
|
3717
|
+
}
|
|
3718
|
+
async cleanupExpired(e, t, n) {
|
|
3719
|
+
return jn(this, e, t, n);
|
|
3720
|
+
}
|
|
3721
|
+
async checkRepositoryUpdates(e, t) {
|
|
3722
|
+
return An(this.rxdb, e, t);
|
|
3723
|
+
}
|
|
3724
|
+
async getRepositorySyncStatus(e, t) {
|
|
3725
|
+
return In(this.rxdb, e, t);
|
|
3726
|
+
}
|
|
3727
|
+
async getAllRepositorySyncStatus(e) {
|
|
3728
|
+
return Ln(this.rxdb, e);
|
|
3729
|
+
}
|
|
3730
|
+
async refreshPullableCount() {
|
|
3731
|
+
let e = this.history.beginPullableSettlement(), t = (await Ln(this.rxdb)).reduce((e, t) => e + (t.enabled ? t.pullableCount : 0), 0);
|
|
3732
|
+
return this.history.reconcilePullableCount(e, t), t;
|
|
3733
|
+
}
|
|
3734
|
+
async bulkSync(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;
|
|
3737
|
+
}
|
|
3738
|
+
getRepositoryDependencyGraph() {
|
|
3739
|
+
return z(this.rxdb.config.entities.map((e) => A(e)));
|
|
3740
|
+
}
|
|
3741
|
+
getRepositorySyncOrder(e) {
|
|
3742
|
+
return Me(this.getRepositoryDependencyGraph(), e);
|
|
3743
|
+
}
|
|
3744
|
+
async #r(e) {
|
|
3745
|
+
let t = this.history.beginPullableSettlement(), n;
|
|
3746
|
+
try {
|
|
3747
|
+
n = await Un(this, e);
|
|
3748
|
+
} catch (e) {
|
|
3749
|
+
let n = e instanceof g ? e.result : void 0;
|
|
3750
|
+
throw this.history.settleAbortedPull(t, n ? n.pulled : 0), e;
|
|
3751
|
+
}
|
|
3752
|
+
return this.history.settlePull(t, e, n), n;
|
|
3753
|
+
}
|
|
3754
|
+
}, wi = class extends _ {
|
|
3755
|
+
lifecycle = "scoped";
|
|
3756
|
+
inject = ["plugin:history"];
|
|
3757
|
+
name = "sync";
|
|
3758
|
+
install(e) {
|
|
3759
|
+
let t = new Ci(this.rxdb, this.rxdb.versionManager.syncBridge);
|
|
3760
|
+
e.acquire(() => () => t.destroy(), "sync:syncManager"), e.acquire(() => (Object.defineProperty(this.rxdb, "syncManager", {
|
|
3761
|
+
value: t,
|
|
3762
|
+
configurable: !0,
|
|
3763
|
+
enumerable: !0
|
|
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(() => {
|
|
3765
|
+
t.refreshPullableCount().catch((e) => {
|
|
3766
|
+
let t = e instanceof Error ? e.message : String(e);
|
|
3767
|
+
console.warn(`[RxDB Sync] 重算待拉数失败:${t}。`);
|
|
3768
|
+
});
|
|
3769
|
+
}), "sync:pullableRefresh");
|
|
3770
|
+
}
|
|
3771
|
+
}, Ti = (e) => new wi(e);
|
|
3772
|
+
//#endregion
|
|
3773
|
+
export { wi as RxDBPluginSync, ht as countQueryCacheOutbox, dt as flushQueryCacheOutbox, gt as pendingQueryCacheWriteIds, Ti as rxDBPluginSync };
|