@aiao/rxdb 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
- import { isFunction as Bt, isArray as Rn, orderBy as Cn, get as In, isEqual as Dt, once as S, performChunk as Tn, pick as An, isSymbol as Sn, nextMicroTask as Mn, createBroadcastTopic as On, LeaderElection as xn, needArray as Nn, isNil as mt, deepFreeze as Pn, isPromise as $n } from "@aiao/utils";
2
- import { v7 as Bn } from "uuid";
3
- import Lt from "object-hash";
4
- import { finalize as Ft, forkJoin as Dn, concat as Ln, of as Q, EMPTY as Fn, BehaviorSubject as J, ReplaySubject as Un, takeUntil as jn, distinctUntilChanged as Fe, tap as k, switchMap as x, Observable as Ut, map as $, shareReplay as P, firstValueFrom as L, Subject as Yn, defer as ae, combineLatest as Ne, filter as Ce } from "rxjs";
1
+ import { isFunction as Dt, isArray as Cn, orderBy as In, get as An, isEqual as Lt, once as S, performChunk as Tn, pick as Sn, isSymbol as Mn, nextMicroTask as On, createBroadcastTopic as xn, LeaderElection as Nn, needArray as Pn, isNil as gt, deepFreeze as $n, isPromise as Bn } from "@aiao/utils";
2
+ import { v7 as Dn } from "uuid";
3
+ import { finalize as Ft, forkJoin as Ln, concat as Fn, of as Q, EMPTY as Un, BehaviorSubject as J, ReplaySubject as jn, takeUntil as Yn, distinctUntilChanged as Ue, tap as k, switchMap as x, Observable as Ut, map as $, shareReplay as P, firstValueFrom as L, Subject as zn, defer as ae, combineLatest as Pe, filter as Ie } from "rxjs";
5
4
  class R extends Error {
6
5
  constructor(e) {
7
6
  super(e), this.name = "RxDBError", Object.setPrototypeOf(this, R.prototype);
@@ -13,56 +12,56 @@ class et extends R {
13
12
  super(`NetworkOfflineError: ${e.message}`), this.name = "NetworkOfflineError", this.originalError = e, Object.setPrototypeOf(this, et.prototype);
14
13
  }
15
14
  }
16
- const zn = "ENTITY_LOCAL_NEW", ne = "ENTITY_LOCAL_CREATE", oe = "ENTITY_LOCAL_UPDATE", ce = "ENTITY_LOCAL_REMOVE", Ue = "ENTITY_REMOTE_CREATE", je = "ENTITY_REMOTE_UPDATE", Ye = "ENTITY_REMOTE_REMOVE", tt = "TRANSACTION_BEGIN", nt = "TRANSACTION_COMMIT", rt = "TRANSACTION_ROLLBACK", kn = "SWITCH_BRANCH_BEGIN", Wn = "SWITCH_BRANCH_COMMIT", Kn = "SWITCH_BRANCH_ROLLBACK", Hn = "SYNC_BEGIN", qn = "SYNC_COMPLETE", Vn = "SYNC_ERROR", Vi = "REMOTE_CHANGES_PENDING", Gn = "CONFLICT_DETECTED", Qn = "CONFLICT_PENDING", Jn = "REPOSITORY_SYNC_BEGIN", jt = "REPOSITORY_SYNC_COMPLETE", Xn = "REPOSITORY_SYNC_ERROR";
17
- class Zn {
15
+ const kn = "ENTITY_LOCAL_NEW", ne = "ENTITY_LOCAL_CREATE", oe = "ENTITY_LOCAL_UPDATE", ce = "ENTITY_LOCAL_REMOVE", je = "ENTITY_REMOTE_CREATE", Ye = "ENTITY_REMOTE_UPDATE", ze = "ENTITY_REMOTE_REMOVE", tt = "TRANSACTION_BEGIN", nt = "TRANSACTION_COMMIT", rt = "TRANSACTION_ROLLBACK", Wn = "SWITCH_BRANCH_BEGIN", Hn = "SWITCH_BRANCH_COMMIT", Kn = "SWITCH_BRANCH_ROLLBACK", qn = "MERGE_BRANCH_BEGIN", Gn = "MERGE_BRANCH_COMMIT", Vn = "MERGE_BRANCH_ROLLBACK", Qn = "SYNC_BEGIN", Jn = "SYNC_COMPLETE", Xn = "SYNC_ERROR", ea = "REMOTE_CHANGES_PENDING", Zn = "CONFLICT_DETECTED", er = "CONFLICT_PENDING", tr = "REPOSITORY_SYNC_BEGIN", jt = "REPOSITORY_SYNC_COMPLETE", nr = "REPOSITORY_SYNC_ERROR";
16
+ class rr {
18
17
  constructor(e) {
19
18
  this.entities = e;
20
19
  }
21
- type = zn;
20
+ type = kn;
22
21
  }
23
- class Gi {
22
+ class ta {
24
23
  constructor(e) {
25
24
  this.entities = e;
26
25
  }
27
26
  type = ne;
28
27
  }
29
- class Qi {
28
+ class na {
30
29
  constructor(e) {
31
30
  this.entities = e;
32
31
  }
33
32
  type = oe;
34
33
  }
35
- class Ji {
34
+ class ra {
36
35
  constructor(e) {
37
36
  this.entities = e;
38
37
  }
39
38
  type = ce;
40
39
  }
41
- class Xi {
40
+ class sa {
42
41
  constructor(e) {
43
42
  this.entities = e;
44
43
  }
45
- type = Ue;
44
+ type = je;
46
45
  }
47
- class Zi {
46
+ class ia {
48
47
  constructor(e) {
49
48
  this.entities = e;
50
49
  }
51
- type = je;
50
+ type = Ye;
52
51
  }
53
- class ea {
52
+ class aa {
54
53
  constructor(e) {
55
54
  this.entities = e;
56
55
  }
57
- type = Ye;
56
+ type = ze;
58
57
  }
59
- class ta {
58
+ class oa {
60
59
  type = tt;
61
60
  }
62
- class na {
61
+ class ca {
63
62
  type = nt;
64
63
  }
65
- class ra {
64
+ class la {
66
65
  type = rt;
67
66
  }
68
67
  class st {
@@ -70,79 +69,99 @@ class st {
70
69
  this.branchName = e;
71
70
  }
72
71
  }
73
- class er extends st {
74
- type = kn;
75
- }
76
- class tr extends st {
72
+ class sr extends st {
77
73
  type = Wn;
78
74
  }
79
- class nr extends st {
75
+ class ir extends st {
76
+ type = Hn;
77
+ }
78
+ class ar extends st {
80
79
  type = Kn;
81
80
  }
81
+ class it {
82
+ constructor(e, t) {
83
+ this.sourceBranch = e, this.targetBranch = t;
84
+ }
85
+ }
86
+ class or extends it {
87
+ type = qn;
88
+ }
89
+ class cr extends it {
90
+ type = Gn;
91
+ }
92
+ class lr extends it {
93
+ type = Vn;
94
+ }
82
95
  class Yt {
83
96
  constructor(e) {
84
97
  this.direction = e;
85
98
  }
86
- type = Hn;
99
+ type = Qn;
87
100
  }
88
101
  class zt {
89
102
  constructor(e, t) {
90
103
  this.direction = e, this.result = t;
91
104
  }
92
- type = qn;
105
+ type = Jn;
93
106
  }
94
107
  class kt {
95
108
  constructor(e, t) {
96
109
  this.direction = e, this.error = t;
97
110
  }
98
- type = Vn;
111
+ type = Xn;
99
112
  }
100
- class sa {
113
+ class ua {
101
114
  constructor(e, t, n) {
102
115
  this.conflicts = e, this.resolved = t, this.deferred = n;
103
116
  }
104
- type = Gn;
117
+ type = Zn;
105
118
  }
106
- class ia {
119
+ class da {
107
120
  constructor(e) {
108
121
  this.conflicts = e;
109
122
  }
110
- type = Qn;
123
+ type = er;
111
124
  }
112
- class it {
125
+ class at {
113
126
  constructor(e, t, n, s) {
114
127
  this.direction = e, this.namespace = t, this.entity = n, this.includeRelated = s;
115
128
  }
116
- type = Jn;
129
+ type = tr;
117
130
  }
118
- class at {
131
+ class ot {
119
132
  constructor(e, t, n, s) {
120
133
  this.direction = e, this.namespace = t, this.entity = n, this.result = s;
121
134
  }
122
135
  type = jt;
123
136
  }
124
- class ot {
137
+ class ct {
125
138
  constructor(e, t, n, s) {
126
139
  this.direction = e, this.namespace = t, this.entity = n, this.error = s;
127
140
  }
128
- type = Xn;
141
+ type = nr;
129
142
  }
130
- const Wt = /* @__PURE__ */ Symbol("ɵProxy"), ze = /* @__PURE__ */ Symbol("ɵMetadata"), Kt = /* @__PURE__ */ Symbol("ɵStatus"), ke = /* @__PURE__ */ Symbol("ɵEntityManager"), We = /* @__PURE__ */ Symbol("ɵEntityType"), rr = (r, e) => e.sync.local?.adapter === r, sr = (r) => [tt, nt, rt].includes(r.type), I = (r) => r[ze] || r.constructor[ze], aa = (r) => r[We] || r.constructor[We], O = (r) => r && r[Kt], oa = (r) => r && !!O(r), ca = (r, e, t, n) => {
143
+ const Wt = /* @__PURE__ */ Symbol("ɵProxy"), ke = /* @__PURE__ */ Symbol("ɵMetadata"), Ht = /* @__PURE__ */ Symbol("ɵStatus"), We = /* @__PURE__ */ Symbol("ɵEntityManager"), He = /* @__PURE__ */ Symbol("ɵEntityType"), ur = (r, e) => e.sync.local?.adapter === r, dr = (r) => [tt, nt, rt].includes(r.type), I = (r) => {
144
+ const e = r;
145
+ return e[ke] || e.constructor[ke];
146
+ }, ha = (r) => {
147
+ const e = r;
148
+ return e[He] || e.constructor[He];
149
+ }, O = (r) => r && r[Ht], pa = (r) => r && !!O(r), fa = (r, e, t, n) => {
131
150
  let s = n > 1 ? void 0 : n ? Object.getOwnPropertyDescriptor(e, t) : e;
132
151
  for (let i = r.length - 1, a; i >= 0; i--)
133
152
  (a = r[i]) && (s = a(s) || s);
134
153
  return s;
135
- }, Ht = () => Bn(), ir = ["id", "createdAt", "updatedAt", "createdBy", "updatedBy"], ar = ["rev"], la = (r) => !!(ir.includes(r) || ar.includes(r) || r.startsWith("_")), M = (r, e, t) => Object.defineProperty(r, e, {
154
+ }, Kt = () => Dn(), hr = ["id", "createdAt", "updatedAt", "createdBy", "updatedBy"], pr = ["rev"], ya = (r) => !!(hr.includes(r) || pr.includes(r) || r.startsWith("_")), M = (r, e, t) => Object.defineProperty(r, e, {
136
155
  value: t,
137
156
  enumerable: !1,
138
157
  configurable: !1,
139
158
  writable: !1
140
- }), or = (r, e, t) => Object.defineProperty(r, e, {
159
+ }), fr = (r, e, t) => Object.defineProperty(r, e, {
141
160
  value: t,
142
161
  enumerable: !1,
143
162
  configurable: !1,
144
163
  writable: !0
145
- }), he = (r, e, t) => {
164
+ }), pe = (r, e, t) => {
146
165
  let n;
147
166
  const s = {
148
167
  get: () => (n = t(), s.get = () => n, n),
@@ -150,18 +169,18 @@ const Wt = /* @__PURE__ */ Symbol("ɵProxy"), ze = /* @__PURE__ */ Symbol("ɵMet
150
169
  configurable: !1
151
170
  };
152
171
  return Object.defineProperty(r, e, s);
153
- }, cr = (r, e) => {
172
+ }, yr = (r, e) => {
154
173
  const t = {};
155
174
  let n = !1;
156
175
  r.defaultValueProperties.forEach((s) => {
157
- e[s.name] === void 0 && (n = !0, Bt(s.default) ? t[s.name] = s.default() : t[s.name] = s.default);
176
+ e[s.name] === void 0 && (n = !0, Dt(s.default) ? t[s.name] = s.default() : t[s.name] = s.default);
158
177
  }), n && Object.assign(e, t);
159
- }, lr = (r, e, t) => {
178
+ }, mr = (r, e, t) => {
160
179
  const { propertyMap: n, foreignKeyNames: s } = I(e);
161
180
  Object.keys(t).forEach((i) => {
162
181
  n.has(i) ? r.propertyMap.get(i)?.readonly !== !0 && (e[i] = t[i]) : s.includes(i) && (e[i] = t[i]);
163
182
  });
164
- }, gt = (r) => {
183
+ }, _t = (r) => {
165
184
  const e = /* @__PURE__ */ new Set(), t = (s) => {
166
185
  const a = O(s).getNeedSaveEntities();
167
186
  a.length && n(a);
@@ -169,14 +188,14 @@ const Wt = /* @__PURE__ */ Symbol("ɵProxy"), ze = /* @__PURE__ */ Symbol("ɵMet
169
188
  e.add(i), t(i);
170
189
  });
171
190
  return n(r), Array.from(e).filter((s) => O(s).modified);
172
- }, ur = (r) => {
191
+ }, gr = (r) => {
173
192
  const e = /* @__PURE__ */ new Set(), t = (n) => {
174
193
  O(n).getNeedRemoveEntities().forEach((a) => {
175
194
  e.has(a) || (e.add(a), t(a));
176
195
  });
177
196
  };
178
197
  return r.forEach((n) => t(n)), Array.from(e).filter((n) => O(n).local);
179
- }, Pe = (r) => {
198
+ }, $e = (r) => {
180
199
  const { need_save_entities: e, need_remove_entities: t } = r, n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
181
200
  for (let a = 0; a < e.length; a++) {
182
201
  const o = e[a];
@@ -193,27 +212,27 @@ const Wt = /* @__PURE__ */ Symbol("ɵProxy"), ze = /* @__PURE__ */ Symbol("ɵMet
193
212
  update: s
194
213
  };
195
214
  };
196
- var C = /* @__PURE__ */ ((r) => (r.uuid = "uuid", r.string = "string", r.enum = "enum", r.number = "number", r.integer = "integer", r.boolean = "boolean", r.date = "date", r.stringArray = "stringArray", r.numberArray = "numberArray", r.keyValue = "keyValue", r.json = "json", r))(C || {}), T = /* @__PURE__ */ ((r) => (r.ONE_TO_ONE = "1:1", r.ONE_TO_MANY = "1:m", r.MANY_TO_ONE = "m:1", r.MANY_TO_MANY = "m:n", r))(T || {}), W = /* @__PURE__ */ ((r) => (r.NO_ACTION = "NO ACTION", r.RESTRICT = "RESTRICT", r.CASCADE = "CASCADE", r.SET_NULL = "SET NULL", r.SET_DEFAULT = "SET DEFAULT", r))(W || {}), qt = /* @__PURE__ */ ((r) => (r.NO_ACTION = "NO ACTION", r.RESTRICT = "RESTRICT", r.CASCADE = "CASCADE", r.SET_NULL = "SET NULL", r.SET_DEFAULT = "SET DEFAULT", r))(qt || {}), fe = /* @__PURE__ */ ((r) => (r.Full = "full", r.Filter = "filter", r.QueryCache = "QueryCache", r.None = "none", r))(fe || {});
197
- const dr = (r, e, t = !1) => {
198
- const n = hr(e, t);
215
+ var C = /* @__PURE__ */ ((r) => (r.uuid = "uuid", r.string = "string", r.enum = "enum", r.number = "number", r.integer = "integer", r.boolean = "boolean", r.date = "date", r.stringArray = "stringArray", r.numberArray = "numberArray", r.keyValue = "keyValue", r.json = "json", r))(C || {}), A = /* @__PURE__ */ ((r) => (r.ONE_TO_ONE = "1:1", r.ONE_TO_MANY = "1:m", r.MANY_TO_ONE = "m:1", r.MANY_TO_MANY = "m:n", r))(A || {}), W = /* @__PURE__ */ ((r) => (r.NO_ACTION = "NO ACTION", r.RESTRICT = "RESTRICT", r.CASCADE = "CASCADE", r.SET_NULL = "SET NULL", r.SET_DEFAULT = "SET DEFAULT", r))(W || {}), qt = /* @__PURE__ */ ((r) => (r.NO_ACTION = "NO ACTION", r.RESTRICT = "RESTRICT", r.CASCADE = "CASCADE", r.SET_NULL = "SET NULL", r.SET_DEFAULT = "SET DEFAULT", r))(qt || {}), ye = /* @__PURE__ */ ((r) => (r.Full = "full", r.Filter = "filter", r.QueryCache = "QueryCache", r.None = "none", r))(ye || {});
216
+ const _r = (r, e, t = !1) => {
217
+ const n = br(e, t);
199
218
  return {
200
219
  onDelete: r.onDelete ?? n.onDelete,
201
220
  onUpdate: r.onUpdate ?? n.onUpdate
202
221
  };
203
- }, hr = (r, e = !1) => {
222
+ }, br = (r, e = !1) => {
204
223
  const t = qt.RESTRICT;
205
224
  switch (r) {
206
- case T.ONE_TO_ONE:
225
+ case A.ONE_TO_ONE:
207
226
  return {
208
227
  onDelete: W.CASCADE,
209
228
  onUpdate: t
210
229
  };
211
- case T.ONE_TO_MANY:
230
+ case A.ONE_TO_MANY:
212
231
  return {
213
232
  onDelete: W.CASCADE,
214
233
  onUpdate: t
215
234
  };
216
- case T.MANY_TO_ONE:
235
+ case A.MANY_TO_ONE:
217
236
  return e ? {
218
237
  onDelete: W.SET_NULL,
219
238
  onUpdate: t
@@ -221,7 +240,7 @@ const dr = (r, e, t = !1) => {
221
240
  onDelete: W.RESTRICT,
222
241
  onUpdate: t
223
242
  };
224
- case T.MANY_TO_MANY:
243
+ case A.MANY_TO_MANY:
225
244
  return {
226
245
  onDelete: W.RESTRICT,
227
246
  onUpdate: t
@@ -232,16 +251,16 @@ const dr = (r, e, t = !1) => {
232
251
  onUpdate: t
233
252
  };
234
253
  }
235
- }, pr = (r) => r.kind !== T.ONE_TO_MANY, fr = (r, e) => {
254
+ }, wr = (r) => r.kind !== A.ONE_TO_MANY, vr = (r, e) => {
236
255
  const t = [];
237
256
  t.push(r);
238
257
  const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = { ...r };
239
258
  if (o.repository = o.repository || "Repository", o.namespace = o.namespace || "public", o.properties = o.properties || [], o.relations = o.relations || [], o.indexes = o.indexes || [], o.computedProperties = o.computedProperties || [], e) {
240
- if (Bt(e)) {
259
+ if (Dt(e)) {
241
260
  let u = e, d = r;
242
261
  for (; u !== Object.prototype && d; )
243
262
  u = Object.getPrototypeOf(u), d = I(u), d && t.push(d);
244
- } else Rn(e) ? t.push(...e) : t.push(e);
263
+ } else Cn(e) ? t.push(...e) : t.push(e);
245
264
  const c = t.map((u) => u.name);
246
265
  c.shift(), o.extends = c;
247
266
  }
@@ -252,7 +271,7 @@ const dr = (r, e, t = !1) => {
252
271
  u.columnName || (u.columnName = u.name), s.set(u.name, u);
253
272
  }), c.relations?.forEach((u) => {
254
273
  u.mappedNamespace = u.mappedNamespace || "public";
255
- const d = "nullable" in u ? u.nullable ?? !1 : !1, h = dr(
274
+ const d = "nullable" in u ? u.nullable ?? !1 : !1, p = _r(
256
275
  {
257
276
  onDelete: u.onDelete,
258
277
  onUpdate: u.onUpdate
@@ -260,9 +279,9 @@ const dr = (r, e, t = !1) => {
260
279
  u.kind,
261
280
  d
262
281
  );
263
- if (u.onDelete = h.onDelete, u.onUpdate = h.onUpdate, pr(u) && !u.columnName && (u.columnName = u.name + "Id"), u.mappedEntity === c.name && u.mappedNamespace === c.namespace) {
264
- const p = { ...u };
265
- p.mappedEntity = o.name, p.mappedNamespace = o.namespace, i.set(u.name, p);
282
+ if (u.onDelete = p.onDelete, u.onUpdate = p.onUpdate, wr(u) && !u.columnName && (u.columnName = u.name + "Id"), u.mappedEntity === c.name && u.mappedNamespace === c.namespace) {
283
+ const h = { ...u };
284
+ h.mappedEntity = o.name, h.mappedNamespace = o.namespace, i.set(u.name, h);
266
285
  } else
267
286
  i.set(u.name, u);
268
287
  }), c.indexes?.forEach((u) => a.set(u.name, u));
@@ -270,20 +289,20 @@ const dr = (r, e, t = !1) => {
270
289
  const l = /* @__PURE__ */ new Map();
271
290
  return n.forEach((c, u) => {
272
291
  l.set(c.columnName, u);
273
- }), M(o, "columnNameToPropertyName", l), he(
292
+ }), M(o, "columnNameToPropertyName", l), pe(
274
293
  o,
275
294
  "defaultValueProperties",
276
295
  () => Array.from(n.values()).filter((c) => c.default !== void 0)
277
- ), he(
296
+ ), pe(
278
297
  o,
279
298
  "foreignKeyRelations",
280
299
  () => Array.from(o.relationMap.values()).filter(
281
- (c) => c.kind === T.MANY_TO_ONE || c.kind === T.ONE_TO_ONE
300
+ (c) => c.kind === A.MANY_TO_ONE || c.kind === A.ONE_TO_ONE
282
301
  )
283
- ), he(o, "foreignKeyRelationMap", () => {
302
+ ), pe(o, "foreignKeyRelationMap", () => {
284
303
  const c = /* @__PURE__ */ new Map();
285
304
  return o.foreignKeyRelations.forEach((u) => c.set(`${u.name}Id`, u)), c;
286
- }), he(o, "foreignKeyNames", () => o.foreignKeyRelations.map((c) => `${c.name}Id`)), he(
305
+ }), pe(o, "foreignKeyNames", () => o.foreignKeyRelations.map((c) => `${c.name}Id`)), pe(
287
306
  o,
288
307
  "foreignKeyColumnNames",
289
308
  () => o.foreignKeyRelations.filter((c) => !!c.columnName).map((c) => c.columnName)
@@ -293,8 +312,8 @@ const dr = (r, e, t = !1) => {
293
312
  (c) => c && c.endsWith("Id") && o.foreignKeyNames.includes(c)
294
313
  ), o;
295
314
  }, ie = (r) => (e) => {
296
- const t = fr(r, e);
297
- if (M(e, ze, t), r.abstract) return e;
315
+ const t = vr(r, e);
316
+ if (M(e, ke, t), r.abstract) return e;
298
317
  const n = e;
299
318
  return class extends n {
300
319
  /**
@@ -310,12 +329,12 @@ const dr = (r, e, t = !1) => {
310
329
  */
311
330
  constructor(s) {
312
331
  super(s);
313
- const i = this[ke];
332
+ const i = this[We];
314
333
  if (!i) throw new R("need init rxdb");
315
- return cr(t, this), s && lr(t, this, s), i[Wt](this);
334
+ return yr(t, this), s && mr(t, this, s), i[Wt](this);
316
335
  }
317
336
  };
318
- }, yr = (r) => {
337
+ }, Er = (r) => {
319
338
  const e = r.features?.tree ?? {};
320
339
  return ie({
321
340
  ...r,
@@ -329,13 +348,13 @@ const dr = (r, e, t = !1) => {
329
348
  },
330
349
  repository: r.repository ?? "TreeRepository"
331
350
  });
332
- }, ct = /* @__PURE__ */ Symbol("ɵEntityStaticTypes");
333
- var mr = Object.getOwnPropertyDescriptor, gr = (r, e, t, n) => {
334
- for (var s = n > 1 ? void 0 : n ? mr(e, t) : e, i = r.length - 1, a; i >= 0; i--)
351
+ }, lt = /* @__PURE__ */ Symbol("ɵEntityStaticTypes");
352
+ var Rr = Object.getOwnPropertyDescriptor, Cr = (r, e, t, n) => {
353
+ for (var s = n > 1 ? void 0 : n ? Rr(e, t) : e, i = r.length - 1, a; i >= 0; i--)
335
354
  (a = r[i]) && (s = a(s) || s);
336
355
  return s;
337
356
  };
338
- const _r = {
357
+ const Ir = {
339
358
  name: "EntityBase",
340
359
  abstract: !0,
341
360
  // 标记为抽象类,不会直接创建此类的实例
@@ -350,7 +369,7 @@ const _r = {
350
369
  // 唯一索引
351
370
  readonly: !0,
352
371
  // 创建后不可修改
353
- default: () => Ht()
372
+ default: () => Kt()
354
373
  // 默认生成 UUID
355
374
  },
356
375
  {
@@ -383,7 +402,7 @@ const _r = {
383
402
  }
384
403
  ]
385
404
  };
386
- let Ie = class {
405
+ let Ae = class {
387
406
  /**
388
407
  * 实体唯一标识符
389
408
  * 自动生成的UUID,作为主键
@@ -419,15 +438,15 @@ let Ie = class {
419
438
  constructor(r) {
420
439
  }
421
440
  };
422
- Ie = gr([
423
- ie(_r)
424
- ], Ie);
425
- var br = Object.getOwnPropertyDescriptor, wr = (r, e, t, n) => {
426
- for (var s = n > 1 ? void 0 : n ? br(e, t) : e, i = r.length - 1, a; i >= 0; i--)
441
+ Ae = Cr([
442
+ ie(Ir)
443
+ ], Ae);
444
+ var Ar = Object.getOwnPropertyDescriptor, Tr = (r, e, t, n) => {
445
+ for (var s = n > 1 ? void 0 : n ? Ar(e, t) : e, i = r.length - 1, a; i >= 0; i--)
427
446
  (a = r[i]) && (s = a(s) || s);
428
447
  return s;
429
448
  };
430
- const vr = {
449
+ const Sr = {
431
450
  name: "TreeAdjacencyListEntityBase",
432
451
  abstract: !0,
433
452
  // 标记为抽象类,不会直接创建此类的实例
@@ -447,7 +466,7 @@ const vr = {
447
466
  name: "children",
448
467
  // 子节点关系名称
449
468
  displayName: "子节点",
450
- kind: T.ONE_TO_MANY,
469
+ kind: A.ONE_TO_MANY,
451
470
  // 一对多关系
452
471
  mappedEntity: "TreeAdjacencyListEntityBase",
453
472
  // 关联到同一实体类型
@@ -460,7 +479,7 @@ const vr = {
460
479
  columnName: "parentId",
461
480
  // 外键列名
462
481
  displayName: "父节点",
463
- kind: T.MANY_TO_ONE,
482
+ kind: A.MANY_TO_ONE,
464
483
  // 多对一关系
465
484
  mappedEntity: "TreeAdjacencyListEntityBase",
466
485
  // 关联到同一实体类型
@@ -481,16 +500,16 @@ const vr = {
481
500
  }
482
501
  }
483
502
  };
484
- let _t = class extends Ie {
503
+ let bt = class extends Ae {
485
504
  /**
486
505
  * 父节点ID
487
506
  */
488
507
  parentId;
489
508
  };
490
- _t = wr([
491
- ie(vr)
492
- ], _t);
493
- const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r) => r.operator === "exists" || r.operator === "notExists", Cr = (r, e) => {
509
+ bt = Tr([
510
+ ie(Sr)
511
+ ], bt);
512
+ const Gt = (r) => !!(r && r.combinator), Mr = (r) => !!(r && r.field), Or = (r) => r.operator === "exists" || r.operator === "notExists", xr = (r, e) => {
494
513
  const t = Reflect.get(e, r.field), { operator: n } = r;
495
514
  switch (n) {
496
515
  case "in":
@@ -520,7 +539,7 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
520
539
  }
521
540
  case "=":
522
541
  case "!=": {
523
- const { value: s } = r, i = Dt(s, t);
542
+ const { value: s } = r, i = Lt(s, t);
524
543
  return n === "=" ? i : !i;
525
544
  }
526
545
  case ">":
@@ -543,7 +562,7 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
543
562
  }
544
563
  case "exists":
545
564
  case "notExists": {
546
- const s = Rr(r) ? r.where : void 0;
565
+ const s = Or(r) ? r.where : void 0;
547
566
  if (Array.isArray(t)) {
548
567
  let i = t;
549
568
  s && (i = t.filter((o) => Y(o, s)));
@@ -562,13 +581,13 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
562
581
  throw new R(`Unknown operator: ${n}`);
563
582
  }
564
583
  }, Ke = (r, e) => {
565
- if (Vt(r)) {
584
+ if (Gt(r)) {
566
585
  const { combinator: t, rules: n } = r;
567
586
  return t === "and" ? n.every((s) => Ke(s, e)) : n.some((s) => Ke(s, e));
568
587
  } else
569
- return Cr(r, e);
570
- }, Y = (r, e) => r == null ? !1 : Ke(e, r), Ir = (r, e, t) => {
571
- const { field: n, sort: s } = t, i = In(r, n);
588
+ return xr(r, e);
589
+ }, Y = (r, e) => r == null ? !1 : Ke(e, r), Nr = (r, e, t) => {
590
+ const { field: n, sort: s } = t, i = An(r, n);
572
591
  if (s === "asc") {
573
592
  if (e.some((l) => i < Reflect.get(l, n))) return !0;
574
593
  if (e.every((l) => i > Reflect.get(l, n))) return !1;
@@ -576,10 +595,10 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
576
595
  if (e.some((l) => i > Reflect.get(l, n))) return !0;
577
596
  if (e.every((l) => i < Reflect.get(l, n))) return !1;
578
597
  }
579
- }, Tr = (r, e, t) => {
598
+ }, Pr = (r, e, t) => {
580
599
  if (!t || t.length === 0 || e.length === 0 || !r) return !0;
581
600
  for (let n = 0; n < t.length; n++) {
582
- const s = t[n], i = Ir(r, e, s);
601
+ const s = t[n], i = Nr(r, e, s);
583
602
  if (i === void 0) {
584
603
  const { field: a } = s, o = Reflect.get(r, a);
585
604
  e = e.filter((l) => Reflect.get(l, a) === o);
@@ -590,28 +609,24 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
590
609
  const t = [], n = [];
591
610
  return e.forEach((s) => {
592
611
  t.push(s.field), n.push(s.sort);
593
- }), Cn(r, t, n);
594
- }, me = (r, e, t) => {
595
- const n = bt(r, t);
612
+ }), In(r, t, n);
613
+ }, ge = (r, e, t) => {
614
+ const n = wt(r, t);
596
615
  return {
597
- refresh: n === !1 && bt(r, e),
616
+ refresh: n === !1 && wt(r, e),
598
617
  recalculate: n
599
618
  };
600
- }, bt = (r, e) => e.some((t) => t.every((n) => r[n]())), Ar = (r, e, t, n, s) => {
619
+ }, wt = (r, e) => e.some((t) => t.every((n) => r[n]())), $r = (r, e, t, n, s) => {
601
620
  const i = t.slice(0, n);
602
621
  let a = e;
603
622
  for (const o of i) {
604
623
  if (!a?.relationMap.has(o))
605
624
  return !1;
606
625
  const l = a.relationMap.get(o), c = r.schemaManager.getEntityType(l.mappedEntity, l.mappedNamespace);
607
- if (c && s.add(c), l.kind === T.MANY_TO_MANY) {
608
- const u = l.junctionEntityType;
609
- u && s.add(u);
610
- }
611
- a = r.schemaManager.getEntityMetadata(l.mappedEntity, l.mappedNamespace);
626
+ c && s.add(c), l.kind === A.MANY_TO_MANY && l.junctionEntityType && s.add(l.junctionEntityType), a = r.schemaManager.getEntityMetadata(l.mappedEntity, l.mappedNamespace);
612
627
  }
613
628
  return a !== void 0;
614
- }, Sr = (r, e, t, n) => {
629
+ }, Br = (r, e, t, n) => {
615
630
  const s = t.split(".");
616
631
  try {
617
632
  const i = r.schemaManager.getFieldRelations(e, t);
@@ -619,7 +634,7 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
619
634
  return;
620
635
  i.relations.forEach(({ relation: a }) => {
621
636
  const o = r.schemaManager.getEntityType(a.mappedEntity, a.mappedNamespace);
622
- if (o && n.add(o), a.kind === T.MANY_TO_MANY) {
637
+ if (o && n.add(o), a.kind === A.MANY_TO_MANY) {
623
638
  const l = a.junctionEntityType;
624
639
  l && n.add(l);
625
640
  }
@@ -636,7 +651,7 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
636
651
  for (let i = s.length - 1; i > 0; i--) {
637
652
  const a = s.slice(i);
638
653
  if (a.length === 0) continue;
639
- if (Ar(r, e, s, i, n)) {
654
+ if ($r(r, e, s, i, n)) {
640
655
  const l = s.slice(0, i);
641
656
  let c = e;
642
657
  for (const u of l) {
@@ -650,7 +665,7 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
650
665
  }
651
666
  }
652
667
  }
653
- }, lt = (r, e, t, n) => {
668
+ }, ut = (r, e, t, n) => {
654
669
  n.add(t);
655
670
  const s = I(t), i = (a) => {
656
671
  if (a.rules)
@@ -663,10 +678,10 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
663
678
  if (u === "exists" || u === "notExists") {
664
679
  const d = s.relationMap.get(c);
665
680
  if (d) {
666
- const h = r.schemaManager.getEntityType(d.mappedEntity, d.mappedNamespace);
667
- if (h && n.add(h), d.kind === T.MANY_TO_MANY) {
668
- const p = d.junctionEntityType;
669
- p && n.add(p);
681
+ const p = r.schemaManager.getEntityType(d.mappedEntity, d.mappedNamespace);
682
+ if (p && n.add(p), d.kind === A.MANY_TO_MANY) {
683
+ const h = d.junctionEntityType;
684
+ h && n.add(h);
670
685
  }
671
686
  if (l.where && r.schemaManager.getEntityMetadata(
672
687
  d.mappedEntity,
@@ -676,14 +691,14 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
676
691
  d.mappedEntity,
677
692
  d.mappedNamespace
678
693
  );
679
- f && (lt(r, l.where, f, m), m.forEach((y) => n.add(y)));
694
+ f && (ut(r, l.where, f, m), m.forEach((y) => n.add(y)));
680
695
  }
681
696
  }
682
697
  continue;
683
698
  }
684
699
  if (c && c.includes("."))
685
700
  try {
686
- Sr(r, s, c, n);
701
+ Br(r, s, c, n);
687
702
  } catch (d) {
688
703
  d instanceof R || console.warn("[entity_type_dependencies] Failed to resolve dotted field:", c, d);
689
704
  }
@@ -691,7 +706,7 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
691
706
  };
692
707
  i(e);
693
708
  };
694
- function Mr(r, e) {
709
+ function Dr(r, e) {
695
710
  const { rxdb: t, entityType: n } = r, s = I(n);
696
711
  if (!s) return !1;
697
712
  const i = t.schemaManager.getEntityMetadata(e.entity, e.namespace);
@@ -699,7 +714,7 @@ function Mr(r, e) {
699
714
  const a = r.options?.where;
700
715
  if (a) {
701
716
  const o = /* @__PURE__ */ new Set();
702
- lt(t, a, n, o);
717
+ ut(t, a, n, o);
703
718
  for (const l of o) {
704
719
  const c = I(l);
705
720
  if (c && c.name === e.entity && c.namespace === e.namespace)
@@ -710,7 +725,7 @@ function Mr(r, e) {
710
725
  (o) => o.mappedEntity === s.name && o.mappedNamespace === s.namespace
711
726
  );
712
727
  }
713
- function Gt(r, e) {
728
+ function Vt(r, e) {
714
729
  const t = I(r.entityType);
715
730
  if (!t)
716
731
  return {
@@ -719,19 +734,19 @@ function Gt(r, e) {
719
734
  };
720
735
  const n = [], s = [];
721
736
  return e.forEach((i) => {
722
- const a = i.entity === t.name && i.namespace === t.namespace, o = Mr(r, i);
737
+ const a = i.entity === t.name && i.namespace === t.namespace, o = Dr(r, i);
723
738
  a ? (n.push(i), o && r.type !== "findByCursor" && s.push(i)) : o && s.push(i);
724
739
  }), { current_entities: n, relation_entities: s };
725
740
  }
726
- function Or(r, e) {
741
+ function Lr(r, e) {
727
742
  const t = new Set(
728
743
  e.relations ? e.relations.map((s) => s.name) : Array.from(e.relationMap?.keys() ?? [])
729
744
  ), n = (s) => {
730
745
  if (!s) return !1;
731
746
  for (const i of s.rules)
732
- if (Vt(i)) {
747
+ if (Gt(i)) {
733
748
  if (n(i)) return !0;
734
- } else if (Er(i)) {
749
+ } else if (Mr(i)) {
735
750
  const a = i.field;
736
751
  if (a.includes(".")) return !0;
737
752
  const o = a.split(":")[0];
@@ -742,7 +757,7 @@ function Or(r, e) {
742
757
  return n(r);
743
758
  }
744
759
  const ee = S(() => !0);
745
- class ut {
760
+ class dt {
746
761
  constructor(e, t, n, s = !1) {
747
762
  this.task = e, this.current_entities = t, this.hasRelationChanges = n, this.whereUsesRelations = s, this.entityIds = S(() => t.map((i) => i.id));
748
763
  }
@@ -838,19 +853,19 @@ class ut {
838
853
  buildOrderByRule() {
839
854
  const e = "orderBy" in this.task.options ? this.task.options.orderBy : void 0;
840
855
  return e ? S(
841
- () => this.current_entities.some((t) => Tr(t.patch, Array.from(this.task.resultEntitySet), e))
856
+ () => this.current_entities.some((t) => Pr(t.patch, Array.from(this.task.resultEntitySet), e))
842
857
  ) : ee;
843
858
  }
844
859
  }
845
- const $e = S(() => !0), xr = (r, e, t, n) => {
860
+ const Be = S(() => !0), Fr = (r, e, t, n) => {
846
861
  if (!I(r.entityType)) {
847
- const c = S(() => e.map((_) => _.id)), u = $e, d = $e, h = $e, p = S(() => !1), m = S(() => !0), f = S(() => c().some((_) => r.resultEntitySet?.has(_))), y = S(() => f() === !1);
862
+ const c = S(() => e.map((_) => _.id)), u = Be, d = Be, p = Be, h = S(() => !1), m = S(() => !0), f = S(() => c().some((_) => r.resultEntitySet?.has(_))), y = S(() => f() === !1);
848
863
  return {
849
- ...me({
864
+ ...ge({
850
865
  match_where: u,
851
866
  not_match_where: d,
852
- match_order_by: h,
853
- match_relation_where: p,
867
+ match_order_by: p,
868
+ match_relation_where: h,
854
869
  not_match_relation_where: m,
855
870
  result_contains: f,
856
871
  result_not_contains: y
@@ -859,19 +874,19 @@ const $e = S(() => !0), xr = (r, e, t, n) => {
859
874
  relation_entities: []
860
875
  };
861
876
  }
862
- const { current_entities: i, relation_entities: a } = Gt(r, e), l = new ut(r, i, a.length > 0).buildCreateRules();
877
+ const { current_entities: i, relation_entities: a } = Vt(r, e), l = new dt(r, i, a.length > 0).buildCreateRules();
863
878
  return {
864
- ...me(l, t, n),
879
+ ...ge(l, t, n),
865
880
  current_entities: i,
866
881
  relation_entities: a
867
882
  };
868
- }, Nr = (r, e, t, n) => {
869
- const i = new ut(r, e, !1).buildRemoveRules();
870
- return me(i, t, n);
871
- }, wt = S(() => !0), Pr = (r, e, t, n) => {
883
+ }, Ur = (r, e, t, n) => {
884
+ const i = new dt(r, e, !1).buildRemoveRules();
885
+ return ge(i, t, n);
886
+ }, vt = S(() => !0), jr = (r, e, t, n) => {
872
887
  const s = I(r.entityType);
873
888
  if (!s) {
874
- const { options: d, resultEntityIds: h } = r, p = S(() => e.map((E) => E.id)), m = "where" in d ? d.where : void 0, f = m ? S(() => e.some((E) => Y(E.patch, m))) : wt, y = S(() => f() === !1), g = m ? S(() => e.some((E) => Y(E.inversePatch, m))) : wt, _ = S(() => g() === !1), v = S(() => p().some((E) => h.has(E))), b = S(() => v() === !1), w = {
889
+ const { options: d, resultEntityIds: p } = r, h = S(() => e.map((E) => E.id)), m = "where" in d ? d.where : void 0, f = m ? S(() => e.some((E) => Y(E.patch, m))) : vt, y = S(() => f() === !1), g = m ? S(() => e.some((E) => Y(E.inversePatch, m))) : vt, _ = S(() => g() === !1), v = S(() => h().some((E) => p.has(E))), b = S(() => v() === !1), w = {
875
890
  match_where: f,
876
891
  not_match_where: y,
877
892
  match_where_before: g,
@@ -881,19 +896,19 @@ const $e = S(() => !0), xr = (r, e, t, n) => {
881
896
  result_contains: v,
882
897
  result_not_contains: b
883
898
  };
884
- return me(w, t, n);
899
+ return ge(w, t, n);
885
900
  }
886
- const { current_entities: i, relation_entities: a } = Gt(r, e), o = "where" in r.options ? r.options.where : void 0;
901
+ const { current_entities: i, relation_entities: a } = Vt(r, e), o = "where" in r.options ? r.options.where : void 0;
887
902
  let l = !1;
888
- o && (l = Or(o, s));
889
- const u = new ut(r, i, a.length > 0, l).buildUpdateRules();
903
+ o && (l = Lr(o, s));
904
+ const u = new dt(r, i, a.length > 0, l).buildUpdateRules();
890
905
  return {
891
- ...me(u, t, n),
906
+ ...ge(u, t, n),
892
907
  current_entities: i,
893
908
  relation_entities: a
894
909
  };
895
910
  };
896
- function $r(r, e) {
911
+ function Yr(r, e) {
897
912
  const t = [], n = [], s = [], i = /* @__PURE__ */ new Set();
898
913
  for (const o of r) {
899
914
  const l = e.get(o.id);
@@ -907,12 +922,12 @@ function $r(r, e) {
907
922
  function F(r) {
908
923
  return typeof r == "function";
909
924
  }
910
- function Br(r) {
925
+ function zr(r) {
911
926
  return F(r?.lift);
912
927
  }
913
- function we(r) {
928
+ function ve(r) {
914
929
  return function(e) {
915
- if (Br(e))
930
+ if (zr(e))
916
931
  return e.lift(function(t) {
917
932
  try {
918
933
  return r(t, this);
@@ -923,23 +938,23 @@ function we(r) {
923
938
  throw new TypeError("Unable to lift unknown Observable type");
924
939
  };
925
940
  }
926
- var He = function(r, e) {
927
- return He = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, n) {
941
+ var qe = function(r, e) {
942
+ return qe = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, n) {
928
943
  t.__proto__ = n;
929
944
  } || function(t, n) {
930
945
  for (var s in n) Object.prototype.hasOwnProperty.call(n, s) && (t[s] = n[s]);
931
- }, He(r, e);
946
+ }, qe(r, e);
932
947
  };
933
- function de(r, e) {
948
+ function he(r, e) {
934
949
  if (typeof e != "function" && e !== null)
935
950
  throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
936
- He(r, e);
951
+ qe(r, e);
937
952
  function t() {
938
953
  this.constructor = r;
939
954
  }
940
955
  r.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
941
956
  }
942
- function Dr(r, e, t, n) {
957
+ function kr(r, e, t, n) {
943
958
  function s(i) {
944
959
  return i instanceof t ? i : new t(function(a) {
945
960
  a(i);
@@ -1053,7 +1068,7 @@ function Te(r, e) {
1053
1068
  }
1054
1069
  return i;
1055
1070
  }
1056
- function Ae(r, e, t) {
1071
+ function Se(r, e, t) {
1057
1072
  if (t || arguments.length === 2) for (var n = 0, s = e.length, i; n < s; n++)
1058
1073
  (i || !(n in e)) && (i || (i = Array.prototype.slice.call(e, 0, n)), i[n] = e[n]);
1059
1074
  return r.concat(i || Array.prototype.slice.call(e));
@@ -1061,45 +1076,45 @@ function Ae(r, e, t) {
1061
1076
  function le(r) {
1062
1077
  return this instanceof le ? (this.v = r, this) : new le(r);
1063
1078
  }
1064
- function Lr(r, e, t) {
1079
+ function Wr(r, e, t) {
1065
1080
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1066
1081
  var n = t.apply(r, e || []), s, i = [];
1067
1082
  return s = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), o("next"), o("throw"), o("return", a), s[Symbol.asyncIterator] = function() {
1068
1083
  return this;
1069
1084
  }, s;
1070
- function a(p) {
1085
+ function a(h) {
1071
1086
  return function(m) {
1072
- return Promise.resolve(m).then(p, d);
1087
+ return Promise.resolve(m).then(h, d);
1073
1088
  };
1074
1089
  }
1075
- function o(p, m) {
1076
- n[p] && (s[p] = function(f) {
1090
+ function o(h, m) {
1091
+ n[h] && (s[h] = function(f) {
1077
1092
  return new Promise(function(y, g) {
1078
- i.push([p, f, y, g]) > 1 || l(p, f);
1093
+ i.push([h, f, y, g]) > 1 || l(h, f);
1079
1094
  });
1080
- }, m && (s[p] = m(s[p])));
1095
+ }, m && (s[h] = m(s[h])));
1081
1096
  }
1082
- function l(p, m) {
1097
+ function l(h, m) {
1083
1098
  try {
1084
- c(n[p](m));
1099
+ c(n[h](m));
1085
1100
  } catch (f) {
1086
- h(i[0][3], f);
1101
+ p(i[0][3], f);
1087
1102
  }
1088
1103
  }
1089
- function c(p) {
1090
- p.value instanceof le ? Promise.resolve(p.value.v).then(u, d) : h(i[0][2], p);
1104
+ function c(h) {
1105
+ h.value instanceof le ? Promise.resolve(h.value.v).then(u, d) : p(i[0][2], h);
1091
1106
  }
1092
- function u(p) {
1093
- l("next", p);
1107
+ function u(h) {
1108
+ l("next", h);
1094
1109
  }
1095
- function d(p) {
1096
- l("throw", p);
1110
+ function d(h) {
1111
+ l("throw", h);
1097
1112
  }
1098
- function h(p, m) {
1099
- p(m), i.shift(), i.length && l(i[0][0], i[0][1]);
1113
+ function p(h, m) {
1114
+ h(m), i.shift(), i.length && l(i[0][0], i[0][1]);
1100
1115
  }
1101
1116
  }
1102
- function Fr(r) {
1117
+ function Hr(r) {
1103
1118
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1104
1119
  var e = r[Symbol.asyncIterator], t;
1105
1120
  return e ? e.call(r) : (r = typeof ue == "function" ? ue(r) : r[Symbol.iterator](), t = {}, n("next"), n("throw"), n("return"), t[Symbol.asyncIterator] = function() {
@@ -1118,10 +1133,10 @@ function Fr(r) {
1118
1133
  }, a);
1119
1134
  }
1120
1135
  }
1121
- var Ur = (function(r) {
1136
+ var Kr = (function(r) {
1122
1137
  return r && typeof r.length == "number" && typeof r != "function";
1123
1138
  });
1124
- function jr(r) {
1139
+ function qr(r) {
1125
1140
  return F(r?.then);
1126
1141
  }
1127
1142
  function Jt(r) {
@@ -1130,7 +1145,7 @@ function Jt(r) {
1130
1145
  }, t = r(e);
1131
1146
  return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
1132
1147
  }
1133
- var Be = Jt(function(r) {
1148
+ var De = Jt(function(r) {
1134
1149
  return function(t) {
1135
1150
  r(this), this.message = t ? t.length + ` errors occurred during unsubscription:
1136
1151
  ` + t.map(function(n, s) {
@@ -1139,13 +1154,13 @@ var Be = Jt(function(r) {
1139
1154
  `) : "", this.name = "UnsubscriptionError", this.errors = t;
1140
1155
  };
1141
1156
  });
1142
- function qe(r, e) {
1157
+ function Ge(r, e) {
1143
1158
  if (r) {
1144
1159
  var t = r.indexOf(e);
1145
1160
  0 <= t && r.splice(t, 1);
1146
1161
  }
1147
1162
  }
1148
- var Se = (function() {
1163
+ var Me = (function() {
1149
1164
  function r(e) {
1150
1165
  this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
1151
1166
  }
@@ -1177,38 +1192,38 @@ var Se = (function() {
1177
1192
  try {
1178
1193
  u();
1179
1194
  } catch (f) {
1180
- i = f instanceof Be ? f.errors : [f];
1195
+ i = f instanceof De ? f.errors : [f];
1181
1196
  }
1182
1197
  var d = this._finalizers;
1183
1198
  if (d) {
1184
1199
  this._finalizers = null;
1185
1200
  try {
1186
- for (var h = ue(d), p = h.next(); !p.done; p = h.next()) {
1187
- var m = p.value;
1201
+ for (var p = ue(d), h = p.next(); !h.done; h = p.next()) {
1202
+ var m = h.value;
1188
1203
  try {
1189
- vt(m);
1204
+ Et(m);
1190
1205
  } catch (f) {
1191
- i = i ?? [], f instanceof Be ? i = Ae(Ae([], Te(i)), Te(f.errors)) : i.push(f);
1206
+ i = i ?? [], f instanceof De ? i = Se(Se([], Te(i)), Te(f.errors)) : i.push(f);
1192
1207
  }
1193
1208
  }
1194
1209
  } catch (f) {
1195
1210
  n = { error: f };
1196
1211
  } finally {
1197
1212
  try {
1198
- p && !p.done && (s = h.return) && s.call(h);
1213
+ h && !h.done && (s = p.return) && s.call(p);
1199
1214
  } finally {
1200
1215
  if (n) throw n.error;
1201
1216
  }
1202
1217
  }
1203
1218
  }
1204
1219
  if (i)
1205
- throw new Be(i);
1220
+ throw new De(i);
1206
1221
  }
1207
1222
  }, r.prototype.add = function(e) {
1208
1223
  var t;
1209
1224
  if (e && e !== this)
1210
1225
  if (this.closed)
1211
- vt(e);
1226
+ Et(e);
1212
1227
  else {
1213
1228
  if (e instanceof r) {
1214
1229
  if (e.closed || e._hasParent(this))
@@ -1225,28 +1240,28 @@ var Se = (function() {
1225
1240
  this._parentage = Array.isArray(t) ? (t.push(e), t) : t ? [t, e] : e;
1226
1241
  }, r.prototype._removeParent = function(e) {
1227
1242
  var t = this._parentage;
1228
- t === e ? this._parentage = null : Array.isArray(t) && qe(t, e);
1243
+ t === e ? this._parentage = null : Array.isArray(t) && Ge(t, e);
1229
1244
  }, r.prototype.remove = function(e) {
1230
1245
  var t = this._finalizers;
1231
- t && qe(t, e), e instanceof r && e._removeParent(this);
1246
+ t && Ge(t, e), e instanceof r && e._removeParent(this);
1232
1247
  }, r.EMPTY = (function() {
1233
1248
  var e = new r();
1234
1249
  return e.closed = !0, e;
1235
1250
  })(), r;
1236
- })(), Xt = Se.EMPTY;
1251
+ })(), Xt = Me.EMPTY;
1237
1252
  function Zt(r) {
1238
- return r instanceof Se || r && "closed" in r && F(r.remove) && F(r.add) && F(r.unsubscribe);
1253
+ return r instanceof Me || r && "closed" in r && F(r.remove) && F(r.add) && F(r.unsubscribe);
1239
1254
  }
1240
- function vt(r) {
1255
+ function Et(r) {
1241
1256
  F(r) ? r() : r.unsubscribe();
1242
1257
  }
1243
- var Yr = {
1258
+ var Gr = {
1244
1259
  Promise: void 0
1245
- }, zr = {
1260
+ }, Vr = {
1246
1261
  setTimeout: function(r, e) {
1247
1262
  for (var t = [], n = 2; n < arguments.length; n++)
1248
1263
  t[n - 2] = arguments[n];
1249
- return setTimeout.apply(void 0, Ae([r, e], Te(t)));
1264
+ return setTimeout.apply(void 0, Se([r, e], Te(t)));
1250
1265
  },
1251
1266
  clearTimeout: function(r) {
1252
1267
  return clearTimeout(r);
@@ -1254,23 +1269,23 @@ var Yr = {
1254
1269
  delegate: void 0
1255
1270
  };
1256
1271
  function en(r) {
1257
- zr.setTimeout(function() {
1272
+ Vr.setTimeout(function() {
1258
1273
  throw r;
1259
1274
  });
1260
1275
  }
1261
- function Et() {
1276
+ function Rt() {
1262
1277
  }
1263
- function Ee(r) {
1278
+ function Re(r) {
1264
1279
  r();
1265
1280
  }
1266
- var dt = (function(r) {
1267
- de(e, r);
1281
+ var ht = (function(r) {
1282
+ he(e, r);
1268
1283
  function e(t) {
1269
1284
  var n = r.call(this) || this;
1270
- return n.isStopped = !1, t ? (n.destination = t, Zt(t) && t.add(n)) : n.destination = Kr, n;
1285
+ return n.isStopped = !1, t ? (n.destination = t, Zt(t) && t.add(n)) : n.destination = Xr, n;
1271
1286
  }
1272
1287
  return e.create = function(t, n, s) {
1273
- return new ge(t, n, s);
1288
+ return new _e(t, n, s);
1274
1289
  }, e.prototype.next = function(t) {
1275
1290
  this.isStopped || this._next(t);
1276
1291
  }, e.prototype.error = function(t) {
@@ -1294,7 +1309,7 @@ var dt = (function(r) {
1294
1309
  this.unsubscribe();
1295
1310
  }
1296
1311
  }, e;
1297
- })(Se), kr = (function() {
1312
+ })(Me), Qr = (function() {
1298
1313
  function r(e) {
1299
1314
  this.partialObserver = e;
1300
1315
  }
@@ -1304,7 +1319,7 @@ var dt = (function(r) {
1304
1319
  try {
1305
1320
  t.next(e);
1306
1321
  } catch (n) {
1307
- ve(n);
1322
+ Ee(n);
1308
1323
  }
1309
1324
  }, r.prototype.error = function(e) {
1310
1325
  var t = this.partialObserver;
@@ -1312,50 +1327,50 @@ var dt = (function(r) {
1312
1327
  try {
1313
1328
  t.error(e);
1314
1329
  } catch (n) {
1315
- ve(n);
1330
+ Ee(n);
1316
1331
  }
1317
1332
  else
1318
- ve(e);
1333
+ Ee(e);
1319
1334
  }, r.prototype.complete = function() {
1320
1335
  var e = this.partialObserver;
1321
1336
  if (e.complete)
1322
1337
  try {
1323
1338
  e.complete();
1324
1339
  } catch (t) {
1325
- ve(t);
1340
+ Ee(t);
1326
1341
  }
1327
1342
  }, r;
1328
- })(), ge = (function(r) {
1329
- de(e, r);
1343
+ })(), _e = (function(r) {
1344
+ he(e, r);
1330
1345
  function e(t, n, s) {
1331
1346
  var i = r.call(this) || this, a;
1332
1347
  return F(t) || !t ? a = {
1333
1348
  next: t ?? void 0,
1334
1349
  error: n ?? void 0,
1335
1350
  complete: s ?? void 0
1336
- } : a = t, i.destination = new kr(a), i;
1351
+ } : a = t, i.destination = new Qr(a), i;
1337
1352
  }
1338
1353
  return e;
1339
- })(dt);
1340
- function ve(r) {
1354
+ })(ht);
1355
+ function Ee(r) {
1341
1356
  en(r);
1342
1357
  }
1343
- function Wr(r) {
1358
+ function Jr(r) {
1344
1359
  throw r;
1345
1360
  }
1346
- var Kr = {
1361
+ var Xr = {
1347
1362
  closed: !0,
1348
- next: Et,
1349
- error: Wr,
1350
- complete: Et
1351
- }, ht = (function() {
1363
+ next: Rt,
1364
+ error: Jr,
1365
+ complete: Rt
1366
+ }, pt = (function() {
1352
1367
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
1353
1368
  })();
1354
- function Hr(r) {
1369
+ function Zr(r) {
1355
1370
  return r;
1356
1371
  }
1357
- function qr(r) {
1358
- return r.length === 0 ? Hr : r.length === 1 ? r[0] : function(t) {
1372
+ function es(r) {
1373
+ return r.length === 0 ? Zr : r.length === 1 ? r[0] : function(t) {
1359
1374
  return r.reduce(function(n, s) {
1360
1375
  return s(n);
1361
1376
  }, t);
@@ -1369,8 +1384,8 @@ var re = (function() {
1369
1384
  var t = new r();
1370
1385
  return t.source = this, t.operator = e, t;
1371
1386
  }, r.prototype.subscribe = function(e, t, n) {
1372
- var s = this, i = Gr(e) ? e : new ge(e, t, n);
1373
- return Ee(function() {
1387
+ var s = this, i = ns(e) ? e : new _e(e, t, n);
1388
+ return Re(function() {
1374
1389
  var a = s, o = a.operator, l = a.source;
1375
1390
  i.add(o ? o.call(i, l) : l ? s._subscribe(i) : s._trySubscribe(i));
1376
1391
  }), i;
@@ -1382,8 +1397,8 @@ var re = (function() {
1382
1397
  }
1383
1398
  }, r.prototype.forEach = function(e, t) {
1384
1399
  var n = this;
1385
- return t = Rt(t), new t(function(s, i) {
1386
- var a = new ge({
1400
+ return t = Ct(t), new t(function(s, i) {
1401
+ var a = new _e({
1387
1402
  next: function(o) {
1388
1403
  try {
1389
1404
  e(o);
@@ -1399,15 +1414,15 @@ var re = (function() {
1399
1414
  }, r.prototype._subscribe = function(e) {
1400
1415
  var t;
1401
1416
  return (t = this.source) === null || t === void 0 ? void 0 : t.subscribe(e);
1402
- }, r.prototype[ht] = function() {
1417
+ }, r.prototype[pt] = function() {
1403
1418
  return this;
1404
1419
  }, r.prototype.pipe = function() {
1405
1420
  for (var e = [], t = 0; t < arguments.length; t++)
1406
1421
  e[t] = arguments[t];
1407
- return qr(e)(this);
1422
+ return es(e)(this);
1408
1423
  }, r.prototype.toPromise = function(e) {
1409
1424
  var t = this;
1410
- return e = Rt(e), new e(function(n, s) {
1425
+ return e = Ct(e), new e(function(n, s) {
1411
1426
  var i;
1412
1427
  t.subscribe(function(a) {
1413
1428
  return i = a;
@@ -1421,34 +1436,34 @@ var re = (function() {
1421
1436
  return new r(e);
1422
1437
  }, r;
1423
1438
  })();
1424
- function Rt(r) {
1439
+ function Ct(r) {
1425
1440
  var e;
1426
- return (e = r ?? Yr.Promise) !== null && e !== void 0 ? e : Promise;
1441
+ return (e = r ?? Gr.Promise) !== null && e !== void 0 ? e : Promise;
1427
1442
  }
1428
- function Vr(r) {
1443
+ function ts(r) {
1429
1444
  return r && F(r.next) && F(r.error) && F(r.complete);
1430
1445
  }
1431
- function Gr(r) {
1432
- return r && r instanceof dt || Vr(r) && Zt(r);
1446
+ function ns(r) {
1447
+ return r && r instanceof ht || ts(r) && Zt(r);
1433
1448
  }
1434
- function Qr(r) {
1435
- return F(r[ht]);
1449
+ function rs(r) {
1450
+ return F(r[pt]);
1436
1451
  }
1437
- function Jr(r) {
1452
+ function ss(r) {
1438
1453
  return Symbol.asyncIterator && F(r?.[Symbol.asyncIterator]);
1439
1454
  }
1440
- function Xr(r) {
1455
+ function is(r) {
1441
1456
  return new TypeError("You provided " + (r !== null && typeof r == "object" ? "an invalid object" : "'" + r + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
1442
1457
  }
1443
- function Zr() {
1458
+ function as() {
1444
1459
  return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
1445
1460
  }
1446
- var es = Zr();
1447
- function ts(r) {
1448
- return F(r?.[es]);
1461
+ var os = as();
1462
+ function cs(r) {
1463
+ return F(r?.[os]);
1449
1464
  }
1450
- function ns(r) {
1451
- return Lr(this, arguments, function() {
1465
+ function ls(r) {
1466
+ return Wr(this, arguments, function() {
1452
1467
  var t, n, s, i;
1453
1468
  return Qt(this, function(a) {
1454
1469
  switch (a.label) {
@@ -1478,44 +1493,44 @@ function ns(r) {
1478
1493
  });
1479
1494
  });
1480
1495
  }
1481
- function rs(r) {
1496
+ function us(r) {
1482
1497
  return F(r?.getReader);
1483
1498
  }
1484
- function Me(r) {
1499
+ function Oe(r) {
1485
1500
  if (r instanceof re)
1486
1501
  return r;
1487
1502
  if (r != null) {
1488
- if (Qr(r))
1489
- return ss(r);
1490
- if (Ur(r))
1491
- return is(r);
1492
- if (jr(r))
1493
- return as(r);
1494
- if (Jr(r))
1495
- return tn(r);
1496
- if (ts(r))
1497
- return os(r);
1498
1503
  if (rs(r))
1499
- return cs(r);
1504
+ return ds(r);
1505
+ if (Kr(r))
1506
+ return hs(r);
1507
+ if (qr(r))
1508
+ return ps(r);
1509
+ if (ss(r))
1510
+ return tn(r);
1511
+ if (cs(r))
1512
+ return fs(r);
1513
+ if (us(r))
1514
+ return ys(r);
1500
1515
  }
1501
- throw Xr(r);
1516
+ throw is(r);
1502
1517
  }
1503
- function ss(r) {
1518
+ function ds(r) {
1504
1519
  return new re(function(e) {
1505
- var t = r[ht]();
1520
+ var t = r[pt]();
1506
1521
  if (F(t.subscribe))
1507
1522
  return t.subscribe(e);
1508
1523
  throw new TypeError("Provided object does not correctly implement Symbol.observable");
1509
1524
  });
1510
1525
  }
1511
- function is(r) {
1526
+ function hs(r) {
1512
1527
  return new re(function(e) {
1513
1528
  for (var t = 0; t < r.length && !e.closed; t++)
1514
1529
  e.next(r[t]);
1515
1530
  e.complete();
1516
1531
  });
1517
1532
  }
1518
- function as(r) {
1533
+ function ps(r) {
1519
1534
  return new re(function(e) {
1520
1535
  r.then(function(t) {
1521
1536
  e.closed || (e.next(t), e.complete());
@@ -1524,7 +1539,7 @@ function as(r) {
1524
1539
  }).then(null, en);
1525
1540
  });
1526
1541
  }
1527
- function os(r) {
1542
+ function fs(r) {
1528
1543
  return new re(function(e) {
1529
1544
  var t, n;
1530
1545
  try {
@@ -1547,22 +1562,22 @@ function os(r) {
1547
1562
  }
1548
1563
  function tn(r) {
1549
1564
  return new re(function(e) {
1550
- ls(r, e).catch(function(t) {
1565
+ ms(r, e).catch(function(t) {
1551
1566
  return e.error(t);
1552
1567
  });
1553
1568
  });
1554
1569
  }
1555
- function cs(r) {
1556
- return tn(ns(r));
1570
+ function ys(r) {
1571
+ return tn(ls(r));
1557
1572
  }
1558
- function ls(r, e) {
1573
+ function ms(r, e) {
1559
1574
  var t, n, s, i;
1560
- return Dr(this, void 0, void 0, function() {
1575
+ return kr(this, void 0, void 0, function() {
1561
1576
  var a, o;
1562
1577
  return Qt(this, function(l) {
1563
1578
  switch (l.label) {
1564
1579
  case 0:
1565
- l.trys.push([0, 5, 6, 11]), t = Fr(r), l.label = 1;
1580
+ l.trys.push([0, 5, 6, 11]), t = Hr(r), l.label = 1;
1566
1581
  case 1:
1567
1582
  return [4, t.next()];
1568
1583
  case 2:
@@ -1593,11 +1608,11 @@ function ls(r, e) {
1593
1608
  });
1594
1609
  });
1595
1610
  }
1596
- function _e(r, e, t, n, s) {
1597
- return new us(r, e, t, n, s);
1611
+ function be(r, e, t, n, s) {
1612
+ return new gs(r, e, t, n, s);
1598
1613
  }
1599
- var us = (function(r) {
1600
- de(e, r);
1614
+ var gs = (function(r) {
1615
+ he(e, r);
1601
1616
  function e(t, n, s, i, a, o) {
1602
1617
  var l = r.call(this, t) || this;
1603
1618
  return l.onFinalize = a, l.shouldUnsubscribe = o, l._next = n ? function(c) {
@@ -1631,47 +1646,47 @@ var us = (function(r) {
1631
1646
  r.prototype.unsubscribe.call(this), !n && ((t = this.onFinalize) === null || t === void 0 || t.call(this));
1632
1647
  }
1633
1648
  }, e;
1634
- })(dt), nn = {
1649
+ })(ht), nn = {
1635
1650
  now: function() {
1636
1651
  return (nn.delegate || Date).now();
1637
1652
  },
1638
1653
  delegate: void 0
1639
1654
  };
1640
- function Re(r) {
1641
- return we(function(e, t) {
1655
+ function Ce(r) {
1656
+ return ve(function(e, t) {
1642
1657
  var n = null, s = !1, i;
1643
- n = e.subscribe(_e(t, void 0, void 0, function(a) {
1644
- i = Me(r(a, Re(r)(e))), n ? (n.unsubscribe(), n = null, i.subscribe(t)) : s = !0;
1658
+ n = e.subscribe(be(t, void 0, void 0, function(a) {
1659
+ i = Oe(r(a, Ce(r)(e))), n ? (n.unsubscribe(), n = null, i.subscribe(t)) : s = !0;
1645
1660
  })), s && (n.unsubscribe(), n = null, i.subscribe(t));
1646
1661
  });
1647
1662
  }
1648
1663
  function te(r, e) {
1649
- return we(function(t, n) {
1664
+ return ve(function(t, n) {
1650
1665
  var s = 0;
1651
- t.subscribe(_e(n, function(i) {
1666
+ t.subscribe(be(n, function(i) {
1652
1667
  n.next(r.call(e, i, s++));
1653
1668
  }));
1654
1669
  });
1655
1670
  }
1656
- var ds = Jt(function(r) {
1671
+ var _s = Jt(function(r) {
1657
1672
  return function() {
1658
1673
  r(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
1659
1674
  };
1660
- }), pt = (function(r) {
1661
- de(e, r);
1675
+ }), ft = (function(r) {
1676
+ he(e, r);
1662
1677
  function e() {
1663
1678
  var t = r.call(this) || this;
1664
1679
  return t.closed = !1, t.currentObservers = null, t.observers = [], t.isStopped = !1, t.hasError = !1, t.thrownError = null, t;
1665
1680
  }
1666
1681
  return e.prototype.lift = function(t) {
1667
- var n = new Ct(this, this);
1682
+ var n = new It(this, this);
1668
1683
  return n.operator = t, n;
1669
1684
  }, e.prototype._throwIfClosed = function() {
1670
1685
  if (this.closed)
1671
- throw new ds();
1686
+ throw new _s();
1672
1687
  }, e.prototype.next = function(t) {
1673
1688
  var n = this;
1674
- Ee(function() {
1689
+ Re(function() {
1675
1690
  var s, i;
1676
1691
  if (n._throwIfClosed(), !n.isStopped) {
1677
1692
  n.currentObservers || (n.currentObservers = Array.from(n.observers));
@@ -1693,7 +1708,7 @@ var ds = Jt(function(r) {
1693
1708
  });
1694
1709
  }, e.prototype.error = function(t) {
1695
1710
  var n = this;
1696
- Ee(function() {
1711
+ Re(function() {
1697
1712
  if (n._throwIfClosed(), !n.isStopped) {
1698
1713
  n.hasError = n.isStopped = !0, n.thrownError = t;
1699
1714
  for (var s = n.observers; s.length; )
@@ -1702,7 +1717,7 @@ var ds = Jt(function(r) {
1702
1717
  });
1703
1718
  }, e.prototype.complete = function() {
1704
1719
  var t = this;
1705
- Ee(function() {
1720
+ Re(function() {
1706
1721
  if (t._throwIfClosed(), !t.isStopped) {
1707
1722
  t.isStopped = !0;
1708
1723
  for (var n = t.observers; n.length; )
@@ -1724,8 +1739,8 @@ var ds = Jt(function(r) {
1724
1739
  return this._throwIfClosed(), this._checkFinalizedStatuses(t), this._innerSubscribe(t);
1725
1740
  }, e.prototype._innerSubscribe = function(t) {
1726
1741
  var n = this, s = this, i = s.hasError, a = s.isStopped, o = s.observers;
1727
- return i || a ? Xt : (this.currentObservers = null, o.push(t), new Se(function() {
1728
- n.currentObservers = null, qe(o, t);
1742
+ return i || a ? Xt : (this.currentObservers = null, o.push(t), new Me(function() {
1743
+ n.currentObservers = null, Ge(o, t);
1729
1744
  }));
1730
1745
  }, e.prototype._checkFinalizedStatuses = function(t) {
1731
1746
  var n = this, s = n.hasError, i = n.thrownError, a = n.isStopped;
@@ -1734,10 +1749,10 @@ var ds = Jt(function(r) {
1734
1749
  var t = new re();
1735
1750
  return t.source = this, t;
1736
1751
  }, e.create = function(t, n) {
1737
- return new Ct(t, n);
1752
+ return new It(t, n);
1738
1753
  }, e;
1739
- })(re), Ct = (function(r) {
1740
- de(e, r);
1754
+ })(re), It = (function(r) {
1755
+ he(e, r);
1741
1756
  function e(t, n) {
1742
1757
  var s = r.call(this) || this;
1743
1758
  return s.destination = t, s.source = n, s;
@@ -1755,17 +1770,17 @@ var ds = Jt(function(r) {
1755
1770
  var n, s;
1756
1771
  return (s = (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(t)) !== null && s !== void 0 ? s : Xt;
1757
1772
  }, e;
1758
- })(pt);
1759
- function It(r, e) {
1760
- return we(function(t, n) {
1773
+ })(ft);
1774
+ function At(r, e) {
1775
+ return ve(function(t, n) {
1761
1776
  var s = 0;
1762
- t.subscribe(_e(n, function(i) {
1777
+ t.subscribe(be(n, function(i) {
1763
1778
  return r.call(e, i, s++) && n.next(i);
1764
1779
  }));
1765
1780
  });
1766
1781
  }
1767
- var hs = (function(r) {
1768
- de(e, r);
1782
+ var bs = (function(r) {
1783
+ he(e, r);
1769
1784
  function e(t, n, s) {
1770
1785
  t === void 0 && (t = 1 / 0), n === void 0 && (n = 1 / 0), s === void 0 && (s = nn);
1771
1786
  var i = r.call(this) || this;
@@ -1787,41 +1802,41 @@ var hs = (function(r) {
1787
1802
  c && i.splice(0, c + 1);
1788
1803
  }
1789
1804
  }, e;
1790
- })(pt);
1791
- function ps(r) {
1805
+ })(ft);
1806
+ function ws(r) {
1792
1807
  r === void 0 && (r = {});
1793
1808
  var e = r.connector, t = e === void 0 ? function() {
1794
- return new pt();
1809
+ return new ft();
1795
1810
  } : e, n = r.resetOnError, s = n === void 0 ? !0 : n, i = r.resetOnComplete, a = i === void 0 ? !0 : i, o = r.resetOnRefCountZero, l = o === void 0 ? !0 : o;
1796
1811
  return function(c) {
1797
- var u, d, h, p = 0, m = !1, f = !1, y = function() {
1812
+ var u, d, p, h = 0, m = !1, f = !1, y = function() {
1798
1813
  d?.unsubscribe(), d = void 0;
1799
1814
  }, g = function() {
1800
- y(), u = h = void 0, m = f = !1;
1815
+ y(), u = p = void 0, m = f = !1;
1801
1816
  }, _ = function() {
1802
1817
  var v = u;
1803
1818
  g(), v?.unsubscribe();
1804
1819
  };
1805
- return we(function(v, b) {
1806
- p++, !f && !m && y();
1807
- var w = h = h ?? t();
1820
+ return ve(function(v, b) {
1821
+ h++, !f && !m && y();
1822
+ var w = p = p ?? t();
1808
1823
  b.add(function() {
1809
- p--, p === 0 && !f && !m && (d = De(_, l));
1810
- }), w.subscribe(b), !u && p > 0 && (u = new ge({
1824
+ h--, h === 0 && !f && !m && (d = Le(_, l));
1825
+ }), w.subscribe(b), !u && h > 0 && (u = new _e({
1811
1826
  next: function(E) {
1812
1827
  return w.next(E);
1813
1828
  },
1814
1829
  error: function(E) {
1815
- f = !0, y(), d = De(g, s, E), w.error(E);
1830
+ f = !0, y(), d = Le(g, s, E), w.error(E);
1816
1831
  },
1817
1832
  complete: function() {
1818
- m = !0, y(), d = De(g, a), w.complete();
1833
+ m = !0, y(), d = Le(g, a), w.complete();
1819
1834
  }
1820
- }), Me(v).subscribe(u));
1835
+ }), Oe(v).subscribe(u));
1821
1836
  })(c);
1822
1837
  };
1823
1838
  }
1824
- function De(r, e) {
1839
+ function Le(r, e) {
1825
1840
  for (var t = [], n = 2; n < arguments.length; n++)
1826
1841
  t[n - 2] = arguments[n];
1827
1842
  if (e === !0) {
@@ -1829,34 +1844,34 @@ function De(r, e) {
1829
1844
  return;
1830
1845
  }
1831
1846
  if (e !== !1) {
1832
- var s = new ge({
1847
+ var s = new _e({
1833
1848
  next: function() {
1834
1849
  s.unsubscribe(), r();
1835
1850
  }
1836
1851
  });
1837
- return Me(e.apply(void 0, Ae([], Te(t)))).subscribe(s);
1852
+ return Oe(e.apply(void 0, Se([], Te(t)))).subscribe(s);
1838
1853
  }
1839
1854
  }
1840
- function fs(r, e, t) {
1855
+ function vs(r, e, t) {
1841
1856
  var n, s = !1;
1842
- return n = r, ps({
1857
+ return n = r, ws({
1843
1858
  connector: function() {
1844
- return new hs(n, e, t);
1859
+ return new bs(n, e, t);
1845
1860
  },
1846
1861
  resetOnError: !0,
1847
1862
  resetOnComplete: !1,
1848
1863
  resetOnRefCountZero: s
1849
1864
  });
1850
1865
  }
1851
- function V(r, e) {
1852
- return we(function(t, n) {
1866
+ function G(r, e) {
1867
+ return ve(function(t, n) {
1853
1868
  var s = null, i = 0, a = !1, o = function() {
1854
1869
  return a && !s && n.complete();
1855
1870
  };
1856
- t.subscribe(_e(n, function(l) {
1871
+ t.subscribe(be(n, function(l) {
1857
1872
  s?.unsubscribe();
1858
1873
  var c = 0, u = i++;
1859
- Me(r(l, u)).subscribe(s = _e(n, function(d) {
1874
+ Oe(r(l, u)).subscribe(s = be(n, function(d) {
1860
1875
  return n.next(e ? e(l, d, u, c++) : d);
1861
1876
  }, function() {
1862
1877
  s = null, o();
@@ -1866,7 +1881,7 @@ function V(r, e) {
1866
1881
  }));
1867
1882
  });
1868
1883
  }
1869
- class ua {
1884
+ class ma {
1870
1885
  constructor(e, t, n) {
1871
1886
  this.remoteAdapter = t, this.localAdapter = n, this.entityName = e;
1872
1887
  }
@@ -1913,7 +1928,7 @@ class ua {
1913
1928
  let s;
1914
1929
  e.localCacheFirst ? s = this.#n(e) : s = this.#s(e), e.offlineFallback && (s = this.#i(s));
1915
1930
  const i = s.pipe(
1916
- fs(1),
1931
+ vs(1),
1917
1932
  Ft(() => {
1918
1933
  this.#e.delete(t);
1919
1934
  })
@@ -1937,16 +1952,16 @@ class ua {
1937
1952
  combinator: "and",
1938
1953
  rules: [{ field: "id", operator: "=", value: e }]
1939
1954
  };
1940
- return Dn({
1955
+ return Ln({
1941
1956
  remoteMetadata: this.remoteAdapter.fetchMetadata(this.entityName, t),
1942
1957
  localMetadata: this.localAdapter.getMetadataByIds(this.entityName, [e])
1943
1958
  }).pipe(
1944
- V(({ remoteMetadata: n, localMetadata: s }) => {
1959
+ G(({ remoteMetadata: n, localMetadata: s }) => {
1945
1960
  if (n.length === 0)
1946
1961
  return Q(null);
1947
1962
  const i = n[0].updatedAt, a = s.get(e);
1948
1963
  return a && a >= i ? this.#a([e]).pipe(te((o) => o[0] || null)) : this.remoteAdapter.findByIds(this.entityName, [e]).pipe(
1949
- V((o) => o.length === 0 ? Q(null) : this.localAdapter.upsertMany(this.entityName, o).pipe(te(() => o[0])))
1964
+ G((o) => o.length === 0 ? Q(null) : this.localAdapter.upsertMany(this.entityName, o).pipe(te(() => o[0])))
1950
1965
  );
1951
1966
  })
1952
1967
  );
@@ -1976,7 +1991,7 @@ class ua {
1976
1991
  if (!this.remoteAdapter.create)
1977
1992
  throw new Error(`Remote adapter does not support create operation for ${this.entityName}`);
1978
1993
  return this.remoteAdapter.create(this.entityName, e).pipe(
1979
- V((t) => this.localAdapter.upsertMany(this.entityName, [t]).pipe(te(() => t)))
1994
+ G((t) => this.localAdapter.upsertMany(this.entityName, [t]).pipe(te(() => t)))
1980
1995
  );
1981
1996
  }
1982
1997
  /**
@@ -2002,7 +2017,7 @@ class ua {
2002
2017
  if (!this.remoteAdapter.update)
2003
2018
  throw new Error(`Remote adapter does not support update operation for ${this.entityName}`);
2004
2019
  return this.remoteAdapter.update(this.entityName, e, t).pipe(
2005
- V((n) => this.localAdapter.upsertMany(this.entityName, [n]).pipe(te(() => n)))
2020
+ G((n) => this.localAdapter.upsertMany(this.entityName, [n]).pipe(te(() => n)))
2006
2021
  );
2007
2022
  }
2008
2023
  /**
@@ -2027,7 +2042,7 @@ class ua {
2027
2042
  throw new Error(`Remote adapter does not support delete operation for ${this.entityName}`);
2028
2043
  const t = Array.isArray(e) ? e : [e];
2029
2044
  return this.remoteAdapter.delete(this.entityName, e).pipe(
2030
- V(() => this.localAdapter.deleteByIds(this.entityName, t))
2045
+ G(() => this.localAdapter.deleteByIds(this.entityName, t))
2031
2046
  );
2032
2047
  }
2033
2048
  // ============================================
@@ -2043,16 +2058,16 @@ class ua {
2043
2058
  * 4. 如果远程数据有变化,再次发射
2044
2059
  */
2045
2060
  #n(e) {
2046
- const t = this.#t().pipe(Re(() => Q([])));
2061
+ const t = this.#t().pipe(Ce(() => Q([])));
2047
2062
  let n = !1, s = "";
2048
2063
  const i = this.#s(e).pipe(
2049
- It((a) => n ? this.#r(a) !== s : !0),
2050
- Re(() => Fn)
2064
+ At((a) => n ? this.#r(a) !== s : !0),
2065
+ Ce(() => Un)
2051
2066
  // 远程失败时静默处理,保留缓存数据
2052
2067
  );
2053
- return Ln(
2068
+ return Fn(
2054
2069
  t.pipe(
2055
- It((a) => a.length > 0),
2070
+ At((a) => a.length > 0),
2056
2071
  // 只有有缓存时才发射
2057
2072
  te((a) => (n = !0, s = this.#r(a), a))
2058
2073
  ),
@@ -2084,8 +2099,8 @@ class ua {
2084
2099
  */
2085
2100
  #i(e) {
2086
2101
  return e.pipe(
2087
- Re((t) => this.#t().pipe(
2088
- V((n) => {
2102
+ Ce((t) => this.#t().pipe(
2103
+ G((n) => {
2089
2104
  if (n.length > 0)
2090
2105
  return Q(n);
2091
2106
  throw new et(t);
@@ -2099,7 +2114,7 @@ class ua {
2099
2114
  #s(e) {
2100
2115
  const t = e.where, n = Date.now();
2101
2116
  return this.remoteAdapter.fetchMetadata(this.entityName, t).pipe(
2102
- V((s) => {
2117
+ G((s) => {
2103
2118
  if (s.length === 0)
2104
2119
  return this.#o(e.onSyncStats, {
2105
2120
  remoteCount: 0,
@@ -2112,8 +2127,8 @@ class ua {
2112
2127
  }), Q([]);
2113
2128
  const i = s.map((a) => a.id);
2114
2129
  return this.localAdapter.getMetadataByIds(this.entityName, i).pipe(
2115
- V((a) => {
2116
- const o = $r(s, a), l = [...o.missingIds, ...o.staleIds];
2130
+ G((a) => {
2131
+ const o = Yr(s, a), l = [...o.missingIds, ...o.staleIds];
2117
2132
  return l.length === 0 ? this.#a(o.freshIds).pipe(
2118
2133
  te((c) => (this.#o(e.onSyncStats, {
2119
2134
  remoteCount: s.length,
@@ -2125,7 +2140,7 @@ class ua {
2125
2140
  durationMs: Date.now() - n
2126
2141
  }), c))
2127
2142
  ) : this.remoteAdapter.findByIds(this.entityName, l).pipe(
2128
- V((c) => c.length === 0 ? this.#a(o.freshIds).pipe(
2143
+ G((c) => c.length === 0 ? this.#a(o.freshIds).pipe(
2129
2144
  te((u) => (this.#o(e.onSyncStats, {
2130
2145
  remoteCount: s.length,
2131
2146
  missingCount: o.missingIds.length,
@@ -2136,7 +2151,7 @@ class ua {
2136
2151
  durationMs: Date.now() - n
2137
2152
  }), u))
2138
2153
  ) : this.localAdapter.upsertMany(this.entityName, c).pipe(
2139
- V(() => o.freshIds.length === 0 ? (this.#o(e.onSyncStats, {
2154
+ G(() => o.freshIds.length === 0 ? (this.#o(e.onSyncStats, {
2140
2155
  remoteCount: s.length,
2141
2156
  missingCount: o.missingIds.length,
2142
2157
  staleCount: o.staleIds.length,
@@ -2181,10 +2196,10 @@ class ua {
2181
2196
  * @returns 查询指纹字符串
2182
2197
  */
2183
2198
  #c(e) {
2184
- return Lt(e);
2199
+ return JSON.stringify(e);
2185
2200
  }
2186
2201
  }
2187
- class ys {
2202
+ class Es {
2188
2203
  /**
2189
2204
  * 刷新
2190
2205
  * 重新执行 SQL 查询
@@ -2193,7 +2208,7 @@ class ys {
2193
2208
  /**
2194
2209
  * 销毁
2195
2210
  */
2196
- #n = new Un(1);
2211
+ #n = new jn(1);
2197
2212
  /**
2198
2213
  * 是否首次运行
2199
2214
  * 标识查询是否为第一次执行
@@ -2295,12 +2310,12 @@ class ys {
2295
2310
  if (this.#t === !0) return;
2296
2311
  this.#t = !0;
2297
2312
  const e = this.options && typeof this.options == "object" && "where" in this.options ? this.options.where : void 0;
2298
- e && (lt(this.rxdb, e, this.entityType, this.relationEntityTypes), this.relationEntityTypes.forEach((t) => {
2313
+ e && (ut(this.rxdb, e, this.entityType, this.relationEntityTypes), this.relationEntityTypes.forEach((t) => {
2299
2314
  const n = this.depEntityTypeMap.get(t) || 0;
2300
2315
  this.depEntityTypeMap.set(t, n + 1);
2301
2316
  })), this.refresh$.pipe(
2302
- jn(this.destroy$),
2303
- Fe(),
2317
+ Yn(this.destroy$),
2318
+ Ue(),
2304
2319
  k(() => this.refreshCount++),
2305
2320
  x(() => this.runner())
2306
2321
  ).subscribe({
@@ -2347,8 +2362,8 @@ class ys {
2347
2362
  this.#e.next(this.refreshCount + 1);
2348
2363
  };
2349
2364
  }
2350
- var ms = /* @__PURE__ */ ((r) => (r.Synced = "Synced", r.Syncing = "Syncing", r.Never = "Never", r))(ms || {});
2351
- const Ve = (r) => Array.isArray(r) ? r : [r], Le = (r) => r ? [O(r).fingerprint] : [r], ye = (r) => r.map((e) => O(e).fingerprint), D = (r) => r?.parentId || null;
2365
+ var Rs = /* @__PURE__ */ ((r) => (r.Synced = "Synced", r.Syncing = "Syncing", r.Never = "Never", r))(Rs || {});
2366
+ const Ve = (r) => Array.isArray(r) ? r : [r], Fe = (r) => r ? [O(r).fingerprint] : [r], me = (r) => r.map((e) => O(e).fingerprint), D = (r) => r?.parentId || null;
2352
2367
  function* rn(r, e, t = {}) {
2353
2368
  const { maxLevel: n, maxDepth: s = 1e3 } = t, i = /* @__PURE__ */ new Set();
2354
2369
  let a = D(r), o = 1;
@@ -2359,7 +2374,7 @@ function* rn(r, e, t = {}) {
2359
2374
  yield { entity: l, level: o }, a = D(l), o++;
2360
2375
  }
2361
2376
  }
2362
- function gs(r, e, t, n) {
2377
+ function Cs(r, e, t, n) {
2363
2378
  if (e == null)
2364
2379
  return r.parentId === null;
2365
2380
  const s = /* @__PURE__ */ new Set();
@@ -2376,7 +2391,7 @@ function gs(r, e, t, n) {
2376
2391
  }
2377
2392
  return !1;
2378
2393
  }
2379
- function _s(r, e, t) {
2394
+ function Is(r, e, t) {
2380
2395
  const n = t.get(e);
2381
2396
  if (!n) return !1;
2382
2397
  for (const { entity: s } of rn(n, t))
@@ -2384,7 +2399,7 @@ function _s(r, e, t) {
2384
2399
  return !0;
2385
2400
  return !1;
2386
2401
  }
2387
- function Ge(r, e) {
2402
+ function Qe(r, e) {
2388
2403
  const t = /* @__PURE__ */ new Map();
2389
2404
  return r.forEach((n) => {
2390
2405
  const s = e(n);
@@ -2394,7 +2409,7 @@ function Ge(r, e) {
2394
2409
  function Tt(r, e) {
2395
2410
  return r.length !== e.length ? !0 : r.some((t, n) => t !== e[n]);
2396
2411
  }
2397
- const bs = (r, e) => {
2412
+ const As = (r, e) => {
2398
2413
  const t = r.options.where, n = e.filter((i) => !t || Y(i.patch, t));
2399
2414
  if (n.length === 0) return;
2400
2415
  const s = n.map((i) => r.serialize(i));
@@ -2435,22 +2450,22 @@ const bs = (r, e) => {
2435
2450
  const i = r.options, { before: a, after: o, orderBy: l } = i;
2436
2451
  if (!l?.length) return;
2437
2452
  const c = Array.from(r.resultEntitySet.values()), u = [...c, ...s], d = X(u, l);
2438
- let h;
2453
+ let p;
2439
2454
  if (o || a) {
2440
- const p = [...u];
2441
- o && !p.includes(o) && p.push(o), a && !p.includes(a) && p.push(a);
2442
- const m = X(p, l);
2455
+ const h = [...u];
2456
+ o && !h.includes(o) && h.push(o), a && !h.includes(a) && h.push(a);
2457
+ const m = X(h, l);
2443
2458
  if (o) {
2444
2459
  const f = m.findIndex((y) => y === o);
2445
- f !== -1 ? h = m.slice(f + 1).filter((y) => c.includes(y) || s.includes(y)) : h = c;
2460
+ f !== -1 ? p = m.slice(f + 1).filter((y) => c.includes(y) || s.includes(y)) : p = c;
2446
2461
  } else {
2447
2462
  const f = m.findIndex((y) => y === a);
2448
- f !== -1 ? h = m.slice(0, f).filter((y) => c.includes(y) || s.includes(y)) : h = c;
2463
+ f !== -1 ? p = m.slice(0, f).filter((y) => c.includes(y) || s.includes(y)) : p = c;
2449
2464
  }
2450
2465
  } else
2451
- h = d;
2452
- if (!Tt(c, h)) return;
2453
- r.next(h, !0);
2466
+ p = d;
2467
+ if (!Tt(c, p)) return;
2468
+ r.next(p, !0);
2454
2469
  break;
2455
2470
  }
2456
2471
  case "count": {
@@ -2459,21 +2474,21 @@ const bs = (r, e) => {
2459
2474
  break;
2460
2475
  }
2461
2476
  case "findDescendants": {
2462
- const i = r.options, a = Array.from(r.resultEntitySet.values()), o = Ge(a, (c) => c.id), l = s.filter(
2463
- (c) => gs(c, i.entityId, o, i.level)
2477
+ const i = r.options, a = Array.from(r.resultEntitySet.values()), o = Qe(a, (c) => c.id), l = s.filter(
2478
+ (c) => Cs(c, i.entityId, o, i.level)
2464
2479
  );
2465
2480
  if (l.length === 0) return;
2466
2481
  l.forEach((c) => r.resultEntitySet.add(c)), r.next(Array.from(r.resultEntitySet.values()), !0);
2467
2482
  break;
2468
2483
  }
2469
2484
  case "findAncestors": {
2470
- const i = r.options, o = [...Array.from(r.resultEntitySet.values()), ...s], l = Ge(o, (u) => u.id), c = s.filter((u) => u.id === i.entityId ? !0 : i.entityId ? _s(u, i.entityId, l) : !1);
2485
+ const i = r.options, o = [...Array.from(r.resultEntitySet.values()), ...s], l = Qe(o, (u) => u.id), c = s.filter((u) => u.id === i.entityId ? !0 : i.entityId ? Is(u, i.entityId, l) : !1);
2471
2486
  if (c.length === 0) return;
2472
2487
  c.forEach((u) => r.resultEntitySet.add(u)), r.next(Array.from(r.resultEntitySet.values()), !0);
2473
2488
  break;
2474
2489
  }
2475
2490
  }
2476
- }, Qe = (r, e) => {
2491
+ }, Je = (r, e) => {
2477
2492
  const t = [], n = [], s = () => {
2478
2493
  n.push(["match_where", "not_match_relation_where"]), t.push(["match_relation_where"]);
2479
2494
  };
@@ -2495,9 +2510,9 @@ const bs = (r, e) => {
2495
2510
  t.push(["match_where"], ["match_relation_where"]);
2496
2511
  break;
2497
2512
  }
2498
- const i = xr(r, e, t, n);
2499
- i.refresh ? r.refresh() : i.recalculate && bs(r, i.current_entities);
2500
- }, ws = (r, e) => {
2513
+ const i = Fr(r, e, t, n);
2514
+ i.refresh ? r.refresh() : i.recalculate && As(r, i.current_entities);
2515
+ }, Ts = (r, e) => {
2501
2516
  const t = new Set(e.map((n) => n.id));
2502
2517
  switch (r.type) {
2503
2518
  case "findAll": {
@@ -2530,7 +2545,7 @@ const bs = (r, e) => {
2530
2545
  break;
2531
2546
  }
2532
2547
  case "findDescendants": {
2533
- const n = r.options, s = Array.from(r.resultEntitySet.values()), i = Ge(s, (c) => c.id);
2548
+ const n = r.options, s = Array.from(r.resultEntitySet.values()), i = Qe(s, (c) => c.id);
2534
2549
  let a = !1;
2535
2550
  const o = s.filter((c) => {
2536
2551
  if (t.has(c.id))
@@ -2552,7 +2567,7 @@ const bs = (r, e) => {
2552
2567
  break;
2553
2568
  }
2554
2569
  }
2555
- }, Je = (r, e) => {
2570
+ }, Xe = (r, e) => {
2556
2571
  const t = [], n = [];
2557
2572
  switch (r.type) {
2558
2573
  case "find":
@@ -2576,13 +2591,13 @@ const bs = (r, e) => {
2576
2591
  t.push(["match_where"]);
2577
2592
  break;
2578
2593
  }
2579
- const s = Nr(r, e, t, n);
2580
- s.refresh ? r.refresh() : s.recalculate && ws(r, e);
2594
+ const s = Ur(r, e, t, n);
2595
+ s.refresh ? r.refresh() : s.recalculate && Ts(r, e);
2581
2596
  }, N = (r) => {
2582
2597
  if (r)
2583
2598
  return r.id;
2584
2599
  };
2585
- class vs {
2600
+ class Ss {
2586
2601
  constructor(e, t) {
2587
2602
  this.serialize = t, e.forEach((n) => this.dataById.set(n.id, n));
2588
2603
  }
@@ -2617,7 +2632,7 @@ class vs {
2617
2632
  return this.dataById.get(e);
2618
2633
  }
2619
2634
  }
2620
- const Es = (r, e, t) => {
2635
+ const Ms = (r, e, t) => {
2621
2636
  const n = new Set(r.map((d) => d.id)), s = r.filter((d) => !e || t(d.patch, e)), i = r.filter((d) => !e || t(d.inversePatch, e)), a = new Set(s.map((d) => d.id)), o = new Set(i.map((d) => d.id)), l = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
2622
2637
  return s.forEach((d) => {
2623
2638
  o.has(d.id) ? u.add(d.id) : l.add(d.id);
@@ -2631,7 +2646,7 @@ const Es = (r, e, t) => {
2631
2646
  newlyUnmatchedIds: c,
2632
2647
  stillMatchedIds: u
2633
2648
  };
2634
- }, Rs = (r, e, t) => {
2649
+ }, Os = (r, e, t) => {
2635
2650
  const n = r.options, s = n.where, i = Array.from(r.resultEntitySet.values()), a = [];
2636
2651
  for (const u of i) {
2637
2652
  const d = N(u);
@@ -2639,25 +2654,25 @@ const Es = (r, e, t) => {
2639
2654
  a.push(u);
2640
2655
  continue;
2641
2656
  }
2642
- const h = t.getData(d);
2643
- h?.patch ? (Object.assign(u, h.patch), (!s || Y(u, s)) && a.push(u)) : a.push(u);
2657
+ const p = t.getData(d);
2658
+ p?.patch ? (Object.assign(u, p.patch), (!s || Y(u, s)) && a.push(u)) : a.push(u);
2644
2659
  }
2645
2660
  const o = new Set(a.map((u) => N(u)).filter(Boolean)), l = Array.from(e.newlyMatchedIds).filter((u) => !o.has(u)).map((u) => t.getSerializedUpdate(u)).filter((u) => !!u);
2646
2661
  let c = [...a, ...l];
2647
2662
  n.orderBy?.length && (c = X(c, n.orderBy)), r.next(c, !0);
2648
- }, Cs = (r, e) => {
2663
+ }, xs = (r, e) => {
2649
2664
  const n = Array.from(r.resultEntitySet.values()).some((i) => {
2650
2665
  const a = N(i);
2651
2666
  return !!a && e.updatedIds.has(a);
2652
2667
  }), s = e.newlyMatchedIds.size > 0;
2653
2668
  (n || s) && r.refresh();
2654
- }, Is = (r, e) => {
2669
+ }, Ns = (r, e) => {
2655
2670
  const n = Array.from(r.resultEntitySet.values()).some((i) => {
2656
2671
  const a = N(i);
2657
2672
  return !!a && e.updatedIds.has(a);
2658
2673
  }), s = e.newlyMatchedIds.size > 0;
2659
2674
  (n || s) && r.refresh();
2660
- }, Ts = (r, e, t) => {
2675
+ }, Ps = (r, e, t) => {
2661
2676
  const n = r.options, s = n.where;
2662
2677
  if (r.result === null || r.result === void 0) {
2663
2678
  e.newlyMatchedIds.size > 0 && r.refresh();
@@ -2680,14 +2695,14 @@ const Es = (r, e, t) => {
2680
2695
  return;
2681
2696
  }
2682
2697
  e.newlyMatchedIds.size > 0 && r.refresh();
2683
- }, As = (r, e) => {
2698
+ }, $s = (r, e) => {
2684
2699
  const t = r.result || 0, n = e.newlyMatchedIds.size, s = e.newlyUnmatchedIds.size;
2685
2700
  if (n > 0 || s > 0) {
2686
2701
  const i = Math.max(0, t + n - s);
2687
2702
  r.next(i);
2688
2703
  }
2689
2704
  };
2690
- class Oe {
2705
+ class xe {
2691
2706
  constructor(e, t) {
2692
2707
  this.cache = e, this.oldResultMap = t;
2693
2708
  }
@@ -2840,15 +2855,15 @@ class Oe {
2840
2855
  return !1;
2841
2856
  }
2842
2857
  }
2843
- const Ss = (r, e, t, n) => {
2858
+ const Bs = (r, e, t, n) => {
2844
2859
  const s = r.options, i = s.entityId, a = s.level, o = Array.from(r.resultEntitySet.values()), l = /* @__PURE__ */ new Map();
2845
2860
  o.forEach((y) => {
2846
2861
  const g = N(y);
2847
2862
  g && l.set(g, y);
2848
2863
  });
2849
- const c = new Oe(n, l);
2864
+ const c = new xe(n, l);
2850
2865
  let u = !1;
2851
- const h = o.filter((y) => {
2866
+ const p = o.filter((y) => {
2852
2867
  const g = N(y);
2853
2868
  if (!g) return !0;
2854
2869
  if (t.updatedIds.has(g)) {
@@ -2874,7 +2889,7 @@ const Ss = (r, e, t, n) => {
2874
2889
  _ && (Object.assign(y, _.patch), u = !0);
2875
2890
  }
2876
2891
  return y;
2877
- }), p = [];
2892
+ }), h = [];
2878
2893
  if (e.filter((y) => {
2879
2894
  const g = y.id, _ = l.has(g), v = "parentId" in y.patch;
2880
2895
  return t.matchNowIds.has(g) && !_ && v;
@@ -2883,7 +2898,7 @@ const Ss = (r, e, t, n) => {
2883
2898
  if (!g) return;
2884
2899
  const { isDescendant: _, level: v } = c.isEntityDescendant(g, i);
2885
2900
  if (_ && (a === void 0 || v <= a)) {
2886
- u = !0, p.push(g);
2901
+ u = !0, h.push(g);
2887
2902
  const b = N(g);
2888
2903
  b && l.set(b, g);
2889
2904
  }
@@ -2893,27 +2908,27 @@ const Ss = (r, e, t, n) => {
2893
2908
  const _ = n.getSerializedUpdate(g);
2894
2909
  if (_) {
2895
2910
  const { isDescendant: v, level: b } = c.isEntityDescendant(_, i);
2896
- v && (a === void 0 || b <= a) && (h.some((E) => N(E) === g) || p.some((E) => N(E) === g) || l.has(g) || (u = !0, p.push(_), l.set(g, _)));
2911
+ v && (a === void 0 || b <= a) && (p.some((E) => N(E) === g) || h.some((E) => N(E) === g) || l.has(g) || (u = !0, h.push(_), l.set(g, _)));
2897
2912
  }
2898
2913
  }
2899
2914
  }), !u)
2900
2915
  return;
2901
- const f = [...h, ...p];
2916
+ const f = [...p, ...h];
2902
2917
  r.next(f, !0);
2903
- }, Ms = (r, e, t, n) => {
2918
+ }, Ds = (r, e, t, n) => {
2904
2919
  const i = r.options.entityId, a = Array.from(r.resultEntitySet.values()), o = /* @__PURE__ */ new Map();
2905
2920
  a.forEach((b) => {
2906
2921
  const w = N(b);
2907
2922
  w && o.set(w, b);
2908
2923
  });
2909
- const l = new Oe(n, o), c = () => {
2924
+ const l = new xe(n, o), c = () => {
2910
2925
  if (!i)
2911
2926
  return;
2912
2927
  const b = n.getSerializedUpdate(i);
2913
2928
  return b || o.get(i);
2914
2929
  };
2915
2930
  let u = !1;
2916
- const h = (i ? t.updatedIds.has(i) : !1) && i ? n.getData(i) : void 0, m = h && "parentId" in h.patch, y = a.filter((b) => {
2931
+ const p = (i ? t.updatedIds.has(i) : !1) && i ? n.getData(i) : void 0, m = p && "parentId" in p.patch, y = a.filter((b) => {
2917
2932
  const w = N(b);
2918
2933
  if (!w) return !0;
2919
2934
  if (t.newlyUnmatchedIds.has(w))
@@ -2924,10 +2939,10 @@ const Ss = (r, e, t, n) => {
2924
2939
  } else if (t.updatedIds.has(w) && t.matchNowIds.has(w)) {
2925
2940
  const E = n.getData(w);
2926
2941
  if (E && "parentId" in E.patch) {
2927
- const U = n.getSerializedUpdate(w), A = c();
2928
- if (!A)
2942
+ const U = n.getSerializedUpdate(w), T = c();
2943
+ if (!T)
2929
2944
  return !0;
2930
- if (U && !l.isEntityAncestor(A, U))
2945
+ if (U && !l.isEntityAncestor(T, U))
2931
2946
  return u = !0, !1;
2932
2947
  }
2933
2948
  }
@@ -2955,17 +2970,17 @@ const Ss = (r, e, t, n) => {
2955
2970
  return;
2956
2971
  const v = [...y, ...g];
2957
2972
  r.next(v, !0);
2958
- }, Os = (r, e, t, n, s, i) => {
2959
- const o = r.options.entityId, l = r.result || 0, c = /* @__PURE__ */ new Map(), u = new Oe(n, c);
2960
- let d = !1, h = 0;
2961
- for (const p of e) {
2962
- const m = !s || i(p.inversePatch, s), f = n.getSerializedBefore(p.id, p.inversePatch), y = u.isEntityDescendantForCount(f, o);
2973
+ }, Ls = (r, e, t, n, s, i) => {
2974
+ const o = r.options.entityId, l = r.result || 0, c = /* @__PURE__ */ new Map(), u = new xe(n, c);
2975
+ let d = !1, p = 0;
2976
+ for (const h of e) {
2977
+ const m = !s || i(h.inversePatch, s), f = n.getSerializedBefore(h.id, h.inversePatch), y = u.isEntityDescendantForCount(f, o);
2963
2978
  if (y === void 0) {
2964
2979
  d = !0;
2965
2980
  break;
2966
2981
  }
2967
- const g = m && y, _ = !s || i(p.patch, s), v = u.isEntityDescendantForCount(
2968
- n.getSerializedUpdate(p.id),
2982
+ const g = m && y, _ = !s || i(h.patch, s), v = u.isEntityDescendantForCount(
2983
+ n.getSerializedUpdate(h.id),
2969
2984
  o
2970
2985
  );
2971
2986
  if (v === void 0) {
@@ -2973,15 +2988,15 @@ const Ss = (r, e, t, n) => {
2973
2988
  break;
2974
2989
  }
2975
2990
  const b = _ && v;
2976
- b && !g ? h++ : !b && g && h--;
2991
+ b && !g ? p++ : !b && g && p--;
2977
2992
  }
2978
2993
  if (d)
2979
2994
  r.refresh();
2980
- else if (h !== 0) {
2981
- const p = Math.max(0, l + h);
2982
- r.next(p);
2995
+ else if (p !== 0) {
2996
+ const h = Math.max(0, l + p);
2997
+ r.next(h);
2983
2998
  }
2984
- }, xs = (r, e, t, n, s, i) => {
2999
+ }, Fs = (r, e, t, n, s, i) => {
2985
3000
  const o = r.options.entityId, l = r.result || 0;
2986
3001
  if (!o) {
2987
3002
  r.refresh();
@@ -2992,12 +3007,12 @@ const Ss = (r, e, t, n) => {
2992
3007
  r.refresh();
2993
3008
  return;
2994
3009
  }
2995
- const u = /* @__PURE__ */ new Map(), d = new Oe(n, u), h = n.getSerializedBefore(c.id, c.inversePatch), p = n.getSerializedUpdate(c.id);
2996
- if (!h || !p) {
3010
+ const u = /* @__PURE__ */ new Map(), d = new xe(n, u), p = n.getSerializedBefore(c.id, c.inversePatch), h = n.getSerializedUpdate(c.id);
3011
+ if (!p || !h) {
2997
3012
  r.refresh();
2998
3013
  return;
2999
3014
  }
3000
- const m = D(h), f = D(p);
3015
+ const m = D(p), f = D(h);
3001
3016
  if (m !== f) {
3002
3017
  r.refresh();
3003
3018
  return;
@@ -3012,8 +3027,8 @@ const Ss = (r, e, t, n) => {
3012
3027
  w || (w = {}, _.set(b, w));
3013
3028
  const E = !s || i(v.inversePatch, s);
3014
3029
  if (w.before === void 0) {
3015
- const xe = n.getSerializedBefore(v.id, v.inversePatch);
3016
- w.before = d.isEntityAncestorForCount(h, xe);
3030
+ const Ne = n.getSerializedBefore(v.id, v.inversePatch);
3031
+ w.before = d.isEntityAncestorForCount(p, Ne);
3017
3032
  }
3018
3033
  const B = w.before;
3019
3034
  if (B === void 0) {
@@ -3022,15 +3037,15 @@ const Ss = (r, e, t, n) => {
3022
3037
  }
3023
3038
  const U = !s || i(v.patch, s);
3024
3039
  if (w.after === void 0) {
3025
- const xe = n.getSerializedUpdate(v.id);
3026
- w.after = d.isEntityAncestorForCount(p, xe);
3040
+ const Ne = n.getSerializedUpdate(v.id);
3041
+ w.after = d.isEntityAncestorForCount(h, Ne);
3027
3042
  }
3028
- const A = w.after;
3029
- if (A === void 0) {
3043
+ const T = w.after;
3044
+ if (T === void 0) {
3030
3045
  g = !0;
3031
3046
  break;
3032
3047
  }
3033
- const q = E && B, Z = U && A;
3048
+ const q = E && B, Z = U && T;
3034
3049
  Z && !q ? y++ : !Z && q && y--;
3035
3050
  }
3036
3051
  if (g)
@@ -3039,39 +3054,39 @@ const Ss = (r, e, t, n) => {
3039
3054
  const v = Math.max(0, l + y);
3040
3055
  r.next(v);
3041
3056
  }
3042
- }, Ns = (r, e) => {
3043
- const t = r.options.where, n = new vs(e, (i) => r.serialize(i)), s = Es(e, t, Y);
3057
+ }, Us = (r, e) => {
3058
+ const t = r.options.where, n = new Ss(e, (i) => r.serialize(i)), s = Ms(e, t, Y);
3044
3059
  switch (r.type) {
3045
3060
  case "findAll":
3046
- Rs(r, s, n);
3061
+ Os(r, s, n);
3047
3062
  break;
3048
3063
  case "find":
3049
- Cs(r, s);
3064
+ xs(r, s);
3050
3065
  break;
3051
3066
  case "findOne":
3052
3067
  case "findOneOrFail":
3053
- Ts(r, s, n);
3068
+ Ps(r, s, n);
3054
3069
  break;
3055
3070
  case "findByCursor":
3056
- Is(r, s);
3071
+ Ns(r, s);
3057
3072
  break;
3058
3073
  case "count":
3059
- As(r, s);
3074
+ $s(r, s);
3060
3075
  break;
3061
3076
  case "findDescendants":
3062
- Ss(r, e, s, n);
3077
+ Bs(r, e, s, n);
3063
3078
  break;
3064
3079
  case "findAncestors":
3065
- Ms(r, e, s, n);
3080
+ Ds(r, e, s, n);
3066
3081
  break;
3067
3082
  case "countDescendants":
3068
- Os(r, e, s, n, t, Y);
3083
+ Ls(r, e, s, n, t, Y);
3069
3084
  break;
3070
3085
  case "countAncestors":
3071
- xs(r, e, s, n, t, Y);
3086
+ Fs(r, e, s, n, t, Y);
3072
3087
  break;
3073
3088
  }
3074
- }, Xe = (r, e) => {
3089
+ }, Ze = (r, e) => {
3075
3090
  const t = [], n = [];
3076
3091
  switch (r.type) {
3077
3092
  case "find":
@@ -3135,10 +3150,10 @@ const Ss = (r, e, t, n) => {
3135
3150
  t.push(["match_where"]), t.push(["match_where_before"]), t.push(["match_relation_where"]);
3136
3151
  break;
3137
3152
  }
3138
- const s = Pr(r, e, t, n);
3139
- s.refresh ? r.refresh() : s.recalculate && Ns(r, e);
3153
+ const s = jr(r, e, t, n);
3154
+ s.refresh ? r.refresh() : s.recalculate && Us(r, e);
3140
3155
  };
3141
- class Ps {
3156
+ class js {
3142
3157
  /**
3143
3158
  * 构造函数
3144
3159
  *
@@ -3173,7 +3188,7 @@ class Ps {
3173
3188
  * @returns 查询任务对象,包含 result$ 用于订阅查询结果
3174
3189
  */
3175
3190
  createTask(e) {
3176
- const t = Lt(e.options);
3191
+ const t = JSON.stringify(e.options);
3177
3192
  let n = this.#e.get(t);
3178
3193
  return n || (n = this.#o(t, e), this.#e.set(t, n)), n.result$ = this.#u(n), n;
3179
3194
  }
@@ -3194,7 +3209,7 @@ class Ps {
3194
3209
  * @returns 新创建的查询任务
3195
3210
  */
3196
3211
  #o(e, t) {
3197
- return new ys({
3212
+ return new Es({
3198
3213
  cacheKey: e,
3199
3214
  ...t,
3200
3215
  entityType: this.EntityType,
@@ -3274,13 +3289,13 @@ class Ps {
3274
3289
  Tn(Array.from(this.#e.values()), (i) => {
3275
3290
  switch (t.type) {
3276
3291
  case ne:
3277
- (this.#t.get(i.type) || Qe)(i, s);
3292
+ (this.#t.get(i.type) || Je)(i, s);
3278
3293
  break;
3279
3294
  case oe:
3280
- (this.#r.get(i.type) || Xe)(i, s);
3295
+ (this.#r.get(i.type) || Ze)(i, s);
3281
3296
  break;
3282
3297
  case ce:
3283
- (this.#i.get(i.type) || Je)(i, s);
3298
+ (this.#i.get(i.type) || Xe)(i, s);
3284
3299
  break;
3285
3300
  }
3286
3301
  });
@@ -3289,7 +3304,7 @@ class Ps {
3289
3304
  this.#s = e, this.rxdb.addEventListener(ne, e), this.rxdb.addEventListener(oe, e), this.rxdb.addEventListener(ce, e);
3290
3305
  }
3291
3306
  }
3292
- class $s {
3307
+ class Ys {
3293
3308
  constructor(e, t) {
3294
3309
  this.rxdb = e, this.EntityType = t;
3295
3310
  }
@@ -3326,7 +3341,7 @@ class $s {
3326
3341
  n.origin = { ...t }, Object.assign(e, t);
3327
3342
  }
3328
3343
  }
3329
- class sn extends $s {
3344
+ class sn extends Ys {
3330
3345
  static _STATIC_METHODS = [
3331
3346
  ...super._STATIC_METHODS,
3332
3347
  "get",
@@ -3370,7 +3385,7 @@ class sn extends $s {
3370
3385
  const n = I(t);
3371
3386
  this.sync = n.sync || e.config.sync;
3372
3387
  const { local: s, remote: i } = this.sync, a = !s && !!i;
3373
- this.primary$ = a ? this.remote$ : this.local$, this.queryManager = new Ps(e, t, this);
3388
+ this.primary$ = a ? this.remote$ : this.local$, this.queryManager = new js(e, t, this);
3374
3389
  }
3375
3390
  /**
3376
3391
  * 根据 id 获取实体
@@ -3400,7 +3415,7 @@ class sn extends $s {
3400
3415
  return this.queryManager.createTask({
3401
3416
  options: { type: "get", options: e },
3402
3417
  runner: n,
3403
- getFingerprint: Le
3418
+ getFingerprint: Fe
3404
3419
  }).result$;
3405
3420
  }
3406
3421
  /**
@@ -3416,7 +3431,7 @@ class sn extends $s {
3416
3431
  return this.queryManager.createTask({
3417
3432
  options: { type: "findOne", options: e },
3418
3433
  runner: t,
3419
- getFingerprint: Le
3434
+ getFingerprint: Fe
3420
3435
  }).result$;
3421
3436
  }
3422
3437
  /**
@@ -3435,7 +3450,7 @@ class sn extends $s {
3435
3450
  return this.queryManager.createTask({
3436
3451
  options: { type: "findOneOrFail", options: e },
3437
3452
  runner: t,
3438
- getFingerprint: Le
3453
+ getFingerprint: Fe
3439
3454
  }).result$;
3440
3455
  }
3441
3456
  /**
@@ -3450,7 +3465,7 @@ class sn extends $s {
3450
3465
  return this.queryManager.createTask({
3451
3466
  options: { type: "find", options: e },
3452
3467
  runner: t,
3453
- getFingerprint: ye
3468
+ getFingerprint: me
3454
3469
  }).result$;
3455
3470
  }
3456
3471
  /**
@@ -3466,7 +3481,7 @@ class sn extends $s {
3466
3481
  return this.queryManager.createTask({
3467
3482
  options: { type: "findAll", options: e },
3468
3483
  runner: t,
3469
- getFingerprint: ye
3484
+ getFingerprint: me
3470
3485
  }).result$;
3471
3486
  }
3472
3487
  /**
@@ -3481,8 +3496,8 @@ class sn extends $s {
3481
3496
  if (e.before && e.after)
3482
3497
  throw new R("before and after cannot be used together in cursor-based pagination");
3483
3498
  let n = structuredClone(e.where);
3484
- const s = Bs(e);
3485
- s && (n = Ds(n, s));
3499
+ const s = zs(e);
3500
+ s && (n = ks(n, s));
3486
3501
  const i = () => this.primary$.pipe(
3487
3502
  x((a) => a.find({ ...e, where: n })),
3488
3503
  k(this._setLocals)
@@ -3490,7 +3505,7 @@ class sn extends $s {
3490
3505
  return this.queryManager.createTask({
3491
3506
  options: { type: "findByCursor", options: e },
3492
3507
  runner: i,
3493
- getFingerprint: ye
3508
+ getFingerprint: me
3494
3509
  }).result$;
3495
3510
  }
3496
3511
  /**
@@ -3545,7 +3560,7 @@ class sn extends $s {
3545
3560
  };
3546
3561
  _setLocals = (e) => e.forEach(this._setLocal);
3547
3562
  }
3548
- const Bs = (r) => {
3563
+ const zs = (r) => {
3549
3564
  const e = r.after || r.before;
3550
3565
  if (!e) return null;
3551
3566
  const t = !!r.after;
@@ -3560,14 +3575,14 @@ const Bs = (r) => {
3560
3575
  for (let s = 0; s < r.orderBy.length; s++) {
3561
3576
  const { field: i, sort: a } = r.orderBy[s], l = a === "asc" === t, c = [];
3562
3577
  for (let d = 0; d < s; d++) {
3563
- const h = r.orderBy[d].field;
3564
- c.push({ field: h, operator: "=", value: e[h] });
3578
+ const p = r.orderBy[d].field;
3579
+ c.push({ field: p, operator: "=", value: e[p] });
3565
3580
  }
3566
3581
  const u = l ? ">" : "<";
3567
3582
  c.push({ field: i, operator: u, value: e[i] }), n.push({ combinator: "and", rules: c });
3568
3583
  }
3569
3584
  return { combinator: "or", rules: n };
3570
- }, Ds = (r, e) => r.combinator === "and" ? { ...r, rules: [...r.rules, e] } : { combinator: "and", rules: [r, e] };
3585
+ }, ks = (r, e) => r.combinator === "and" ? { ...r, rules: [...r.rules, e] } : { combinator: "and", rules: [r, e] };
3571
3586
  class an {
3572
3587
  constructor(e) {
3573
3588
  this.rxdb = e;
@@ -3583,17 +3598,17 @@ class an {
3583
3598
  this.repository_map.set(e, t);
3584
3599
  }
3585
3600
  }
3586
- class da extends an {
3601
+ class ga extends an {
3587
3602
  }
3588
- class ha extends an {
3603
+ class _a extends an {
3589
3604
  }
3590
- class pa {
3605
+ class ba {
3591
3606
  constructor(e) {
3592
3607
  this.rxdb = e;
3593
3608
  }
3594
3609
  }
3595
- const At = 100;
3596
- class Ls extends sn {
3610
+ const St = 100;
3611
+ class Ws extends sn {
3597
3612
  static _STATIC_METHODS = [
3598
3613
  ...super._STATIC_METHODS,
3599
3614
  "findDescendants",
@@ -3613,7 +3628,7 @@ class Ls extends sn {
3613
3628
  return this.queryManager.createTask({
3614
3629
  options: { type: "findDescendants", options: e },
3615
3630
  runner: t,
3616
- getFingerprint: ye
3631
+ getFingerprint: me
3617
3632
  }).result$;
3618
3633
  }
3619
3634
  /**
@@ -3640,7 +3655,7 @@ class Ls extends sn {
3640
3655
  return this.queryManager.createTask({
3641
3656
  options: { type: "findAncestors", options: e },
3642
3657
  runner: t,
3643
- getFingerprint: ye
3658
+ getFingerprint: me
3644
3659
  }).result$;
3645
3660
  }
3646
3661
  /**
@@ -3657,10 +3672,10 @@ class Ls extends sn {
3657
3672
  }
3658
3673
  #e(e) {
3659
3674
  const t = { ...e }, n = t.level ?? 0;
3660
- return n < 0 ? t.level = 0 : n > At ? t.level = At : t.level = n, t.entityId = t.entityId ?? null, t;
3675
+ return n < 0 ? t.level = 0 : n > St ? t.level = St : t.level = n, t.entityId = t.entityId ?? null, t;
3661
3676
  }
3662
3677
  }
3663
- class Fs {
3678
+ class Hs {
3664
3679
  /**
3665
3680
  * 创建实体状态实例
3666
3681
  *
@@ -3711,7 +3726,7 @@ class Fs {
3711
3726
  * 每次调用 checkChange 时发布最新的 patches 数组
3712
3727
  * 使用 shareReplay(1) 确保新订阅者能立即收到最近的变更记录
3713
3728
  */
3714
- #t = new Yn();
3729
+ #t = new zn();
3715
3730
  /**
3716
3731
  * 状态快照数组
3717
3732
  * 存储实体在不同时间点的完整状态,用于支持撤销/重做功能
@@ -3835,7 +3850,7 @@ class Fs {
3835
3850
  * 例如:patch = { name: 'new' } → inversePatch = { name: 'old' }
3836
3851
  */
3837
3852
  get inversePatch() {
3838
- return this.patch && An(this.origin, Object.keys(this.patch)) || null;
3853
+ return this.patch && Sn(this.origin, Object.keys(this.patch)) || null;
3839
3854
  }
3840
3855
  /**
3841
3856
  * 获取变化
@@ -3977,10 +3992,10 @@ class Fs {
3977
3992
  */
3978
3993
  addRelationEntity(e, t) {
3979
3994
  const n = this.getRelationCache(e);
3980
- if (e.kind === T.MANY_TO_MANY) {
3981
- const s = e.junctionEntityType, i = e.name + "Id", a = e.mappedProperty + "Id", o = (h) => h instanceof s && h[i] === t.id && h[a] === this.target.id;
3995
+ if (e.kind === A.MANY_TO_MANY) {
3996
+ const s = e.junctionEntityType, i = e.name + "Id", a = e.mappedProperty + "Id", o = (p) => p instanceof s && p[i] === t.id && p[a] === this.target.id;
3982
3997
  if (Array.from(n.values()).find(o)) return;
3983
- const c = I(t.constructor).relations.find((h) => h.name === e.mappedProperty);
3998
+ const c = I(t.constructor).relations.find((p) => p.name === e.mappedProperty);
3984
3999
  let u, d;
3985
4000
  c && (u = O(t).getRelationCache(c), d = Array.from(u.values()).find(o)), (!d || O(d).removed) && (d = new s({
3986
4001
  [i]: t.id,
@@ -4008,7 +4023,7 @@ class Fs {
4008
4023
  */
4009
4024
  removeRelationEntity(e, t) {
4010
4025
  const n = this.getRelationCache(e);
4011
- if (e.kind === T.MANY_TO_MANY) {
4026
+ if (e.kind === A.MANY_TO_MANY) {
4012
4027
  const s = e.junctionEntityType, i = e.name + "Id", a = e.mappedProperty + "Id", o = Array.from(n.values()).find(
4013
4028
  (l) => l instanceof s && l[i] === t.id && l[a] === this.target.id
4014
4029
  );
@@ -4057,7 +4072,7 @@ class Fs {
4057
4072
  this._patch_cache = void 0, this._fingerprint = void 0;
4058
4073
  }
4059
4074
  }
4060
- const Us = (r) => {
4075
+ const Ks = (r) => {
4061
4076
  const e = O(r), t = I(r.constructor), n = () => e.checkChange();
4062
4077
  let s;
4063
4078
  const i = {
@@ -4067,16 +4082,16 @@ const Us = (r) => {
4067
4082
  * 同时根据 metadata 配置进行类型转换
4068
4083
  */
4069
4084
  set: (a, o, l, c) => {
4070
- if (Dt(a[o], l)) return !0;
4071
- if (Sn(o) === !1 && (e.markChanged(o), e.modified = !0, clearTimeout(s), s = setTimeout(() => n(), 0), l === null && t.isForeignKey(o))) {
4085
+ if (Lt(a[o], l)) return !0;
4086
+ if (Mn(o) === !1 && (e.markChanged(o), e.modified = !0, clearTimeout(s), s = setTimeout(() => n(), 0), l === null && t.isForeignKey(o))) {
4072
4087
  const u = t.foreignKeyRelationMap.get(o);
4073
- u && (u.kind === T.MANY_TO_ONE || u.kind === T.ONE_TO_ONE) && e.cleanRelationEntity(u);
4088
+ u && (u.kind === A.MANY_TO_ONE || u.kind === A.ONE_TO_ONE) && e.cleanRelationEntity(u);
4074
4089
  }
4075
4090
  return Reflect.set(a, o, l, c);
4076
4091
  }
4077
4092
  };
4078
4093
  return new Proxy(r, i);
4079
- }, js = (r, e, t) => {
4094
+ }, qs = (r, e, t) => {
4080
4095
  const n = t.rxdb.schemaManager.getEntityType(r.mappedEntity, r.mappedNamespace);
4081
4096
  if (!n) throw new R(`mapped entity not found: ${r.mappedEntity}`);
4082
4097
  const s = r.name + "Id", i = r.name + "$";
@@ -4087,8 +4102,8 @@ const Us = (r) => {
4087
4102
  * 创建一个可观察对象,通过外键ID获取关联实体
4088
4103
  * 提供set和remove方法操作关系
4089
4104
  */
4090
- case T.MANY_TO_ONE:
4091
- case T.ONE_TO_ONE:
4105
+ case A.MANY_TO_ONE:
4106
+ case A.ONE_TO_ONE:
4092
4107
  a = function() {
4093
4108
  const o = this, l = O(o), c = new J(o[s]), u = c.asObservable().pipe(
4094
4109
  x((d) => d ? t.getRepository(n).get(d) : Q(null)),
@@ -4110,7 +4125,7 @@ const Us = (r) => {
4110
4125
  * 创建一个可观察对象,查询所有关联到当前实体的实体集合
4111
4126
  * 提供add和remove方法操作关系集合
4112
4127
  */
4113
- case T.ONE_TO_MANY:
4128
+ case A.ONE_TO_MANY:
4114
4129
  a = function() {
4115
4130
  const o = r.mappedProperty + "Id", l = r.mappedProperty + "$", c = this, u = O(c), d = ae(
4116
4131
  () => t.getRepository(n).findAll({
@@ -4125,7 +4140,7 @@ const Us = (r) => {
4125
4140
  ]
4126
4141
  }
4127
4142
  })
4128
- ), h = ae(
4143
+ ), p = ae(
4129
4144
  () => t.getRepository(n).count({
4130
4145
  where: {
4131
4146
  combinator: "and",
@@ -4139,12 +4154,12 @@ const Us = (r) => {
4139
4154
  }
4140
4155
  })
4141
4156
  );
4142
- return M(d, "count$", h), M(d, "add", (...p) => {
4143
- p.forEach((m) => {
4157
+ return M(d, "count$", p), M(d, "add", (...h) => {
4158
+ h.forEach((m) => {
4144
4159
  u.addRelationEntity(r, m), m[l].set(c);
4145
4160
  });
4146
- }), M(d, "remove", (...p) => {
4147
- p.forEach((m) => {
4161
+ }), M(d, "remove", (...h) => {
4162
+ h.forEach((m) => {
4148
4163
  u.removeRelationEntity(r, m), m[l].remove();
4149
4164
  });
4150
4165
  }), Object.freeze(d);
@@ -4156,7 +4171,7 @@ const Us = (r) => {
4156
4171
  * 创建一个可观察对象,查询通过中间表关联到当前实体的实体集合
4157
4172
  * 提供add和remove方法操作关系集合
4158
4173
  */
4159
- case T.MANY_TO_MANY:
4174
+ case A.MANY_TO_MANY:
4160
4175
  a = function() {
4161
4176
  const o = this, l = O(o), c = r.name + "Id";
4162
4177
  if (!r.junctionEntityType) throw new R("junction entity not found");
@@ -4173,8 +4188,8 @@ const Us = (r) => {
4173
4188
  ]
4174
4189
  }
4175
4190
  }).pipe(
4176
- x((h) => {
4177
- const p = h.map((m) => m[c]);
4191
+ x((p) => {
4192
+ const h = p.map((m) => m[c]);
4178
4193
  return t.getRepository(n).findAll({
4179
4194
  where: {
4180
4195
  combinator: "and",
@@ -4182,7 +4197,7 @@ const Us = (r) => {
4182
4197
  {
4183
4198
  field: "id",
4184
4199
  operator: "in",
4185
- value: p
4200
+ value: h
4186
4201
  }
4187
4202
  ]
4188
4203
  }
@@ -4206,12 +4221,12 @@ const Us = (r) => {
4206
4221
  return M(u, "count$", d), M(
4207
4222
  u,
4208
4223
  "add",
4209
- (...h) => h.forEach((p) => l.addRelationEntity(r, p))
4224
+ (...p) => p.forEach((h) => l.addRelationEntity(r, h))
4210
4225
  ), M(
4211
4226
  u,
4212
4227
  "remove",
4213
- (...h) => h.forEach((p) => {
4214
- l.removeRelationEntity(r, p);
4228
+ (...p) => p.forEach((h) => {
4229
+ l.removeRelationEntity(r, h);
4215
4230
  })
4216
4231
  ), Object.freeze(u);
4217
4232
  };
@@ -4225,7 +4240,7 @@ const Us = (r) => {
4225
4240
  configurable: !1
4226
4241
  });
4227
4242
  };
4228
- class Ys {
4243
+ class Gs {
4229
4244
  /**
4230
4245
  * 创建实体管理器实例
4231
4246
  *
@@ -4240,16 +4255,16 @@ class Ys {
4240
4255
  this.rxdb = e, e.repository("Repository", {
4241
4256
  class: sn,
4242
4257
  mergeOperations: {
4243
- create: Qe,
4244
- update: Xe,
4245
- remove: Je
4258
+ create: Je,
4259
+ update: Ze,
4260
+ remove: Xe
4246
4261
  }
4247
4262
  }).repository("TreeRepository", {
4248
- class: Ls,
4263
+ class: Ws,
4249
4264
  mergeOperations: {
4250
- create: Qe,
4251
- update: Xe,
4252
- remove: Je
4265
+ create: Je,
4266
+ update: Ze,
4267
+ remove: Xe
4253
4268
  }
4254
4269
  });
4255
4270
  }
@@ -4267,7 +4282,7 @@ class Ys {
4267
4282
  init() {
4268
4283
  this.rxdb.config.entities.forEach((e) => {
4269
4284
  const t = I(e);
4270
- M(e.prototype, ke, this), M(t, ke, this), M(t, We, e);
4285
+ M(e.prototype, We, this), M(t, We, this), M(t, He, e);
4271
4286
  const n = this.rxdb.getRepositoryConfig(t.repository);
4272
4287
  n && n.class.staticMethods.forEach(
4273
4288
  (i) => M(
@@ -4275,14 +4290,14 @@ class Ys {
4275
4290
  i,
4276
4291
  (a) => this.#t(e)[i](a)
4277
4292
  )
4278
- ), Object.keys(St).forEach(
4279
- (s) => M(e.prototype, s, St[s](this, e))
4280
- ), t.relationMap.forEach((s) => js(s, e, this));
4293
+ ), Object.keys(Mt).forEach(
4294
+ (s) => M(e.prototype, s, Mt[s](this, e))
4295
+ ), t.relationMap.forEach((s) => qs(s, e, this));
4281
4296
  }), M(this, Wt, (e) => {
4282
4297
  const t = this.#i(e, { local: !1, remote: !1, modified: !0 });
4283
- return Mn(() => {
4298
+ return On(() => {
4284
4299
  this.addEntityCache(t);
4285
- const n = I(e), s = new Zn([
4300
+ const n = I(e), s = new rr([
4286
4301
  {
4287
4302
  type: "NEW",
4288
4303
  namespace: n.namespace,
@@ -4379,14 +4394,14 @@ class Ys {
4379
4394
  * @returns 保存后的实体实例
4380
4395
  */
4381
4396
  async save(e) {
4382
- const t = gt([e]), n = ur([e]);
4397
+ const t = _t([e]), n = gr([e]);
4383
4398
  if (t.length === 1 && n.length === 0) {
4384
4399
  const s = t[0];
4385
4400
  O(s).local ? await this.update(s) : await this.create(s);
4386
4401
  } else if (t.length === 0 && n.length === 1)
4387
4402
  await this.remove(n[0]);
4388
4403
  else if (t.length || n.length) {
4389
- const s = Pe({
4404
+ const s = $e({
4390
4405
  need_save_entities: t,
4391
4406
  need_remove_entities: n
4392
4407
  });
@@ -4400,7 +4415,7 @@ class Ys {
4400
4415
  * @returns
4401
4416
  */
4402
4417
  async saveMany(e) {
4403
- const t = gt(e), n = Pe({
4418
+ const t = _t(e), n = $e({
4404
4419
  need_save_entities: t,
4405
4420
  need_remove_entities: []
4406
4421
  });
@@ -4412,7 +4427,7 @@ class Ys {
4412
4427
  * @returns
4413
4428
  */
4414
4429
  async removeMany(e) {
4415
- const t = Pe({
4430
+ const t = $e({
4416
4431
  need_save_entities: [],
4417
4432
  need_remove_entities: e
4418
4433
  });
@@ -4525,13 +4540,13 @@ class Ys {
4525
4540
  * @returns 初始化后的代理实体实例
4526
4541
  */
4527
4542
  #i(e, t) {
4528
- const n = new Fs(this.rxdb, { target: e, ...t });
4529
- or(e, Kt, n);
4530
- const s = Us(e);
4543
+ const n = new Hs(this.rxdb, { target: e, ...t });
4544
+ fr(e, Ht, n);
4545
+ const s = Ks(e);
4531
4546
  return M(n, "proxyTarget", s), s;
4532
4547
  }
4533
4548
  }
4534
- const St = {
4549
+ const Mt = {
4535
4550
  save: (r) => function() {
4536
4551
  return r.save(this);
4537
4552
  },
@@ -4541,8 +4556,8 @@ const St = {
4541
4556
  reset: (r) => function() {
4542
4557
  return r.reset(this);
4543
4558
  }
4544
- }, Mt = "entity_event", Ot = "hello", xt = "first_connected_at";
4545
- class zs {
4559
+ }, Ot = "entity_event", xt = "hello", Nt = "first_connected_at";
4560
+ class Vs {
4546
4561
  #e;
4547
4562
  #n;
4548
4563
  #t;
@@ -4570,7 +4585,7 @@ class zs {
4570
4585
  return this.#o;
4571
4586
  }
4572
4587
  constructor(e) {
4573
- this.#t = e.clientId, this.#e = On(`${e.dbName}_gateway`), this.#n = new xn(`${e.dbName}_leader`);
4588
+ this.#t = e.clientId, this.#e = xn(`${e.dbName}_gateway`), this.#n = new Nn(`${e.dbName}_leader`);
4574
4589
  }
4575
4590
  /**
4576
4591
  * 初始化网关
@@ -4599,7 +4614,7 @@ class zs {
4599
4614
  */
4600
4615
  #f(e) {
4601
4616
  this.#u || this.#e.emit({
4602
- type: Mt,
4617
+ type: Ot,
4603
4618
  messageId: this.#l(),
4604
4619
  clientId: this.#t,
4605
4620
  event: e
@@ -4610,7 +4625,7 @@ class zs {
4610
4625
  */
4611
4626
  #h() {
4612
4627
  this.#e.emit({
4613
- type: Ot,
4628
+ type: xt,
4614
4629
  messageId: this.#l(),
4615
4630
  clientId: this.#t
4616
4631
  });
@@ -4620,7 +4635,7 @@ class zs {
4620
4635
  */
4621
4636
  #p() {
4622
4637
  this.#a && this.#e.emit({
4623
- type: xt,
4638
+ type: Nt,
4624
4639
  messageId: this.#l(),
4625
4640
  clientId: this.#t,
4626
4641
  firstConnectedAt: this.#a.toISOString()
@@ -4633,7 +4648,7 @@ class zs {
4633
4648
  const t = this.#e.message$.subscribe((n) => {
4634
4649
  if (n.clientId !== this.#t)
4635
4650
  switch (n.type) {
4636
- case Mt:
4651
+ case Ot:
4637
4652
  this.#u = !0;
4638
4653
  try {
4639
4654
  e(n.event);
@@ -4641,10 +4656,10 @@ class zs {
4641
4656
  this.#u = !1;
4642
4657
  }
4643
4658
  break;
4644
- case Ot:
4659
+ case xt:
4645
4660
  this.#o && this.#p();
4646
4661
  break;
4647
- case xt:
4662
+ case Nt:
4648
4663
  this.#a || (this.#a = new Date(n.firstConnectedAt));
4649
4664
  break;
4650
4665
  }
@@ -4667,7 +4682,7 @@ class zs {
4667
4682
  });
4668
4683
  }
4669
4684
  }
4670
- const ks = (r) => {
4685
+ const Qs = (r) => {
4671
4686
  const [{ metadata: e, relation: t }, { metadata: n, relation: s }] = r, i = Array.from(/* @__PURE__ */ new Set([e.namespace, n.namespace])).sort().join("_") || void 0;
4672
4687
  return {
4673
4688
  name: Array.from(/* @__PURE__ */ new Set([e.name, n.name])).sort().join("_"),
@@ -4684,7 +4699,7 @@ const ks = (r) => {
4684
4699
  * 不能使用 RESTRICT,否则会阻止删除有关联的实体
4685
4700
  */
4686
4701
  name: t.name,
4687
- kind: T.MANY_TO_ONE,
4702
+ kind: A.MANY_TO_ONE,
4688
4703
  mappedNamespace: n.namespace,
4689
4704
  mappedEntity: n.name,
4690
4705
  mappedProperty: s.name,
@@ -4696,7 +4711,7 @@ const ks = (r) => {
4696
4711
  * 同样需要 CASCADE 删除
4697
4712
  */
4698
4713
  name: s.name,
4699
- kind: T.MANY_TO_ONE,
4714
+ kind: A.MANY_TO_ONE,
4700
4715
  mappedNamespace: e.namespace,
4701
4716
  mappedEntity: e.name,
4702
4717
  mappedProperty: t.name,
@@ -4705,13 +4720,13 @@ const ks = (r) => {
4705
4720
  ]
4706
4721
  };
4707
4722
  };
4708
- var Ws = Object.defineProperty, Ks = Object.getOwnPropertyDescriptor, Hs = (r, e, t) => e in r ? Ws(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, qs = (r, e, t, n) => {
4709
- for (var s = n > 1 ? void 0 : n ? Ks(e, t) : e, i = r.length - 1, a; i >= 0; i--)
4723
+ var Js = Object.defineProperty, Xs = Object.getOwnPropertyDescriptor, Zs = (r, e, t) => e in r ? Js(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ei = (r, e, t, n) => {
4724
+ for (var s = n > 1 ? void 0 : n ? Xs(e, t) : e, i = r.length - 1, a; i >= 0; i--)
4710
4725
  (a = r[i]) && (s = a(s) || s);
4711
4726
  return s;
4712
- }, Vs = (r, e, t) => Hs(r, typeof e != "symbol" ? e + "" : e, t), on;
4713
- on = ct;
4714
- let K = class {
4727
+ }, ti = (r, e, t) => Zs(r, typeof e != "symbol" ? e + "" : e, t), on;
4728
+ on = lt;
4729
+ let H = class {
4715
4730
  /**
4716
4731
  * id
4717
4732
  */
@@ -4763,9 +4778,9 @@ let K = class {
4763
4778
  */
4764
4779
  children$;
4765
4780
  };
4766
- Vs(K, on);
4767
- K = qs([
4768
- yr({
4781
+ ti(H, on);
4782
+ H = ei([
4783
+ Er({
4769
4784
  name: "RxDBBranch",
4770
4785
  tableName: "rxdb_branch",
4771
4786
  log: !1,
@@ -4814,39 +4829,39 @@ K = qs([
4814
4829
  relations: [
4815
4830
  {
4816
4831
  name: "changes",
4817
- kind: T.ONE_TO_MANY,
4832
+ kind: A.ONE_TO_MANY,
4818
4833
  mappedEntity: "RxDBChange",
4819
4834
  mappedProperty: "branch"
4820
4835
  },
4821
4836
  {
4822
4837
  name: "syncs",
4823
- kind: T.ONE_TO_MANY,
4838
+ kind: A.ONE_TO_MANY,
4824
4839
  mappedEntity: "RxDBSync",
4825
4840
  mappedProperty: "branch"
4826
4841
  },
4827
4842
  {
4828
4843
  name: "children",
4829
- kind: T.ONE_TO_MANY,
4844
+ kind: A.ONE_TO_MANY,
4830
4845
  mappedEntity: "RxDBBranch",
4831
4846
  mappedProperty: "parent"
4832
4847
  },
4833
4848
  {
4834
4849
  name: "parent",
4835
- kind: T.MANY_TO_ONE,
4850
+ kind: A.MANY_TO_ONE,
4836
4851
  mappedEntity: "RxDBBranch",
4837
4852
  mappedProperty: "children",
4838
4853
  nullable: !0
4839
4854
  }
4840
4855
  ]
4841
4856
  })
4842
- ], K);
4843
- var Gs = Object.defineProperty, Qs = Object.getOwnPropertyDescriptor, Js = (r, e, t) => e in r ? Gs(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Xs = (r, e, t, n) => {
4844
- for (var s = n > 1 ? void 0 : n ? Qs(e, t) : e, i = r.length - 1, a; i >= 0; i--)
4857
+ ], H);
4858
+ var ni = Object.defineProperty, ri = Object.getOwnPropertyDescriptor, si = (r, e, t) => e in r ? ni(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ii = (r, e, t, n) => {
4859
+ for (var s = n > 1 ? void 0 : n ? ri(e, t) : e, i = r.length - 1, a; i >= 0; i--)
4845
4860
  (a = r[i]) && (s = a(s) || s);
4846
4861
  return s;
4847
- }, Zs = (r, e, t) => Js(r, typeof e != "symbol" ? e + "" : e, t), cn;
4848
- cn = ct;
4849
- let H = class {
4862
+ }, ai = (r, e, t) => si(r, typeof e != "symbol" ? e + "" : e, t), cn;
4863
+ cn = lt;
4864
+ let K = class {
4850
4865
  /**
4851
4866
  * id
4852
4867
  */
@@ -5381,8 +5396,8 @@ let H = class {
5381
5396
  */
5382
5397
  branch$;
5383
5398
  };
5384
- Zs(H, cn);
5385
- H = Xs([
5399
+ ai(K, cn);
5400
+ K = ii([
5386
5401
  ie({
5387
5402
  name: "RxDBChange",
5388
5403
  tableName: "rxdb_change",
@@ -5468,20 +5483,20 @@ H = Xs([
5468
5483
  relations: [
5469
5484
  {
5470
5485
  name: "branch",
5471
- kind: T.MANY_TO_ONE,
5486
+ kind: A.MANY_TO_ONE,
5472
5487
  mappedEntity: "RxDBBranch",
5473
5488
  mappedProperty: "changes",
5474
5489
  nullable: !0
5475
5490
  }
5476
5491
  ]
5477
5492
  })
5478
- ], H);
5479
- var ei = Object.defineProperty, ti = Object.getOwnPropertyDescriptor, ni = (r, e, t) => e in r ? ei(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ri = (r, e, t, n) => {
5480
- for (var s = n > 1 ? void 0 : n ? ti(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5493
+ ], K);
5494
+ var oi = Object.defineProperty, ci = Object.getOwnPropertyDescriptor, li = (r, e, t) => e in r ? oi(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ui = (r, e, t, n) => {
5495
+ for (var s = n > 1 ? void 0 : n ? ci(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5481
5496
  (a = r[i]) && (s = a(s) || s);
5482
5497
  return s;
5483
- }, si = (r, e, t) => ni(r, typeof e != "symbol" ? e + "" : e, t), ln;
5484
- ln = ct;
5498
+ }, di = (r, e, t) => li(r, typeof e != "symbol" ? e + "" : e, t), ln;
5499
+ ln = lt;
5485
5500
  let se = class {
5486
5501
  /**
5487
5502
  * id
@@ -5497,8 +5512,8 @@ let se = class {
5497
5512
  */
5498
5513
  name;
5499
5514
  };
5500
- si(se, ln);
5501
- se = ri([
5515
+ di(se, ln);
5516
+ se = ui([
5502
5517
  ie({
5503
5518
  name: "RxDBMigration",
5504
5519
  tableName: "rxdb_migration",
@@ -5523,8 +5538,8 @@ se = ri([
5523
5538
  ]
5524
5539
  })
5525
5540
  ], se);
5526
- var ii = Object.getOwnPropertyDescriptor, ai = (r, e, t, n) => {
5527
- for (var s = n > 1 ? void 0 : n ? ii(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5541
+ var hi = Object.getOwnPropertyDescriptor, pi = (r, e, t, n) => {
5542
+ for (var s = n > 1 ? void 0 : n ? hi(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5528
5543
  (a = r[i]) && (s = a(s) || s);
5529
5544
  return s;
5530
5545
  };
@@ -5592,7 +5607,7 @@ let z = class {
5592
5607
  */
5593
5608
  branch;
5594
5609
  };
5595
- z = ai([
5610
+ z = pi([
5596
5611
  ie({
5597
5612
  name: "RxDBSync",
5598
5613
  tableName: "rxdb_sync",
@@ -5674,7 +5689,7 @@ z = ai([
5674
5689
  relations: [
5675
5690
  {
5676
5691
  name: "branch",
5677
- kind: T.MANY_TO_ONE,
5692
+ kind: A.MANY_TO_ONE,
5678
5693
  mappedEntity: "RxDBBranch",
5679
5694
  mappedProperty: "syncs",
5680
5695
  onDelete: W.CASCADE
@@ -5682,13 +5697,13 @@ z = ai([
5682
5697
  ]
5683
5698
  })
5684
5699
  ], z);
5685
- var oi = Object.getOwnPropertyDescriptor, ci = (r, e, t, n) => {
5686
- for (var s = n > 1 ? void 0 : n ? oi(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5700
+ var fi = Object.getOwnPropertyDescriptor, yi = (r, e, t, n) => {
5701
+ for (var s = n > 1 ? void 0 : n ? fi(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5687
5702
  (a = r[i]) && (s = a(s) || s);
5688
5703
  return s;
5689
5704
  };
5690
- const G = (r, e) => e + ":" + r;
5691
- class li {
5705
+ const V = (r, e) => e + ":" + r;
5706
+ class mi {
5692
5707
  constructor(e) {
5693
5708
  this.rxdb = e;
5694
5709
  }
@@ -5698,31 +5713,31 @@ class li {
5698
5713
  #r = /* @__PURE__ */ new Map();
5699
5714
  init() {
5700
5715
  const { entities: e } = this.rxdb.config;
5701
- e.push(K, H, se, z), new Set(e).forEach((t) => {
5702
- const n = I(t), { name: s, namespace: i } = n, a = G(s, i);
5716
+ e.push(H, K, se, z), new Set(e).forEach((t) => {
5717
+ const n = I(t), { name: s, namespace: i } = n, a = V(s, i);
5703
5718
  this.#e.set(a, n), this.#n.set(a, t);
5704
5719
  const o = this.rxdb.getRepositoryConfig(n.repository);
5705
5720
  if (o?.entityGenerator) {
5706
5721
  const l = o.entityGenerator(n);
5707
- Nn(l).forEach((u) => {
5708
- const d = I(u), h = G(d.name, d.namespace);
5709
- this.#e.has(h) || (this.#e.set(h, d), this.#n.set(h, u), e.push(u));
5722
+ Pn(l).forEach((u) => {
5723
+ const d = I(u), p = V(d.name, d.namespace);
5724
+ this.#e.has(p) || (this.#e.set(p, d), this.#n.set(p, u), e.push(u));
5710
5725
  });
5711
5726
  }
5712
5727
  }), this.#e.forEach(
5713
5728
  (t) => t.relations.forEach((n) => {
5714
- if (n.kind === T.MANY_TO_MANY) {
5729
+ if (n.kind === A.MANY_TO_MANY) {
5715
5730
  const s = n, i = this.findMappedRelation(t, s);
5716
5731
  if (!i)
5717
5732
  throw new R("mapped relation not found");
5718
- const a = ks([
5733
+ const a = Qs([
5719
5734
  { metadata: t, relation: s },
5720
5735
  i
5721
- ]), o = G(a.name, a.namespace);
5736
+ ]), o = V(a.name, a.namespace);
5722
5737
  if (this.#e.has(o) === !1) {
5723
- let l = class extends Ie {
5738
+ let l = class extends Ae {
5724
5739
  };
5725
- l = ci([
5740
+ l = yi([
5726
5741
  ie(a)
5727
5742
  ], l);
5728
5743
  const c = I(l);
@@ -5732,7 +5747,7 @@ class li {
5732
5747
  }
5733
5748
  })
5734
5749
  ), this.#e.forEach((t, n) => {
5735
- const { name: s, namespace: i, tableName: a } = t, o = G(a, i);
5750
+ const { name: s, namespace: i, tableName: a } = t, o = V(a, i);
5736
5751
  this.#t.set(o, this.#n.get(n)), this.#r.set(o, t);
5737
5752
  let l = this.rxdb;
5738
5753
  i !== "public" && (M(l, i, {}), l = l[i]), M(l, s, this.#n.get(n));
@@ -5747,17 +5762,17 @@ class li {
5747
5762
  if (n.relations && n.name === t.mappedEntity && n.namespace === t.mappedNamespace) {
5748
5763
  let s;
5749
5764
  switch (t.kind) {
5750
- case T.MANY_TO_MANY:
5751
- s = (a) => a.kind === T.MANY_TO_MANY && a.name === t.mappedProperty && a.mappedProperty === t.name;
5765
+ case A.MANY_TO_MANY:
5766
+ s = (a) => a.kind === A.MANY_TO_MANY && a.name === t.mappedProperty && a.mappedProperty === t.name;
5752
5767
  break;
5753
- case T.ONE_TO_MANY:
5754
- s = (a) => a.kind === T.MANY_TO_ONE && a.name === t.mappedProperty;
5768
+ case A.ONE_TO_MANY:
5769
+ s = (a) => a.kind === A.MANY_TO_ONE && a.name === t.mappedProperty;
5755
5770
  break;
5756
- case T.MANY_TO_ONE:
5757
- s = (a) => a.kind === T.ONE_TO_MANY && a.mappedProperty === t.name;
5771
+ case A.MANY_TO_ONE:
5772
+ s = (a) => a.kind === A.ONE_TO_MANY && a.mappedProperty === t.name;
5758
5773
  break;
5759
- case T.ONE_TO_ONE:
5760
- s = (a) => a.kind === T.ONE_TO_ONE && a.mappedEntity === e.name;
5774
+ case A.ONE_TO_ONE:
5775
+ s = (a) => a.kind === A.ONE_TO_ONE && a.mappedEntity === e.name;
5761
5776
  break;
5762
5777
  }
5763
5778
  const i = n.relations.find(s);
@@ -5782,8 +5797,8 @@ class li {
5782
5797
  o = a.propertyMap.get(u);
5783
5798
  } else {
5784
5799
  if (a.relationMap.has(u) === !1) throw new R(`relation '${u}' not found`);
5785
- const h = a.relationMap.get(u);
5786
- n.push({ relation: h, metadata: a }), a = this.getEntityMetadata(h.mappedEntity, h.mappedNamespace);
5800
+ const p = a.relationMap.get(u);
5801
+ n.push({ relation: p, metadata: a }), a = this.getEntityMetadata(p.mappedEntity, p.mappedNamespace);
5787
5802
  }
5788
5803
  }), {
5789
5804
  property: o,
@@ -5796,14 +5811,14 @@ class li {
5796
5811
  * 获取实体元数据
5797
5812
  */
5798
5813
  getEntityMetadata(e, t) {
5799
- const n = G(e, t);
5814
+ const n = V(e, t);
5800
5815
  return this.#e.get(n);
5801
5816
  }
5802
5817
  /**
5803
5818
  * 获取实体元数据
5804
5819
  */
5805
5820
  getEntityType(e, t) {
5806
- const n = G(e, t);
5821
+ const n = V(e, t);
5807
5822
  return this.#n.get(n);
5808
5823
  }
5809
5824
  /**
@@ -5812,7 +5827,7 @@ class li {
5812
5827
  * @param namespace 命名空间
5813
5828
  */
5814
5829
  getEntityTypeByTableName(e, t) {
5815
- return this.#t.get(G(e, t)) ?? this.#n.get(G(e, t));
5830
+ return this.#t.get(V(e, t)) ?? this.#n.get(V(e, t));
5816
5831
  }
5817
5832
  /**
5818
5833
  * 通过 tableName 获取实体元数据
@@ -5820,10 +5835,10 @@ class li {
5820
5835
  * @param namespace 命名空间
5821
5836
  */
5822
5837
  getEntityMetadataByTableName(e, t) {
5823
- return this.#r.get(G(e, t)) ?? this.#e.get(G(e, t));
5838
+ return this.#r.get(V(e, t)) ?? this.#e.get(V(e, t));
5824
5839
  }
5825
5840
  }
5826
- const ui = "0.0.10", Ze = (r) => `${r.namespace}:${r.entity}:${r.entityId}`, fa = (r) => r.split(":");
5841
+ const gi = "0.0.15", we = (r) => `${r.namespace}:${r.entity}:${r.entityId}`, wa = (r) => r.split(":", 3);
5827
5842
  function un(r, e = {
5828
5843
  deletes: /* @__PURE__ */ new Map(),
5829
5844
  updates: /* @__PURE__ */ new Map(),
@@ -5831,7 +5846,7 @@ function un(r, e = {
5831
5846
  }) {
5832
5847
  const t = [...r].sort((n, s) => n.id - s.id);
5833
5848
  for (const n of t) {
5834
- const s = Ze(n);
5849
+ const s = we(n);
5835
5850
  switch (n.type) {
5836
5851
  case "INSERT":
5837
5852
  e.inserts.set(s, {
@@ -5861,7 +5876,7 @@ function un(r, e = {
5861
5876
  }
5862
5877
  return e;
5863
5878
  }
5864
- function ft(r) {
5879
+ function yt(r) {
5865
5880
  const e = /* @__PURE__ */ new Map();
5866
5881
  for (const t of r) {
5867
5882
  const n = `${t.namespace}:${t.name}`, s = {
@@ -5871,7 +5886,7 @@ function ft(r) {
5871
5886
  };
5872
5887
  if (t.relations) {
5873
5888
  for (const i of t.relations)
5874
- if (i.kind === T.MANY_TO_ONE || i.kind === T.ONE_TO_ONE) {
5889
+ if (i.kind === A.MANY_TO_ONE || i.kind === A.ONE_TO_ONE) {
5875
5890
  const a = i.mappedEntity, o = i.mappedNamespace || t.namespace;
5876
5891
  s.dependsOn.push({
5877
5892
  namespace: o,
@@ -5886,9 +5901,9 @@ function ft(r) {
5886
5901
  const s = `${n.namespace}:${n.entity}`, i = e.get(s);
5887
5902
  i && i.requiredBy.push(t.repository);
5888
5903
  }
5889
- return di(e), e;
5904
+ return _i(e), e;
5890
5905
  }
5891
- function di(r) {
5906
+ function _i(r) {
5892
5907
  const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set(), n = [];
5893
5908
  function s(i) {
5894
5909
  e.add(i), t.add(i), n.push(i);
@@ -5910,20 +5925,20 @@ function di(r) {
5910
5925
  for (const i of r.keys())
5911
5926
  e.has(i) || s(i);
5912
5927
  }
5913
- function hi(r, e) {
5928
+ function bi(r, e) {
5914
5929
  return r.sync || e;
5915
5930
  }
5916
5931
  function j(r, e) {
5917
- const t = hi(r, e);
5932
+ const t = bi(r, e);
5918
5933
  if (!t)
5919
5934
  return "none";
5920
- if (t.type === fe.Filter)
5935
+ if (t.type === ye.Filter)
5921
5936
  return "filter";
5922
- if (t.type === fe.QueryCache)
5937
+ if (t.type === ye.QueryCache)
5923
5938
  return "querycache";
5924
- if (t.type === fe.Full)
5939
+ if (t.type === ye.Full)
5925
5940
  return "full";
5926
- if (t.type === fe.None) {
5941
+ if (t.type === ye.None) {
5927
5942
  const n = !!t.local, s = !!t.remote;
5928
5943
  return !r.sync && n && s ? "full" : n && s ? "none" : s && !n ? "remote" : n && !s ? "local" : "none";
5929
5944
  }
@@ -5933,17 +5948,17 @@ function dn(r, e) {
5933
5948
  const t = j(r, e);
5934
5949
  return t === "full" || t === "filter" || t === "remote";
5935
5950
  }
5936
- function pi(r, e) {
5951
+ function wi(r, e) {
5937
5952
  const t = j(r, e);
5938
5953
  return t === "full" || t === "filter" || t === "local";
5939
5954
  }
5940
- function fi(r, e) {
5955
+ function vi(r, e) {
5941
5956
  return j(r, e) === "none";
5942
5957
  }
5943
- function ya(r, e) {
5944
- return r.filter((t) => !fi(t, e));
5958
+ function va(r, e) {
5959
+ return r.filter((t) => !vi(t, e));
5945
5960
  }
5946
- function ma(r, e) {
5961
+ function Ea(r, e) {
5947
5962
  const t = {
5948
5963
  full: [],
5949
5964
  filter: [],
@@ -5958,7 +5973,7 @@ function ma(r, e) {
5958
5973
  }
5959
5974
  return t;
5960
5975
  }
5961
- function yt(r, e) {
5976
+ function mt(r, e) {
5962
5977
  const t = [], n = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
5963
5978
  function i(a) {
5964
5979
  if (n.has(a)) return;
@@ -5979,39 +5994,39 @@ function yt(r, e) {
5979
5994
  i(a);
5980
5995
  return t;
5981
5996
  }
5982
- function yi(r) {
5983
- return yt(r, "pull");
5997
+ function Ei(r) {
5998
+ return mt(r, "pull");
5984
5999
  }
5985
- function mi(r) {
5986
- return yt(r, "push");
6000
+ function Ri(r) {
6001
+ return mt(r, "push");
5987
6002
  }
5988
6003
  function hn(r) {
5989
6004
  if (!r || typeof r != "object") return !1;
5990
6005
  const e = r;
5991
6006
  return (e.combinator === "and" || e.combinator === "or") && Array.isArray(e.rules);
5992
6007
  }
5993
- const gi = {
6008
+ const Ci = {
5994
6009
  limit: 1e3,
5995
6010
  fetchAll: !1,
5996
6011
  includeRelated: !0,
5997
6012
  filter: void 0
5998
6013
  };
5999
6014
  async function pn(r, e, t, n) {
6000
- const s = { ...gi, ...n }, i = r.rxdb;
6001
- i.dispatchEvent(new it("pull", e, t, s.includeRelated));
6015
+ const s = { ...Ci, ...n }, i = r.rxdb;
6016
+ i.dispatchEvent(new at("pull", e, t, s.includeRelated));
6002
6017
  try {
6003
- const a = await _i(r, e, t, s);
6018
+ const a = await Ii(r, e, t, s);
6004
6019
  return i.dispatchEvent(
6005
- new at("pull", e, t, {
6020
+ new ot("pull", e, t, {
6006
6021
  pulled: a.pulled,
6007
6022
  compacted: a.compacted
6008
6023
  })
6009
6024
  ), a;
6010
6025
  } catch (a) {
6011
- throw i.dispatchEvent(new ot("pull", e, t, a)), a;
6026
+ throw i.dispatchEvent(new ct("pull", e, t, a)), a;
6012
6027
  }
6013
6028
  }
6014
- async function _i(r, e, t, n) {
6029
+ async function Ii(r, e, t, n) {
6015
6030
  const s = r.rxdb.config.entities.find((c) => {
6016
6031
  const u = I(c);
6017
6032
  return u.namespace === e && u.name === t;
@@ -6041,15 +6056,15 @@ async function _i(r, e, t, n) {
6041
6056
  }
6042
6057
  }
6043
6058
  const l = { ...n, filter: o };
6044
- return n.includeRelated ? await bi(r, e, t, l) : await fn(r, e, t, l);
6059
+ return n.includeRelated ? await Ai(r, e, t, l) : await fn(r, e, t, l);
6045
6060
  }
6046
- async function bi(r, e, t, n) {
6047
- const s = r.rxdb.config.entities.map((y) => I(y)), i = ft(s), a = new Map(
6061
+ async function Ai(r, e, t, n) {
6062
+ const s = r.rxdb.config.entities.map((y) => I(y)), i = yt(s), a = new Map(
6048
6063
  r.rxdb.config.entities.map((y) => {
6049
6064
  const g = I(y);
6050
6065
  return [`${g.namespace}:${g.name}`, y];
6051
6066
  })
6052
- ), o = yi(i), l = `${e}:${t}`;
6067
+ ), o = Ei(i), l = `${e}:${t}`;
6053
6068
  if (!i.get(l))
6054
6069
  throw new R(`Repository ${e}:${t} not found in dependency graph`);
6055
6070
  const u = /* @__PURE__ */ new Set([l]), d = (y) => {
@@ -6061,17 +6076,17 @@ async function bi(r, e, t, n) {
6061
6076
  }
6062
6077
  };
6063
6078
  d(l);
6064
- const h = o.filter((y) => {
6079
+ const p = o.filter((y) => {
6065
6080
  const g = `${y.namespace}:${y.entity}`;
6066
6081
  return u.has(g);
6067
- }), p = [], m = /* @__PURE__ */ new Set();
6068
- for (const y of h) {
6082
+ }), h = [], m = /* @__PURE__ */ new Set();
6083
+ for (const y of p) {
6069
6084
  const g = `${y.namespace}:${y.entity}`;
6070
6085
  if (i.get(g)?.dependsOn.some((b) => {
6071
6086
  const w = `${b.namespace}:${b.entity}`;
6072
6087
  return m.has(w);
6073
6088
  })) {
6074
- p.push({
6089
+ h.push({
6075
6090
  repository: y,
6076
6091
  success: !1,
6077
6092
  skipped: "Dependency failed",
@@ -6088,10 +6103,10 @@ async function bi(r, e, t, n) {
6088
6103
  if (b) {
6089
6104
  const B = I(b), U = j(B, r.rxdb.config.sync);
6090
6105
  if (U === "filter") {
6091
- const A = B.sync;
6092
- if (A?.remote?.filter)
6106
+ const T = B.sync;
6107
+ if (T?.remote?.filter)
6093
6108
  try {
6094
- const q = A.remote.filter();
6109
+ const q = T.remote.filter();
6095
6110
  q && hn(q) && (w = q);
6096
6111
  } catch {
6097
6112
  w = void 0;
@@ -6104,9 +6119,9 @@ async function bi(r, e, t, n) {
6104
6119
  includeRelated: !1
6105
6120
  // 防止递归级联
6106
6121
  });
6107
- E.success = !0, p.push(E);
6122
+ E.success = !0, h.push(E);
6108
6123
  } catch (b) {
6109
- p.push({
6124
+ h.push({
6110
6125
  repository: y,
6111
6126
  success: !1,
6112
6127
  error: b instanceof Error ? b : new Error(String(b)),
@@ -6117,10 +6132,10 @@ async function bi(r, e, t, n) {
6117
6132
  }), m.add(g);
6118
6133
  }
6119
6134
  }
6120
- const f = p.find((y) => y.repository.namespace === e && y.repository.entity === t);
6135
+ const f = h.find((y) => y.repository.namespace === e && y.repository.entity === t);
6121
6136
  if (!f)
6122
6137
  throw new R("Internal error: target repository result not found");
6123
- if (f.relatedResults = p.filter((y) => y !== f), !f.success && f.error)
6138
+ if (f.relatedResults = h.filter((y) => y !== f), !f.success && f.error)
6124
6139
  throw f.error;
6125
6140
  return f;
6126
6141
  }
@@ -6128,29 +6143,29 @@ async function fn(r, e, t, n) {
6128
6143
  if (!r.rxdb.config.sync?.remote?.adapter)
6129
6144
  throw new R("Remote adapter not configured.");
6130
6145
  const { adapter: a } = await r.getRemoteRepositories(), { adapter: o } = await r.getLocalRepositories(), l = await r.getCurrentBranch(), c = `${e}:${t}:${l.id}`, u = o.getRepository(z);
6131
- let h = (await u.find({
6146
+ let p = (await u.find({
6132
6147
  where: {
6133
6148
  combinator: "and",
6134
6149
  rules: [{ field: "id", operator: "=", value: c }]
6135
6150
  },
6136
6151
  limit: 1
6137
6152
  }))[0];
6138
- if (!h) {
6153
+ if (!p) {
6139
6154
  const E = r.rxdb.config.entities.find((q) => {
6140
6155
  const Z = I(q);
6141
6156
  return Z.namespace === e && Z.name === t;
6142
- }), B = I(E), U = j(B, r.rxdb.config.sync), A = new z();
6143
- A.id = c, A.namespace = e, A.entity = t, A.branchId = l.id, A.syncType = U, A.lastPushedChangeId = null, A.lastPushedAt = null, A.lastPulledAt = null, A.lastPullRemoteChangeId = null, A.enabled = !0, A.createdAt = /* @__PURE__ */ new Date(), A.updatedAt = /* @__PURE__ */ new Date(), h = await u.create(A);
6157
+ }), B = I(E), U = j(B, r.rxdb.config.sync), T = new z();
6158
+ T.id = c, T.namespace = e, T.entity = t, T.branchId = l.id, T.syncType = U, T.lastPushedChangeId = null, T.lastPushedAt = null, T.lastPulledAt = null, T.lastPullRemoteChangeId = null, T.enabled = !0, T.createdAt = /* @__PURE__ */ new Date(), T.updatedAt = /* @__PURE__ */ new Date(), p = await u.create(T);
6144
6159
  }
6145
- const p = await u.find({
6160
+ const h = await u.find({
6146
6161
  where: {
6147
6162
  combinator: "and",
6148
6163
  rules: [{ field: "id", operator: "=", value: c }]
6149
6164
  },
6150
6165
  limit: 1
6151
6166
  });
6152
- p.length > 0 && (h = p[0]);
6153
- const m = h.lastPullRemoteChangeId;
6167
+ h.length > 0 && (p = h[0]);
6168
+ const m = p.lastPullRemoteChangeId;
6154
6169
  let f = 0, y = 0, g = 0, _ = !1, v, b = m ?? 0;
6155
6170
  const w = {
6156
6171
  deletes: /* @__PURE__ */ new Map(),
@@ -6167,7 +6182,7 @@ async function fn(r, e, t, n) {
6167
6182
  const B = w.inserts.size + w.updates.size + w.deletes.size;
6168
6183
  if (y += E.length - B, _ = E.length >= n.limit, await o.mergeChanges(w, void 0, !0), B > 0) {
6169
6184
  const U = v.id;
6170
- h = await u.update(h, {
6185
+ p = await u.update(p, {
6171
6186
  lastPullRemoteChangeId: U,
6172
6187
  lastPulledAt: /* @__PURE__ */ new Date(),
6173
6188
  updatedAt: /* @__PURE__ */ new Date()
@@ -6183,27 +6198,27 @@ async function fn(r, e, t, n) {
6183
6198
  hasMore: _
6184
6199
  };
6185
6200
  }
6186
- const wi = {
6201
+ const Ti = {
6187
6202
  batchSize: 1e3,
6188
6203
  includeRelated: !0
6189
6204
  };
6190
6205
  async function yn(r, e, t, n) {
6191
- const s = { ...wi, ...n }, i = r.rxdb;
6192
- i.dispatchEvent(new it("push", e, t, s.includeRelated));
6206
+ const s = { ...Ti, ...n }, i = r.rxdb;
6207
+ i.dispatchEvent(new at("push", e, t, s.includeRelated));
6193
6208
  try {
6194
- const a = await vi(r, e, t, s);
6209
+ const a = await Si(r, e, t, s);
6195
6210
  return i.dispatchEvent(
6196
- new at("push", e, t, {
6211
+ new ot("push", e, t, {
6197
6212
  pushed: a.pushed,
6198
6213
  compacted: a.compacted,
6199
6214
  failed: a.failed
6200
6215
  })
6201
6216
  ), a;
6202
6217
  } catch (a) {
6203
- throw i.dispatchEvent(new ot("push", e, t, a)), a;
6218
+ throw i.dispatchEvent(new ct("push", e, t, a)), a;
6204
6219
  }
6205
6220
  }
6206
- async function vi(r, e, t, n) {
6221
+ async function Si(r, e, t, n) {
6207
6222
  const s = r.rxdb.config.entities.find((o) => {
6208
6223
  const l = I(o);
6209
6224
  return l.namespace === e && l.name === t;
@@ -6215,10 +6230,10 @@ async function vi(r, e, t, n) {
6215
6230
  throw new R(`Cannot push repository ${e}:${t}: syncType is 'none'.`);
6216
6231
  if (a === "remote")
6217
6232
  throw new R(`Cannot push repository ${e}:${t}: syncType is 'remote' (read-only).`);
6218
- return n.includeRelated ? await Ei(r, e, t, n) : await mn(r, e, t);
6233
+ return n.includeRelated ? await Mi(r, e, t, n) : await mn(r, e, t);
6219
6234
  }
6220
- async function Ei(r, e, t, n) {
6221
- const s = r.rxdb.config.entities.map((f) => I(f)), i = ft(s), a = mi(i), o = `${e}:${t}`;
6235
+ async function Mi(r, e, t, n) {
6236
+ const s = r.rxdb.config.entities.map((f) => I(f)), i = yt(s), a = Ri(i), o = `${e}:${t}`;
6222
6237
  if (!i.get(o))
6223
6238
  throw new R(`Repository ${e}:${t} not found in dependency graph`);
6224
6239
  const c = /* @__PURE__ */ new Set([o]), u = (f) => {
@@ -6233,14 +6248,14 @@ async function Ei(r, e, t, n) {
6233
6248
  const d = a.filter((f) => {
6234
6249
  const y = `${f.namespace}:${f.entity}`;
6235
6250
  return c.has(y);
6236
- }), h = [], p = /* @__PURE__ */ new Set();
6251
+ }), p = [], h = /* @__PURE__ */ new Set();
6237
6252
  for (const f of d) {
6238
6253
  const y = `${f.namespace}:${f.entity}`;
6239
6254
  if (i.get(y)?.dependsOn.some((v) => {
6240
6255
  const b = `${v.namespace}:${v.entity}`;
6241
- return p.has(b);
6256
+ return h.has(b);
6242
6257
  })) {
6243
- h.push({
6258
+ p.push({
6244
6259
  repository: f,
6245
6260
  success: !1,
6246
6261
  skipped: "Dependency failed",
@@ -6248,7 +6263,7 @@ async function Ei(r, e, t, n) {
6248
6263
  failed: 0,
6249
6264
  compacted: 0,
6250
6265
  originalCount: 0
6251
- }), p.add(y);
6266
+ }), h.add(y);
6252
6267
  continue;
6253
6268
  }
6254
6269
  try {
@@ -6257,9 +6272,9 @@ async function Ei(r, e, t, n) {
6257
6272
  includeRelated: !1
6258
6273
  // 防止递归级联
6259
6274
  });
6260
- v.success = !0, h.push(v);
6275
+ v.success = !0, p.push(v);
6261
6276
  } catch (v) {
6262
- h.push({
6277
+ p.push({
6263
6278
  repository: f,
6264
6279
  success: !1,
6265
6280
  error: v instanceof Error ? v : new Error(String(v)),
@@ -6267,13 +6282,13 @@ async function Ei(r, e, t, n) {
6267
6282
  failed: 0,
6268
6283
  compacted: 0,
6269
6284
  originalCount: 0
6270
- }), p.add(y);
6285
+ }), h.add(y);
6271
6286
  }
6272
6287
  }
6273
- const m = h.find((f) => f.repository.namespace === e && f.repository.entity === t);
6288
+ const m = p.find((f) => f.repository.namespace === e && f.repository.entity === t);
6274
6289
  if (!m)
6275
6290
  throw new R("Internal error: target repository result not found");
6276
- if (m.relatedResults = h.filter((f) => f !== m), !m.success && m.error)
6291
+ if (m.relatedResults = p.filter((f) => f !== m), !m.success && m.error)
6277
6292
  throw m.error;
6278
6293
  return m;
6279
6294
  }
@@ -6293,10 +6308,10 @@ async function mn(r, e, t, n) {
6293
6308
  const E = r.rxdb.config.entities.find((q) => {
6294
6309
  const Z = I(q);
6295
6310
  return Z.namespace === e && Z.name === t;
6296
- }), B = I(E), U = j(B, r.rxdb.config.sync), A = new z();
6297
- A.id = l, A.namespace = e, A.entity = t, A.branchId = o.id, A.syncType = U, A.lastPushedChangeId = null, A.lastPushedAt = null, A.lastPulledAt = null, A.lastPullRemoteChangeId = null, A.enabled = !0, A.createdAt = /* @__PURE__ */ new Date(), A.updatedAt = /* @__PURE__ */ new Date(), d = await c.create(A);
6311
+ }), B = I(E), U = j(B, r.rxdb.config.sync), T = new z();
6312
+ T.id = l, T.namespace = e, T.entity = t, T.branchId = o.id, T.syncType = U, T.lastPushedChangeId = null, T.lastPushedAt = null, T.lastPulledAt = null, T.lastPullRemoteChangeId = null, T.enabled = !0, T.createdAt = /* @__PURE__ */ new Date(), T.updatedAt = /* @__PURE__ */ new Date(), d = await c.create(T);
6298
6313
  }
6299
- const h = d.lastPushedChangeId, p = a.getRepository(H), m = await Ri(p, o.id, h, [t]), f = m.length;
6314
+ const p = d.lastPushedChangeId, h = a.getRepository(K), m = await Oi(h, o.id, p, [t]), f = m.length;
6300
6315
  if (f === 0)
6301
6316
  return {
6302
6317
  repository: { namespace: e, entity: t },
@@ -6357,7 +6372,7 @@ async function mn(r, e, t, n) {
6357
6372
  originalCount: f
6358
6373
  };
6359
6374
  }
6360
- async function Ri(r, e, t, n) {
6375
+ async function Oi(r, e, t, n) {
6361
6376
  const s = [
6362
6377
  { field: "branchId", operator: "=", value: e },
6363
6378
  { field: "revertChangeId", operator: "=", value: null },
@@ -6373,23 +6388,23 @@ async function Ri(r, e, t, n) {
6373
6388
  }
6374
6389
  async function gn(r, e, t, n) {
6375
6390
  const s = r.rxdb, i = n?.pull?.includeRelated ?? n?.push?.includeRelated ?? !0;
6376
- s.dispatchEvent(new it("sync", e, t, i));
6391
+ s.dispatchEvent(new at("sync", e, t, i));
6377
6392
  try {
6378
- const a = await Ci(r, e, t, n), o = {
6393
+ const a = await xi(r, e, t, n), o = {
6379
6394
  pulled: a.pullResult?.pulled ?? 0,
6380
6395
  pushed: a.pushResult?.pushed ?? 0,
6381
6396
  compacted: (a.pullResult?.compacted ?? 0) + (a.pushResult?.compacted ?? 0),
6382
6397
  failed: a.pushResult?.failed ?? 0
6383
6398
  };
6384
- return s.dispatchEvent(new at("sync", e, t, o)), a;
6399
+ return s.dispatchEvent(new ot("sync", e, t, o)), a;
6385
6400
  } catch (a) {
6386
- throw s.dispatchEvent(new ot("sync", e, t, a)), a;
6401
+ throw s.dispatchEvent(new ct("sync", e, t, a)), a;
6387
6402
  }
6388
6403
  }
6389
- async function Ci(r, e, t, n) {
6404
+ async function xi(r, e, t, n) {
6390
6405
  const s = r.rxdb.config.entities.find((d) => {
6391
- const h = I(d);
6392
- return h.namespace === e && h.name === t;
6406
+ const p = I(d);
6407
+ return p.namespace === e && p.name === t;
6393
6408
  });
6394
6409
  if (!s)
6395
6410
  throw new R(`Entity not found: ${e}:${t}`);
@@ -6418,7 +6433,7 @@ async function Ci(r, e, t, n) {
6418
6433
  pushResult: c
6419
6434
  };
6420
6435
  }
6421
- function Ii(r, e) {
6436
+ function Ni(r, e) {
6422
6437
  if (e.repositories && e.repositories.length > 0)
6423
6438
  return e.repositories;
6424
6439
  const t = [];
@@ -6447,7 +6462,7 @@ async function _n(r, e, t) {
6447
6462
  };
6448
6463
  }
6449
6464
  }
6450
- async function Ti(r, e, t) {
6465
+ async function Pi(r, e, t) {
6451
6466
  const n = [];
6452
6467
  for (const s of e) {
6453
6468
  const i = await _n(r, s, t);
@@ -6455,7 +6470,7 @@ async function Ti(r, e, t) {
6455
6470
  }
6456
6471
  return n;
6457
6472
  }
6458
- async function Ai(r, e, t, n) {
6473
+ async function $i(r, e, t, n) {
6459
6474
  const s = [];
6460
6475
  for (let i = 0; i < e.length; i += n) {
6461
6476
  const o = e.slice(i, i + n).map((c) => _n(r, c, t)), l = await Promise.all(o);
@@ -6463,14 +6478,14 @@ async function Ai(r, e, t, n) {
6463
6478
  }
6464
6479
  return s;
6465
6480
  }
6466
- async function Si(r, e = {}) {
6467
- const t = Date.now(), n = Ii(r, e), s = {
6481
+ async function Bi(r, e = {}) {
6482
+ const t = Date.now(), n = Ni(r, e), s = {
6468
6483
  direction: e.operation,
6469
6484
  pull: e.pull,
6470
6485
  push: e.push
6471
6486
  }, i = e.concurrent ?? !1, a = e.concurrency ?? 3;
6472
6487
  let o;
6473
- i ? o = await Ai(r, n, s, a) : o = await Ti(r, n, s);
6488
+ i ? o = await $i(r, n, s, a) : o = await Pi(r, n, s);
6474
6489
  const l = o.filter((d) => d.success).length, c = o.filter((d) => !d.success).length, u = Date.now() - t;
6475
6490
  return {
6476
6491
  succeeded: l,
@@ -6495,7 +6510,7 @@ async function bn(r, e, t) {
6495
6510
  pendingCount: 0,
6496
6511
  hasUpdates: !1
6497
6512
  };
6498
- const o = (await r.versionManager.getCurrentBranch()).id, { adapter: l } = await r.versionManager.getLocalRepositories(), c = l.getRepository(z), u = `${e}:${t}:${o}`, p = (await c.find({
6513
+ const o = (await r.versionManager.getCurrentBranch()).id, { adapter: l } = await r.versionManager.getLocalRepositories(), c = l.getRepository(z), u = `${e}:${t}:${o}`, h = (await c.find({
6499
6514
  where: {
6500
6515
  combinator: "and",
6501
6516
  rules: [{ field: "id", operator: "=", value: u }]
@@ -6504,16 +6519,16 @@ async function bn(r, e, t) {
6504
6519
  }))[0]?.lastPullRemoteChangeId ?? null, { adapter: m } = await r.versionManager.getRemoteRepositories();
6505
6520
  if (!m)
6506
6521
  throw new Error("Remote adapter not configured");
6507
- const f = p ?? 0, y = i.name, { count: g, latestChangeId: _ } = await m.getChangeCount(f, [y]);
6522
+ const f = h ?? 0, y = i.name, { count: g, latestChangeId: _ } = await m.getChangeCount(f, [y]);
6508
6523
  return {
6509
6524
  repository: n,
6510
6525
  remoteLatestChangeId: _,
6511
- localLastPullRemoteChangeId: p,
6526
+ localLastPullRemoteChangeId: h,
6512
6527
  pendingCount: g,
6513
6528
  hasUpdates: g > 0
6514
6529
  };
6515
6530
  }
6516
- async function Mi(r, e, t, n) {
6531
+ async function Di(r, e, t, n) {
6517
6532
  const s = r.rxdb, { adapter: i } = await r.getLocalRepositories(), a = s.config.entities.find((f) => {
6518
6533
  const y = I(f);
6519
6534
  return y.namespace === e && y.name === t;
@@ -6537,33 +6552,33 @@ async function Mi(r, e, t, n) {
6537
6552
  throw new R(
6538
6553
  `No filter provided and entity ${e}:${t} does not have a Filter sync configuration.`
6539
6554
  );
6540
- const u = wn(c), h = await i.getRepository(a).find({
6555
+ const u = wn(c), p = await i.getRepository(a).find({
6541
6556
  where: u
6542
- }), p = h.map((f) => f.id), m = p.length;
6557
+ }), h = p.map((f) => f.id), m = h.length;
6543
6558
  if (n?.dryRun)
6544
6559
  return {
6545
6560
  removed: m,
6546
- removedIds: p
6561
+ removedIds: h
6547
6562
  };
6548
6563
  if (m > 0) {
6549
6564
  const f = /* @__PURE__ */ new Map();
6550
- for (const g of h)
6565
+ for (const g of p)
6551
6566
  f.set(`${e}:${t}:${g.id}`, { patch: null, inversePatch: null });
6552
6567
  const y = { deletes: f, updates: /* @__PURE__ */ new Map(), inserts: /* @__PURE__ */ new Map() };
6553
6568
  await i.mergeChanges(y, void 0, !0);
6554
6569
  }
6555
6570
  return {
6556
6571
  removed: m,
6557
- removedIds: p
6572
+ removedIds: h
6558
6573
  };
6559
6574
  }
6560
6575
  function wn(r) {
6561
6576
  return {
6562
6577
  combinator: r.combinator === "and" ? "or" : "and",
6563
- rules: r.rules.map((e) => "combinator" in e ? wn(e) : Oi(e))
6578
+ rules: r.rules.map((e) => "combinator" in e ? wn(e) : Li(e))
6564
6579
  };
6565
6580
  }
6566
- function Oi(r) {
6581
+ function Li(r) {
6567
6582
  const t = {
6568
6583
  "=": "!=",
6569
6584
  "!=": "=",
@@ -6591,7 +6606,7 @@ function Oi(r) {
6591
6606
  operator: t
6592
6607
  };
6593
6608
  }
6594
- const xi = async (r, e, t) => {
6609
+ const Fi = async (r, e, t) => {
6595
6610
  const { branchRepository: n, changeRepository: s } = await r.getLocalRepositories();
6596
6611
  if ((await n.find({
6597
6612
  where: {
@@ -6618,11 +6633,11 @@ const xi = async (r, e, t) => {
6618
6633
  limit: 1
6619
6634
  }))[0];
6620
6635
  } else
6621
- a = await r.getCurrentBranch(), a && (o = await Ni(r, a.id));
6636
+ a = await r.getCurrentBranch(), a && (o = await Ui(r, a.id));
6622
6637
  if (!a) throw new R("Source branch not found");
6623
- const l = new K();
6638
+ const l = new H();
6624
6639
  return l.id = e, l.activated = !1, l.local = !0, l.remote = !1, l.fromChangeId = o?.id ?? null, l.parentId = a.id, await l.save(), l;
6625
- }, Ni = async (r, e) => {
6640
+ }, Ui = async (r, e) => {
6626
6641
  const { changeRepository: t } = await r.getLocalRepositories();
6627
6642
  return (await t.find({
6628
6643
  where: {
@@ -6640,8 +6655,8 @@ const xi = async (r, e, t) => {
6640
6655
  limit: 1
6641
6656
  }))[0];
6642
6657
  };
6643
- async function Pi(r, e, t, n, s) {
6644
- const { adapter: i } = await r.versionManager.getLocalRepositories(), a = i.getRepository(H), o = [
6658
+ async function ji(r, e, t, n, s) {
6659
+ const { adapter: i } = await r.versionManager.getLocalRepositories(), a = i.getRepository(K), o = [
6645
6660
  { field: "namespace", operator: "=", value: e },
6646
6661
  { field: "entity", operator: "=", value: t },
6647
6662
  { field: "branchId", operator: "=", value: n },
@@ -6655,7 +6670,7 @@ async function Pi(r, e, t, n, s) {
6655
6670
  }
6656
6671
  })).length;
6657
6672
  }
6658
- async function $i(r, e, t) {
6673
+ async function Yi(r, e, t) {
6659
6674
  try {
6660
6675
  return (await bn(r, e, t)).pendingCount;
6661
6676
  } catch (n) {
@@ -6672,28 +6687,28 @@ async function vn(r, e, t) {
6672
6687
  const s = I(n), i = j(s, r.config.sync), o = (await r.versionManager.getCurrentBranch()).id, { adapter: l } = await r.versionManager.getLocalRepositories(), c = l.getRepository(z), d = {
6673
6688
  combinator: "and",
6674
6689
  rules: [{ field: "id", operator: "=", value: `${e}:${t}:${o}` }]
6675
- }, h = await c.find({ where: d, limit: 1 }), p = h.length > 0 ? h[0] : null;
6690
+ }, p = await c.find({ where: d, limit: 1 }), h = p.length > 0 ? p[0] : null;
6676
6691
  let m = 0, f = 0;
6677
- return pi(s) && (m = await Pi(
6692
+ return wi(s) && (m = await ji(
6678
6693
  r,
6679
6694
  e,
6680
6695
  t,
6681
6696
  o,
6682
- p?.lastPushedChangeId ?? null
6683
- )), dn(s) && (f = await $i(r, e, t)), {
6697
+ h?.lastPushedChangeId ?? null
6698
+ )), dn(s) && (f = await Yi(r, e, t)), {
6684
6699
  repository: { namespace: e, entity: t },
6685
6700
  branchId: o,
6686
6701
  syncType: i,
6687
6702
  enabled: i !== "none",
6688
- lastPushedChangeId: p?.lastPushedChangeId ?? null,
6689
- lastPushedAt: p?.lastPushedAt ?? null,
6690
- lastPulledAt: p?.lastPulledAt ?? null,
6691
- lastPullRemoteChangeId: p?.lastPullRemoteChangeId ?? null,
6703
+ lastPushedChangeId: h?.lastPushedChangeId ?? null,
6704
+ lastPushedAt: h?.lastPushedAt ?? null,
6705
+ lastPulledAt: h?.lastPulledAt ?? null,
6706
+ lastPullRemoteChangeId: h?.lastPullRemoteChangeId ?? null,
6692
6707
  pushableCount: m,
6693
6708
  pullableCount: f
6694
6709
  };
6695
6710
  }
6696
- async function Bi(r, e) {
6711
+ async function zi(r, e) {
6697
6712
  const t = r.config.entities, n = [];
6698
6713
  for (const i of t) {
6699
6714
  const a = I(i), o = a.namespace, l = a.name, c = await vn(r, o, l);
@@ -6702,7 +6717,7 @@ async function Bi(r, e) {
6702
6717
  let s = n;
6703
6718
  return e?.syncType && e.syncType.length > 0 && (s = s.filter((i) => e.syncType.includes(i.syncType))), e?.enabled !== void 0 && (s = s.filter((i) => i.enabled === e.enabled)), e?.hasPendingChanges !== void 0 && (e.hasPendingChanges ? s = s.filter((i) => i.pushableCount > 0 || i.pullableCount > 0) : s = s.filter((i) => i.pushableCount === 0 && i.pullableCount === 0)), s;
6704
6719
  }
6705
- const Di = (r) => {
6720
+ const ki = (r) => {
6706
6721
  const { branches: e, currentBranch: t, nextBranch: n } = r, s = r.currentChangeId ?? t.fromChangeId ?? 0, i = r.nextChangeId ?? n.fromChangeId ?? 0;
6707
6722
  if (s === i)
6708
6723
  return [];
@@ -6715,11 +6730,11 @@ const Di = (r) => {
6715
6730
  }
6716
6731
  ];
6717
6732
  const a = /* @__PURE__ */ new Map();
6718
- for (const p of e)
6719
- a.set(p.id, p);
6720
- const o = (p) => {
6721
- const m = [p];
6722
- let f = p;
6733
+ for (const h of e)
6734
+ a.set(h.id, h);
6735
+ const o = (h) => {
6736
+ const m = [h];
6737
+ let f = h;
6723
6738
  for (; f.parentId; ) {
6724
6739
  const y = a.get(f.parentId);
6725
6740
  if (!y) break;
@@ -6728,41 +6743,41 @@ const Di = (r) => {
6728
6743
  return m;
6729
6744
  }, l = o(t), c = o(n);
6730
6745
  let u = null, d = -1;
6731
- for (let p = 0; p < l.length; p++)
6732
- if (c.findIndex((f) => f.id === l[p].id) !== -1) {
6733
- u = l[p], d = p;
6746
+ for (let h = 0; h < l.length; h++)
6747
+ if (c.findIndex((f) => f.id === l[h].id) !== -1) {
6748
+ u = l[h], d = h;
6734
6749
  break;
6735
6750
  }
6736
- const h = [];
6751
+ const p = [];
6737
6752
  if (u) {
6738
6753
  for (let f = 0; f < d; f++) {
6739
6754
  const y = l[f], g = f === 0 ? s : l[f - 1].fromChangeId ?? 0, _ = y.fromChangeId ?? 0;
6740
- g !== _ && h.push({
6755
+ g !== _ && p.push({
6741
6756
  branch: y,
6742
6757
  fromChangeId: g,
6743
6758
  toChangeId: _
6744
6759
  });
6745
6760
  }
6746
- const p = c.findIndex((f) => f.id === u.id);
6747
- if (p === 0) {
6761
+ const h = c.findIndex((f) => f.id === u.id);
6762
+ if (h === 0) {
6748
6763
  const f = d === 0 ? s : l[d - 1].fromChangeId ?? 0, y = i;
6749
- f !== y && h.push({
6764
+ f !== y && p.push({
6750
6765
  branch: u,
6751
6766
  fromChangeId: f,
6752
6767
  toChangeId: y
6753
6768
  });
6754
- } else if (p > 0) {
6755
- const f = d === 0 ? s : l[d - 1].fromChangeId ?? 0, y = c[p - 1].fromChangeId ?? 0;
6756
- f !== y && h.push({
6769
+ } else if (h > 0) {
6770
+ const f = d === 0 ? s : l[d - 1].fromChangeId ?? 0, y = c[h - 1].fromChangeId ?? 0;
6771
+ f !== y && p.push({
6757
6772
  branch: u,
6758
6773
  fromChangeId: f,
6759
6774
  toChangeId: y
6760
6775
  });
6761
6776
  }
6762
- const m = c.slice(0, p).reverse();
6777
+ const m = c.slice(0, h).reverse();
6763
6778
  for (let f = 0; f < m.length; f++) {
6764
6779
  const y = m[f], g = y.fromChangeId ?? 0, _ = f === m.length - 1 ? i ?? 0 : m[f + 1].fromChangeId ?? 0;
6765
- g !== _ && h.push({
6780
+ g !== _ && p.push({
6766
6781
  branch: y,
6767
6782
  fromChangeId: g,
6768
6783
  toChangeId: _
@@ -6771,20 +6786,20 @@ const Di = (r) => {
6771
6786
  } else {
6772
6787
  for (let _ = 0; _ < l.length; _++) {
6773
6788
  const v = l[_], b = _ === 0 ? s : l[_ - 1].fromChangeId ?? 0, w = v.fromChangeId ?? 0;
6774
- b !== w && h.push({
6789
+ b !== w && p.push({
6775
6790
  branch: v,
6776
6791
  fromChangeId: b,
6777
6792
  toChangeId: w
6778
6793
  });
6779
6794
  }
6780
- const p = l[l.length - 1], m = p.fromChangeId ?? 0;
6781
- m !== 0 && h.push({
6782
- branch: p,
6795
+ const h = l[l.length - 1], m = h.fromChangeId ?? 0;
6796
+ m !== 0 && p.push({
6797
+ branch: h,
6783
6798
  fromChangeId: m,
6784
6799
  toChangeId: 0
6785
6800
  });
6786
6801
  const f = c[c.length - 1], y = c.length > 1 ? c[c.length - 2].fromChangeId ?? 0 : i ?? 0;
6787
- y !== 0 && h.push({
6802
+ y !== 0 && p.push({
6788
6803
  branch: f,
6789
6804
  fromChangeId: 0,
6790
6805
  toChangeId: y
@@ -6792,15 +6807,15 @@ const Di = (r) => {
6792
6807
  const g = c.slice(0, c.length - 1).reverse();
6793
6808
  for (let _ = 0; _ < g.length; _++) {
6794
6809
  const v = g[_], b = v.fromChangeId ?? 0, w = _ === g.length - 1 ? i ?? 0 : g[_ + 1].fromChangeId ?? 0;
6795
- b !== w && h.push({
6810
+ b !== w && p.push({
6796
6811
  branch: v,
6797
6812
  fromChangeId: b,
6798
6813
  toChangeId: w
6799
6814
  });
6800
6815
  }
6801
6816
  }
6802
- return h;
6803
- }, Li = async (r, e) => {
6817
+ return p;
6818
+ }, Wi = async (r, e) => {
6804
6819
  const { branchRepository: t, changeRepository: n } = await r.getLocalRepositories(), s = await t.find({
6805
6820
  where: {
6806
6821
  combinator: "and",
@@ -6813,7 +6828,7 @@ const Di = (r) => {
6813
6828
  if (!a) throw new R(`Branch (${e}) not found`);
6814
6829
  if (i.id === a.id)
6815
6830
  throw new R("Cannot switch to the same branch");
6816
- const o = await Nt(n, i.id), l = await Nt(n, a.id), c = Di({
6831
+ const o = await Pt(n, i.id), l = await Pt(n, a.id), c = ki({
6817
6832
  branches: s,
6818
6833
  currentBranch: i,
6819
6834
  currentChangeId: o ? o.id : null,
@@ -6825,23 +6840,23 @@ const Di = (r) => {
6825
6840
  inserts: /* @__PURE__ */ new Map()
6826
6841
  };
6827
6842
  for (let d = 0; d < c.length; d++) {
6828
- const { branch: h, fromChangeId: p, toChangeId: m } = c[d], f = p < m, y = p > m, g = Math.min(p, m), _ = Math.max(p, m), v = {
6843
+ const { branch: p, fromChangeId: h, toChangeId: m } = c[d], f = h < m, y = h > m, g = Math.min(h, m), _ = Math.max(h, m), v = {
6829
6844
  where: {
6830
6845
  combinator: "and",
6831
6846
  rules: [
6832
- { field: "branchId", operator: "=", value: h.id },
6847
+ { field: "branchId", operator: "=", value: p.id },
6833
6848
  { field: "id", operator: ">", value: g },
6834
6849
  { field: "id", operator: "<=", value: _ },
6835
6850
  { field: "revertChangeId", operator: "=", value: null }
6836
6851
  ]
6837
6852
  }
6838
6853
  };
6839
- h.fromChangeId && g < h.fromChangeId && v.where.rules.push({ field: "id", operator: ">", value: h.fromChangeId });
6854
+ p.fromChangeId && g < p.fromChangeId && v.where.rules.push({ field: "id", operator: ">", value: p.fromChangeId });
6840
6855
  const b = await n.find(v);
6841
- y ? Ui(b, u) : f && Fi(b, u);
6856
+ y ? Ki(b, u) : f && Hi(b, u);
6842
6857
  }
6843
6858
  return u;
6844
- }, Fi = (r, e) => be(r, !0, e), Ui = (r, e) => be(r, !1, e), be = (r, e, t = {
6859
+ }, Hi = (r, e) => de(r, !0, e), Ki = (r, e) => de(r, !1, e), de = (r, e, t = {
6845
6860
  deletes: /* @__PURE__ */ new Map(),
6846
6861
  updates: /* @__PURE__ */ new Map(),
6847
6862
  inserts: /* @__PURE__ */ new Map()
@@ -6849,7 +6864,7 @@ const Di = (r) => {
6849
6864
  if (e) {
6850
6865
  const n = [...r].sort((s, i) => s.id - i.id);
6851
6866
  for (const s of n) {
6852
- const i = Ze(s);
6867
+ const i = we(s);
6853
6868
  switch (s.type) {
6854
6869
  case "INSERT":
6855
6870
  t.inserts.set(i, {
@@ -6877,7 +6892,7 @@ const Di = (r) => {
6877
6892
  } else {
6878
6893
  const n = [...r].sort((s, i) => i.id - s.id);
6879
6894
  for (const s of n) {
6880
- const i = Ze(s);
6895
+ const i = we(s);
6881
6896
  switch (s.type) {
6882
6897
  case "INSERT":
6883
6898
  t.deletes.set(i, {
@@ -6904,7 +6919,7 @@ const Di = (r) => {
6904
6919
  }
6905
6920
  }
6906
6921
  return t;
6907
- }, Nt = async (r, e) => (await r.find({
6922
+ }, Pt = async (r, e) => (await r.find({
6908
6923
  where: {
6909
6924
  combinator: "and",
6910
6925
  rules: [
@@ -6915,7 +6930,7 @@ const Di = (r) => {
6915
6930
  orderBy: [{ field: "id", sort: "desc" }],
6916
6931
  limit: 1
6917
6932
  }))[0];
6918
- function pe(r, e) {
6933
+ function fe(r, e) {
6919
6934
  return e.type === "database" ? r : r.map((t) => {
6920
6935
  const n = t.changes.filter((s) => e.type === "repository" ? s.namespace === e.namespace && s.entity === e.entity : s.namespace === e.namespace && s.entity === e.entity && s.entityId === e.entityId);
6921
6936
  return n.length === 0 ? null : {
@@ -6949,24 +6964,24 @@ function En(r) {
6949
6964
  ), t = [];
6950
6965
  return e.insert && t.push(`创建${e.insert}条`), e.update && t.push(`更新${e.update}条`), e.delete && t.push(`删除${e.delete}条`), `事务: ${t.join(", ")}`;
6951
6966
  }
6952
- function ji(r) {
6967
+ function qi(r) {
6953
6968
  return r.type === "database" ? "database" : r.type === "repository" ? `${r.namespace}:${r.entity}` : `${r.namespace}:${r.entity}:${r.entityId}`;
6954
6969
  }
6955
- class Yi {
6970
+ class Gi {
6956
6971
  constructor(e) {
6957
6972
  this.rxdb = e;
6958
- const t = e.entityManager.getRepository(K).findOne({
6973
+ const t = e.entityManager.getRepository(H).findOne({
6959
6974
  where: {
6960
6975
  combinator: "and",
6961
6976
  rules: [{ field: "activated", operator: "=", value: !0 }]
6962
6977
  }
6963
6978
  });
6964
- this.#r = Ne({
6979
+ this.#r = Pe({
6965
6980
  connected: this.rxdb.connected$,
6966
6981
  branch: t
6967
6982
  }).pipe(
6968
- Ce(({ connected: n, branch: s }) => n && !!s),
6969
- x(({ branch: n }) => (this.#i || (this.#i = /* @__PURE__ */ new Date()), H.findAll({
6983
+ Ie(({ connected: n, branch: s }) => n && !!s),
6984
+ x(({ branch: n }) => (this.#i || (this.#i = /* @__PURE__ */ new Date()), K.findAll({
6970
6985
  where: {
6971
6986
  combinator: "and",
6972
6987
  rules: [
@@ -6990,7 +7005,7 @@ class Yi {
6990
7005
  ), this.count$ = this.histories$.pipe(
6991
7006
  $((n) => n.length),
6992
7007
  P(1)
6993
- ), this.undoHistories$ = Ne({
7008
+ ), this.undoHistories$ = Pe({
6994
7009
  histories: this.histories$,
6995
7010
  syncCleared: this.#s,
6996
7011
  trigger: this.#t
@@ -7001,7 +7016,7 @@ class Yi {
7001
7016
  return [];
7002
7017
  try {
7003
7018
  const i = await L(
7004
- this.rxdb.entityManager.getRepository(K).findOne({
7019
+ this.rxdb.entityManager.getRepository(H).findOne({
7005
7020
  where: {
7006
7021
  combinator: "and",
7007
7022
  rules: [{ field: "activated", operator: "=", value: !0 }]
@@ -7018,22 +7033,22 @@ class Yi {
7018
7033
  for (const u of l) {
7019
7034
  let d = null;
7020
7035
  try {
7021
- const h = await o.find({
7036
+ const p = await o.find({
7022
7037
  where: {
7023
7038
  combinator: "and",
7024
7039
  rules: [{ field: "id", operator: "=", value: u.id }]
7025
7040
  },
7026
7041
  limit: 1
7027
7042
  });
7028
- h.length > 0 && (d = h[0].lastPushedChangeId);
7043
+ p.length > 0 && (d = p[0].lastPushedChangeId);
7029
7044
  } catch {
7030
7045
  d = null;
7031
7046
  }
7032
7047
  d !== null && c.set(u.entity, d);
7033
7048
  }
7034
7049
  return n.filter((u) => u.changes.every((d) => {
7035
- const h = d.revertChangeId == null, p = d.remoteId == null, m = c.get(d.entity), f = m == null || d.id > m;
7036
- return h && p && f;
7050
+ const p = d.revertChangeId == null, h = d.remoteId == null, m = c.get(d.entity), f = m == null || d.id > m;
7051
+ return p && h && f;
7037
7052
  }));
7038
7053
  } catch (i) {
7039
7054
  return console.error("[undoHistories$] error", i), [];
@@ -7046,18 +7061,18 @@ class Yi {
7046
7061
  ), this.redoCount$ = this.redoHistories$.pipe(
7047
7062
  $((n) => n.length),
7048
7063
  P(1)
7049
- ), this.pushableCount$ = this.#n.asObservable(), this.pullableCount$ = this.#e.asObservable(), Ne({
7064
+ ), this.pushableCount$ = this.#n.asObservable(), this.pullableCount$ = this.#e.asObservable(), Pe({
7050
7065
  connected: this.rxdb.connected$,
7051
7066
  branch: t
7052
7067
  }).pipe(
7053
- Ce(({ connected: n, branch: s }) => n && !!s),
7068
+ Ie(({ connected: n, branch: s }) => n && !!s),
7054
7069
  x(({ branch: n }) => {
7055
7070
  const s = [
7056
7071
  { field: "branchId", operator: "=", value: n.id },
7057
7072
  { field: "revertChangeId", operator: "=", value: null },
7058
7073
  { field: "remoteId", operator: "=", value: null }
7059
7074
  ];
7060
- return H.count({
7075
+ return K.count({
7061
7076
  where: { combinator: "and", rules: s }
7062
7077
  });
7063
7078
  })
@@ -7266,7 +7281,7 @@ class Yi {
7266
7281
  try {
7267
7282
  const e = await L(this.redoHistories$);
7268
7283
  if (e.length === 0) return;
7269
- const t = e.flatMap((o) => o.changes), n = /* @__PURE__ */ new Date(), s = be([], !1), { adapter: i } = await this.rxdb.versionManager.getLocalRepositories();
7284
+ const t = e.flatMap((o) => o.changes), n = /* @__PURE__ */ new Date(), s = de([], !1), { adapter: i } = await this.rxdb.versionManager.getLocalRepositories();
7270
7285
  t.forEach((o) => {
7271
7286
  const l = `${o.namespace}:RxDBChange:${o.id}`;
7272
7287
  s.updates.set(l, {
@@ -7348,7 +7363,7 @@ class Yi {
7348
7363
  entity: m.name
7349
7364
  };
7350
7365
  }
7351
- const n = ji(t);
7366
+ const n = qi(t);
7352
7367
  if (this.history_cache) {
7353
7368
  const m = this.history_cache.get(n);
7354
7369
  if (m)
@@ -7363,7 +7378,7 @@ class Yi {
7363
7378
  const m = (this.history_ref_counts.get(n) || 0) + 1;
7364
7379
  this.history_ref_counts.set(n, m);
7365
7380
  }, a = this.histories$.pipe(
7366
- $((m) => pe(m, t)),
7381
+ $((m) => fe(m, t)),
7367
7382
  Ft(s),
7368
7383
  P({ bufferSize: 1, refCount: !0 })
7369
7384
  ), o = (m) => new Ut((f) => {
@@ -7374,12 +7389,12 @@ class Yi {
7374
7389
  };
7375
7390
  }), l = o(
7376
7391
  this.undoHistories$.pipe(
7377
- $((m) => pe(m, t)),
7392
+ $((m) => fe(m, t)),
7378
7393
  P({ bufferSize: 1, refCount: !0 })
7379
7394
  )
7380
7395
  ), c = o(
7381
7396
  this.redoHistories$.pipe(
7382
- $((m) => pe(m, t)),
7397
+ $((m) => fe(m, t)),
7383
7398
  P({ bufferSize: 1, refCount: !0 })
7384
7399
  )
7385
7400
  ), u = o(
@@ -7392,29 +7407,29 @@ class Yi {
7392
7407
  $((m) => m.length),
7393
7408
  P({ bufferSize: 1, refCount: !0 })
7394
7409
  )
7395
- ), h = o(
7410
+ ), p = o(
7396
7411
  c.pipe(
7397
7412
  $((m) => m.length),
7398
7413
  P({ bufferSize: 1, refCount: !0 })
7399
7414
  )
7400
- ), p = {
7415
+ ), h = {
7401
7416
  type: t.type,
7402
7417
  histories$: a,
7403
7418
  undoHistories$: l,
7404
7419
  redoHistories$: c,
7405
7420
  count$: u,
7406
7421
  undoCount$: d,
7407
- redoCount$: h,
7422
+ redoCount$: p,
7408
7423
  undo: async (m = 1) => {
7409
- const y = (await this.#o()).filter((v) => v.changes.every((b) => b.revertChangeId == null)), _ = pe(y, t).slice(0, m);
7424
+ const y = (await this.#o()).filter((v) => v.changes.every((b) => b.revertChangeId == null)), _ = fe(y, t).slice(0, m);
7410
7425
  _.length !== 0 && await this.#u("undo", _);
7411
7426
  },
7412
7427
  redo: async (m = 1) => {
7413
- const f = await L(this.redoHistories$), g = pe(f, t).slice(0, m);
7428
+ const f = await L(this.redoHistories$), g = fe(f, t).slice(0, m);
7414
7429
  g.length !== 0 && await this.#u("redo", g);
7415
7430
  }
7416
7431
  };
7417
- return this.history_cache && this.history_cache.set(n, p), p;
7432
+ return this.history_cache && this.history_cache.set(n, h), h;
7418
7433
  }
7419
7434
  /**
7420
7435
  * 直接从数据库查询最新变更并转换为历史项
@@ -7491,10 +7506,10 @@ class Yi {
7491
7506
  * @returns 结构化的历史项,包含描述、类型、状态等信息
7492
7507
  */
7493
7508
  #c(e) {
7494
- const t = e[0], n = e.length, s = t.transactionId ?? null, i = t.createdAt, a = t.namespace, o = t.entity, l = s ? "TRANSACTION" : t.type, c = [l, t.entityId, i.getTime()].join(":"), u = e.some((h) => mt(h.revertChangeId) === !1), d = e.some((h) => mt(h.redoInvalidatedAt) === !1);
7509
+ const t = e[0], n = e.length, s = t.transactionId ?? null, i = t.createdAt, a = t.namespace, o = t.entity, l = s ? "TRANSACTION" : t.type, c = [l, t.entityId, i.getTime()].join(":"), u = e.some((p) => gt(p.revertChangeId) === !1), d = e.some((p) => gt(p.redoInvalidatedAt) === !1);
7495
7510
  return {
7496
7511
  transactionId: s,
7497
- changeId: Math.max(...e.map((h) => h.id)),
7512
+ changeId: Math.max(...e.map((p) => p.id)),
7498
7513
  fingerprint: c,
7499
7514
  changes: e,
7500
7515
  type: l,
@@ -7524,18 +7539,18 @@ class Yi {
7524
7539
  async #u(e, t) {
7525
7540
  this.isUndoRedoInProgress = !0;
7526
7541
  try {
7527
- const n = t.flatMap((o) => o.changes).sort((o, l) => e === "undo" ? l.id - o.id : o.id - l.id), s = be(n, e === "redo");
7542
+ const n = t.flatMap((o) => o.changes).sort((o, l) => e === "undo" ? l.id - o.id : o.id - l.id), s = de(n, e === "redo");
7528
7543
  if (e === "undo") {
7529
7544
  const { adapter: o } = await this.rxdb.versionManager.getLocalRepositories(), l = await o.getRxDBChangeSequence(), c = /* @__PURE__ */ new Date();
7530
7545
  n.forEach((u, d) => {
7531
- const h = `${u.namespace}:RxDBChange:${u.id}`, p = s.updates.get(h) || { patch: {}, inversePatch: null };
7532
- s.updates.set(h, {
7546
+ const p = `${u.namespace}:RxDBChange:${u.id}`, h = s.updates.get(p) || { patch: {}, inversePatch: null };
7547
+ s.updates.set(p, {
7533
7548
  patch: {
7534
- ...p.patch,
7549
+ ...h.patch,
7535
7550
  revertChangeId: l + d + 1,
7536
7551
  revertChangedAt: c
7537
7552
  },
7538
- inversePatch: p.inversePatch
7553
+ inversePatch: h.inversePatch
7539
7554
  });
7540
7555
  }), s.updateRxDBChangeSequence = l + n.length;
7541
7556
  } else
@@ -7569,7 +7584,7 @@ class Yi {
7569
7584
  return;
7570
7585
  }
7571
7586
  const n = (await L(this.rxdb.localAdapter$)).getRepository(z), s = await L(
7572
- this.rxdb.entityManager.getRepository(K).findOne({
7587
+ this.rxdb.entityManager.getRepository(H).findOne({
7573
7588
  where: {
7574
7589
  combinator: "and",
7575
7590
  rules: [{ field: "activated", operator: "=", value: !0 }]
@@ -7604,7 +7619,7 @@ class Yi {
7604
7619
  rules: u
7605
7620
  };
7606
7621
  }), l = await L(
7607
- H.count({
7622
+ K.count({
7608
7623
  where: {
7609
7624
  combinator: "and",
7610
7625
  rules: [
@@ -7623,7 +7638,90 @@ class Yi {
7623
7638
  }
7624
7639
  }
7625
7640
  }
7626
- async function Pt(r, e) {
7641
+ const Rn = async (r, e) => {
7642
+ const { branchRepository: t, changeRepository: n, adapter: s } = await r.getLocalRepositories();
7643
+ if (e === "main")
7644
+ throw new R("Cannot remove main branch");
7645
+ const i = (await t.find({
7646
+ where: {
7647
+ combinator: "and",
7648
+ rules: [{ field: "id", operator: "=", value: e }]
7649
+ },
7650
+ limit: 1
7651
+ }))[0];
7652
+ if (!i)
7653
+ throw new R(`Branch '${e}' not found`);
7654
+ if (i.activated)
7655
+ throw new R(`Cannot remove active branch '${e}'. Switch to another branch first.`);
7656
+ const a = await n.find({
7657
+ where: {
7658
+ combinator: "and",
7659
+ rules: [{ field: "branchId", operator: "=", value: e }]
7660
+ }
7661
+ });
7662
+ if (a.length > 0) {
7663
+ const o = a.map((c) => c.id);
7664
+ if ((await t.find({
7665
+ where: {
7666
+ combinator: "and",
7667
+ rules: [
7668
+ { field: "fromChangeId", operator: "in", value: o },
7669
+ { field: "id", operator: "!=", value: e }
7670
+ ]
7671
+ },
7672
+ limit: 1
7673
+ }))?.length)
7674
+ throw new R(`Cannot remove branch '${e}' because it has child branches`);
7675
+ }
7676
+ await s.removeMany([...a, i]);
7677
+ }, Vi = async (r, e, t, n) => {
7678
+ const s = n?.strategy ?? "squash", i = n?.deleteSource ?? !1, { branchRepository: a, changeRepository: o, adapter: l } = await r.getLocalRepositories();
7679
+ if (e === t)
7680
+ throw new R(`Cannot merge branch '${e}' into itself`);
7681
+ const c = (await a.find({
7682
+ where: {
7683
+ combinator: "and",
7684
+ rules: [{ field: "id", operator: "=", value: e }]
7685
+ },
7686
+ limit: 1
7687
+ }))[0];
7688
+ if (!c)
7689
+ throw new R(`Branch '${e}' not found`);
7690
+ const u = await o.find({
7691
+ where: {
7692
+ combinator: "and",
7693
+ rules: [
7694
+ { field: "branchId", operator: "=", value: e },
7695
+ { field: "revertChangeId", operator: "=", value: null },
7696
+ ...c.fromChangeId != null ? [{ field: "id", operator: ">", value: c.fromChangeId }] : []
7697
+ ]
7698
+ },
7699
+ orderBy: [{ field: "id", sort: "asc" }]
7700
+ }), d = async () => i ? (await Rn(r, e), !0) : !1;
7701
+ if (u.length === 0)
7702
+ return { merged: 0, strategy: s, sourceDeleted: await d() };
7703
+ let p;
7704
+ if (s === "normal") {
7705
+ for (const h of u) {
7706
+ const m = {
7707
+ deletes: /* @__PURE__ */ new Map(),
7708
+ updates: /* @__PURE__ */ new Map(),
7709
+ inserts: /* @__PURE__ */ new Map()
7710
+ }, f = we(h);
7711
+ h.type === "INSERT" ? m.inserts.set(f, { patch: h.patch, inversePatch: null }) : h.type === "UPDATE" ? m.updates.set(f, { patch: h.patch, inversePatch: h.inversePatch }) : h.type === "DELETE" && m.deletes.set(f, { patch: null, inversePatch: h.inversePatch }), await l.mergeChanges(m, void 0, !1);
7712
+ }
7713
+ p = u.length;
7714
+ } else {
7715
+ const h = de(u, !0), m = new Set(u.filter((f) => f.type === "INSERT").map((f) => we(f)));
7716
+ for (const f of m)
7717
+ h.deletes.has(f) && h.deletes.delete(f);
7718
+ if (p = h.inserts.size + h.updates.size + h.deletes.size, p === 0)
7719
+ return { merged: 0, strategy: s, sourceDeleted: await d() };
7720
+ await l.mergeChanges(h, void 0, !1);
7721
+ }
7722
+ return { merged: p, strategy: s, sourceDeleted: await d() };
7723
+ };
7724
+ async function $t(r, e) {
7627
7725
  const t = r.rxdb;
7628
7726
  if (!t.config.sync?.remote?.adapter)
7629
7727
  throw new R("Remote adapter not configured.");
@@ -7636,8 +7734,8 @@ async function Pt(r, e) {
7636
7734
  let a = 0, o = 0, l = 0, c = !1;
7637
7735
  for (const d of i.results)
7638
7736
  if (d.success && d.result) {
7639
- const h = d.result.pullResult;
7640
- a += h.pulled ?? 0, o += h.compacted ?? 0, l += h.applied ?? 0, h.hasMore && (c = !0);
7737
+ const p = d.result.pullResult;
7738
+ a += p.pulled ?? 0, o += p.compacted ?? 0, l += p.applied ?? 0, p.hasMore && (c = !0);
7641
7739
  }
7642
7740
  const u = {
7643
7741
  pulled: a,
@@ -7650,7 +7748,7 @@ async function Pt(r, e) {
7650
7748
  throw t.dispatchEvent(new kt("pull", s)), s;
7651
7749
  }
7652
7750
  }
7653
- async function $t(r, e) {
7751
+ async function Bt(r, e) {
7654
7752
  const t = r.rxdb;
7655
7753
  if (!t.config.sync?.remote?.adapter)
7656
7754
  throw new R("Remote adapter not configured.");
@@ -7663,8 +7761,8 @@ async function $t(r, e) {
7663
7761
  let a = 0, o = 0, l = 0, c = 0;
7664
7762
  for (const d of i.results)
7665
7763
  if (d.success && d.result) {
7666
- const h = d.result.pushResult;
7667
- a += h.pushed ?? 0, o += h.failed ?? 0, l += h.compacted ?? 0, c += h.originalCount ?? 0;
7764
+ const p = d.result.pushResult;
7765
+ a += p.pushed ?? 0, o += p.failed ?? 0, l += p.compacted ?? 0, c += p.originalCount ?? 0;
7668
7766
  } else
7669
7767
  o++;
7670
7768
  const u = {
@@ -7678,46 +7776,9 @@ async function $t(r, e) {
7678
7776
  throw t.dispatchEvent(new kt("push", s)), s;
7679
7777
  }
7680
7778
  }
7681
- const zi = async (r, e) => {
7682
- const { branchRepository: t, changeRepository: n, adapter: s } = await r.getLocalRepositories();
7683
- if (e === "main")
7684
- throw new R("Cannot remove main branch");
7685
- const i = (await t.find({
7686
- where: {
7687
- combinator: "and",
7688
- rules: [{ field: "id", operator: "=", value: e }]
7689
- },
7690
- limit: 1
7691
- }))[0];
7692
- if (!i)
7693
- throw new R(`Branch '${e}' not found`);
7694
- if (i.activated)
7695
- throw new R(`Cannot remove active branch '${e}'. Switch to another branch first.`);
7696
- const a = await n.find({
7697
- where: {
7698
- combinator: "and",
7699
- rules: [{ field: "branchId", operator: "=", value: e }]
7700
- }
7701
- });
7702
- if (a.length > 0) {
7703
- const o = a.map((c) => c.id);
7704
- if ((await t.find({
7705
- where: {
7706
- combinator: "and",
7707
- rules: [
7708
- { field: "fromChangeId", operator: "in", value: o },
7709
- { field: "id", operator: "!=", value: e }
7710
- ]
7711
- },
7712
- limit: 1
7713
- }))?.length)
7714
- throw new R(`Cannot remove branch '${e}' because it has child branches`);
7715
- }
7716
- await s.removeMany([...a, i]);
7717
- };
7718
- class ki {
7779
+ class Qi {
7719
7780
  constructor(e) {
7720
- this.rxdb = e, this.historyManager = new Yi(this.rxdb);
7781
+ this.rxdb = e, this.historyManager = new Gi(this.rxdb);
7721
7782
  }
7722
7783
  #e = [];
7723
7784
  /**
@@ -7764,14 +7825,14 @@ class ki {
7764
7825
  * @param fromChangeId 从哪个 changeId 创建新分支
7765
7826
  */
7766
7827
  async createBranch(e, t) {
7767
- return xi(this, e, t);
7828
+ return Fi(this, e, t);
7768
7829
  }
7769
7830
  /**
7770
7831
  * 删除分支
7771
7832
  * @param branchId 分支 id
7772
7833
  */
7773
7834
  async removeBranch(e) {
7774
- return zi(this, e);
7835
+ return Rn(this, e);
7775
7836
  }
7776
7837
  // ============================================
7777
7838
  // Pull/Push 同步方法
@@ -7795,7 +7856,7 @@ class ki {
7795
7856
  * ```
7796
7857
  */
7797
7858
  async pull(e) {
7798
- const t = await this.historyManager.syncing(() => Pt(this, e));
7859
+ const t = await this.historyManager.syncing(() => $t(this, e));
7799
7860
  return this.historyManager.resetPullableCount(), t.pulled > 0 && this.historyManager.clearUndoHistory(), t;
7800
7861
  }
7801
7862
  /**
@@ -7822,7 +7883,7 @@ class ki {
7822
7883
  * ```
7823
7884
  */
7824
7885
  async push(e) {
7825
- const t = await this.historyManager.syncing(() => $t(this, e));
7886
+ const t = await this.historyManager.syncing(() => Bt(this, e));
7826
7887
  return t.pushed > 0 && this.historyManager.clearUndoHistory(), t;
7827
7888
  }
7828
7889
  /**
@@ -7844,35 +7905,34 @@ class ki {
7844
7905
  */
7845
7906
  async sync(e) {
7846
7907
  const t = await this.historyManager.syncing(async () => {
7847
- const n = await Pt(this, e?.pull), s = await $t(this, e?.push);
7908
+ const n = await $t(this, e?.pull), s = await Bt(this, e?.push);
7848
7909
  return { pullResult: n, pushResult: s };
7849
7910
  });
7850
7911
  return (t.pullResult.pulled > 0 || t.pushResult.pushed > 0) && this.historyManager.clearUndoHistory(), t;
7851
7912
  }
7852
7913
  // ============================================
7853
- // Repository-level sync methods
7914
+ // Repository 级别同步方法
7854
7915
  // ============================================
7855
7916
  /**
7856
- * Pull changes for a specific repository
7917
+ * 拉取指定 Repository 的远程变更
7857
7918
  *
7858
- * Provides fine-grained control over synchronization at the entity type level.
7859
- * Supports cascade synchronization to automatically pull related entities.
7919
+ * 提供实体类型级别的精细同步控制,支持级联同步以自动拉取关联实体。
7860
7920
  *
7861
- * @param namespace - Entity namespace (e.g., "public")
7862
- * @param entity - Entity name (e.g., "Todo")
7863
- * @param options - Pull options
7864
- * @returns Pull result
7921
+ * @param namespace - 实体命名空间(如 "public"
7922
+ * @param entity - 实体名称(如 "Todo"
7923
+ * @param options - 拉取选项
7924
+ * @returns 拉取结果
7865
7925
  *
7866
7926
  * @example
7867
7927
  * ```typescript
7868
- * // Pull Todo repository with cascading dependencies
7928
+ * // 拉取 Todo 并级联拉取依赖
7869
7929
  * const result = await rxdb.versionManager.pullRepository('public', 'Todo', {
7870
- * includeRelated: true // Default: automatically pulls User if Todo has foreign key
7930
+ * includeRelated: true // 默认:若 Todo 有外键则自动拉取 User
7871
7931
  * });
7872
7932
  *
7873
- * // Pull without cascading
7933
+ * // 不级联拉取
7874
7934
  * const result = await rxdb.versionManager.pullRepository('public', 'Todo', {
7875
- * includeRelated: false // Only pull Todo, may cause foreign key errors
7935
+ * includeRelated: false // 仅拉取 Todo,可能引发外键错误
7876
7936
  * });
7877
7937
  * ```
7878
7938
  */
@@ -7881,26 +7941,25 @@ class ki {
7881
7941
  return s.pulled > 0 && this.historyManager.clearUndoHistory(), s;
7882
7942
  }
7883
7943
  /**
7884
- * Push changes for a specific repository
7944
+ * 推送指定 Repository 的本地变更
7885
7945
  *
7886
- * Provides fine-grained control over synchronization at the entity type level.
7887
- * Supports cascade synchronization to automatically push dependent entities.
7946
+ * 提供实体类型级别的精细同步控制,支持级联同步以自动推送依赖实体。
7888
7947
  *
7889
- * @param namespace - Entity namespace (e.g., "public")
7890
- * @param entity - Entity name (e.g., "User")
7891
- * @param options - Push options
7892
- * @returns Push result
7948
+ * @param namespace - 实体命名空间(如 "public"
7949
+ * @param entity - 实体名称(如 "User"
7950
+ * @param options - 推送选项
7951
+ * @returns 推送结果
7893
7952
  *
7894
7953
  * @example
7895
7954
  * ```typescript
7896
- * // Push User repository with cascading dependents
7955
+ * // 推送 User 并级联推送依赖方
7897
7956
  * const result = await rxdb.versionManager.pushRepository('public', 'User', {
7898
- * includeRelated: true // Default: automatically pushes Post if Post references User
7957
+ * includeRelated: true // 默认:若 Post 引用 User 则自动推送 Post
7899
7958
  * });
7900
7959
  *
7901
- * // Push without cascading
7960
+ * // 不级联推送
7902
7961
  * const result = await rxdb.versionManager.pushRepository('public', 'User', {
7903
- * includeRelated: false // Only push User, dependent data may be incomplete
7962
+ * includeRelated: false // 仅推送 User,依赖数据可能不完整
7904
7963
  * });
7905
7964
  * ```
7906
7965
  */
@@ -7909,23 +7968,23 @@ class ki {
7909
7968
  return s.pushed > 0 && this.historyManager.clearUndoHistory(), s;
7910
7969
  }
7911
7970
  /**
7912
- * Sync a specific repository (pull then push)
7971
+ * 同步指定 Repository(先 pull push
7913
7972
  *
7914
- * Combines pull and push operations for a single repository, ensuring proper execution order.
7915
- * Recommended for ensuring data consistency when syncing a specific entity type.
7973
+ * 将单个 Repository 的 pull push 合并为一次操作,保证正确的执行顺序。
7974
+ * 推荐在需要确保特定实体类型数据一致性时使用。
7916
7975
  *
7917
- * @param namespace - Entity namespace (e.g., "public")
7918
- * @param entity - Entity name (e.g., "Todo")
7919
- * @param options - Sync options (separate pull and push options)
7920
- * @returns Sync result (contains both pull and push results)
7976
+ * @param namespace - 实体命名空间(如 "public"
7977
+ * @param entity - 实体名称(如 "Todo"
7978
+ * @param options - 同步选项(分别配置 pull push
7979
+ * @returns 同步结果(包含 pull push 结果)
7921
7980
  *
7922
7981
  * @example
7923
7982
  * ```typescript
7924
- * // Basic usage
7983
+ * // 基本用法
7925
7984
  * const result = await rxdb.versionManager.syncRepository('public', 'Todo');
7926
7985
  * console.log(`Pulled ${result.pullResult.pulled}, Pushed ${result.pushResult.pushed}`);
7927
7986
  *
7928
- * // Custom options for pull and push
7987
+ * // 自定义 pull push 选项
7929
7988
  * const result = await rxdb.versionManager.syncRepository('public', 'Todo', {
7930
7989
  * pull: { limit: 500, fetchAll: true },
7931
7990
  * push: { batchSize: 100 }
@@ -7960,26 +8019,25 @@ class ki {
7960
8019
  * ```
7961
8020
  */
7962
8021
  async cleanupExpired(e, t, n) {
7963
- return Mi(this, e, t, n);
8022
+ return Di(this, e, t, n);
7964
8023
  }
7965
8024
  /**
7966
- * Check for remote updates without downloading data (T040, US2)
8025
+ * 检查远程是否有更新,不下载数据
7967
8026
  *
7968
- * This method only queries how many new changes exist remotely,
7969
- * without actually pulling the data. Useful for showing
7970
- * "N updates available" messages to save bandwidth and time.
8027
+ * 仅查询远程有多少新变更,不实际拉取数据。
8028
+ * 适用于显示「有 N 条远程更新」提示,节省带宽和时间。
7971
8029
  *
7972
- * @param namespace - Entity namespace (e.g., "public")
7973
- * @param entity - Entity name (e.g., "Todo")
7974
- * @returns Update check result
8030
+ * @param namespace - 实体命名空间(如 "public"
8031
+ * @param entity - 实体名称(如 "Todo"
8032
+ * @returns 更新检查结果
7975
8033
  *
7976
8034
  * @example
7977
8035
  * ```typescript
7978
- * // Check if Todo has remote updates
8036
+ * // 检查 Todo 是否有远程更新
7979
8037
  * const result = await rxdb.versionManager.checkRepositoryUpdates('public', 'Todo');
7980
8038
  * if (result.hasUpdates) {
7981
- * console.log(`${result.pendingCount} updates available`);
7982
- * // User clicks "Update" button, then call pullRepository()
8039
+ * console.log(`有 ${result.pendingCount} 条更新可拉取`);
8040
+ * // 用户点击「更新」按钮后再调用 pullRepository()
7983
8041
  * }
7984
8042
  * ```
7985
8043
  */
@@ -7987,47 +8045,47 @@ class ki {
7987
8045
  return bn(this.rxdb, e, t);
7988
8046
  }
7989
8047
  /**
7990
- * Get sync status for a single repository (T052, US3)
8048
+ * 获取单个 Repository 的同步状态
7991
8049
  *
7992
- * Returns comprehensive sync status including:
7993
- * - syncType (full/remote/local/disabled)
7994
- * - pushableCount (number of local changes pending push)
7995
- * - pullableCount (number of remote changes available to pull)
7996
- * - Last sync timestamps
8050
+ * 返回完整的同步状态信息,包括:
8051
+ * - syncTypefull/remote/local/disabled
8052
+ * - pushableCount(待推送的本地变更数)
8053
+ * - pullableCount(可拉取的远程变更数)
8054
+ * - 最近同步时间戳
7997
8055
  *
7998
- * @param namespace - Entity namespace (e.g., "public")
7999
- * @param entity - Entity name (e.g., "Todo")
8000
- * @returns Repository sync status
8056
+ * @param namespace - 实体命名空间(如 "public"
8057
+ * @param entity - 实体名称(如 "Todo"
8058
+ * @returns Repository 同步状态
8001
8059
  *
8002
8060
  * @example
8003
8061
  * ```typescript
8004
8062
  * const status = await rxdb.versionManager.getRepositorySyncStatus('public', 'Todo');
8005
- * console.log(`Sync type: ${status.syncType}`);
8006
- * console.log(`Pushable: ${status.pushableCount}, Pullable: ${status.pullableCount}`);
8063
+ * console.log(`同步类型: ${status.syncType}`);
8064
+ * console.log(`待推送: ${status.pushableCount},可拉取: ${status.pullableCount}`);
8007
8065
  * ```
8008
8066
  */
8009
8067
  async getRepositorySyncStatus(e, t) {
8010
8068
  return vn(this.rxdb, e, t);
8011
8069
  }
8012
8070
  /**
8013
- * Get sync status for all repositories (T053, US3)
8071
+ * 获取所有 Repository 的同步状态
8014
8072
  *
8015
- * Returns status for all registered entities, with optional filtering.
8073
+ * 返回所有已注册实体的状态,支持可选过滤。
8016
8074
  *
8017
- * @param filter - Optional filter conditions
8018
- * @returns Array of repository sync statuses
8075
+ * @param filter - 可选过滤条件
8076
+ * @returns Repository 同步状态数组
8019
8077
  *
8020
8078
  * @example
8021
8079
  * ```typescript
8022
- * // Get all statuses
8080
+ * // 获取全部状态
8023
8081
  * const statuses = await rxdb.versionManager.getAllRepositorySyncStatus();
8024
8082
  *
8025
- * // Only get repositories with pending changes
8083
+ * // 仅获取有待处理变更的 Repository
8026
8084
  * const pending = await rxdb.versionManager.getAllRepositorySyncStatus({
8027
8085
  * hasPendingChanges: true
8028
8086
  * });
8029
8087
  *
8030
- * // Only get enabled full-sync repositories
8088
+ * // 仅获取已启用的全量同步 Repository
8031
8089
  * const fullSync = await rxdb.versionManager.getAllRepositorySyncStatus({
8032
8090
  * syncType: ['full'],
8033
8091
  * enabled: true
@@ -8035,24 +8093,23 @@ class ki {
8035
8093
  * ```
8036
8094
  */
8037
8095
  async getAllRepositorySyncStatus(e) {
8038
- return Bi(this.rxdb, e);
8096
+ return zi(this.rxdb, e);
8039
8097
  }
8040
8098
  /**
8041
- * Bulk sync multiple repositories
8099
+ * 批量同步多个 Repository
8042
8100
  *
8043
- * Syncs multiple repositories in a single operation with support for
8044
- * sequential or concurrent execution.
8101
+ * 在单次操作中同步多个 Repository,支持顺序或并发执行。
8045
8102
  *
8046
- * @param options - Bulk sync options
8047
- * @returns Bulk sync result with success/failure counts
8103
+ * @param options - 批量同步选项
8104
+ * @returns 批量同步结果(包含成功/失败计数)
8048
8105
  *
8049
8106
  * @example
8050
8107
  * ```typescript
8051
- * // Sync all enabled repositories sequentially
8108
+ * // 顺序同步所有已启用的 Repository
8052
8109
  * const result = await rxdb.versionManager.bulkSync();
8053
- * console.log(`Succeeded: ${result.succeeded}, Failed: ${result.failed}`);
8110
+ * console.log(`成功: ${result.succeeded},失败: ${result.failed}`);
8054
8111
  *
8055
- * // Sync specific repositories
8112
+ * // 同步指定 Repository
8056
8113
  * const result = await rxdb.versionManager.bulkSync({
8057
8114
  * repositories: [
8058
8115
  * { namespace: 'public', entity: 'Todo' },
@@ -8060,17 +8117,17 @@ class ki {
8060
8117
  * ]
8061
8118
  * });
8062
8119
  *
8063
- * // Concurrent sync with pull only
8120
+ * // 并发模式仅 pull
8064
8121
  * const result = await rxdb.versionManager.bulkSync({
8065
8122
  * concurrent: true,
8066
8123
  * concurrency: 3,
8067
8124
  * push: false
8068
8125
  * });
8069
8126
  *
8070
- * // Inspect results
8127
+ * // 检查每项结果
8071
8128
  * for (const item of result.results) {
8072
8129
  * if (item.success) {
8073
- * console.log(`${item.repository.entity}: pulled ${item.result.pull?.pulled || 0}`);
8130
+ * console.log(`${item.repository.entity}: 已拉取 ${item.result.pull?.pulled || 0} 条`);
8074
8131
  * } else {
8075
8132
  * console.error(`${item.repository.entity}: ${item.error.message}`);
8076
8133
  * }
@@ -8078,54 +8135,53 @@ class ki {
8078
8135
  * ```
8079
8136
  */
8080
8137
  async bulkSync(e) {
8081
- return Si(this.rxdb, e);
8138
+ return Bi(this.rxdb, e);
8082
8139
  }
8083
8140
  /**
8084
- * Get dependency graph for all repositories
8141
+ * 获取所有 Repository 的依赖图
8085
8142
  *
8086
- * Analyzes entity relationships (MANY_TO_ONE, ONE_TO_ONE) to build
8087
- * a dependency graph showing which repositories depend on others.
8143
+ * 分析实体关系(MANY_TO_ONEONE_TO_ONE)以构建依赖图,
8144
+ * 展示各 Repository 之间的依赖关系。
8088
8145
  *
8089
- * @returns Dependency graph with repository dependencies
8146
+ * @returns 包含依赖关系的依赖图
8090
8147
  *
8091
8148
  * @example
8092
8149
  * ```typescript
8093
8150
  * const graph = rxdb.versionManager.getRepositoryDependencyGraph();
8094
8151
  *
8095
- * // Iterate through dependencies
8152
+ * // 遍历依赖关系
8096
8153
  * for (const [key, dep] of graph) {
8097
- * console.log(`${key} depends on:`, dep.dependsOn);
8098
- * console.log(`${key} is required by:`, dep.requiredBy);
8154
+ * console.log(`${key} 依赖:`, dep.dependsOn);
8155
+ * console.log(`${key} 被依赖:`, dep.requiredBy);
8099
8156
  * }
8100
8157
  * ```
8101
8158
  */
8102
8159
  getRepositoryDependencyGraph() {
8103
8160
  const e = this.rxdb.config.entities.map((t) => I(t));
8104
- return ft(e);
8161
+ return yt(e);
8105
8162
  }
8106
8163
  /**
8107
- * Get sync order for repositories based on dependencies
8164
+ * 根据依赖关系获取 Repository 的同步顺序
8108
8165
  *
8109
- * Uses topological sort to determine the correct order for syncing
8110
- * repositories based on their dependencies.
8166
+ * 通过拓扑排序确定基于依赖关系的正确同步顺序。
8111
8167
  *
8112
- * @param direction - Sort direction: 'pull' (parent first) or 'push' (child first)
8113
- * @returns Ordered list of repositories
8168
+ * @param direction - 排序方向:'pull'(父节点优先)或 'push'(子节点优先)
8169
+ * @returns 有序的 Repository 列表
8114
8170
  *
8115
8171
  * @example
8116
8172
  * ```typescript
8117
- * // Get pull order (parents before children)
8173
+ * // 获取 pull 顺序(父节点优先)
8118
8174
  * const pullOrder = rxdb.versionManager.getRepositorySyncOrder('pull');
8119
8175
  * // [User, Todo, Comment]
8120
8176
  *
8121
- * // Get push order (children before parents)
8177
+ * // 获取 push 顺序(子节点优先)
8122
8178
  * const pushOrder = rxdb.versionManager.getRepositorySyncOrder('push');
8123
8179
  * // [Comment, Todo, User]
8124
8180
  * ```
8125
8181
  */
8126
8182
  getRepositorySyncOrder(e) {
8127
8183
  const t = this.getRepositoryDependencyGraph();
8128
- return yt(t, e);
8184
+ return mt(t, e);
8129
8185
  }
8130
8186
  // ============================================
8131
8187
  // Branch management
@@ -8142,16 +8198,63 @@ class ki {
8142
8198
  async switchBranch(e) {
8143
8199
  if ((await this.getCurrentBranch())?.id !== e)
8144
8200
  try {
8145
- this.rxdb.dispatchEvent(new er(e));
8146
- const { adapter: n } = await this.getLocalRepositories(), s = await Li(this, e), i = await n.switchBranch({
8201
+ this.rxdb.dispatchEvent(new sr(e));
8202
+ const { adapter: n } = await this.getLocalRepositories(), s = await Wi(this, e), i = await n.switchBranch({
8147
8203
  branchId: e,
8148
8204
  actions: s
8149
8205
  });
8150
- return this.historyManager.clearRedoStack(), this.rxdb.dispatchEvent(new tr(e)), i;
8206
+ return this.historyManager.clearRedoStack(), this.rxdb.dispatchEvent(new ir(e)), i;
8151
8207
  } catch (n) {
8152
- throw this.rxdb.dispatchEvent(new nr(e)), n;
8208
+ throw this.rxdb.dispatchEvent(new ar(e)), n;
8153
8209
  }
8154
8210
  }
8211
+ /**
8212
+ * 合并分支
8213
+ *
8214
+ * 将源分支的变更合并到当前激活分支(目标分支)。
8215
+ *
8216
+ * @param sourceBranchId - 源分支 ID
8217
+ * @param options - 合并选项
8218
+ * @returns 合并结果
8219
+ *
8220
+ * @remarks
8221
+ * 支持两种策略:
8222
+ * - `squash`(默认):将源分支所有变更压缩为最小操作集后一次性应用,目标分支只产生一组变更记录
8223
+ * - `normal`:逐条应用源分支变更,每条变更在目标分支产生独立的变更记录(保留历史细节)
8224
+ *
8225
+ * 合并后会清空 undo/redo 历史,因为合并操作不可逆。
8226
+ * 可选通过 `deleteSource: true` 在合并后删除源分支。
8227
+ *
8228
+ * @example
8229
+ * ```typescript
8230
+ * // 压缩合并(默认)
8231
+ * const result = await rxdb.versionManager.mergeBranch('feature-x');
8232
+ * console.log(`Merged ${result.merged} changes`);
8233
+ *
8234
+ * // 普通合并
8235
+ * const result = await rxdb.versionManager.mergeBranch('feature-x', {
8236
+ * strategy: 'normal'
8237
+ * });
8238
+ *
8239
+ * // 合并后删除源分支
8240
+ * const result = await rxdb.versionManager.mergeBranch('feature-x', {
8241
+ * deleteSource: true
8242
+ * });
8243
+ * ```
8244
+ */
8245
+ async mergeBranch(e, t) {
8246
+ const n = await this.getCurrentBranch();
8247
+ if (!n)
8248
+ throw new R("No active branch found");
8249
+ const s = n.id;
8250
+ try {
8251
+ this.rxdb.dispatchEvent(new or(e, s));
8252
+ const i = await Vi(this, e, s, t);
8253
+ return i.merged > 0 && this.historyManager.clearUndoHistory(), this.rxdb.dispatchEvent(new cr(e, s)), i;
8254
+ } catch (i) {
8255
+ throw this.rxdb.dispatchEvent(new lr(e, s)), i;
8256
+ }
8257
+ }
8155
8258
  /**
8156
8259
  * 获取特定作用域的历史记录 API
8157
8260
  *
@@ -8201,7 +8304,7 @@ class ki {
8201
8304
  throw new R(`Cannot restore from non-DELETE change (type=${a.type})`);
8202
8305
  if (!a.inversePatch)
8203
8306
  throw new R(`RxDBChange ${t.changeId} has no inversePatch`);
8204
- const o = be([a], !1), l = await this.getCurrentBranch();
8307
+ const o = de([a], !1), l = await this.getCurrentBranch();
8205
8308
  await s.switchBranch({ branchId: l.id, actions: o });
8206
8309
  const c = e.constructor;
8207
8310
  return (await s.getRepository(c).find({
@@ -8213,11 +8316,11 @@ class ki {
8213
8316
  }))[0];
8214
8317
  }
8215
8318
  async getLocalRepositories() {
8216
- const e = await L(this.rxdb.localAdapter$), t = e.getRepository(K), n = e.getRepository(H);
8319
+ const e = await L(this.rxdb.localAdapter$), t = e.getRepository(H), n = e.getRepository(K);
8217
8320
  return { branchRepository: t, changeRepository: n, adapter: e };
8218
8321
  }
8219
8322
  async getRemoteRepositories() {
8220
- const e = await L(this.rxdb.remoteAdapter$), t = e.getRepository(K), n = e.getRepository(H);
8323
+ const e = await L(this.rxdb.remoteAdapter$), t = e.getRepository(H), n = e.getRepository(K);
8221
8324
  return { branchRepository: t, changeRepository: n, adapter: e };
8222
8325
  }
8223
8326
  async getCurrentBranch() {
@@ -8238,14 +8341,14 @@ class ki {
8238
8341
  }, n = (s) => {
8239
8342
  this.historyManager.incrementPullableCount(s.entities.length);
8240
8343
  };
8241
- this.rxdb.addEventListener(Ue, e), this.rxdb.addEventListener(je, t), this.rxdb.addEventListener(Ye, n), this.#e.push(
8242
- { type: Ue, handler: e },
8243
- { type: je, handler: t },
8244
- { type: Ye, handler: n }
8344
+ this.rxdb.addEventListener(je, e), this.rxdb.addEventListener(Ye, t), this.rxdb.addEventListener(ze, n), this.#e.push(
8345
+ { type: je, handler: e },
8346
+ { type: Ye, handler: t },
8347
+ { type: ze, handler: n }
8245
8348
  );
8246
8349
  }
8247
8350
  }
8248
- class ga {
8351
+ class Ra {
8249
8352
  #e = new J("");
8250
8353
  #n = new J("");
8251
8354
  /**
@@ -8304,8 +8407,8 @@ class ga {
8304
8407
  * 本地适配器
8305
8408
  */
8306
8409
  localAdapter$ = this.#e.asObservable().pipe(
8307
- Ce(Boolean),
8308
- Fe(),
8410
+ Ie(Boolean),
8411
+ Ue(),
8309
8412
  x(
8310
8413
  (e) => ae(() => this.getAdapter(e)).pipe($((t) => t))
8311
8414
  ),
@@ -8315,8 +8418,8 @@ class ga {
8315
8418
  * 远程适配器
8316
8419
  */
8317
8420
  remoteAdapter$ = this.#n.asObservable().pipe(
8318
- Ce(Boolean),
8319
- Fe(),
8421
+ Ie(Boolean),
8422
+ Ue(),
8320
8423
  x(
8321
8424
  (e) => ae(() => this.getAdapter(e)).pipe($((t) => t))
8322
8425
  ),
@@ -8357,7 +8460,7 @@ class ga {
8357
8460
  * 获取 RxDB 版本号
8358
8461
  */
8359
8462
  get version() {
8360
- return ui;
8463
+ return gi;
8361
8464
  }
8362
8465
  get config() {
8363
8466
  return this.#t;
@@ -8367,14 +8470,14 @@ class ga {
8367
8470
  * @param options - RxDB 配置选项
8368
8471
  */
8369
8472
  constructor(e) {
8370
- this.#t = e, this.schemaManager = new li(this), this.entityManager = new Ys(this), this.versionManager = new ki(this), this.context = { ...this.#t.context }, this.#t.dbName = this.#t.dbName + "@" + this.version.replace(/\./g, "_"), Pn(this.#t), globalThis.rxdb = this;
8473
+ this.#t = e, this.schemaManager = new mi(this), this.entityManager = new Gs(this), this.versionManager = new Qi(this), this.context = { ...this.#t.context }, this.#t.dbName = this.#t.dbName + "@" + this.version.replace(/\./g, "_"), $n(this.#t), globalThis.rxdb = this;
8371
8474
  }
8372
8475
  /**
8373
8476
  * 初始化 RxDB
8374
8477
  */
8375
8478
  init() {
8376
8479
  if (this.#r) return;
8377
- this.#r = !0, this.#d.clientId || (this.#d.clientId = Ht());
8480
+ this.#r = !0, this.#d.clientId || (this.#d.clientId = Kt());
8378
8481
  const { local: e, remote: t } = this.#t.sync || {};
8379
8482
  e && this.#e.next(e.adapter), t && this.#n.next(t.adapter), this.#_(), this.schemaManager.init(), this.entityManager.init(), this.versionManager.init(), this.#y(), this.#m();
8380
8483
  }
@@ -8424,7 +8527,7 @@ class ga {
8424
8527
  const t = this.#f.get(e);
8425
8528
  if (!t)
8426
8529
  throw new Error(`Adapter "${String(e)}" not found. Please register it first using rxdb.adapter()`);
8427
- const n = t(this), s = $n(n) ? n : Promise.resolve(n);
8530
+ const n = t(this), s = Bn(n) ? n : Promise.resolve(n);
8428
8531
  return this.#h.set(e, s), s;
8429
8532
  }
8430
8533
  /**
@@ -8447,11 +8550,11 @@ class ga {
8447
8550
  const t = (async () => {
8448
8551
  this.init();
8449
8552
  const n = await this.getAdapter(e);
8450
- if (await n.connect(), rr(e, this.#t))
8553
+ if (await n.connect(), ur(e, this.#t))
8451
8554
  if (await n.isTableExisted(se))
8452
8555
  await this.#w(n);
8453
8556
  else {
8454
- const i = new K();
8557
+ const i = new H();
8455
8558
  i.id = "main", i.activated = !0, await n.createTables(this.#t.entities, [i]);
8456
8559
  }
8457
8560
  return this.#o.next(!0), n;
@@ -8493,14 +8596,14 @@ class ga {
8493
8596
  * @param event - 要派发的事件对象
8494
8597
  */
8495
8598
  dispatchEvent(e) {
8496
- this.#l && sr(e) === !1 ? this.#u.push(e) : this.#g(e.type).forEach((t) => t.call(this, e));
8599
+ this.#l && dr(e) === !1 ? this.#u.push(e) : this.#g(e.type).forEach((t) => t.call(this, e));
8497
8600
  }
8498
8601
  /**
8499
8602
  * 初始化网关
8500
8603
  * 设置统一的多 Tab 通信网关
8501
8604
  */
8502
8605
  #y() {
8503
- this.#c = new zs({
8606
+ this.#c = new Vs({
8504
8607
  dbName: this.#t.dbName,
8505
8608
  clientId: this.#d.clientId
8506
8609
  }), this.#c.init(
@@ -8576,7 +8679,7 @@ class ga {
8576
8679
  });
8577
8680
  }
8578
8681
  }
8579
- class _a {
8682
+ class Ca {
8580
8683
  /**
8581
8684
  * 解决单个冲突
8582
8685
  *
@@ -8603,109 +8706,116 @@ class _a {
8603
8706
  }
8604
8707
  }
8605
8708
  export {
8606
- Gn as CONFLICT_DETECTED_EVENT,
8607
- Qn as CONFLICT_PENDING_EVENT,
8608
- sa as ConflictDetectedEvent,
8609
- ia as ConflictPendingEvent,
8610
- _r as ENTITY_BASE_METADATA_OPTIONS,
8709
+ Zn as CONFLICT_DETECTED_EVENT,
8710
+ er as CONFLICT_PENDING_EVENT,
8711
+ ua as ConflictDetectedEvent,
8712
+ da as ConflictPendingEvent,
8713
+ Ir as ENTITY_BASE_METADATA_OPTIONS,
8611
8714
  ne as ENTITY_LOCAL_CREATE_EVENT,
8612
- zn as ENTITY_LOCAL_NEW_EVENT,
8715
+ kn as ENTITY_LOCAL_NEW_EVENT,
8613
8716
  ce as ENTITY_LOCAL_REMOVE_EVENT,
8614
8717
  oe as ENTITY_LOCAL_UPDATE_EVENT,
8615
- Ue as ENTITY_REMOTE_CREATE_EVENT,
8616
- Ye as ENTITY_REMOTE_REMOVE_EVENT,
8617
- je as ENTITY_REMOTE_UPDATE_EVENT,
8618
- ct as ENTITY_STATIC_TYPES,
8718
+ je as ENTITY_REMOTE_CREATE_EVENT,
8719
+ ze as ENTITY_REMOTE_REMOVE_EVENT,
8720
+ Ye as ENTITY_REMOTE_UPDATE_EVENT,
8721
+ lt as ENTITY_STATIC_TYPES,
8619
8722
  ie as Entity,
8620
- Ie as EntityBase,
8621
- Gi as EntityLocalCreatedEvent,
8622
- Zn as EntityLocalNewEvent,
8623
- Ji as EntityLocalRemovedEvent,
8624
- Qi as EntityLocalUpdatedEvent,
8625
- Xi as EntityRemoteCreatedEvent,
8626
- ea as EntityRemoteRemovedEvent,
8627
- Zi as EntityRemoteUpdatedEvent,
8628
- _a as LWWConflictResolver,
8723
+ Ae as EntityBase,
8724
+ ta as EntityLocalCreatedEvent,
8725
+ rr as EntityLocalNewEvent,
8726
+ ra as EntityLocalRemovedEvent,
8727
+ na as EntityLocalUpdatedEvent,
8728
+ sa as EntityRemoteCreatedEvent,
8729
+ aa as EntityRemoteRemovedEvent,
8730
+ ia as EntityRemoteUpdatedEvent,
8731
+ Ca as LWWConflictResolver,
8732
+ qn as MERGE_BRANCH_BEGIN,
8733
+ Gn as MERGE_BRANCH_COMMIT,
8734
+ Vn as MERGE_BRANCH_ROLLBACK,
8735
+ or as MergeBranchBeginEvent,
8736
+ cr as MergeBranchCommitEvent,
8737
+ it as MergeBranchEventBase,
8738
+ lr as MergeBranchRollbackEvent,
8629
8739
  et as NetworkOfflineError,
8630
8740
  W as OnDeleteAction,
8631
8741
  qt as OnUpdateAction,
8632
8742
  C as PropertyType,
8633
- ua as QueryCacheRepository,
8634
- ys as QueryTask,
8635
- Vi as REMOTE_CHANGES_PENDING_EVENT,
8636
- Jn as REPOSITORY_SYNC_BEGIN_EVENT,
8743
+ ma as QueryCacheRepository,
8744
+ Es as QueryTask,
8745
+ ea as REMOTE_CHANGES_PENDING_EVENT,
8746
+ tr as REPOSITORY_SYNC_BEGIN_EVENT,
8637
8747
  jt as REPOSITORY_SYNC_COMPLETE_EVENT,
8638
- Xn as REPOSITORY_SYNC_ERROR_EVENT,
8639
- T as RelationKind,
8748
+ nr as REPOSITORY_SYNC_ERROR_EVENT,
8749
+ A as RelationKind,
8640
8750
  sn as Repository,
8641
- $s as RepositoryBase,
8642
- it as RepositorySyncBeginEvent,
8643
- at as RepositorySyncCompleteEvent,
8644
- ot as RepositorySyncErrorEvent,
8645
- ga as RxDB,
8751
+ Ys as RepositoryBase,
8752
+ at as RepositorySyncBeginEvent,
8753
+ ot as RepositorySyncCompleteEvent,
8754
+ ct as RepositorySyncErrorEvent,
8755
+ Ra as RxDB,
8646
8756
  an as RxDBAdapterBase,
8647
- da as RxDBAdapterLocalBase,
8648
- ha as RxDBAdapterRemoteBase,
8649
- K as RxDBBranch,
8650
- H as RxDBChange,
8757
+ ga as RxDBAdapterLocalBase,
8758
+ _a as RxDBAdapterRemoteBase,
8759
+ H as RxDBBranch,
8760
+ K as RxDBChange,
8651
8761
  R as RxDBError,
8652
8762
  se as RxDBMigration,
8653
- pa as RxDBPluginBase,
8763
+ ba as RxDBPluginBase,
8654
8764
  z as RxDBSync,
8655
- kn as SWITCH_BRANCH_BEGIN,
8656
- Wn as SWITCH_BRANCH_COMMIT,
8765
+ Wn as SWITCH_BRANCH_BEGIN,
8766
+ Hn as SWITCH_BRANCH_COMMIT,
8657
8767
  Kn as SWITCH_BRANCH_ROLLBACK,
8658
- Hn as SYNC_BEGIN_EVENT,
8659
- qn as SYNC_COMPLETE_EVENT,
8660
- Vn as SYNC_ERROR_EVENT,
8661
- er as SwitchBranchBeginEvent,
8662
- tr as SwitchBranchCommitEvent,
8768
+ Qn as SYNC_BEGIN_EVENT,
8769
+ Jn as SYNC_COMPLETE_EVENT,
8770
+ Xn as SYNC_ERROR_EVENT,
8771
+ sr as SwitchBranchBeginEvent,
8772
+ ir as SwitchBranchCommitEvent,
8663
8773
  st as SwitchBranchEventBase,
8664
- nr as SwitchBranchRollbackEvent,
8774
+ ar as SwitchBranchRollbackEvent,
8665
8775
  Yt as SyncBeginEvent,
8666
8776
  zt as SyncCompleteEvent,
8667
8777
  kt as SyncErrorEvent,
8668
- ms as SyncStatus,
8669
- fe as SyncType,
8778
+ Rs as SyncStatus,
8779
+ ye as SyncType,
8670
8780
  tt as TRANSACTION_BEGIN,
8671
8781
  nt as TRANSACTION_COMMIT,
8672
8782
  rt as TRANSACTION_ROLLBACK,
8673
- vr as TREE_ADJACENCY_LIST_ENTITY_BASE_OPTIONS,
8674
- ta as TransactionBeginEvent,
8675
- na as TransactionCommitEvent,
8676
- ra as TransactionRollbackEvent,
8677
- _t as TreeAdjacencyListEntityBase,
8678
- yr as TreeEntity,
8679
- ca as __decorateClass,
8680
- Mi as cleanupExpired,
8783
+ Sr as TREE_ADJACENCY_LIST_ENTITY_BASE_OPTIONS,
8784
+ oa as TransactionBeginEvent,
8785
+ ca as TransactionCommitEvent,
8786
+ la as TransactionRollbackEvent,
8787
+ bt as TreeAdjacencyListEntityBase,
8788
+ Er as TreeEntity,
8789
+ fa as __decorateClass,
8790
+ Di as cleanupExpired,
8681
8791
  un as compactChanges,
8682
- $r as diffMetadata,
8683
- cr as fillDefaultValue,
8684
- lr as fillInitValue,
8792
+ Yr as diffMetadata,
8793
+ yr as fillDefaultValue,
8794
+ mr as fillInitValue,
8685
8795
  I as getEntityMetadata,
8686
- Pe as getEntityMutations,
8796
+ $e as getEntityMutations,
8687
8797
  O as getEntityStatus,
8688
- aa as getEntityType,
8689
- ur as getNeedRemoveEntities,
8690
- gt as getNeedSaveEntities,
8691
- Ze as getRxDBChangeKey,
8692
- hi as getSyncConfig,
8798
+ ha as getEntityType,
8799
+ gr as getNeedRemoveEntities,
8800
+ _t as getNeedSaveEntities,
8801
+ we as getRxDBChangeKey,
8802
+ bi as getSyncConfig,
8693
8803
  j as getSyncType,
8694
- ya as getSyncableRepositories,
8695
- ma as groupBySyncType,
8696
- la as isEntityInternalName,
8697
- fi as isNoSync,
8698
- Vt as isRuleGroup,
8699
- oa as isRxDBEntity,
8804
+ va as getSyncableRepositories,
8805
+ Ea as groupBySyncType,
8806
+ ya as isEntityInternalName,
8807
+ vi as isNoSync,
8808
+ Gt as isRuleGroup,
8809
+ pa as isRxDBEntity,
8700
8810
  dn as needsPull,
8701
- pi as needsPush,
8702
- fa as parseRxDBChangeKey,
8703
- xr as queryNeedRefreshCreate,
8704
- Nr as queryNeedRefreshRemove,
8705
- Pr as queryNeedRefreshUpdate,
8811
+ wi as needsPush,
8812
+ wa as parseRxDBChangeKey,
8813
+ Fr as queryNeedRefreshCreate,
8814
+ Ur as queryNeedRefreshRemove,
8815
+ jr as queryNeedRefreshUpdate,
8706
8816
  M as setSafeObjectKey,
8707
- he as setSafeObjectKeyLazyInitOnce,
8708
- or as setSafeObjectWritableKey,
8709
- fr as transitionMetadata,
8710
- Ht as uuid
8817
+ pe as setSafeObjectKeyLazyInitOnce,
8818
+ fr as setSafeObjectWritableKey,
8819
+ vr as transitionMetadata,
8820
+ Kt as uuid
8711
8821
  };