@aiao/rxdb 0.0.11 → 0.0.12

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
@@ -13,56 +13,56 @@ class et extends R {
13
13
  super(`NetworkOfflineError: ${e.message}`), this.name = "NetworkOfflineError", this.originalError = e, Object.setPrototypeOf(this, et.prototype);
14
14
  }
15
15
  }
16
- const Wn = "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", Kn = "SWITCH_BRANCH_COMMIT", Hn = "SWITCH_BRANCH_ROLLBACK", qn = "SYNC_BEGIN", Vn = "SYNC_COMPLETE", Gn = "SYNC_ERROR", Vi = "REMOTE_CHANGES_PENDING", Qn = "CONFLICT_DETECTED", Jn = "CONFLICT_PENDING", Xn = "REPOSITORY_SYNC_BEGIN", jt = "REPOSITORY_SYNC_COMPLETE", Zn = "REPOSITORY_SYNC_ERROR";
16
+ const Wn = "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", Kn = "SWITCH_BRANCH_COMMIT", Hn = "SWITCH_BRANCH_ROLLBACK", qn = "SYNC_BEGIN", Vn = "SYNC_COMPLETE", Gn = "SYNC_ERROR", Gi = "REMOTE_CHANGES_PENDING", Qn = "CONFLICT_DETECTED", Jn = "CONFLICT_PENDING", Xn = "REPOSITORY_SYNC_BEGIN", jt = "REPOSITORY_SYNC_COMPLETE", Zn = "REPOSITORY_SYNC_ERROR";
17
17
  class er {
18
18
  constructor(e) {
19
19
  this.entities = e;
20
20
  }
21
21
  type = Wn;
22
22
  }
23
- class Gi {
23
+ class Qi {
24
24
  constructor(e) {
25
25
  this.entities = e;
26
26
  }
27
27
  type = ne;
28
28
  }
29
- class Qi {
29
+ class Ji {
30
30
  constructor(e) {
31
31
  this.entities = e;
32
32
  }
33
33
  type = oe;
34
34
  }
35
- class Ji {
35
+ class Xi {
36
36
  constructor(e) {
37
37
  this.entities = e;
38
38
  }
39
39
  type = ce;
40
40
  }
41
- class Xi {
41
+ class Zi {
42
42
  constructor(e) {
43
43
  this.entities = e;
44
44
  }
45
45
  type = Ue;
46
46
  }
47
- class Zi {
47
+ class ea {
48
48
  constructor(e) {
49
49
  this.entities = e;
50
50
  }
51
51
  type = je;
52
52
  }
53
- class ea {
53
+ class ta {
54
54
  constructor(e) {
55
55
  this.entities = e;
56
56
  }
57
57
  type = Ye;
58
58
  }
59
- class ta {
59
+ class na {
60
60
  type = tt;
61
61
  }
62
- class na {
62
+ class ra {
63
63
  type = nt;
64
64
  }
65
- class ra {
65
+ class sa {
66
66
  type = rt;
67
67
  }
68
68
  class st {
@@ -97,13 +97,13 @@ class Wt {
97
97
  }
98
98
  type = Gn;
99
99
  }
100
- class sa {
100
+ class ia {
101
101
  constructor(e, t, n) {
102
102
  this.conflicts = e, this.resolved = t, this.deferred = n;
103
103
  }
104
104
  type = Qn;
105
105
  }
106
- class ia {
106
+ class aa {
107
107
  constructor(e) {
108
108
  this.conflicts = e;
109
109
  }
@@ -127,12 +127,12 @@ class ot {
127
127
  }
128
128
  type = Zn;
129
129
  }
130
- const kt = /* @__PURE__ */ Symbol("ɵProxy"), ze = /* @__PURE__ */ Symbol("ɵMetadata"), Kt = /* @__PURE__ */ Symbol("ɵStatus"), We = /* @__PURE__ */ Symbol("ɵEntityManager"), ke = /* @__PURE__ */ Symbol("ɵEntityType"), sr = (r, e) => e.sync.local?.adapter === r, ir = (r) => [tt, nt, rt].includes(r.type), I = (r) => r[ze] || r.constructor[ze], aa = (r) => r[ke] || r.constructor[ke], O = (r) => r && r[Kt], oa = (r) => r && !!O(r), ca = (r, e, t, n) => {
130
+ const kt = /* @__PURE__ */ Symbol("ɵProxy"), ze = /* @__PURE__ */ Symbol("ɵMetadata"), Kt = /* @__PURE__ */ Symbol("ɵStatus"), We = /* @__PURE__ */ Symbol("ɵEntityManager"), ke = /* @__PURE__ */ Symbol("ɵEntityType"), sr = (r, e) => e.sync.local?.adapter === r, ir = (r) => [tt, nt, rt].includes(r.type), I = (r) => r[ze] || r.constructor[ze], oa = (r) => r[ke] || r.constructor[ke], O = (r) => r && r[Kt], ca = (r) => r && !!O(r), la = (r, e, t, n) => {
131
131
  let s = n > 1 ? void 0 : n ? Object.getOwnPropertyDescriptor(e, t) : e;
132
132
  for (let i = r.length - 1, a; i >= 0; i--)
133
133
  (a = r[i]) && (s = a(s) || s);
134
134
  return s;
135
- }, Ht = () => Dn(), ar = ["id", "createdAt", "updatedAt", "createdBy", "updatedBy"], or = ["rev"], la = (r) => !!(ar.includes(r) || or.includes(r) || r.startsWith("_")), M = (r, e, t) => Object.defineProperty(r, e, {
135
+ }, Ht = () => Dn(), ar = ["id", "createdAt", "updatedAt", "createdBy", "updatedBy"], or = ["rev"], ua = (r) => !!(ar.includes(r) || or.includes(r) || r.startsWith("_")), M = (r, e, t) => Object.defineProperty(r, e, {
136
136
  value: t,
137
137
  enumerable: !1,
138
138
  configurable: !1,
@@ -184,8 +184,8 @@ const kt = /* @__PURE__ */ Symbol("ɵProxy"), ze = /* @__PURE__ */ Symbol("ɵMet
184
184
  }
185
185
  for (const a of t)
186
186
  if (O(a).local) {
187
- const c = a.constructor;
188
- i.has(c) || i.set(c, /* @__PURE__ */ new Set()), i.get(c).add(a);
187
+ const l = a.constructor;
188
+ i.has(l) || i.set(l, /* @__PURE__ */ new Set()), i.get(l).add(a);
189
189
  }
190
190
  return {
191
191
  create: n,
@@ -232,7 +232,7 @@ const hr = (r, e, t = !1) => {
232
232
  onUpdate: t
233
233
  };
234
234
  }
235
- }, fr = (r, e) => {
235
+ }, fr = (r) => r.kind !== T.ONE_TO_MANY, yr = (r, e) => {
236
236
  const t = [];
237
237
  t.push(r);
238
238
  const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = { ...r };
@@ -242,16 +242,16 @@ const hr = (r, e, t = !1) => {
242
242
  for (; u !== Object.prototype && d; )
243
243
  u = Object.getPrototypeOf(u), d = I(u), d && t.push(d);
244
244
  } else Rn(e) ? t.push(...e) : t.push(e);
245
- const l = t.map((u) => u.name);
246
- l.shift(), o.extends = l;
245
+ const c = t.map((u) => u.name);
246
+ c.shift(), o.extends = c;
247
247
  }
248
- o.extends = o.extends || [], o.displayName || (o.displayName = o.name), o.tableName || (o.tableName = o.name), t.reverse().forEach((l) => {
249
- l.namespace = l.namespace || "public", l.properties?.forEach((u) => {
248
+ o.extends = o.extends || [], o.displayName || (o.displayName = o.name), o.tableName || (o.tableName = o.name), t.reverse().forEach((c) => {
249
+ c.namespace = c.namespace || "public", c.properties?.forEach((u) => {
250
250
  u.columnName || (u.columnName = u.name), n.set(u.name, u);
251
- }), l.computedProperties?.forEach((u) => {
251
+ }), c.computedProperties?.forEach((u) => {
252
252
  u.columnName || (u.columnName = u.name), s.set(u.name, u);
253
- }), l.relations?.forEach((u) => {
254
- u.mappedNamespace = u.mappedNamespace || "public", u.columnName || (u.columnName = u.name + "Id");
253
+ }), c.relations?.forEach((u) => {
254
+ u.mappedNamespace = u.mappedNamespace || "public";
255
255
  const d = "nullable" in u ? u.nullable ?? !1 : !1, h = hr(
256
256
  {
257
257
  onDelete: u.onDelete,
@@ -260,40 +260,40 @@ const hr = (r, e, t = !1) => {
260
260
  u.kind,
261
261
  d
262
262
  );
263
- if (u.onDelete = h.onDelete, u.onUpdate = h.onUpdate, u.mappedEntity === l.name && u.mappedNamespace === l.namespace) {
263
+ if (u.onDelete = h.onDelete, u.onUpdate = h.onUpdate, fr(u) && !u.columnName && (u.columnName = u.name + "Id"), u.mappedEntity === c.name && u.mappedNamespace === c.namespace) {
264
264
  const p = { ...u };
265
265
  p.mappedEntity = o.name, p.mappedNamespace = o.namespace, i.set(u.name, p);
266
266
  } else
267
267
  i.set(u.name, u);
268
- }), l.indexes?.forEach((u) => a.set(u.name, u));
268
+ }), c.indexes?.forEach((u) => a.set(u.name, u));
269
269
  }), M(o, "propertyMap", n), M(o, "computedPropertyMap", s), M(o, "relationMap", i), M(o, "indexMap", a);
270
- const c = /* @__PURE__ */ new Map();
271
- return n.forEach((l, u) => {
272
- c.set(l.columnName, u);
273
- }), M(o, "columnNameToPropertyName", c), he(
270
+ const l = /* @__PURE__ */ new Map();
271
+ return n.forEach((c, u) => {
272
+ l.set(c.columnName, u);
273
+ }), M(o, "columnNameToPropertyName", l), he(
274
274
  o,
275
275
  "defaultValueProperties",
276
- () => Array.from(n.values()).filter((l) => l.default !== void 0)
276
+ () => Array.from(n.values()).filter((c) => c.default !== void 0)
277
277
  ), he(
278
278
  o,
279
279
  "foreignKeyRelations",
280
280
  () => Array.from(o.relationMap.values()).filter(
281
- (l) => l.kind === T.MANY_TO_ONE || l.kind === T.ONE_TO_ONE
281
+ (c) => c.kind === T.MANY_TO_ONE || c.kind === T.ONE_TO_ONE
282
282
  )
283
283
  ), he(o, "foreignKeyRelationMap", () => {
284
- const l = /* @__PURE__ */ new Map();
285
- return o.foreignKeyRelations.forEach((u) => l.set(`${u.name}Id`, u)), l;
286
- }), he(o, "foreignKeyNames", () => o.foreignKeyRelations.map((l) => `${l.name}Id`)), he(
284
+ const c = /* @__PURE__ */ new Map();
285
+ return o.foreignKeyRelations.forEach((u) => c.set(`${u.name}Id`, u)), c;
286
+ }), he(o, "foreignKeyNames", () => o.foreignKeyRelations.map((c) => `${c.name}Id`)), he(
287
287
  o,
288
288
  "foreignKeyColumnNames",
289
- () => o.foreignKeyRelations.map((l) => l.columnName)
289
+ () => o.foreignKeyRelations.filter((c) => !!c.columnName).map((c) => c.columnName)
290
290
  ), M(
291
291
  o,
292
292
  "isForeignKey",
293
- (l) => l && l.endsWith("Id") && o.foreignKeyNames.includes(l)
293
+ (c) => c && c.endsWith("Id") && o.foreignKeyNames.includes(c)
294
294
  ), o;
295
295
  }, ie = (r) => (e) => {
296
- const t = fr(r, e);
296
+ const t = yr(r, e);
297
297
  if (M(e, ze, t), r.abstract) return e;
298
298
  const n = e;
299
299
  return class extends n {
@@ -315,7 +315,7 @@ const hr = (r, e, t = !1) => {
315
315
  return lr(t, this), s && ur(t, this, s), i[kt](this);
316
316
  }
317
317
  };
318
- }, yr = (r) => {
318
+ }, mr = (r) => {
319
319
  const e = r.features?.tree ?? {};
320
320
  return ie({
321
321
  ...r,
@@ -330,12 +330,12 @@ const hr = (r, e, t = !1) => {
330
330
  repository: r.repository ?? "TreeRepository"
331
331
  });
332
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--)
333
+ var gr = Object.getOwnPropertyDescriptor, _r = (r, e, t, n) => {
334
+ for (var s = n > 1 ? void 0 : n ? gr(e, t) : e, i = r.length - 1, a; i >= 0; i--)
335
335
  (a = r[i]) && (s = a(s) || s);
336
336
  return s;
337
337
  };
338
- const _r = {
338
+ const br = {
339
339
  name: "EntityBase",
340
340
  abstract: !0,
341
341
  // 标记为抽象类,不会直接创建此类的实例
@@ -419,15 +419,15 @@ let Ie = class {
419
419
  constructor(r) {
420
420
  }
421
421
  };
422
- Ie = gr([
423
- ie(_r)
422
+ Ie = _r([
423
+ ie(br)
424
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--)
425
+ var wr = Object.getOwnPropertyDescriptor, vr = (r, e, t, n) => {
426
+ for (var s = n > 1 ? void 0 : n ? wr(e, t) : e, i = r.length - 1, a; i >= 0; i--)
427
427
  (a = r[i]) && (s = a(s) || s);
428
428
  return s;
429
429
  };
430
- const vr = {
430
+ const Er = {
431
431
  name: "TreeAdjacencyListEntityBase",
432
432
  abstract: !0,
433
433
  // 标记为抽象类,不会直接创建此类的实例
@@ -457,11 +457,15 @@ const vr = {
457
457
  {
458
458
  name: "parent",
459
459
  // 父节点关系名称
460
+ columnName: "parentId",
461
+ // 外键列名
460
462
  displayName: "父节点",
461
463
  kind: T.MANY_TO_ONE,
462
464
  // 多对一关系
463
465
  mappedEntity: "TreeAdjacencyListEntityBase",
464
466
  // 关联到同一实体类型
467
+ mappedProperty: "children",
468
+ // 映射到父实体的 children 属性
465
469
  nullable: !0,
466
470
  // 允许根节点没有父节点
467
471
  onDelete: k.CASCADE
@@ -483,10 +487,10 @@ let _t = class extends Ie {
483
487
  */
484
488
  parentId;
485
489
  };
486
- _t = wr([
487
- ie(vr)
490
+ _t = vr([
491
+ ie(Er)
488
492
  ], _t);
489
- const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r) => r.operator === "exists" || r.operator === "notExists", Cr = (r, e) => {
493
+ const Vt = (r) => !!(r && r.combinator), Rr = (r) => !!(r && r.field), Cr = (r) => r.operator === "exists" || r.operator === "notExists", Ir = (r, e) => {
490
494
  const t = Reflect.get(e, r.field), { operator: n } = r;
491
495
  switch (n) {
492
496
  case "in":
@@ -539,7 +543,7 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
539
543
  }
540
544
  case "exists":
541
545
  case "notExists": {
542
- const s = Rr(r) ? r.where : void 0;
546
+ const s = Cr(r) ? r.where : void 0;
543
547
  if (Array.isArray(t)) {
544
548
  let i = t;
545
549
  s && (i = t.filter((o) => Y(o, s)));
@@ -562,23 +566,23 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
562
566
  const { combinator: t, rules: n } = r;
563
567
  return t === "and" ? n.every((s) => Ke(s, e)) : n.some((s) => Ke(s, e));
564
568
  } else
565
- return Cr(r, e);
566
- }, Y = (r, e) => r == null ? !1 : Ke(e, r), Ir = (r, e, t) => {
569
+ return Ir(r, e);
570
+ }, Y = (r, e) => r == null ? !1 : Ke(e, r), Tr = (r, e, t) => {
567
571
  const { field: n, sort: s } = t, i = In(r, n);
568
572
  if (s === "asc") {
569
- if (e.some((c) => i < Reflect.get(c, n))) return !0;
570
- if (e.every((c) => i > Reflect.get(c, n))) return !1;
573
+ if (e.some((l) => i < Reflect.get(l, n))) return !0;
574
+ if (e.every((l) => i > Reflect.get(l, n))) return !1;
571
575
  } else {
572
- if (e.some((c) => i > Reflect.get(c, n))) return !0;
573
- if (e.every((c) => i < Reflect.get(c, n))) return !1;
576
+ if (e.some((l) => i > Reflect.get(l, n))) return !0;
577
+ if (e.every((l) => i < Reflect.get(l, n))) return !1;
574
578
  }
575
- }, Tr = (r, e, t) => {
579
+ }, Ar = (r, e, t) => {
576
580
  if (!t || t.length === 0 || e.length === 0 || !r) return !0;
577
581
  for (let n = 0; n < t.length; n++) {
578
- const s = t[n], i = Ir(r, e, s);
582
+ const s = t[n], i = Tr(r, e, s);
579
583
  if (i === void 0) {
580
584
  const { field: a } = s, o = Reflect.get(r, a);
581
- e = e.filter((c) => Reflect.get(c, a) === o);
585
+ e = e.filter((l) => Reflect.get(l, a) === o);
582
586
  } else
583
587
  return i;
584
588
  }
@@ -593,21 +597,21 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
593
597
  refresh: n === !1 && bt(r, e),
594
598
  recalculate: n
595
599
  };
596
- }, bt = (r, e) => e.some((t) => t.every((n) => r[n]())), Ar = (r, e, t, n, s) => {
600
+ }, bt = (r, e) => e.some((t) => t.every((n) => r[n]())), Sr = (r, e, t, n, s) => {
597
601
  const i = t.slice(0, n);
598
602
  let a = e;
599
603
  for (const o of i) {
600
604
  if (!a?.relationMap.has(o))
601
605
  return !1;
602
- const c = a.relationMap.get(o), l = r.schemaManager.getEntityType(c.mappedEntity, c.mappedNamespace);
603
- if (l && s.add(l), c.kind === T.MANY_TO_MANY) {
604
- const u = c.junctionEntityType;
606
+ 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;
605
609
  u && s.add(u);
606
610
  }
607
- a = r.schemaManager.getEntityMetadata(c.mappedEntity, c.mappedNamespace);
611
+ a = r.schemaManager.getEntityMetadata(l.mappedEntity, l.mappedNamespace);
608
612
  }
609
613
  return a !== void 0;
610
- }, Sr = (r, e, t, n) => {
614
+ }, Mr = (r, e, t, n) => {
611
615
  const s = t.split(".");
612
616
  try {
613
617
  const i = r.schemaManager.getFieldRelations(e, t);
@@ -616,8 +620,8 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
616
620
  i.relations.forEach(({ relation: a }) => {
617
621
  const o = r.schemaManager.getEntityType(a.mappedEntity, a.mappedNamespace);
618
622
  if (o && n.add(o), a.kind === T.MANY_TO_MANY) {
619
- const c = a.junctionEntityType;
620
- c && n.add(c);
623
+ const l = a.junctionEntityType;
624
+ l && n.add(l);
621
625
  }
622
626
  });
623
627
  return;
@@ -631,15 +635,15 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
631
635
  for (let i = s.length - 1; i > 0; i--) {
632
636
  const a = s.slice(i);
633
637
  if (a.length === 0) continue;
634
- if (Ar(r, e, s, i, n)) {
635
- const c = s.slice(0, i);
636
- let l = e;
637
- for (const u of c) {
638
- const d = l?.relationMap.get(u);
639
- d && (l = r.schemaManager.getEntityMetadata(d.mappedEntity, d.mappedNamespace));
638
+ if (Sr(r, e, s, i, n)) {
639
+ const l = s.slice(0, i);
640
+ let c = e;
641
+ for (const u of l) {
642
+ const d = c?.relationMap.get(u);
643
+ d && (c = r.schemaManager.getEntityMetadata(d.mappedEntity, d.mappedNamespace));
640
644
  }
641
- if (l) {
642
- const u = a[0], d = l.propertyMap.get(u);
645
+ if (c) {
646
+ const u = a[0], d = c.propertyMap.get(u);
643
647
  if (d && d.type === C.keyValue)
644
648
  return;
645
649
  }
@@ -654,16 +658,16 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
654
658
  i(o);
655
659
  continue;
656
660
  }
657
- const c = o, l = c.field, u = c.operator;
661
+ const l = o, c = l.field, u = l.operator;
658
662
  if (u === "exists" || u === "notExists") {
659
- const d = s.relationMap.get(l);
663
+ const d = s.relationMap.get(c);
660
664
  if (d) {
661
665
  const h = r.schemaManager.getEntityType(d.mappedEntity, d.mappedNamespace);
662
666
  if (h && n.add(h), d.kind === T.MANY_TO_MANY) {
663
667
  const p = d.junctionEntityType;
664
668
  p && n.add(p);
665
669
  }
666
- if (c.where && r.schemaManager.getEntityMetadata(
670
+ if (l.where && r.schemaManager.getEntityMetadata(
667
671
  d.mappedEntity,
668
672
  d.mappedNamespace
669
673
  )) {
@@ -671,21 +675,21 @@ const Vt = (r) => !!(r && r.combinator), Er = (r) => !!(r && r.field), Rr = (r)
671
675
  d.mappedEntity,
672
676
  d.mappedNamespace
673
677
  );
674
- f && (lt(r, c.where, f, m), m.forEach((y) => n.add(y)));
678
+ f && (lt(r, l.where, f, m), m.forEach((y) => n.add(y)));
675
679
  }
676
680
  }
677
681
  continue;
678
682
  }
679
- if (l && l.includes("."))
683
+ if (c && c.includes("."))
680
684
  try {
681
- Sr(r, s, l, n);
685
+ Mr(r, s, c, n);
682
686
  } catch {
683
687
  }
684
688
  }
685
689
  };
686
690
  i(e);
687
691
  };
688
- function Mr(r, e) {
692
+ function Or(r, e) {
689
693
  const { rxdb: t, entityType: n } = r, s = I(n);
690
694
  if (!s) return !1;
691
695
  const i = t.schemaManager.getEntityMetadata(e.entity, e.namespace);
@@ -694,9 +698,9 @@ function Mr(r, e) {
694
698
  if (a) {
695
699
  const o = /* @__PURE__ */ new Set();
696
700
  lt(t, a, n, o);
697
- for (const c of o) {
698
- const l = I(c);
699
- if (l && l.name === e.entity && l.namespace === e.namespace)
701
+ for (const l of o) {
702
+ const c = I(l);
703
+ if (c && c.name === e.entity && c.namespace === e.namespace)
700
704
  return !0;
701
705
  }
702
706
  }
@@ -713,11 +717,11 @@ function Gt(r, e) {
713
717
  };
714
718
  const n = [], s = [];
715
719
  return e.forEach((i) => {
716
- const a = i.entity === t.name && i.namespace === t.namespace, o = Mr(r, i);
720
+ const a = i.entity === t.name && i.namespace === t.namespace, o = Or(r, i);
717
721
  a ? (n.push(i), o && r.type !== "findByCursor" && s.push(i)) : o && s.push(i);
718
722
  }), { current_entities: n, relation_entities: s };
719
723
  }
720
- function Or(r, e) {
724
+ function xr(r, e) {
721
725
  const t = new Set(
722
726
  e.relations ? e.relations.map((s) => s.name) : Array.from(e.relationMap?.keys() ?? [])
723
727
  ), n = (s) => {
@@ -725,7 +729,7 @@ function Or(r, e) {
725
729
  for (const i of s.rules)
726
730
  if (Vt(i)) {
727
731
  if (n(i)) return !0;
728
- } else if (Er(i)) {
732
+ } else if (Rr(i)) {
729
733
  const a = i.field;
730
734
  if (a.includes(".")) return !0;
731
735
  const o = a.split(":")[0];
@@ -762,7 +766,7 @@ class ut {
762
766
  * 构建完整规则集(UPDATE)
763
767
  */
764
768
  buildUpdateRules() {
765
- const e = this.buildMatchWhere("patch"), t = S(() => e() === !1), n = this.buildMatchWhere("inversePatch"), s = S(() => n() === !1), i = this.buildResultContains(), a = S(() => i() === !1), { matchRelationWhere: o, notMatchRelationWhere: c } = this.buildRelationWhereRulesForUpdate();
769
+ const e = this.buildMatchWhere("patch"), t = S(() => e() === !1), n = this.buildMatchWhere("inversePatch"), s = S(() => n() === !1), i = this.buildResultContains(), a = S(() => i() === !1), { matchRelationWhere: o, notMatchRelationWhere: l } = this.buildRelationWhereRulesForUpdate();
766
770
  return {
767
771
  match_where: e,
768
772
  not_match_where: t,
@@ -770,7 +774,7 @@ class ut {
770
774
  match_where_before: n,
771
775
  not_match_where_before: s,
772
776
  match_relation_where: o,
773
- not_match_relation_where: c,
777
+ not_match_relation_where: l,
774
778
  result_contains: i,
775
779
  result_not_contains: a
776
780
  };
@@ -832,13 +836,13 @@ class ut {
832
836
  buildOrderByRule() {
833
837
  const e = "orderBy" in this.task.options ? this.task.options.orderBy : void 0;
834
838
  return e ? S(
835
- () => this.current_entities.some((t) => Tr(t.patch, Array.from(this.task.resultEntitySet), e))
839
+ () => this.current_entities.some((t) => Ar(t.patch, Array.from(this.task.resultEntitySet), e))
836
840
  ) : ee;
837
841
  }
838
842
  }
839
- const $e = S(() => !0), xr = (r, e, t, n) => {
843
+ const $e = S(() => !0), Nr = (r, e, t, n) => {
840
844
  if (!I(r.entityType)) {
841
- const l = S(() => e.map((_) => _.id)), u = $e, d = $e, h = $e, p = S(() => !1), m = S(() => !0), f = S(() => l().some((_) => r.resultEntitySet?.has(_))), y = S(() => f() === !1);
845
+ 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);
842
846
  return {
843
847
  ...me({
844
848
  match_where: u,
@@ -853,16 +857,16 @@ const $e = S(() => !0), xr = (r, e, t, n) => {
853
857
  relation_entities: []
854
858
  };
855
859
  }
856
- const { current_entities: i, relation_entities: a } = Gt(r, e), c = new ut(r, i, a.length > 0).buildCreateRules();
860
+ const { current_entities: i, relation_entities: a } = Gt(r, e), l = new ut(r, i, a.length > 0).buildCreateRules();
857
861
  return {
858
- ...me(c, t, n),
862
+ ...me(l, t, n),
859
863
  current_entities: i,
860
864
  relation_entities: a
861
865
  };
862
- }, Nr = (r, e, t, n) => {
866
+ }, Pr = (r, e, t, n) => {
863
867
  const i = new ut(r, e, !1).buildRemoveRules();
864
868
  return me(i, t, n);
865
- }, wt = S(() => !0), Pr = (r, e, t, n) => {
869
+ }, wt = S(() => !0), $r = (r, e, t, n) => {
866
870
  const s = I(r.entityType);
867
871
  if (!s) {
868
872
  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 = {
@@ -878,20 +882,20 @@ const $e = S(() => !0), xr = (r, e, t, n) => {
878
882
  return me(w, t, n);
879
883
  }
880
884
  const { current_entities: i, relation_entities: a } = Gt(r, e), o = "where" in r.options ? r.options.where : void 0;
881
- let c = !1;
882
- o && (c = Or(o, s));
883
- const u = new ut(r, i, a.length > 0, c).buildUpdateRules();
885
+ let l = !1;
886
+ o && (l = xr(o, s));
887
+ const u = new ut(r, i, a.length > 0, l).buildUpdateRules();
884
888
  return {
885
889
  ...me(u, t, n),
886
890
  current_entities: i,
887
891
  relation_entities: a
888
892
  };
889
893
  };
890
- function $r(r, e) {
894
+ function Br(r, e) {
891
895
  const t = [], n = [], s = [], i = /* @__PURE__ */ new Set();
892
896
  for (const o of r) {
893
- const c = e.get(o.id);
894
- c === void 0 ? t.push(o.id) : (i.add(o.id), o.updatedAt > c ? n.push(o.id) : s.push(o.id));
897
+ const l = e.get(o.id);
898
+ l === void 0 ? t.push(o.id) : (i.add(o.id), o.updatedAt > l ? n.push(o.id) : s.push(o.id));
895
899
  }
896
900
  const a = [];
897
901
  for (const o of e.keys())
@@ -901,12 +905,12 @@ function $r(r, e) {
901
905
  function F(r) {
902
906
  return typeof r == "function";
903
907
  }
904
- function Br(r) {
908
+ function Dr(r) {
905
909
  return F(r?.lift);
906
910
  }
907
911
  function we(r) {
908
912
  return function(e) {
909
- if (Br(e))
913
+ if (Dr(e))
910
914
  return e.lift(function(t) {
911
915
  try {
912
916
  return r(t, this);
@@ -933,7 +937,7 @@ function de(r, e) {
933
937
  }
934
938
  r.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
935
939
  }
936
- function Dr(r, e, t, n) {
940
+ function Lr(r, e, t, n) {
937
941
  function s(i) {
938
942
  return i instanceof t ? i : new t(function(a) {
939
943
  a(i);
@@ -942,22 +946,22 @@ function Dr(r, e, t, n) {
942
946
  return new (t || (t = Promise))(function(i, a) {
943
947
  function o(u) {
944
948
  try {
945
- l(n.next(u));
949
+ c(n.next(u));
946
950
  } catch (d) {
947
951
  a(d);
948
952
  }
949
953
  }
950
- function c(u) {
954
+ function l(u) {
951
955
  try {
952
- l(n.throw(u));
956
+ c(n.throw(u));
953
957
  } catch (d) {
954
958
  a(d);
955
959
  }
956
960
  }
957
- function l(u) {
958
- u.done ? i(u.value) : s(u.value).then(o, c);
961
+ function c(u) {
962
+ u.done ? i(u.value) : s(u.value).then(o, l);
959
963
  }
960
- l((n = n.apply(r, e || [])).next());
964
+ c((n = n.apply(r, e || [])).next());
961
965
  });
962
966
  }
963
967
  function Qt(r, e) {
@@ -968,56 +972,56 @@ function Qt(r, e) {
968
972
  return a.next = o(0), a.throw = o(1), a.return = o(2), typeof Symbol == "function" && (a[Symbol.iterator] = function() {
969
973
  return this;
970
974
  }), a;
971
- function o(l) {
975
+ function o(c) {
972
976
  return function(u) {
973
- return c([l, u]);
977
+ return l([c, u]);
974
978
  };
975
979
  }
976
- function c(l) {
980
+ function l(c) {
977
981
  if (n) throw new TypeError("Generator is already executing.");
978
- for (; a && (a = 0, l[0] && (t = 0)), t; ) try {
979
- if (n = 1, s && (i = l[0] & 2 ? s.return : l[0] ? s.throw || ((i = s.return) && i.call(s), 0) : s.next) && !(i = i.call(s, l[1])).done) return i;
980
- switch (s = 0, i && (l = [l[0] & 2, i.value]), l[0]) {
982
+ for (; a && (a = 0, c[0] && (t = 0)), t; ) try {
983
+ if (n = 1, s && (i = c[0] & 2 ? s.return : c[0] ? s.throw || ((i = s.return) && i.call(s), 0) : s.next) && !(i = i.call(s, c[1])).done) return i;
984
+ switch (s = 0, i && (c = [c[0] & 2, i.value]), c[0]) {
981
985
  case 0:
982
986
  case 1:
983
- i = l;
987
+ i = c;
984
988
  break;
985
989
  case 4:
986
- return t.label++, { value: l[1], done: !1 };
990
+ return t.label++, { value: c[1], done: !1 };
987
991
  case 5:
988
- t.label++, s = l[1], l = [0];
992
+ t.label++, s = c[1], c = [0];
989
993
  continue;
990
994
  case 7:
991
- l = t.ops.pop(), t.trys.pop();
995
+ c = t.ops.pop(), t.trys.pop();
992
996
  continue;
993
997
  default:
994
- if (i = t.trys, !(i = i.length > 0 && i[i.length - 1]) && (l[0] === 6 || l[0] === 2)) {
998
+ if (i = t.trys, !(i = i.length > 0 && i[i.length - 1]) && (c[0] === 6 || c[0] === 2)) {
995
999
  t = 0;
996
1000
  continue;
997
1001
  }
998
- if (l[0] === 3 && (!i || l[1] > i[0] && l[1] < i[3])) {
999
- t.label = l[1];
1002
+ if (c[0] === 3 && (!i || c[1] > i[0] && c[1] < i[3])) {
1003
+ t.label = c[1];
1000
1004
  break;
1001
1005
  }
1002
- if (l[0] === 6 && t.label < i[1]) {
1003
- t.label = i[1], i = l;
1006
+ if (c[0] === 6 && t.label < i[1]) {
1007
+ t.label = i[1], i = c;
1004
1008
  break;
1005
1009
  }
1006
1010
  if (i && t.label < i[2]) {
1007
- t.label = i[2], t.ops.push(l);
1011
+ t.label = i[2], t.ops.push(c);
1008
1012
  break;
1009
1013
  }
1010
1014
  i[2] && t.ops.pop(), t.trys.pop();
1011
1015
  continue;
1012
1016
  }
1013
- l = e.call(r, t);
1017
+ c = e.call(r, t);
1014
1018
  } catch (u) {
1015
- l = [6, u], s = 0;
1019
+ c = [6, u], s = 0;
1016
1020
  } finally {
1017
1021
  n = i = 0;
1018
1022
  }
1019
- if (l[0] & 5) throw l[1];
1020
- return { value: l[0] ? l[1] : void 0, done: !0 };
1023
+ if (c[0] & 5) throw c[1];
1024
+ return { value: c[0] ? c[1] : void 0, done: !0 };
1021
1025
  }
1022
1026
  }
1023
1027
  function ue(r) {
@@ -1055,7 +1059,7 @@ function Ae(r, e, t) {
1055
1059
  function le(r) {
1056
1060
  return this instanceof le ? (this.v = r, this) : new le(r);
1057
1061
  }
1058
- function Lr(r, e, t) {
1062
+ function Fr(r, e, t) {
1059
1063
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1060
1064
  var n = t.apply(r, e || []), s, i = [];
1061
1065
  return s = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), o("next"), o("throw"), o("return", a), s[Symbol.asyncIterator] = function() {
@@ -1069,31 +1073,31 @@ function Lr(r, e, t) {
1069
1073
  function o(p, m) {
1070
1074
  n[p] && (s[p] = function(f) {
1071
1075
  return new Promise(function(y, g) {
1072
- i.push([p, f, y, g]) > 1 || c(p, f);
1076
+ i.push([p, f, y, g]) > 1 || l(p, f);
1073
1077
  });
1074
1078
  }, m && (s[p] = m(s[p])));
1075
1079
  }
1076
- function c(p, m) {
1080
+ function l(p, m) {
1077
1081
  try {
1078
- l(n[p](m));
1082
+ c(n[p](m));
1079
1083
  } catch (f) {
1080
1084
  h(i[0][3], f);
1081
1085
  }
1082
1086
  }
1083
- function l(p) {
1087
+ function c(p) {
1084
1088
  p.value instanceof le ? Promise.resolve(p.value.v).then(u, d) : h(i[0][2], p);
1085
1089
  }
1086
1090
  function u(p) {
1087
- c("next", p);
1091
+ l("next", p);
1088
1092
  }
1089
1093
  function d(p) {
1090
- c("throw", p);
1094
+ l("throw", p);
1091
1095
  }
1092
1096
  function h(p, m) {
1093
- p(m), i.shift(), i.length && c(i[0][0], i[0][1]);
1097
+ p(m), i.shift(), i.length && l(i[0][0], i[0][1]);
1094
1098
  }
1095
1099
  }
1096
- function Fr(r) {
1100
+ function Ur(r) {
1097
1101
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1098
1102
  var e = r[Symbol.asyncIterator], t;
1099
1103
  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() {
@@ -1101,21 +1105,21 @@ function Fr(r) {
1101
1105
  }, t);
1102
1106
  function n(i) {
1103
1107
  t[i] = r[i] && function(a) {
1104
- return new Promise(function(o, c) {
1105
- a = r[i](a), s(o, c, a.done, a.value);
1108
+ return new Promise(function(o, l) {
1109
+ a = r[i](a), s(o, l, a.done, a.value);
1106
1110
  });
1107
1111
  };
1108
1112
  }
1109
- function s(i, a, o, c) {
1110
- Promise.resolve(c).then(function(l) {
1111
- i({ value: l, done: o });
1113
+ function s(i, a, o, l) {
1114
+ Promise.resolve(l).then(function(c) {
1115
+ i({ value: c, done: o });
1112
1116
  }, a);
1113
1117
  }
1114
1118
  }
1115
- var Ur = (function(r) {
1119
+ var jr = (function(r) {
1116
1120
  return r && typeof r.length == "number" && typeof r != "function";
1117
1121
  });
1118
- function jr(r) {
1122
+ function Yr(r) {
1119
1123
  return F(r?.then);
1120
1124
  }
1121
1125
  function Jt(r) {
@@ -1151,15 +1155,15 @@ var Se = (function() {
1151
1155
  if (a)
1152
1156
  if (this._parentage = null, Array.isArray(a))
1153
1157
  try {
1154
- for (var o = ue(a), c = o.next(); !c.done; c = o.next()) {
1155
- var l = c.value;
1156
- l.remove(this);
1158
+ for (var o = ue(a), l = o.next(); !l.done; l = o.next()) {
1159
+ var c = l.value;
1160
+ c.remove(this);
1157
1161
  }
1158
1162
  } catch (f) {
1159
1163
  e = { error: f };
1160
1164
  } finally {
1161
1165
  try {
1162
- c && !c.done && (t = o.return) && t.call(o);
1166
+ l && !l.done && (t = o.return) && t.call(o);
1163
1167
  } finally {
1164
1168
  if (e) throw e.error;
1165
1169
  }
@@ -1234,9 +1238,9 @@ function Zt(r) {
1234
1238
  function vt(r) {
1235
1239
  F(r) ? r() : r.unsubscribe();
1236
1240
  }
1237
- var Yr = {
1241
+ var zr = {
1238
1242
  Promise: void 0
1239
- }, zr = {
1243
+ }, Wr = {
1240
1244
  setTimeout: function(r, e) {
1241
1245
  for (var t = [], n = 2; n < arguments.length; n++)
1242
1246
  t[n - 2] = arguments[n];
@@ -1248,7 +1252,7 @@ var Yr = {
1248
1252
  delegate: void 0
1249
1253
  };
1250
1254
  function en(r) {
1251
- zr.setTimeout(function() {
1255
+ Wr.setTimeout(function() {
1252
1256
  throw r;
1253
1257
  });
1254
1258
  }
@@ -1261,7 +1265,7 @@ var dt = (function(r) {
1261
1265
  de(e, r);
1262
1266
  function e(t) {
1263
1267
  var n = r.call(this) || this;
1264
- return n.isStopped = !1, t ? (n.destination = t, Zt(t) && t.add(n)) : n.destination = Kr, n;
1268
+ return n.isStopped = !1, t ? (n.destination = t, Zt(t) && t.add(n)) : n.destination = Hr, n;
1265
1269
  }
1266
1270
  return e.create = function(t, n, s) {
1267
1271
  return new ge(t, n, s);
@@ -1288,7 +1292,7 @@ var dt = (function(r) {
1288
1292
  this.unsubscribe();
1289
1293
  }
1290
1294
  }, e;
1291
- })(Se), Wr = (function() {
1295
+ })(Se), kr = (function() {
1292
1296
  function r(e) {
1293
1297
  this.partialObserver = e;
1294
1298
  }
@@ -1327,29 +1331,29 @@ var dt = (function(r) {
1327
1331
  next: t ?? void 0,
1328
1332
  error: n ?? void 0,
1329
1333
  complete: s ?? void 0
1330
- } : a = t, i.destination = new Wr(a), i;
1334
+ } : a = t, i.destination = new kr(a), i;
1331
1335
  }
1332
1336
  return e;
1333
1337
  })(dt);
1334
1338
  function ve(r) {
1335
1339
  en(r);
1336
1340
  }
1337
- function kr(r) {
1341
+ function Kr(r) {
1338
1342
  throw r;
1339
1343
  }
1340
- var Kr = {
1344
+ var Hr = {
1341
1345
  closed: !0,
1342
1346
  next: Et,
1343
- error: kr,
1347
+ error: Kr,
1344
1348
  complete: Et
1345
1349
  }, ht = (function() {
1346
1350
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
1347
1351
  })();
1348
- function Hr(r) {
1352
+ function qr(r) {
1349
1353
  return r;
1350
1354
  }
1351
- function qr(r) {
1352
- return r.length === 0 ? Hr : r.length === 1 ? r[0] : function(t) {
1355
+ function Vr(r) {
1356
+ return r.length === 0 ? qr : r.length === 1 ? r[0] : function(t) {
1353
1357
  return r.reduce(function(n, s) {
1354
1358
  return s(n);
1355
1359
  }, t);
@@ -1363,10 +1367,10 @@ var re = (function() {
1363
1367
  var t = new r();
1364
1368
  return t.source = this, t.operator = e, t;
1365
1369
  }, r.prototype.subscribe = function(e, t, n) {
1366
- var s = this, i = Gr(e) ? e : new ge(e, t, n);
1370
+ var s = this, i = Qr(e) ? e : new ge(e, t, n);
1367
1371
  return Ee(function() {
1368
- var a = s, o = a.operator, c = a.source;
1369
- i.add(o ? o.call(i, c) : c ? s._subscribe(i) : s._trySubscribe(i));
1372
+ var a = s, o = a.operator, l = a.source;
1373
+ i.add(o ? o.call(i, l) : l ? s._subscribe(i) : s._trySubscribe(i));
1370
1374
  }), i;
1371
1375
  }, r.prototype._trySubscribe = function(e) {
1372
1376
  try {
@@ -1381,8 +1385,8 @@ var re = (function() {
1381
1385
  next: function(o) {
1382
1386
  try {
1383
1387
  e(o);
1384
- } catch (c) {
1385
- i(c), a.unsubscribe();
1388
+ } catch (l) {
1389
+ i(l), a.unsubscribe();
1386
1390
  }
1387
1391
  },
1388
1392
  error: i,
@@ -1398,7 +1402,7 @@ var re = (function() {
1398
1402
  }, r.prototype.pipe = function() {
1399
1403
  for (var e = [], t = 0; t < arguments.length; t++)
1400
1404
  e[t] = arguments[t];
1401
- return qr(e)(this);
1405
+ return Vr(e)(this);
1402
1406
  }, r.prototype.toPromise = function(e) {
1403
1407
  var t = this;
1404
1408
  return e = Rt(e), new e(function(n, s) {
@@ -1417,32 +1421,32 @@ var re = (function() {
1417
1421
  })();
1418
1422
  function Rt(r) {
1419
1423
  var e;
1420
- return (e = r ?? Yr.Promise) !== null && e !== void 0 ? e : Promise;
1421
- }
1422
- function Vr(r) {
1423
- return r && F(r.next) && F(r.error) && F(r.complete);
1424
+ return (e = r ?? zr.Promise) !== null && e !== void 0 ? e : Promise;
1424
1425
  }
1425
1426
  function Gr(r) {
1426
- return r && r instanceof dt || Vr(r) && Zt(r);
1427
+ return r && F(r.next) && F(r.error) && F(r.complete);
1427
1428
  }
1428
1429
  function Qr(r) {
1429
- return F(r[ht]);
1430
+ return r && r instanceof dt || Gr(r) && Zt(r);
1430
1431
  }
1431
1432
  function Jr(r) {
1432
- return Symbol.asyncIterator && F(r?.[Symbol.asyncIterator]);
1433
+ return F(r[ht]);
1433
1434
  }
1434
1435
  function Xr(r) {
1436
+ return Symbol.asyncIterator && F(r?.[Symbol.asyncIterator]);
1437
+ }
1438
+ function Zr(r) {
1435
1439
  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.");
1436
1440
  }
1437
- function Zr() {
1441
+ function es() {
1438
1442
  return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
1439
1443
  }
1440
- var es = Zr();
1441
- function ts(r) {
1442
- return F(r?.[es]);
1443
- }
1444
+ var ts = es();
1444
1445
  function ns(r) {
1445
- return Lr(this, arguments, function() {
1446
+ return F(r?.[ts]);
1447
+ }
1448
+ function rs(r) {
1449
+ return Fr(this, arguments, function() {
1446
1450
  var t, n, s, i;
1447
1451
  return Qt(this, function(a) {
1448
1452
  switch (a.label) {
@@ -1472,29 +1476,29 @@ function ns(r) {
1472
1476
  });
1473
1477
  });
1474
1478
  }
1475
- function rs(r) {
1479
+ function ss(r) {
1476
1480
  return F(r?.getReader);
1477
1481
  }
1478
1482
  function Me(r) {
1479
1483
  if (r instanceof re)
1480
1484
  return r;
1481
1485
  if (r != null) {
1482
- if (Qr(r))
1483
- return ss(r);
1484
- if (Ur(r))
1486
+ if (Jr(r))
1485
1487
  return is(r);
1486
1488
  if (jr(r))
1487
1489
  return as(r);
1488
- if (Jr(r))
1489
- return tn(r);
1490
- if (ts(r))
1490
+ if (Yr(r))
1491
1491
  return os(r);
1492
- if (rs(r))
1492
+ if (Xr(r))
1493
+ return tn(r);
1494
+ if (ns(r))
1493
1495
  return cs(r);
1496
+ if (ss(r))
1497
+ return ls(r);
1494
1498
  }
1495
- throw Xr(r);
1499
+ throw Zr(r);
1496
1500
  }
1497
- function ss(r) {
1501
+ function is(r) {
1498
1502
  return new re(function(e) {
1499
1503
  var t = r[ht]();
1500
1504
  if (F(t.subscribe))
@@ -1502,14 +1506,14 @@ function ss(r) {
1502
1506
  throw new TypeError("Provided object does not correctly implement Symbol.observable");
1503
1507
  });
1504
1508
  }
1505
- function is(r) {
1509
+ function as(r) {
1506
1510
  return new re(function(e) {
1507
1511
  for (var t = 0; t < r.length && !e.closed; t++)
1508
1512
  e.next(r[t]);
1509
1513
  e.complete();
1510
1514
  });
1511
1515
  }
1512
- function as(r) {
1516
+ function os(r) {
1513
1517
  return new re(function(e) {
1514
1518
  r.then(function(t) {
1515
1519
  e.closed || (e.next(t), e.complete());
@@ -1518,7 +1522,7 @@ function as(r) {
1518
1522
  }).then(null, en);
1519
1523
  });
1520
1524
  }
1521
- function os(r) {
1525
+ function cs(r) {
1522
1526
  return new re(function(e) {
1523
1527
  var t, n;
1524
1528
  try {
@@ -1541,39 +1545,39 @@ function os(r) {
1541
1545
  }
1542
1546
  function tn(r) {
1543
1547
  return new re(function(e) {
1544
- ls(r, e).catch(function(t) {
1548
+ us(r, e).catch(function(t) {
1545
1549
  return e.error(t);
1546
1550
  });
1547
1551
  });
1548
1552
  }
1549
- function cs(r) {
1550
- return tn(ns(r));
1553
+ function ls(r) {
1554
+ return tn(rs(r));
1551
1555
  }
1552
- function ls(r, e) {
1556
+ function us(r, e) {
1553
1557
  var t, n, s, i;
1554
- return Dr(this, void 0, void 0, function() {
1558
+ return Lr(this, void 0, void 0, function() {
1555
1559
  var a, o;
1556
- return Qt(this, function(c) {
1557
- switch (c.label) {
1560
+ return Qt(this, function(l) {
1561
+ switch (l.label) {
1558
1562
  case 0:
1559
- c.trys.push([0, 5, 6, 11]), t = Fr(r), c.label = 1;
1563
+ l.trys.push([0, 5, 6, 11]), t = Ur(r), l.label = 1;
1560
1564
  case 1:
1561
1565
  return [4, t.next()];
1562
1566
  case 2:
1563
- if (n = c.sent(), !!n.done) return [3, 4];
1567
+ if (n = l.sent(), !!n.done) return [3, 4];
1564
1568
  if (a = n.value, e.next(a), e.closed)
1565
1569
  return [2];
1566
- c.label = 3;
1570
+ l.label = 3;
1567
1571
  case 3:
1568
1572
  return [3, 1];
1569
1573
  case 4:
1570
1574
  return [3, 11];
1571
1575
  case 5:
1572
- return o = c.sent(), s = { error: o }, [3, 11];
1576
+ return o = l.sent(), s = { error: o }, [3, 11];
1573
1577
  case 6:
1574
- return c.trys.push([6, , 9, 10]), n && !n.done && (i = t.return) ? [4, i.call(t)] : [3, 8];
1578
+ return l.trys.push([6, , 9, 10]), n && !n.done && (i = t.return) ? [4, i.call(t)] : [3, 8];
1575
1579
  case 7:
1576
- c.sent(), c.label = 8;
1580
+ l.sent(), l.label = 8;
1577
1581
  case 8:
1578
1582
  return [3, 10];
1579
1583
  case 9:
@@ -1588,35 +1592,35 @@ function ls(r, e) {
1588
1592
  });
1589
1593
  }
1590
1594
  function _e(r, e, t, n, s) {
1591
- return new us(r, e, t, n, s);
1595
+ return new ds(r, e, t, n, s);
1592
1596
  }
1593
- var us = (function(r) {
1597
+ var ds = (function(r) {
1594
1598
  de(e, r);
1595
1599
  function e(t, n, s, i, a, o) {
1596
- var c = r.call(this, t) || this;
1597
- return c.onFinalize = a, c.shouldUnsubscribe = o, c._next = n ? function(l) {
1600
+ var l = r.call(this, t) || this;
1601
+ return l.onFinalize = a, l.shouldUnsubscribe = o, l._next = n ? function(c) {
1598
1602
  try {
1599
- n(l);
1603
+ n(c);
1600
1604
  } catch (u) {
1601
1605
  t.error(u);
1602
1606
  }
1603
- } : r.prototype._next, c._error = i ? function(l) {
1607
+ } : r.prototype._next, l._error = i ? function(c) {
1604
1608
  try {
1605
- i(l);
1609
+ i(c);
1606
1610
  } catch (u) {
1607
1611
  t.error(u);
1608
1612
  } finally {
1609
1613
  this.unsubscribe();
1610
1614
  }
1611
- } : r.prototype._error, c._complete = s ? function() {
1615
+ } : r.prototype._error, l._complete = s ? function() {
1612
1616
  try {
1613
1617
  s();
1614
- } catch (l) {
1615
- t.error(l);
1618
+ } catch (c) {
1619
+ t.error(c);
1616
1620
  } finally {
1617
1621
  this.unsubscribe();
1618
1622
  }
1619
- } : r.prototype._complete, c;
1623
+ } : r.prototype._complete, l;
1620
1624
  }
1621
1625
  return e.prototype.unsubscribe = function() {
1622
1626
  var t;
@@ -1647,7 +1651,7 @@ function te(r, e) {
1647
1651
  }));
1648
1652
  });
1649
1653
  }
1650
- var ds = Jt(function(r) {
1654
+ var hs = Jt(function(r) {
1651
1655
  return function() {
1652
1656
  r(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
1653
1657
  };
@@ -1662,7 +1666,7 @@ var ds = Jt(function(r) {
1662
1666
  return n.operator = t, n;
1663
1667
  }, e.prototype._throwIfClosed = function() {
1664
1668
  if (this.closed)
1665
- throw new ds();
1669
+ throw new hs();
1666
1670
  }, e.prototype.next = function(t) {
1667
1671
  var n = this;
1668
1672
  Ee(function() {
@@ -1671,11 +1675,11 @@ var ds = Jt(function(r) {
1671
1675
  n.currentObservers || (n.currentObservers = Array.from(n.observers));
1672
1676
  try {
1673
1677
  for (var a = ue(n.currentObservers), o = a.next(); !o.done; o = a.next()) {
1674
- var c = o.value;
1675
- c.next(t);
1678
+ var l = o.value;
1679
+ l.next(t);
1676
1680
  }
1677
- } catch (l) {
1678
- s = { error: l };
1681
+ } catch (c) {
1682
+ s = { error: c };
1679
1683
  } finally {
1680
1684
  try {
1681
1685
  o && !o.done && (i = a.return) && i.call(a);
@@ -1758,7 +1762,7 @@ function It(r, e) {
1758
1762
  }));
1759
1763
  });
1760
1764
  }
1761
- var hs = (function(r) {
1765
+ var ps = (function(r) {
1762
1766
  de(e, r);
1763
1767
  function e(t, n, s) {
1764
1768
  t === void 0 && (t = 1 / 0), n === void 0 && (n = 1 / 0), s === void 0 && (s = nn);
@@ -1766,28 +1770,28 @@ var hs = (function(r) {
1766
1770
  return i._bufferSize = t, i._windowTime = n, i._timestampProvider = s, i._buffer = [], i._infiniteTimeWindow = !0, i._infiniteTimeWindow = n === 1 / 0, i._bufferSize = Math.max(1, t), i._windowTime = Math.max(1, n), i;
1767
1771
  }
1768
1772
  return e.prototype.next = function(t) {
1769
- var n = this, s = n.isStopped, i = n._buffer, a = n._infiniteTimeWindow, o = n._timestampProvider, c = n._windowTime;
1770
- s || (i.push(t), !a && i.push(o.now() + c)), this._trimBuffer(), r.prototype.next.call(this, t);
1773
+ var n = this, s = n.isStopped, i = n._buffer, a = n._infiniteTimeWindow, o = n._timestampProvider, l = n._windowTime;
1774
+ s || (i.push(t), !a && i.push(o.now() + l)), this._trimBuffer(), r.prototype.next.call(this, t);
1771
1775
  }, e.prototype._subscribe = function(t) {
1772
1776
  this._throwIfClosed(), this._trimBuffer();
1773
- for (var n = this._innerSubscribe(t), s = this, i = s._infiniteTimeWindow, a = s._buffer, o = a.slice(), c = 0; c < o.length && !t.closed; c += i ? 1 : 2)
1774
- t.next(o[c]);
1777
+ for (var n = this._innerSubscribe(t), s = this, i = s._infiniteTimeWindow, a = s._buffer, o = a.slice(), l = 0; l < o.length && !t.closed; l += i ? 1 : 2)
1778
+ t.next(o[l]);
1775
1779
  return this._checkFinalizedStatuses(t), n;
1776
1780
  }, e.prototype._trimBuffer = function() {
1777
1781
  var t = this, n = t._bufferSize, s = t._timestampProvider, i = t._buffer, a = t._infiniteTimeWindow, o = (a ? 1 : 2) * n;
1778
1782
  if (n < 1 / 0 && o < i.length && i.splice(0, i.length - o), !a) {
1779
- for (var c = s.now(), l = 0, u = 1; u < i.length && i[u] <= c; u += 2)
1780
- l = u;
1781
- l && i.splice(0, l + 1);
1783
+ for (var l = s.now(), c = 0, u = 1; u < i.length && i[u] <= l; u += 2)
1784
+ c = u;
1785
+ c && i.splice(0, c + 1);
1782
1786
  }
1783
1787
  }, e;
1784
1788
  })(pt);
1785
- function ps(r) {
1789
+ function fs(r) {
1786
1790
  r === void 0 && (r = {});
1787
1791
  var e = r.connector, t = e === void 0 ? function() {
1788
1792
  return new pt();
1789
- } : e, n = r.resetOnError, s = n === void 0 ? !0 : n, i = r.resetOnComplete, a = i === void 0 ? !0 : i, o = r.resetOnRefCountZero, c = o === void 0 ? !0 : o;
1790
- return function(l) {
1793
+ } : 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;
1794
+ return function(c) {
1791
1795
  var u, d, h, p = 0, m = !1, f = !1, y = function() {
1792
1796
  d?.unsubscribe(), d = void 0;
1793
1797
  }, g = function() {
@@ -1800,7 +1804,7 @@ function ps(r) {
1800
1804
  p++, !f && !m && y();
1801
1805
  var w = h = h ?? t();
1802
1806
  b.add(function() {
1803
- p--, p === 0 && !f && !m && (d = De(_, c));
1807
+ p--, p === 0 && !f && !m && (d = De(_, l));
1804
1808
  }), w.subscribe(b), !u && p > 0 && (u = new ge({
1805
1809
  next: function(E) {
1806
1810
  return w.next(E);
@@ -1812,7 +1816,7 @@ function ps(r) {
1812
1816
  m = !0, y(), d = De(g, a), w.complete();
1813
1817
  }
1814
1818
  }), Me(v).subscribe(u));
1815
- })(l);
1819
+ })(c);
1816
1820
  };
1817
1821
  }
1818
1822
  function De(r, e) {
@@ -1831,11 +1835,11 @@ function De(r, e) {
1831
1835
  return Me(e.apply(void 0, Ae([], Te(t)))).subscribe(s);
1832
1836
  }
1833
1837
  }
1834
- function fs(r, e, t) {
1838
+ function ys(r, e, t) {
1835
1839
  var n, s = !1;
1836
- return n = r, ps({
1840
+ return n = r, fs({
1837
1841
  connector: function() {
1838
- return new hs(n, e, t);
1842
+ return new ps(n, e, t);
1839
1843
  },
1840
1844
  resetOnError: !0,
1841
1845
  resetOnComplete: !1,
@@ -1847,11 +1851,11 @@ function V(r, e) {
1847
1851
  var s = null, i = 0, a = !1, o = function() {
1848
1852
  return a && !s && n.complete();
1849
1853
  };
1850
- t.subscribe(_e(n, function(c) {
1854
+ t.subscribe(_e(n, function(l) {
1851
1855
  s?.unsubscribe();
1852
- var l = 0, u = i++;
1853
- Me(r(c, u)).subscribe(s = _e(n, function(d) {
1854
- return n.next(e ? e(c, d, u, l++) : d);
1856
+ var c = 0, u = i++;
1857
+ Me(r(l, u)).subscribe(s = _e(n, function(d) {
1858
+ return n.next(e ? e(l, d, u, c++) : d);
1855
1859
  }, function() {
1856
1860
  s = null, o();
1857
1861
  }));
@@ -1860,7 +1864,7 @@ function V(r, e) {
1860
1864
  }));
1861
1865
  });
1862
1866
  }
1863
- class ua {
1867
+ class da {
1864
1868
  constructor(e, t, n) {
1865
1869
  this.remoteAdapter = t, this.localAdapter = n, this.entityName = e;
1866
1870
  }
@@ -1907,7 +1911,7 @@ class ua {
1907
1911
  let s;
1908
1912
  e.localCacheFirst ? s = this.#n(e) : s = this.#i(e), e.offlineFallback && (s = this.#s(s));
1909
1913
  const i = s.pipe(
1910
- fs(1),
1914
+ ys(1),
1911
1915
  Ft(() => {
1912
1916
  this.#e.delete(t);
1913
1917
  })
@@ -2107,9 +2111,9 @@ class ua {
2107
2111
  const i = s.map((a) => a.id);
2108
2112
  return this.localAdapter.getMetadataByIds(this.entityName, i).pipe(
2109
2113
  V((a) => {
2110
- const o = $r(s, a), c = [...o.missingIds, ...o.staleIds];
2111
- return c.length === 0 ? this.#a(o.freshIds).pipe(
2112
- te((l) => (this.#o(e.onSyncStats, {
2114
+ const o = Br(s, a), l = [...o.missingIds, ...o.staleIds];
2115
+ return l.length === 0 ? this.#a(o.freshIds).pipe(
2116
+ te((c) => (this.#o(e.onSyncStats, {
2113
2117
  remoteCount: s.length,
2114
2118
  missingCount: 0,
2115
2119
  staleCount: 0,
@@ -2117,9 +2121,9 @@ class ua {
2117
2121
  orphanCount: o.orphanIds.length,
2118
2122
  pulledCount: 0,
2119
2123
  durationMs: Date.now() - n
2120
- }), l))
2121
- ) : this.remoteAdapter.findByIds(this.entityName, c).pipe(
2122
- V((l) => l.length === 0 ? this.#a(o.freshIds).pipe(
2124
+ }), c))
2125
+ ) : this.remoteAdapter.findByIds(this.entityName, l).pipe(
2126
+ V((c) => c.length === 0 ? this.#a(o.freshIds).pipe(
2123
2127
  te((u) => (this.#o(e.onSyncStats, {
2124
2128
  remoteCount: s.length,
2125
2129
  missingCount: o.missingIds.length,
@@ -2129,25 +2133,25 @@ class ua {
2129
2133
  pulledCount: 0,
2130
2134
  durationMs: Date.now() - n
2131
2135
  }), u))
2132
- ) : this.localAdapter.upsertMany(this.entityName, l).pipe(
2136
+ ) : this.localAdapter.upsertMany(this.entityName, c).pipe(
2133
2137
  V(() => o.freshIds.length === 0 ? (this.#o(e.onSyncStats, {
2134
2138
  remoteCount: s.length,
2135
2139
  missingCount: o.missingIds.length,
2136
2140
  staleCount: o.staleIds.length,
2137
2141
  freshCount: 0,
2138
2142
  orphanCount: o.orphanIds.length,
2139
- pulledCount: l.length,
2143
+ pulledCount: c.length,
2140
2144
  durationMs: Date.now() - n
2141
- }), Q(l)) : this.#a(o.freshIds).pipe(
2145
+ }), Q(c)) : this.#a(o.freshIds).pipe(
2142
2146
  te((u) => (this.#o(e.onSyncStats, {
2143
2147
  remoteCount: s.length,
2144
2148
  missingCount: o.missingIds.length,
2145
2149
  staleCount: o.staleIds.length,
2146
2150
  freshCount: o.freshIds.length,
2147
2151
  orphanCount: o.orphanIds.length,
2148
- pulledCount: l.length,
2152
+ pulledCount: c.length,
2149
2153
  durationMs: Date.now() - n
2150
- }), [...u, ...l]))
2154
+ }), [...u, ...c]))
2151
2155
  ))
2152
2156
  ))
2153
2157
  );
@@ -2178,7 +2182,7 @@ class ua {
2178
2182
  return Lt(e);
2179
2183
  }
2180
2184
  }
2181
- class ys {
2185
+ class ms {
2182
2186
  /**
2183
2187
  * 刷新
2184
2188
  * 重新执行 SQL 查询
@@ -2341,19 +2345,19 @@ class ys {
2341
2345
  this.#e.next(this.refreshCount + 1);
2342
2346
  };
2343
2347
  }
2344
- var ms = /* @__PURE__ */ ((r) => (r.Synced = "Synced", r.Syncing = "Syncing", r.Never = "Never", r))(ms || {});
2348
+ var gs = /* @__PURE__ */ ((r) => (r.Synced = "Synced", r.Syncing = "Syncing", r.Never = "Never", r))(gs || {});
2345
2349
  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;
2346
2350
  function* rn(r, e, t = {}) {
2347
2351
  const { maxLevel: n, maxDepth: s = 1e3 } = t, i = /* @__PURE__ */ new Set();
2348
2352
  let a = D(r), o = 1;
2349
2353
  for (; a && !i.has(a) && i.size < s; ) {
2350
2354
  i.add(a);
2351
- const c = e.get(a);
2352
- if (!c || n && o > n) break;
2353
- yield { entity: c, level: o }, a = D(c), o++;
2355
+ const l = e.get(a);
2356
+ if (!l || n && o > n) break;
2357
+ yield { entity: l, level: o }, a = D(l), o++;
2354
2358
  }
2355
2359
  }
2356
- function gs(r, e, t, n) {
2360
+ function _s(r, e, t, n) {
2357
2361
  if (e == null)
2358
2362
  return r.parentId === null;
2359
2363
  const s = /* @__PURE__ */ new Set();
@@ -2370,7 +2374,7 @@ function gs(r, e, t, n) {
2370
2374
  }
2371
2375
  return !1;
2372
2376
  }
2373
- function _s(r, e, t) {
2377
+ function bs(r, e, t) {
2374
2378
  const n = t.get(e);
2375
2379
  if (!n) return !1;
2376
2380
  for (const { entity: s } of rn(n, t))
@@ -2388,7 +2392,7 @@ function Ge(r, e) {
2388
2392
  function Tt(r, e) {
2389
2393
  return r.length !== e.length ? !0 : r.some((t, n) => t !== e[n]);
2390
2394
  }
2391
- const bs = (r, e) => {
2395
+ const ws = (r, e) => {
2392
2396
  const t = r.options.where, n = e.filter((i) => !t || Y(i.patch, t));
2393
2397
  if (n.length === 0) return;
2394
2398
  const s = n.map((i) => r.serialize(i));
@@ -2402,11 +2406,11 @@ const bs = (r, e) => {
2402
2406
  }
2403
2407
  case "find": {
2404
2408
  const i = r.options, a = i.limit || 100, o = Array.from(r.resultEntitySet.values());
2405
- let c = [...o, ...s];
2406
- i.orderBy?.length && (c = X(c, i.orderBy));
2407
- const l = c.slice(0, a);
2408
- if (!Tt(o, l)) return;
2409
- r.next(l, !0);
2409
+ let l = [...o, ...s];
2410
+ i.orderBy?.length && (l = X(l, i.orderBy));
2411
+ const c = l.slice(0, a);
2412
+ if (!Tt(o, c)) return;
2413
+ r.next(c, !0);
2410
2414
  break;
2411
2415
  }
2412
2416
  case "findOne":
@@ -2420,30 +2424,30 @@ const bs = (r, e) => {
2420
2424
  break;
2421
2425
  }
2422
2426
  if (i.orderBy?.length) {
2423
- const c = r.result, l = X([c, o], i.orderBy);
2424
- l[0] !== c && r.next(l[0]);
2427
+ const l = r.result, c = X([l, o], i.orderBy);
2428
+ c[0] !== l && r.next(c[0]);
2425
2429
  }
2426
2430
  break;
2427
2431
  }
2428
2432
  case "findByCursor": {
2429
- const i = r.options, { before: a, after: o, orderBy: c } = i;
2430
- if (!c?.length) return;
2431
- const l = Array.from(r.resultEntitySet.values()), u = [...l, ...s], d = X(u, c);
2433
+ const i = r.options, { before: a, after: o, orderBy: l } = i;
2434
+ if (!l?.length) return;
2435
+ const c = Array.from(r.resultEntitySet.values()), u = [...c, ...s], d = X(u, l);
2432
2436
  let h;
2433
2437
  if (o || a) {
2434
2438
  const p = [...u];
2435
2439
  o && !p.includes(o) && p.push(o), a && !p.includes(a) && p.push(a);
2436
- const m = X(p, c);
2440
+ const m = X(p, l);
2437
2441
  if (o) {
2438
2442
  const f = m.findIndex((y) => y === o);
2439
- f !== -1 ? h = m.slice(f + 1).filter((y) => l.includes(y) || s.includes(y)) : h = l;
2443
+ f !== -1 ? h = m.slice(f + 1).filter((y) => c.includes(y) || s.includes(y)) : h = c;
2440
2444
  } else {
2441
2445
  const f = m.findIndex((y) => y === a);
2442
- f !== -1 ? h = m.slice(0, f).filter((y) => l.includes(y) || s.includes(y)) : h = l;
2446
+ f !== -1 ? h = m.slice(0, f).filter((y) => c.includes(y) || s.includes(y)) : h = c;
2443
2447
  }
2444
2448
  } else
2445
2449
  h = d;
2446
- if (!Tt(l, h)) return;
2450
+ if (!Tt(c, h)) return;
2447
2451
  r.next(h, !0);
2448
2452
  break;
2449
2453
  }
@@ -2453,17 +2457,17 @@ const bs = (r, e) => {
2453
2457
  break;
2454
2458
  }
2455
2459
  case "findDescendants": {
2456
- const i = r.options, a = Array.from(r.resultEntitySet.values()), o = Ge(a, (l) => l.id), c = s.filter(
2457
- (l) => gs(l, i.entityId, o, i.level)
2460
+ const i = r.options, a = Array.from(r.resultEntitySet.values()), o = Ge(a, (c) => c.id), l = s.filter(
2461
+ (c) => _s(c, i.entityId, o, i.level)
2458
2462
  );
2459
- if (c.length === 0) return;
2460
- c.forEach((l) => r.resultEntitySet.add(l)), r.next(Array.from(r.resultEntitySet.values()), !0);
2463
+ if (l.length === 0) return;
2464
+ l.forEach((c) => r.resultEntitySet.add(c)), r.next(Array.from(r.resultEntitySet.values()), !0);
2461
2465
  break;
2462
2466
  }
2463
2467
  case "findAncestors": {
2464
- const i = r.options, o = [...Array.from(r.resultEntitySet.values()), ...s], c = Ge(o, (u) => u.id), l = s.filter((u) => u.id === i.entityId ? !0 : i.entityId ? _s(u, i.entityId, c) : !1);
2465
- if (l.length === 0) return;
2466
- l.forEach((u) => r.resultEntitySet.add(u)), r.next(Array.from(r.resultEntitySet.values()), !0);
2468
+ 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 ? bs(u, i.entityId, l) : !1);
2469
+ if (c.length === 0) return;
2470
+ c.forEach((u) => r.resultEntitySet.add(u)), r.next(Array.from(r.resultEntitySet.values()), !0);
2467
2471
  break;
2468
2472
  }
2469
2473
  }
@@ -2489,9 +2493,9 @@ const bs = (r, e) => {
2489
2493
  t.push(["match_where"], ["match_relation_where"]);
2490
2494
  break;
2491
2495
  }
2492
- const i = xr(r, e, t, n);
2493
- i.refresh ? r.refresh() : i.recalculate && bs(r, i.current_entities);
2494
- }, ws = (r, e) => {
2496
+ const i = Nr(r, e, t, n);
2497
+ i.refresh ? r.refresh() : i.recalculate && ws(r, i.current_entities);
2498
+ }, vs = (r, e) => {
2495
2499
  const t = new Set(e.map((n) => n.id));
2496
2500
  switch (r.type) {
2497
2501
  case "findAll": {
@@ -2524,19 +2528,19 @@ const bs = (r, e) => {
2524
2528
  break;
2525
2529
  }
2526
2530
  case "findDescendants": {
2527
- const n = r.options, s = Array.from(r.resultEntitySet.values()), i = Ge(s, (l) => l.id);
2531
+ const n = r.options, s = Array.from(r.resultEntitySet.values()), i = Ge(s, (c) => c.id);
2528
2532
  let a = !1;
2529
- const o = s.filter((l) => {
2530
- if (t.has(l.id))
2533
+ const o = s.filter((c) => {
2534
+ if (t.has(c.id))
2531
2535
  return a = !0, !1;
2532
- for (const { entity: u } of rn(l, i))
2536
+ for (const { entity: u } of rn(c, i))
2533
2537
  if (u?.id && t.has(u.id))
2534
2538
  return a = !0, !1;
2535
2539
  return !0;
2536
2540
  });
2537
2541
  if (!a) return;
2538
- const c = n.orderBy?.length ? X(o, n.orderBy) : o;
2539
- r.next(c, !0);
2542
+ const l = n.orderBy?.length ? X(o, n.orderBy) : o;
2543
+ r.next(l, !0);
2540
2544
  break;
2541
2545
  }
2542
2546
  case "findAncestors": {
@@ -2570,13 +2574,13 @@ const bs = (r, e) => {
2570
2574
  t.push(["match_where"]);
2571
2575
  break;
2572
2576
  }
2573
- const s = Nr(r, e, t, n);
2574
- s.refresh ? r.refresh() : s.recalculate && ws(r, e);
2577
+ const s = Pr(r, e, t, n);
2578
+ s.refresh ? r.refresh() : s.recalculate && vs(r, e);
2575
2579
  }, N = (r) => {
2576
2580
  if (r)
2577
2581
  return r.id;
2578
2582
  };
2579
- class vs {
2583
+ class Es {
2580
2584
  constructor(e, t) {
2581
2585
  this.serialize = t, e.forEach((n) => this.dataById.set(n.id, n));
2582
2586
  }
@@ -2611,21 +2615,21 @@ class vs {
2611
2615
  return this.dataById.get(e);
2612
2616
  }
2613
2617
  }
2614
- const Es = (r, e, t) => {
2615
- 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)), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
2618
+ const Rs = (r, e, t) => {
2619
+ 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();
2616
2620
  return s.forEach((d) => {
2617
- o.has(d.id) ? u.add(d.id) : c.add(d.id);
2621
+ o.has(d.id) ? u.add(d.id) : l.add(d.id);
2618
2622
  }), i.forEach((d) => {
2619
- a.has(d.id) || l.add(d.id);
2623
+ a.has(d.id) || c.add(d.id);
2620
2624
  }), {
2621
2625
  updatedIds: n,
2622
2626
  matchNowIds: a,
2623
2627
  matchBeforeIds: o,
2624
- newlyMatchedIds: c,
2625
- newlyUnmatchedIds: l,
2628
+ newlyMatchedIds: l,
2629
+ newlyUnmatchedIds: c,
2626
2630
  stillMatchedIds: u
2627
2631
  };
2628
- }, Rs = (r, e, t) => {
2632
+ }, Cs = (r, e, t) => {
2629
2633
  const n = r.options, s = n.where, i = Array.from(r.resultEntitySet.values()), a = [];
2630
2634
  for (const u of i) {
2631
2635
  const d = N(u);
@@ -2636,22 +2640,22 @@ const Es = (r, e, t) => {
2636
2640
  const h = t.getData(d);
2637
2641
  h?.patch ? (Object.assign(u, h.patch), (!s || Y(u, s)) && a.push(u)) : a.push(u);
2638
2642
  }
2639
- const o = new Set(a.map((u) => N(u)).filter(Boolean)), c = Array.from(e.newlyMatchedIds).filter((u) => !o.has(u)).map((u) => t.getSerializedUpdate(u)).filter((u) => !!u);
2640
- let l = [...a, ...c];
2641
- n.orderBy?.length && (l = X(l, n.orderBy)), r.next(l, !0);
2642
- }, Cs = (r, e) => {
2643
+ 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);
2644
+ let c = [...a, ...l];
2645
+ n.orderBy?.length && (c = X(c, n.orderBy)), r.next(c, !0);
2646
+ }, Is = (r, e) => {
2643
2647
  const n = Array.from(r.resultEntitySet.values()).some((i) => {
2644
2648
  const a = N(i);
2645
2649
  return !!a && e.updatedIds.has(a);
2646
2650
  }), s = e.newlyMatchedIds.size > 0;
2647
2651
  (n || s) && r.refresh();
2648
- }, Is = (r, e) => {
2652
+ }, Ts = (r, e) => {
2649
2653
  const n = Array.from(r.resultEntitySet.values()).some((i) => {
2650
2654
  const a = N(i);
2651
2655
  return !!a && e.updatedIds.has(a);
2652
2656
  }), s = e.newlyMatchedIds.size > 0;
2653
2657
  (n || s) && r.refresh();
2654
- }, Ts = (r, e, t) => {
2658
+ }, As = (r, e, t) => {
2655
2659
  const n = r.options, s = n.where;
2656
2660
  if (r.result === null || r.result === void 0) {
2657
2661
  e.newlyMatchedIds.size > 0 && r.refresh();
@@ -2674,7 +2678,7 @@ const Es = (r, e, t) => {
2674
2678
  return;
2675
2679
  }
2676
2680
  e.newlyMatchedIds.size > 0 && r.refresh();
2677
- }, As = (r, e) => {
2681
+ }, Ss = (r, e) => {
2678
2682
  const t = r.result || 0, n = e.newlyMatchedIds.size, s = e.newlyUnmatchedIds.size;
2679
2683
  if (n > 0 || s > 0) {
2680
2684
  const i = Math.max(0, t + n - s);
@@ -2723,12 +2727,12 @@ class Oe {
2723
2727
  isEntityDescendant(e, t) {
2724
2728
  if (t == null) {
2725
2729
  let a = D(e), o = 0;
2726
- const c = /* @__PURE__ */ new Set();
2727
- for (; a && !c.has(a); ) {
2728
- o++, c.add(a);
2729
- const l = this.resolveParentEntity(a);
2730
- if (l)
2731
- a = D(l);
2730
+ const l = /* @__PURE__ */ new Set();
2731
+ for (; a && !l.has(a); ) {
2732
+ o++, l.add(a);
2733
+ const c = this.resolveParentEntity(a);
2734
+ if (c)
2735
+ a = D(c);
2732
2736
  else
2733
2737
  break;
2734
2738
  }
@@ -2834,13 +2838,13 @@ class Oe {
2834
2838
  return !1;
2835
2839
  }
2836
2840
  }
2837
- const Ss = (r, e, t, n) => {
2838
- const s = r.options, i = s.entityId, a = s.level, o = Array.from(r.resultEntitySet.values()), c = /* @__PURE__ */ new Map();
2841
+ const Ms = (r, e, t, n) => {
2842
+ const s = r.options, i = s.entityId, a = s.level, o = Array.from(r.resultEntitySet.values()), l = /* @__PURE__ */ new Map();
2839
2843
  o.forEach((y) => {
2840
2844
  const g = N(y);
2841
- g && c.set(g, y);
2845
+ g && l.set(g, y);
2842
2846
  });
2843
- const l = new Oe(n, c);
2847
+ const c = new Oe(n, l);
2844
2848
  let u = !1;
2845
2849
  const h = o.filter((y) => {
2846
2850
  const g = N(y);
@@ -2853,7 +2857,7 @@ const Ss = (r, e, t, n) => {
2853
2857
  if (_ && "parentId" in _.patch) {
2854
2858
  const b = n.getSerializedUpdate(g);
2855
2859
  if (b) {
2856
- const { isDescendant: w, level: E } = l.isEntityDescendant(b, i);
2860
+ const { isDescendant: w, level: E } = c.isEntityDescendant(b, i);
2857
2861
  if (!w || a !== void 0 && E > a)
2858
2862
  return u = !0, !1;
2859
2863
  }
@@ -2870,37 +2874,37 @@ const Ss = (r, e, t, n) => {
2870
2874
  return y;
2871
2875
  }), p = [];
2872
2876
  if (e.filter((y) => {
2873
- const g = y.id, _ = c.has(g), v = "parentId" in y.patch;
2877
+ const g = y.id, _ = l.has(g), v = "parentId" in y.patch;
2874
2878
  return t.matchNowIds.has(g) && !_ && v;
2875
2879
  }).forEach((y) => {
2876
2880
  const g = n.getSerializedUpdate(y.id);
2877
2881
  if (!g) return;
2878
- const { isDescendant: _, level: v } = l.isEntityDescendant(g, i);
2882
+ const { isDescendant: _, level: v } = c.isEntityDescendant(g, i);
2879
2883
  if (_ && (a === void 0 || v <= a)) {
2880
2884
  u = !0, p.push(g);
2881
2885
  const b = N(g);
2882
- b && c.set(b, g);
2886
+ b && l.set(b, g);
2883
2887
  }
2884
2888
  }), e.forEach((y) => {
2885
2889
  const g = y.id;
2886
2890
  if (t.newlyMatchedIds.has(g)) {
2887
2891
  const _ = n.getSerializedUpdate(g);
2888
2892
  if (_) {
2889
- const { isDescendant: v, level: b } = l.isEntityDescendant(_, i);
2890
- v && (a === void 0 || b <= a) && (h.some((E) => N(E) === g) || p.some((E) => N(E) === g) || c.has(g) || (u = !0, p.push(_), c.set(g, _)));
2893
+ const { isDescendant: v, level: b } = c.isEntityDescendant(_, i);
2894
+ 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, _)));
2891
2895
  }
2892
2896
  }
2893
2897
  }), !u)
2894
2898
  return;
2895
2899
  const f = [...h, ...p];
2896
2900
  r.next(f, !0);
2897
- }, Ms = (r, e, t, n) => {
2901
+ }, Os = (r, e, t, n) => {
2898
2902
  const i = r.options.entityId, a = Array.from(r.resultEntitySet.values()), o = /* @__PURE__ */ new Map();
2899
2903
  a.forEach((b) => {
2900
2904
  const w = N(b);
2901
2905
  w && o.set(w, b);
2902
2906
  });
2903
- const c = new Oe(n, o), l = () => {
2907
+ const l = new Oe(n, o), c = () => {
2904
2908
  if (!i)
2905
2909
  return;
2906
2910
  const b = n.getSerializedUpdate(i);
@@ -2913,15 +2917,15 @@ const Ss = (r, e, t, n) => {
2913
2917
  if (t.newlyUnmatchedIds.has(w))
2914
2918
  return u = !0, !1;
2915
2919
  if (m) {
2916
- if (!c.isEntityAncestor(l(), b))
2920
+ if (!l.isEntityAncestor(c(), b))
2917
2921
  return u = !0, !1;
2918
2922
  } else if (t.updatedIds.has(w) && t.matchNowIds.has(w)) {
2919
2923
  const E = n.getData(w);
2920
2924
  if (E && "parentId" in E.patch) {
2921
- const U = n.getSerializedUpdate(w), A = l();
2925
+ const U = n.getSerializedUpdate(w), A = c();
2922
2926
  if (!A)
2923
2927
  return !0;
2924
- if (U && !c.isEntityAncestor(A, U))
2928
+ if (U && !l.isEntityAncestor(A, U))
2925
2929
  return u = !0, !1;
2926
2930
  }
2927
2931
  }
@@ -2937,10 +2941,10 @@ const Ss = (r, e, t, n) => {
2937
2941
  t.newlyMatchedIds.forEach((b) => {
2938
2942
  const w = n.getSerializedUpdate(b);
2939
2943
  if (!w) return;
2940
- const E = l();
2941
- E && c.isEntityAncestor(E, w) && (u = !0, g.push(w), o.set(b, w));
2944
+ const E = c();
2945
+ E && l.isEntityAncestor(E, w) && (u = !0, g.push(w), o.set(b, w));
2942
2946
  });
2943
- const _ = l();
2947
+ const _ = c();
2944
2948
  if (_) {
2945
2949
  const b = N(_);
2946
2950
  b && (y.some((E) => N(E) === b) || g.some((E) => N(E) === b) || (u = !0, y.push(_)));
@@ -2949,8 +2953,8 @@ const Ss = (r, e, t, n) => {
2949
2953
  return;
2950
2954
  const v = [...y, ...g];
2951
2955
  r.next(v, !0);
2952
- }, Os = (r, e, t, n, s, i) => {
2953
- const o = r.options.entityId, c = r.result || 0, l = /* @__PURE__ */ new Map(), u = new Oe(n, l);
2956
+ }, xs = (r, e, t, n, s, i) => {
2957
+ const o = r.options.entityId, l = r.result || 0, c = /* @__PURE__ */ new Map(), u = new Oe(n, c);
2954
2958
  let d = !1, h = 0;
2955
2959
  for (const p of e) {
2956
2960
  const m = !s || i(p.inversePatch, s), f = n.getSerializedBefore(p.id, p.inversePatch), y = u.isEntityDescendantForCount(f, o);
@@ -2972,21 +2976,21 @@ const Ss = (r, e, t, n) => {
2972
2976
  if (d)
2973
2977
  r.refresh();
2974
2978
  else if (h !== 0) {
2975
- const p = Math.max(0, c + h);
2979
+ const p = Math.max(0, l + h);
2976
2980
  r.next(p);
2977
2981
  }
2978
- }, xs = (r, e, t, n, s, i) => {
2979
- const o = r.options.entityId, c = r.result || 0;
2982
+ }, Ns = (r, e, t, n, s, i) => {
2983
+ const o = r.options.entityId, l = r.result || 0;
2980
2984
  if (!o) {
2981
2985
  r.refresh();
2982
2986
  return;
2983
2987
  }
2984
- const l = n.getData(o);
2985
- if (!l) {
2988
+ const c = n.getData(o);
2989
+ if (!c) {
2986
2990
  r.refresh();
2987
2991
  return;
2988
2992
  }
2989
- const u = /* @__PURE__ */ new Map(), d = new Oe(n, u), h = n.getSerializedBefore(l.id, l.inversePatch), p = n.getSerializedUpdate(l.id);
2993
+ const u = /* @__PURE__ */ new Map(), d = new Oe(n, u), h = n.getSerializedBefore(c.id, c.inversePatch), p = n.getSerializedUpdate(c.id);
2990
2994
  if (!h || !p) {
2991
2995
  r.refresh();
2992
2996
  return;
@@ -3030,39 +3034,39 @@ const Ss = (r, e, t, n) => {
3030
3034
  if (g)
3031
3035
  r.refresh();
3032
3036
  else if (y !== 0) {
3033
- const v = Math.max(0, c + y);
3037
+ const v = Math.max(0, l + y);
3034
3038
  r.next(v);
3035
3039
  }
3036
- }, Ns = (r, e) => {
3037
- const t = r.options.where, n = new vs(e, (i) => r.serialize(i)), s = Es(e, t, Y);
3040
+ }, Ps = (r, e) => {
3041
+ const t = r.options.where, n = new Es(e, (i) => r.serialize(i)), s = Rs(e, t, Y);
3038
3042
  switch (r.type) {
3039
3043
  case "findAll":
3040
- Rs(r, s, n);
3044
+ Cs(r, s, n);
3041
3045
  break;
3042
3046
  case "find":
3043
- Cs(r, s);
3047
+ Is(r, s);
3044
3048
  break;
3045
3049
  case "findOne":
3046
3050
  case "findOneOrFail":
3047
- Ts(r, s, n);
3051
+ As(r, s, n);
3048
3052
  break;
3049
3053
  case "findByCursor":
3050
- Is(r, s);
3054
+ Ts(r, s);
3051
3055
  break;
3052
3056
  case "count":
3053
- As(r, s);
3057
+ Ss(r, s);
3054
3058
  break;
3055
3059
  case "findDescendants":
3056
- Ss(r, e, s, n);
3060
+ Ms(r, e, s, n);
3057
3061
  break;
3058
3062
  case "findAncestors":
3059
- Ms(r, e, s, n);
3063
+ Os(r, e, s, n);
3060
3064
  break;
3061
3065
  case "countDescendants":
3062
- Os(r, e, s, n, t, Y);
3066
+ xs(r, e, s, n, t, Y);
3063
3067
  break;
3064
3068
  case "countAncestors":
3065
- xs(r, e, s, n, t, Y);
3069
+ Ns(r, e, s, n, t, Y);
3066
3070
  break;
3067
3071
  }
3068
3072
  }, Xe = (r, e) => {
@@ -3129,10 +3133,10 @@ const Ss = (r, e, t, n) => {
3129
3133
  t.push(["match_where"]), t.push(["match_where_before"]), t.push(["match_relation_where"]);
3130
3134
  break;
3131
3135
  }
3132
- const s = Pr(r, e, t, n);
3133
- s.refresh ? r.refresh() : s.recalculate && Ns(r, e);
3136
+ const s = $r(r, e, t, n);
3137
+ s.refresh ? r.refresh() : s.recalculate && Ps(r, e);
3134
3138
  };
3135
- class Ps {
3139
+ class $s {
3136
3140
  /**
3137
3141
  * 构造函数
3138
3142
  *
@@ -3188,7 +3192,7 @@ class Ps {
3188
3192
  * @returns 新创建的查询任务
3189
3193
  */
3190
3194
  #o(e, t) {
3191
- return new ys({
3195
+ return new ms({
3192
3196
  cacheKey: e,
3193
3197
  ...t,
3194
3198
  entityType: this.EntityType,
@@ -3283,7 +3287,7 @@ class Ps {
3283
3287
  this.#i = e, this.rxdb.addEventListener(ne, e), this.rxdb.addEventListener(oe, e), this.rxdb.addEventListener(ce, e);
3284
3288
  }
3285
3289
  }
3286
- class $s {
3290
+ class Bs {
3287
3291
  constructor(e, t) {
3288
3292
  this.rxdb = e, this.EntityType = t;
3289
3293
  }
@@ -3320,7 +3324,7 @@ class $s {
3320
3324
  n.origin = { ...t }, Object.assign(e, t);
3321
3325
  }
3322
3326
  }
3323
- class sn extends $s {
3327
+ class sn extends Bs {
3324
3328
  static _STATIC_METHODS = [
3325
3329
  ...super._STATIC_METHODS,
3326
3330
  "get",
@@ -3364,7 +3368,7 @@ class sn extends $s {
3364
3368
  const n = I(t);
3365
3369
  this.sync = n.sync || e.config.sync;
3366
3370
  const { local: s, remote: i } = this.sync, a = !s && !!i;
3367
- this.primary$ = a ? this.remote$ : this.local$, this.queryManager = new Ps(e, t, this);
3371
+ this.primary$ = a ? this.remote$ : this.local$, this.queryManager = new $s(e, t, this);
3368
3372
  }
3369
3373
  /**
3370
3374
  * 根据 id 获取实体
@@ -3475,8 +3479,8 @@ class sn extends $s {
3475
3479
  if (e.before && e.after)
3476
3480
  throw new R("before and after cannot be used together in cursor-based pagination");
3477
3481
  let n = structuredClone(e.where);
3478
- const s = Bs(e);
3479
- s && (n = Ds(n, s));
3482
+ const s = Ds(e);
3483
+ s && (n = Ls(n, s));
3480
3484
  const i = () => this.primary$.pipe(
3481
3485
  x((a) => a.find({ ...e, where: n })),
3482
3486
  W(this._setLocals)
@@ -3539,7 +3543,7 @@ class sn extends $s {
3539
3543
  };
3540
3544
  _setLocals = (e) => e.forEach(this._setLocal);
3541
3545
  }
3542
- const Bs = (r) => {
3546
+ const Ds = (r) => {
3543
3547
  const e = r.after || r.before;
3544
3548
  if (!e) return null;
3545
3549
  const t = !!r.after;
@@ -3552,16 +3556,16 @@ const Bs = (r) => {
3552
3556
  }
3553
3557
  const n = [];
3554
3558
  for (let s = 0; s < r.orderBy.length; s++) {
3555
- const { field: i, sort: a } = r.orderBy[s], c = a === "asc" === t, l = [];
3559
+ const { field: i, sort: a } = r.orderBy[s], l = a === "asc" === t, c = [];
3556
3560
  for (let d = 0; d < s; d++) {
3557
3561
  const h = r.orderBy[d].field;
3558
- l.push({ field: h, operator: "=", value: e[h] });
3562
+ c.push({ field: h, operator: "=", value: e[h] });
3559
3563
  }
3560
- const u = c ? ">" : "<";
3561
- l.push({ field: i, operator: u, value: e[i] }), n.push({ combinator: "and", rules: l });
3564
+ const u = l ? ">" : "<";
3565
+ c.push({ field: i, operator: u, value: e[i] }), n.push({ combinator: "and", rules: c });
3562
3566
  }
3563
3567
  return { combinator: "or", rules: n };
3564
- }, Ds = (r, e) => r.combinator === "and" ? { ...r, rules: [...r.rules, e] } : { combinator: "and", rules: [r, e] };
3568
+ }, Ls = (r, e) => r.combinator === "and" ? { ...r, rules: [...r.rules, e] } : { combinator: "and", rules: [r, e] };
3565
3569
  class an {
3566
3570
  constructor(e) {
3567
3571
  this.rxdb = e;
@@ -3577,17 +3581,17 @@ class an {
3577
3581
  this.repository_map.set(e, t);
3578
3582
  }
3579
3583
  }
3580
- class da extends an {
3581
- }
3582
3584
  class ha extends an {
3583
3585
  }
3584
- class pa {
3586
+ class pa extends an {
3587
+ }
3588
+ class fa {
3585
3589
  constructor(e) {
3586
3590
  this.rxdb = e;
3587
3591
  }
3588
3592
  }
3589
3593
  const At = 100;
3590
- class Ls extends sn {
3594
+ class Fs extends sn {
3591
3595
  static _STATIC_METHODS = [
3592
3596
  ...super._STATIC_METHODS,
3593
3597
  "findDescendants",
@@ -3654,7 +3658,7 @@ class Ls extends sn {
3654
3658
  return n < 0 ? t.level = 0 : n > At ? t.level = At : t.level = n, t.entityId = t.entityId ?? null, t;
3655
3659
  }
3656
3660
  }
3657
- class Fs {
3661
+ class Us {
3658
3662
  /**
3659
3663
  * 创建实体状态实例
3660
3664
  *
@@ -3955,9 +3959,9 @@ class Fs {
3955
3959
  if (e.kind === T.MANY_TO_MANY) {
3956
3960
  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;
3957
3961
  if (Array.from(n.values()).find(o)) return;
3958
- const l = I(t.constructor).relations.find((h) => h.name === e.mappedProperty);
3962
+ const c = I(t.constructor).relations.find((h) => h.name === e.mappedProperty);
3959
3963
  let u, d;
3960
- l && (u = O(t).getRelationCache(l), d = Array.from(u.values()).find(o)), (!d || O(d).removed) && (d = new s({
3964
+ c && (u = O(t).getRelationCache(c), d = Array.from(u.values()).find(o)), (!d || O(d).removed) && (d = new s({
3961
3965
  [i]: t.id,
3962
3966
  [a]: this.target.id
3963
3967
  })), n.add(t), n.add(d), u && (u.add(this.proxyTarget), u.add(d));
@@ -3985,12 +3989,12 @@ class Fs {
3985
3989
  const n = this.getRelationCache(e);
3986
3990
  if (e.kind === T.MANY_TO_MANY) {
3987
3991
  const s = e.junctionEntityType, i = e.name + "Id", a = e.mappedProperty + "Id", o = Array.from(n.values()).find(
3988
- (c) => c instanceof s && c[i] === t.id && c[a] === this.target.id
3992
+ (l) => l instanceof s && l[i] === t.id && l[a] === this.target.id
3989
3993
  );
3990
3994
  if (o) {
3991
3995
  n.delete(o);
3992
- const l = I(t.constructor).relations.find((u) => u.name === e.mappedProperty);
3993
- l && O(t).getRelationCache(l).delete(this.proxyTarget), this.#n.add(o);
3996
+ const c = I(t.constructor).relations.find((u) => u.name === e.mappedProperty);
3997
+ c && O(t).getRelationCache(c).delete(this.proxyTarget), this.#n.add(o);
3994
3998
  }
3995
3999
  n.delete(t);
3996
4000
  } else
@@ -4031,7 +4035,7 @@ class Fs {
4031
4035
  this._patch_cache = void 0, this._fingerprint = void 0;
4032
4036
  }
4033
4037
  }
4034
- const Us = (r) => {
4038
+ const js = (r) => {
4035
4039
  const e = O(r), t = I(r.constructor), n = () => e.checkChange();
4036
4040
  let s;
4037
4041
  const i = {
@@ -4040,17 +4044,17 @@ const Us = (r) => {
4040
4044
  * 当属性值发生变化时,记录变更并安排检查
4041
4045
  * 同时根据 metadata 配置进行类型转换
4042
4046
  */
4043
- set: (a, o, c, l) => {
4044
- if (Dt(a[o], c)) return !0;
4045
- if (Mn(o) === !1 && (e.modified = !0, clearTimeout(s), s = setTimeout(() => n(), 0), c === null && t.isForeignKey(o))) {
4047
+ set: (a, o, l, c) => {
4048
+ if (Dt(a[o], l)) return !0;
4049
+ if (Mn(o) === !1 && (e.modified = !0, clearTimeout(s), s = setTimeout(() => n(), 0), l === null && t.isForeignKey(o))) {
4046
4050
  const u = t.foreignKeyRelationMap.get(o);
4047
4051
  u && (u.kind === T.MANY_TO_ONE || u.kind === T.ONE_TO_ONE) && e.cleanRelationEntity(u);
4048
4052
  }
4049
- return Reflect.set(a, o, c, l);
4053
+ return Reflect.set(a, o, l, c);
4050
4054
  }
4051
4055
  };
4052
4056
  return new Proxy(r, i);
4053
- }, js = (r, e, t) => {
4057
+ }, Ys = (r, e, t) => {
4054
4058
  const n = t.rxdb.schemaManager.getEntityType(r.mappedEntity, r.mappedNamespace);
4055
4059
  if (!n) throw new R(`mapped entity not found: ${r.mappedEntity}`);
4056
4060
  const s = r.name + "Id", i = r.name + "$";
@@ -4064,7 +4068,7 @@ const Us = (r) => {
4064
4068
  case T.MANY_TO_ONE:
4065
4069
  case T.ONE_TO_ONE:
4066
4070
  a = function() {
4067
- const o = this, c = O(o), l = new J(o[s]), u = l.asObservable().pipe(
4071
+ const o = this, l = O(o), c = new J(o[s]), u = c.asObservable().pipe(
4068
4072
  x((d) => d ? t.getRepository(n).get(d) : Q(null)),
4069
4073
  P(1)
4070
4074
  );
@@ -4073,9 +4077,9 @@ const Us = (r) => {
4073
4077
  u.remove();
4074
4078
  return;
4075
4079
  }
4076
- o[s] != d.id && (c.addRelationEntity(r, d), l.next(d.id), o[s] = d.id);
4080
+ o[s] != d.id && (l.addRelationEntity(r, d), c.next(d.id), o[s] = d.id);
4077
4081
  }), M(u, "remove", () => {
4078
- o[s] != null && (l.next(null), c.removeRelationEntity(r, e), o[s] = null);
4082
+ o[s] != null && (c.next(null), l.removeRelationEntity(r, e), o[s] = null);
4079
4083
  }), Object.freeze(u);
4080
4084
  };
4081
4085
  break;
@@ -4086,7 +4090,7 @@ const Us = (r) => {
4086
4090
  */
4087
4091
  case T.ONE_TO_MANY:
4088
4092
  a = function() {
4089
- const o = r.mappedProperty + "Id", c = r.mappedProperty + "$", l = this, u = O(l), d = ae(
4093
+ const o = r.mappedProperty + "Id", l = r.mappedProperty + "$", c = this, u = O(c), d = ae(
4090
4094
  () => t.getRepository(n).findAll({
4091
4095
  where: {
4092
4096
  combinator: "and",
@@ -4094,7 +4098,7 @@ const Us = (r) => {
4094
4098
  {
4095
4099
  field: o,
4096
4100
  operator: "=",
4097
- value: l.id
4101
+ value: c.id
4098
4102
  }
4099
4103
  ]
4100
4104
  }
@@ -4107,7 +4111,7 @@ const Us = (r) => {
4107
4111
  {
4108
4112
  field: o,
4109
4113
  operator: "=",
4110
- value: l.id
4114
+ value: c.id
4111
4115
  }
4112
4116
  ]
4113
4117
  }
@@ -4115,11 +4119,11 @@ const Us = (r) => {
4115
4119
  );
4116
4120
  return M(d, "count$", h), M(d, "add", (...p) => {
4117
4121
  p.forEach((m) => {
4118
- u.addRelationEntity(r, m), m[c].set(l);
4122
+ u.addRelationEntity(r, m), m[l].set(c);
4119
4123
  });
4120
4124
  }), M(d, "remove", (...p) => {
4121
4125
  p.forEach((m) => {
4122
- u.removeRelationEntity(r, m), m[c].remove();
4126
+ u.removeRelationEntity(r, m), m[l].remove();
4123
4127
  });
4124
4128
  }), Object.freeze(d);
4125
4129
  };
@@ -4132,7 +4136,7 @@ const Us = (r) => {
4132
4136
  */
4133
4137
  case T.MANY_TO_MANY:
4134
4138
  a = function() {
4135
- const o = this, c = O(o), l = r.name + "Id";
4139
+ const o = this, l = O(o), c = r.name + "Id";
4136
4140
  if (!r.junctionEntityType) throw new R("junction entity not found");
4137
4141
  const u = ae(
4138
4142
  () => t.getRepository(r.junctionEntityType).findAll({
@@ -4148,7 +4152,7 @@ const Us = (r) => {
4148
4152
  }
4149
4153
  }).pipe(
4150
4154
  x((h) => {
4151
- const p = h.map((m) => m[l]);
4155
+ const p = h.map((m) => m[c]);
4152
4156
  return t.getRepository(n).findAll({
4153
4157
  where: {
4154
4158
  combinator: "and",
@@ -4180,12 +4184,12 @@ const Us = (r) => {
4180
4184
  return M(u, "count$", d), M(
4181
4185
  u,
4182
4186
  "add",
4183
- (...h) => h.forEach((p) => c.addRelationEntity(r, p))
4187
+ (...h) => h.forEach((p) => l.addRelationEntity(r, p))
4184
4188
  ), M(
4185
4189
  u,
4186
4190
  "remove",
4187
4191
  (...h) => h.forEach((p) => {
4188
- c.removeRelationEntity(r, p);
4192
+ l.removeRelationEntity(r, p);
4189
4193
  })
4190
4194
  ), Object.freeze(u);
4191
4195
  };
@@ -4199,7 +4203,7 @@ const Us = (r) => {
4199
4203
  configurable: !1
4200
4204
  });
4201
4205
  };
4202
- class Ys {
4206
+ class zs {
4203
4207
  /**
4204
4208
  * 创建实体管理器实例
4205
4209
  *
@@ -4219,7 +4223,7 @@ class Ys {
4219
4223
  remove: Je
4220
4224
  }
4221
4225
  }).repository("TreeRepository", {
4222
- class: Ls,
4226
+ class: Fs,
4223
4227
  mergeOperations: {
4224
4228
  create: Qe,
4225
4229
  update: Xe,
@@ -4251,7 +4255,7 @@ class Ys {
4251
4255
  )
4252
4256
  ), Object.keys(St).forEach(
4253
4257
  (s) => M(e.prototype, s, St[s](this, e))
4254
- ), t.relationMap.forEach((s) => js(s, e, this));
4258
+ ), t.relationMap.forEach((s) => Ys(s, e, this));
4255
4259
  }), M(this, kt, (e) => {
4256
4260
  const t = this.#s(e, { local: !1, remote: !1, modified: !0 });
4257
4261
  return On(() => {
@@ -4499,9 +4503,9 @@ class Ys {
4499
4503
  * @returns 初始化后的代理实体实例
4500
4504
  */
4501
4505
  #s(e, t) {
4502
- const n = new Fs(this.rxdb, { target: e, ...t });
4506
+ const n = new Us(this.rxdb, { target: e, ...t });
4503
4507
  cr(e, Kt, n);
4504
- const s = Us(e);
4508
+ const s = js(e);
4505
4509
  return M(n, "proxyTarget", s), s;
4506
4510
  }
4507
4511
  }
@@ -4516,7 +4520,7 @@ const St = {
4516
4520
  return r.reset(this);
4517
4521
  }
4518
4522
  }, Mt = "entity_event", Ot = "hello", xt = "first_connected_at";
4519
- class zs {
4523
+ class Ws {
4520
4524
  #e;
4521
4525
  #n;
4522
4526
  #t;
@@ -4641,7 +4645,7 @@ class zs {
4641
4645
  });
4642
4646
  }
4643
4647
  }
4644
- const Ws = (r) => {
4648
+ const ks = (r) => {
4645
4649
  const [{ metadata: e, relation: t }, { metadata: n, relation: s }] = r, i = Array.from(/* @__PURE__ */ new Set([e.namespace, n.namespace])).sort().join("_") || void 0;
4646
4650
  return {
4647
4651
  name: Array.from(/* @__PURE__ */ new Set([e.name, n.name])).sort().join("_"),
@@ -4661,6 +4665,7 @@ const Ws = (r) => {
4661
4665
  kind: T.MANY_TO_ONE,
4662
4666
  mappedNamespace: n.namespace,
4663
4667
  mappedEntity: n.name,
4668
+ mappedProperty: s.name,
4664
4669
  onDelete: k.CASCADE
4665
4670
  },
4666
4671
  {
@@ -4672,16 +4677,17 @@ const Ws = (r) => {
4672
4677
  kind: T.MANY_TO_ONE,
4673
4678
  mappedNamespace: e.namespace,
4674
4679
  mappedEntity: e.name,
4680
+ mappedProperty: t.name,
4675
4681
  onDelete: k.CASCADE
4676
4682
  }
4677
4683
  ]
4678
4684
  };
4679
4685
  };
4680
- var ks = Object.defineProperty, Ks = Object.getOwnPropertyDescriptor, Hs = (r, e, t) => e in r ? ks(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, qs = (r, e, t, n) => {
4681
- for (var s = n > 1 ? void 0 : n ? Ks(e, t) : e, i = r.length - 1, a; i >= 0; i--)
4686
+ var Ks = Object.defineProperty, Hs = Object.getOwnPropertyDescriptor, qs = (r, e, t) => e in r ? Ks(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Vs = (r, e, t, n) => {
4687
+ for (var s = n > 1 ? void 0 : n ? Hs(e, t) : e, i = r.length - 1, a; i >= 0; i--)
4682
4688
  (a = r[i]) && (s = a(s) || s);
4683
4689
  return s;
4684
- }, Vs = (r, e, t) => Hs(r, typeof e != "symbol" ? e + "" : e, t), on;
4690
+ }, Gs = (r, e, t) => qs(r, typeof e != "symbol" ? e + "" : e, t), on;
4685
4691
  on = ct;
4686
4692
  let K = class {
4687
4693
  /**
@@ -4735,9 +4741,9 @@ let K = class {
4735
4741
  */
4736
4742
  children$;
4737
4743
  };
4738
- Vs(K, on);
4739
- K = qs([
4740
- yr({
4744
+ Gs(K, on);
4745
+ K = Vs([
4746
+ mr({
4741
4747
  name: "RxDBBranch",
4742
4748
  tableName: "rxdb_branch",
4743
4749
  log: !1,
@@ -4806,16 +4812,17 @@ K = qs([
4806
4812
  name: "parent",
4807
4813
  kind: T.MANY_TO_ONE,
4808
4814
  mappedEntity: "RxDBBranch",
4815
+ mappedProperty: "children",
4809
4816
  nullable: !0
4810
4817
  }
4811
4818
  ]
4812
4819
  })
4813
4820
  ], K);
4814
- 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) => {
4815
- for (var s = n > 1 ? void 0 : n ? Qs(e, t) : e, i = r.length - 1, a; i >= 0; i--)
4821
+ var Qs = Object.defineProperty, Js = Object.getOwnPropertyDescriptor, Xs = (r, e, t) => e in r ? Qs(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Zs = (r, e, t, n) => {
4822
+ for (var s = n > 1 ? void 0 : n ? Js(e, t) : e, i = r.length - 1, a; i >= 0; i--)
4816
4823
  (a = r[i]) && (s = a(s) || s);
4817
4824
  return s;
4818
- }, Zs = (r, e, t) => Js(r, typeof e != "symbol" ? e + "" : e, t), cn;
4825
+ }, ei = (r, e, t) => Xs(r, typeof e != "symbol" ? e + "" : e, t), cn;
4819
4826
  cn = ct;
4820
4827
  let H = class {
4821
4828
  /**
@@ -5352,8 +5359,8 @@ let H = class {
5352
5359
  */
5353
5360
  branch$;
5354
5361
  };
5355
- Zs(H, cn);
5356
- H = Xs([
5362
+ ei(H, cn);
5363
+ H = Zs([
5357
5364
  ie({
5358
5365
  name: "RxDBChange",
5359
5366
  tableName: "rxdb_change",
@@ -5441,16 +5448,17 @@ H = Xs([
5441
5448
  name: "branch",
5442
5449
  kind: T.MANY_TO_ONE,
5443
5450
  mappedEntity: "RxDBBranch",
5451
+ mappedProperty: "changes",
5444
5452
  nullable: !0
5445
5453
  }
5446
5454
  ]
5447
5455
  })
5448
5456
  ], H);
5449
- 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) => {
5450
- for (var s = n > 1 ? void 0 : n ? ti(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5457
+ var ti = Object.defineProperty, ni = Object.getOwnPropertyDescriptor, ri = (r, e, t) => e in r ? ti(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, si = (r, e, t, n) => {
5458
+ for (var s = n > 1 ? void 0 : n ? ni(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5451
5459
  (a = r[i]) && (s = a(s) || s);
5452
5460
  return s;
5453
- }, si = (r, e, t) => ni(r, typeof e != "symbol" ? e + "" : e, t), ln;
5461
+ }, ii = (r, e, t) => ri(r, typeof e != "symbol" ? e + "" : e, t), ln;
5454
5462
  ln = ct;
5455
5463
  let se = class {
5456
5464
  /**
@@ -5467,8 +5475,8 @@ let se = class {
5467
5475
  */
5468
5476
  name;
5469
5477
  };
5470
- si(se, ln);
5471
- se = ri([
5478
+ ii(se, ln);
5479
+ se = si([
5472
5480
  ie({
5473
5481
  name: "RxDBMigration",
5474
5482
  tableName: "rxdb_migration",
@@ -5493,8 +5501,8 @@ se = ri([
5493
5501
  ]
5494
5502
  })
5495
5503
  ], se);
5496
- var ii = Object.getOwnPropertyDescriptor, ai = (r, e, t, n) => {
5497
- for (var s = n > 1 ? void 0 : n ? ii(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5504
+ var ai = Object.getOwnPropertyDescriptor, oi = (r, e, t, n) => {
5505
+ for (var s = n > 1 ? void 0 : n ? ai(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5498
5506
  (a = r[i]) && (s = a(s) || s);
5499
5507
  return s;
5500
5508
  };
@@ -5523,6 +5531,7 @@ let z = class {
5523
5531
  * 同步类型
5524
5532
  * - full: 本地 ↔ 远程完全同步
5525
5533
  * - filter: 本地 ↔ 远程条件同步(只同步满足条件的数据)
5534
+ * - querycache: 查询缓存同步(根据查询结果集进行本地缓存与远程数据的一致性维护)
5526
5535
  * - remote: 只读远程数据(只 pull,不 push)
5527
5536
  * - local: 只在本地(只 push,不 pull)
5528
5537
  * - none: 不同步(系统表或临时数据)
@@ -5561,7 +5570,7 @@ let z = class {
5561
5570
  */
5562
5571
  branch;
5563
5572
  };
5564
- z = ai([
5573
+ z = oi([
5565
5574
  ie({
5566
5575
  name: "RxDBSync",
5567
5576
  tableName: "rxdb_sync",
@@ -5645,18 +5654,19 @@ z = ai([
5645
5654
  name: "branch",
5646
5655
  kind: T.MANY_TO_ONE,
5647
5656
  mappedEntity: "RxDBBranch",
5657
+ mappedProperty: "syncs",
5648
5658
  onDelete: k.CASCADE
5649
5659
  }
5650
5660
  ]
5651
5661
  })
5652
5662
  ], z);
5653
- var oi = Object.getOwnPropertyDescriptor, ci = (r, e, t, n) => {
5654
- for (var s = n > 1 ? void 0 : n ? oi(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5663
+ var ci = Object.getOwnPropertyDescriptor, li = (r, e, t, n) => {
5664
+ for (var s = n > 1 ? void 0 : n ? ci(e, t) : e, i = r.length - 1, a; i >= 0; i--)
5655
5665
  (a = r[i]) && (s = a(s) || s);
5656
5666
  return s;
5657
5667
  };
5658
5668
  const G = (r, e) => e + ":" + r;
5659
- class li {
5669
+ class ui {
5660
5670
  constructor(e) {
5661
5671
  this.rxdb = e;
5662
5672
  }
@@ -5671,8 +5681,8 @@ class li {
5671
5681
  this.#e.set(a, n), this.#n.set(a, t);
5672
5682
  const o = this.rxdb.getRepositoryConfig(n.repository);
5673
5683
  if (o?.entityGenerator) {
5674
- const c = o.entityGenerator(n);
5675
- Pn(c).forEach((u) => {
5684
+ const l = o.entityGenerator(n);
5685
+ Pn(l).forEach((u) => {
5676
5686
  const d = I(u), h = G(d.name, d.namespace);
5677
5687
  this.#e.has(h) || (this.#e.set(h, d), this.#n.set(h, u), e.push(u));
5678
5688
  });
@@ -5683,18 +5693,18 @@ class li {
5683
5693
  const s = n, i = this.findMappedRelation(t, s);
5684
5694
  if (!i)
5685
5695
  throw new R("mapped relation not found");
5686
- const a = Ws([
5696
+ const a = ks([
5687
5697
  { metadata: t, relation: s },
5688
5698
  i
5689
5699
  ]), o = G(a.name, a.namespace);
5690
5700
  if (this.#e.has(o) === !1) {
5691
- let c = class extends Ie {
5701
+ let l = class extends Ie {
5692
5702
  };
5693
- c = ci([
5703
+ l = li([
5694
5704
  ie(a)
5695
- ], c);
5696
- const l = I(c);
5697
- this.#e.set(o, l), this.#n.set(o, c), e.push(c);
5705
+ ], l);
5706
+ const c = I(l);
5707
+ this.#e.set(o, c), this.#n.set(o, l), e.push(l);
5698
5708
  }
5699
5709
  n.junctionEntityType = this.#n.get(o);
5700
5710
  }
@@ -5702,8 +5712,8 @@ class li {
5702
5712
  ), this.#e.forEach((t, n) => {
5703
5713
  const { name: s, namespace: i, tableName: a } = t, o = G(a, i);
5704
5714
  this.#t.set(o, this.#n.get(n)), this.#r.set(o, t);
5705
- let c = this.rxdb;
5706
- i !== "public" && (M(c, i, {}), c = c[i]), M(c, s, this.#n.get(n));
5715
+ let l = this.rxdb;
5716
+ i !== "public" && (M(l, i, {}), l = l[i]), M(l, s, this.#n.get(n));
5707
5717
  }), Object.freeze(this);
5708
5718
  }
5709
5719
  /**
@@ -5743,8 +5753,8 @@ class li {
5743
5753
  getFieldRelations(e, t) {
5744
5754
  if (t.includes(".") === !1) throw new R(`field '${t}' 必须是关属性查询`);
5745
5755
  const n = [], s = t.split("."), i = s.length - 1;
5746
- let a = e, o, c = !1, l = "";
5747
- return s.length === 2 && s[1] == "id" && (c = a.foreignKeyRelationMap.has(`${s[0]}Id`), l = s[0] + "Id"), s.forEach((u, d) => {
5756
+ let a = e, o, l = !1, c = "";
5757
+ return s.length === 2 && s[1] == "id" && (l = a.foreignKeyRelationMap.has(`${s[0]}Id`), c = s[0] + "Id"), s.forEach((u, d) => {
5748
5758
  if (d === i) {
5749
5759
  if (a.propertyMap.has(u) === !1) throw new R(`property '${u}' not found`);
5750
5760
  o = a.propertyMap.get(u);
@@ -5755,8 +5765,8 @@ class li {
5755
5765
  }
5756
5766
  }), {
5757
5767
  property: o,
5758
- propertyName: l || o.name,
5759
- isForeignKey: c,
5768
+ propertyName: c || o.name,
5769
+ isForeignKey: l,
5760
5770
  relations: n
5761
5771
  };
5762
5772
  }
@@ -5791,7 +5801,7 @@ class li {
5791
5801
  return this.#r.get(G(e, t)) ?? this.#e.get(G(e, t));
5792
5802
  }
5793
5803
  }
5794
- const ui = "0.0.10", Ze = (r) => `${r.namespace}:${r.entity}:${r.entityId}`, fa = (r) => r.split(":");
5804
+ const di = "0.0.10", Ze = (r) => `${r.namespace}:${r.entity}:${r.entityId}`, ya = (r) => r.split(":");
5795
5805
  function un(r, e = {
5796
5806
  deletes: /* @__PURE__ */ new Map(),
5797
5807
  updates: /* @__PURE__ */ new Map(),
@@ -5854,23 +5864,23 @@ function ft(r) {
5854
5864
  const s = `${n.namespace}:${n.entity}`, i = e.get(s);
5855
5865
  i && i.requiredBy.push(t.repository);
5856
5866
  }
5857
- return di(e), e;
5867
+ return hi(e), e;
5858
5868
  }
5859
- function di(r) {
5869
+ function hi(r) {
5860
5870
  const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set(), n = [];
5861
5871
  function s(i) {
5862
5872
  e.add(i), t.add(i), n.push(i);
5863
5873
  const a = r.get(i);
5864
5874
  if (!a) return !1;
5865
5875
  for (const o of a.dependsOn) {
5866
- const c = `${o.namespace}:${o.entity}`;
5867
- if (c !== i) {
5868
- if (e.has(c)) {
5869
- if (t.has(c)) {
5870
- const l = n.indexOf(c), u = [...n.slice(l), c];
5876
+ const l = `${o.namespace}:${o.entity}`;
5877
+ if (l !== i) {
5878
+ if (e.has(l)) {
5879
+ if (t.has(l)) {
5880
+ const c = n.indexOf(l), u = [...n.slice(c), l];
5871
5881
  throw new R(`Circular dependency detected: ${u.join(" -> ")}`);
5872
5882
  }
5873
- } else if (s(c)) return !0;
5883
+ } else if (s(l)) return !0;
5874
5884
  }
5875
5885
  }
5876
5886
  return t.delete(i), n.pop(), !1;
@@ -5878,11 +5888,11 @@ function di(r) {
5878
5888
  for (const i of r.keys())
5879
5889
  e.has(i) || s(i);
5880
5890
  }
5881
- function hi(r, e) {
5891
+ function pi(r, e) {
5882
5892
  return r.sync || e;
5883
5893
  }
5884
5894
  function j(r, e) {
5885
- const t = hi(r, e);
5895
+ const t = pi(r, e);
5886
5896
  if (!t)
5887
5897
  return "none";
5888
5898
  if (t.type === fe.Filter)
@@ -5901,17 +5911,17 @@ function dn(r, e) {
5901
5911
  const t = j(r, e);
5902
5912
  return t === "full" || t === "filter" || t === "remote";
5903
5913
  }
5904
- function pi(r, e) {
5914
+ function fi(r, e) {
5905
5915
  const t = j(r, e);
5906
5916
  return t === "full" || t === "filter" || t === "local";
5907
5917
  }
5908
- function fi(r, e) {
5918
+ function yi(r, e) {
5909
5919
  return j(r, e) === "none";
5910
5920
  }
5911
- function ya(r, e) {
5912
- return r.filter((t) => !fi(t, e));
5913
- }
5914
5921
  function ma(r, e) {
5922
+ return r.filter((t) => !yi(t, e));
5923
+ }
5924
+ function ga(r, e) {
5915
5925
  const t = {
5916
5926
  full: [],
5917
5927
  filter: [],
@@ -5936,9 +5946,9 @@ function yt(r, e) {
5936
5946
  const o = r.get(a);
5937
5947
  if (!o)
5938
5948
  throw new R(`Repository ${a} not found in dependency graph`);
5939
- const c = e === "pull" ? o.dependsOn : o.requiredBy;
5940
- for (const l of c) {
5941
- const u = `${l.namespace}:${l.entity}`;
5949
+ const l = e === "pull" ? o.dependsOn : o.requiredBy;
5950
+ for (const c of l) {
5951
+ const u = `${c.namespace}:${c.entity}`;
5942
5952
  u !== a && i(u);
5943
5953
  }
5944
5954
  s.delete(a), n.add(a), t.push(o.repository);
@@ -5947,10 +5957,10 @@ function yt(r, e) {
5947
5957
  i(a);
5948
5958
  return t;
5949
5959
  }
5950
- function yi(r) {
5960
+ function mi(r) {
5951
5961
  return yt(r, "pull");
5952
5962
  }
5953
- function mi(r) {
5963
+ function gi(r) {
5954
5964
  return yt(r, "push");
5955
5965
  }
5956
5966
  function hn(r) {
@@ -5958,17 +5968,17 @@ function hn(r) {
5958
5968
  const e = r;
5959
5969
  return (e.combinator === "and" || e.combinator === "or") && Array.isArray(e.rules);
5960
5970
  }
5961
- const gi = {
5971
+ const _i = {
5962
5972
  limit: 1e3,
5963
5973
  fetchAll: !1,
5964
5974
  includeRelated: !0,
5965
5975
  filter: void 0
5966
5976
  };
5967
5977
  async function pn(r, e, t, n) {
5968
- const s = { ...gi, ...n }, i = r.rxdb;
5978
+ const s = { ..._i, ...n }, i = r.rxdb;
5969
5979
  i.dispatchEvent(new it("pull", e, t, s.includeRelated));
5970
5980
  try {
5971
- const a = await _i(r, e, t, s);
5981
+ const a = await bi(r, e, t, s);
5972
5982
  return i.dispatchEvent(
5973
5983
  new at("pull", e, t, {
5974
5984
  pulled: a.pulled,
@@ -5979,9 +5989,9 @@ async function pn(r, e, t, n) {
5979
5989
  throw i.dispatchEvent(new ot("pull", e, t, a)), a;
5980
5990
  }
5981
5991
  }
5982
- async function _i(r, e, t, n) {
5983
- const s = r.rxdb.config.entities.find((l) => {
5984
- const u = I(l);
5992
+ async function bi(r, e, t, n) {
5993
+ const s = r.rxdb.config.entities.find((c) => {
5994
+ const u = I(c);
5985
5995
  return u.namespace === e && u.name === t;
5986
5996
  });
5987
5997
  if (!s)
@@ -5993,10 +6003,10 @@ async function _i(r, e, t, n) {
5993
6003
  throw new R(`Cannot pull repository ${e}:${t}: syncType is 'local' (no remote).`);
5994
6004
  let o = n.filter;
5995
6005
  if (a === "filter" && !o) {
5996
- const l = i.sync;
5997
- if (l?.remote?.filter) {
6006
+ const c = i.sync;
6007
+ if (c?.remote?.filter) {
5998
6008
  try {
5999
- o = l.remote.filter();
6009
+ o = c.remote.filter();
6000
6010
  } catch (u) {
6001
6011
  throw new R(
6002
6012
  `Filter function failed for ${e}:${t}: ${u instanceof Error ? u.message : String(u)}`
@@ -6008,19 +6018,19 @@ async function _i(r, e, t, n) {
6008
6018
  );
6009
6019
  }
6010
6020
  }
6011
- const c = { ...n, filter: o };
6012
- return n.includeRelated ? await bi(r, e, t, c) : await fn(r, e, t, c);
6021
+ const l = { ...n, filter: o };
6022
+ return n.includeRelated ? await wi(r, e, t, l) : await fn(r, e, t, l);
6013
6023
  }
6014
- async function bi(r, e, t, n) {
6024
+ async function wi(r, e, t, n) {
6015
6025
  const s = r.rxdb.config.entities.map((y) => I(y)), i = ft(s), a = new Map(
6016
6026
  r.rxdb.config.entities.map((y) => {
6017
6027
  const g = I(y);
6018
6028
  return [`${g.namespace}:${g.name}`, y];
6019
6029
  })
6020
- ), o = yi(i), c = `${e}:${t}`;
6021
- if (!i.get(c))
6030
+ ), o = mi(i), l = `${e}:${t}`;
6031
+ if (!i.get(l))
6022
6032
  throw new R(`Repository ${e}:${t} not found in dependency graph`);
6023
- const u = /* @__PURE__ */ new Set([c]), d = (y) => {
6033
+ const u = /* @__PURE__ */ new Set([l]), d = (y) => {
6024
6034
  const g = i.get(y);
6025
6035
  if (g)
6026
6036
  for (const _ of g.dependsOn) {
@@ -6028,7 +6038,7 @@ async function bi(r, e, t, n) {
6028
6038
  u.has(v) || (u.add(v), d(v));
6029
6039
  }
6030
6040
  };
6031
- d(c);
6041
+ d(l);
6032
6042
  const h = o.filter((y) => {
6033
6043
  const g = `${y.namespace}:${y.entity}`;
6034
6044
  return u.has(g);
@@ -6095,11 +6105,11 @@ async function bi(r, e, t, n) {
6095
6105
  async function fn(r, e, t, n) {
6096
6106
  if (!r.rxdb.config.sync?.remote?.adapter)
6097
6107
  throw new R("Remote adapter not configured.");
6098
- const { adapter: a } = await r.getRemoteRepositories(), { adapter: o } = await r.getLocalRepositories(), c = await r.getCurrentBranch(), l = `${e}:${t}:${c.id}`, u = o.getRepository(z);
6108
+ const { adapter: a } = await r.getRemoteRepositories(), { adapter: o } = await r.getLocalRepositories(), l = await r.getCurrentBranch(), c = `${e}:${t}:${l.id}`, u = o.getRepository(z);
6099
6109
  let h = (await u.find({
6100
6110
  where: {
6101
6111
  combinator: "and",
6102
- rules: [{ field: "id", operator: "=", value: l }]
6112
+ rules: [{ field: "id", operator: "=", value: c }]
6103
6113
  },
6104
6114
  limit: 1
6105
6115
  }))[0];
@@ -6108,12 +6118,12 @@ async function fn(r, e, t, n) {
6108
6118
  const Z = I(q);
6109
6119
  return Z.namespace === e && Z.name === t;
6110
6120
  }), B = I(E), U = j(B, r.rxdb.config.sync), A = new z();
6111
- A.id = l, A.namespace = e, A.entity = t, A.branchId = c.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);
6121
+ 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);
6112
6122
  }
6113
6123
  const p = await u.find({
6114
6124
  where: {
6115
6125
  combinator: "and",
6116
- rules: [{ field: "id", operator: "=", value: l }]
6126
+ rules: [{ field: "id", operator: "=", value: c }]
6117
6127
  },
6118
6128
  limit: 1
6119
6129
  });
@@ -6151,15 +6161,15 @@ async function fn(r, e, t, n) {
6151
6161
  hasMore: _
6152
6162
  };
6153
6163
  }
6154
- const wi = {
6164
+ const vi = {
6155
6165
  batchSize: 1e3,
6156
6166
  includeRelated: !0
6157
6167
  };
6158
6168
  async function yn(r, e, t, n) {
6159
- const s = { ...wi, ...n }, i = r.rxdb;
6169
+ const s = { ...vi, ...n }, i = r.rxdb;
6160
6170
  i.dispatchEvent(new it("push", e, t, s.includeRelated));
6161
6171
  try {
6162
- const a = await vi(r, e, t, s);
6172
+ const a = await Ei(r, e, t, s);
6163
6173
  return i.dispatchEvent(
6164
6174
  new at("push", e, t, {
6165
6175
  pushed: a.pushed,
@@ -6171,10 +6181,10 @@ async function yn(r, e, t, n) {
6171
6181
  throw i.dispatchEvent(new ot("push", e, t, a)), a;
6172
6182
  }
6173
6183
  }
6174
- async function vi(r, e, t, n) {
6184
+ async function Ei(r, e, t, n) {
6175
6185
  const s = r.rxdb.config.entities.find((o) => {
6176
- const c = I(o);
6177
- return c.namespace === e && c.name === t;
6186
+ const l = I(o);
6187
+ return l.namespace === e && l.name === t;
6178
6188
  });
6179
6189
  if (!s)
6180
6190
  throw new R(`Entity not found: ${e}:${t}`);
@@ -6183,24 +6193,24 @@ async function vi(r, e, t, n) {
6183
6193
  throw new R(`Cannot push repository ${e}:${t}: syncType is 'none'.`);
6184
6194
  if (a === "remote")
6185
6195
  throw new R(`Cannot push repository ${e}:${t}: syncType is 'remote' (read-only).`);
6186
- return n.includeRelated ? await Ei(r, e, t, n) : await mn(r, e, t);
6196
+ return n.includeRelated ? await Ri(r, e, t, n) : await mn(r, e, t);
6187
6197
  }
6188
- async function Ei(r, e, t, n) {
6189
- const s = r.rxdb.config.entities.map((f) => I(f)), i = ft(s), a = mi(i), o = `${e}:${t}`;
6198
+ async function Ri(r, e, t, n) {
6199
+ const s = r.rxdb.config.entities.map((f) => I(f)), i = ft(s), a = gi(i), o = `${e}:${t}`;
6190
6200
  if (!i.get(o))
6191
6201
  throw new R(`Repository ${e}:${t} not found in dependency graph`);
6192
- const l = /* @__PURE__ */ new Set([o]), u = (f) => {
6202
+ const c = /* @__PURE__ */ new Set([o]), u = (f) => {
6193
6203
  const y = i.get(f);
6194
6204
  if (y)
6195
6205
  for (const g of y.requiredBy) {
6196
6206
  const _ = `${g.namespace}:${g.entity}`;
6197
- l.has(_) || (l.add(_), u(_));
6207
+ c.has(_) || (c.add(_), u(_));
6198
6208
  }
6199
6209
  };
6200
6210
  u(o);
6201
6211
  const d = a.filter((f) => {
6202
6212
  const y = `${f.namespace}:${f.entity}`;
6203
- return l.has(y);
6213
+ return c.has(y);
6204
6214
  }), h = [], p = /* @__PURE__ */ new Set();
6205
6215
  for (const f of d) {
6206
6216
  const y = `${f.namespace}:${f.entity}`;
@@ -6249,11 +6259,11 @@ async function mn(r, e, t, n) {
6249
6259
  if (!r.rxdb.config.sync?.remote?.adapter)
6250
6260
  throw new R("Remote adapter not configured.");
6251
6261
  await r.getRemoteRepositories();
6252
- const { adapter: a } = await r.getLocalRepositories(), o = await r.getCurrentBranch(), c = `${e}:${t}:${o.id}`, l = a.getRepository(z);
6253
- let d = (await l.find({
6262
+ const { adapter: a } = await r.getLocalRepositories(), o = await r.getCurrentBranch(), l = `${e}:${t}:${o.id}`, c = a.getRepository(z);
6263
+ let d = (await c.find({
6254
6264
  where: {
6255
6265
  combinator: "and",
6256
- rules: [{ field: "id", operator: "=", value: c }]
6266
+ rules: [{ field: "id", operator: "=", value: l }]
6257
6267
  },
6258
6268
  limit: 1
6259
6269
  }))[0];
@@ -6262,9 +6272,9 @@ async function mn(r, e, t, n) {
6262
6272
  const Z = I(q);
6263
6273
  return Z.namespace === e && Z.name === t;
6264
6274
  }), B = I(E), U = j(B, r.rxdb.config.sync), A = new z();
6265
- A.id = c, 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 l.create(A);
6275
+ 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);
6266
6276
  }
6267
- const h = d.lastPushedChangeId, p = a.getRepository(H), m = await Ri(p, o.id, h, [t]), f = m.length;
6277
+ const h = d.lastPushedChangeId, p = a.getRepository(H), m = await Ci(p, o.id, h, [t]), f = m.length;
6268
6278
  if (f === 0)
6269
6279
  return {
6270
6280
  repository: { namespace: e, entity: t },
@@ -6311,7 +6321,7 @@ async function mn(r, e, t, n) {
6311
6321
  }
6312
6322
  if (b > 0) {
6313
6323
  const E = Math.max(...m.map((B) => B.id));
6314
- await l.update(d, {
6324
+ await c.update(d, {
6315
6325
  lastPushedChangeId: E,
6316
6326
  lastPushedAt: /* @__PURE__ */ new Date(),
6317
6327
  updatedAt: /* @__PURE__ */ new Date()
@@ -6325,7 +6335,7 @@ async function mn(r, e, t, n) {
6325
6335
  originalCount: f
6326
6336
  };
6327
6337
  }
6328
- async function Ri(r, e, t, n) {
6338
+ async function Ci(r, e, t, n) {
6329
6339
  const s = [
6330
6340
  { field: "branchId", operator: "=", value: e },
6331
6341
  { field: "revertChangeId", operator: "=", value: null },
@@ -6343,7 +6353,7 @@ async function gn(r, e, t, n) {
6343
6353
  const s = r.rxdb, i = n?.pull?.includeRelated ?? n?.push?.includeRelated ?? !0;
6344
6354
  s.dispatchEvent(new it("sync", e, t, i));
6345
6355
  try {
6346
- const a = await Ci(r, e, t, n), o = {
6356
+ const a = await Ii(r, e, t, n), o = {
6347
6357
  pulled: a.pullResult?.pulled ?? 0,
6348
6358
  pushed: a.pushResult?.pushed ?? 0,
6349
6359
  compacted: (a.pullResult?.compacted ?? 0) + (a.pushResult?.compacted ?? 0),
@@ -6354,7 +6364,7 @@ async function gn(r, e, t, n) {
6354
6364
  throw s.dispatchEvent(new ot("sync", e, t, a)), a;
6355
6365
  }
6356
6366
  }
6357
- async function Ci(r, e, t, n) {
6367
+ async function Ii(r, e, t, n) {
6358
6368
  const s = r.rxdb.config.entities.find((d) => {
6359
6369
  const h = I(d);
6360
6370
  return h.namespace === e && h.name === t;
@@ -6374,8 +6384,8 @@ async function Ci(r, e, t, n) {
6374
6384
  applied: 0,
6375
6385
  hasMore: !1
6376
6386
  };
6377
- let l;
6378
- return (n?.direction === "push" || n?.direction === "sync" || !n?.direction) && (a === "local" || a === "full" || a === "filter") ? l = await yn(r, e, t, n?.push) : l = {
6387
+ let c;
6388
+ return (n?.direction === "push" || n?.direction === "sync" || !n?.direction) && (a === "local" || a === "full" || a === "filter") ? c = await yn(r, e, t, n?.push) : c = {
6379
6389
  repository: { namespace: e, entity: t },
6380
6390
  pushed: 0,
6381
6391
  failed: 0,
@@ -6383,10 +6393,10 @@ async function Ci(r, e, t, n) {
6383
6393
  originalCount: 0
6384
6394
  }, {
6385
6395
  pullResult: o,
6386
- pushResult: l
6396
+ pushResult: c
6387
6397
  };
6388
6398
  }
6389
- function Ii(r, e) {
6399
+ function Ti(r, e) {
6390
6400
  if (e.repositories && e.repositories.length > 0)
6391
6401
  return e.repositories;
6392
6402
  const t = [];
@@ -6415,7 +6425,7 @@ async function _n(r, e, t) {
6415
6425
  };
6416
6426
  }
6417
6427
  }
6418
- async function Ti(r, e, t) {
6428
+ async function Ai(r, e, t) {
6419
6429
  const n = [];
6420
6430
  for (const s of e) {
6421
6431
  const i = await _n(r, s, t);
@@ -6423,26 +6433,26 @@ async function Ti(r, e, t) {
6423
6433
  }
6424
6434
  return n;
6425
6435
  }
6426
- async function Ai(r, e, t, n) {
6436
+ async function Si(r, e, t, n) {
6427
6437
  const s = [];
6428
6438
  for (let i = 0; i < e.length; i += n) {
6429
- const o = e.slice(i, i + n).map((l) => _n(r, l, t)), c = await Promise.all(o);
6430
- s.push(...c);
6439
+ const o = e.slice(i, i + n).map((c) => _n(r, c, t)), l = await Promise.all(o);
6440
+ s.push(...l);
6431
6441
  }
6432
6442
  return s;
6433
6443
  }
6434
- async function Si(r, e = {}) {
6435
- const t = Date.now(), n = Ii(r, e), s = {
6444
+ async function Mi(r, e = {}) {
6445
+ const t = Date.now(), n = Ti(r, e), s = {
6436
6446
  direction: e.operation,
6437
6447
  pull: e.pull,
6438
6448
  push: e.push
6439
6449
  }, i = e.concurrent ?? !1, a = e.concurrency ?? 3;
6440
6450
  let o;
6441
- i ? o = await Ai(r, n, s, a) : o = await Ti(r, n, s);
6442
- const c = o.filter((d) => d.success).length, l = o.filter((d) => !d.success).length, u = Date.now() - t;
6451
+ i ? o = await Si(r, n, s, a) : o = await Ai(r, n, s);
6452
+ const l = o.filter((d) => d.success).length, c = o.filter((d) => !d.success).length, u = Date.now() - t;
6443
6453
  return {
6444
- succeeded: c,
6445
- failed: l,
6454
+ succeeded: l,
6455
+ failed: c,
6446
6456
  results: o,
6447
6457
  durationMs: u
6448
6458
  };
@@ -6463,7 +6473,7 @@ async function bn(r, e, t) {
6463
6473
  pendingCount: 0,
6464
6474
  hasUpdates: !1
6465
6475
  };
6466
- const o = (await r.versionManager.getCurrentBranch()).id, { adapter: c } = await r.versionManager.getLocalRepositories(), l = c.getRepository(z), u = `${e}:${t}:${o}`, p = (await l.find({
6476
+ 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({
6467
6477
  where: {
6468
6478
  combinator: "and",
6469
6479
  rules: [{ field: "id", operator: "=", value: u }]
@@ -6481,31 +6491,31 @@ async function bn(r, e, t) {
6481
6491
  hasUpdates: g > 0
6482
6492
  };
6483
6493
  }
6484
- async function Mi(r, e, t, n) {
6494
+ async function Oi(r, e, t, n) {
6485
6495
  const s = r.rxdb, { adapter: i } = await r.getLocalRepositories(), a = s.config.entities.find((f) => {
6486
6496
  const y = I(f);
6487
6497
  return y.namespace === e && y.name === t;
6488
6498
  });
6489
6499
  if (!a)
6490
6500
  throw new R(`Entity not found: ${e}:${t}`);
6491
- const o = I(a), c = j(o, s.config.sync);
6492
- let l = n?.filter;
6493
- if (!l && c === "filter") {
6501
+ const o = I(a), l = j(o, s.config.sync);
6502
+ let c = n?.filter;
6503
+ if (!c && l === "filter") {
6494
6504
  const f = o.sync;
6495
6505
  if (f?.remote?.filter)
6496
6506
  try {
6497
- l = f.remote.filter();
6507
+ c = f.remote.filter();
6498
6508
  } catch (y) {
6499
6509
  throw new R(
6500
6510
  `Filter function failed for ${e}:${t}: ${y instanceof Error ? y.message : String(y)}`
6501
6511
  );
6502
6512
  }
6503
6513
  }
6504
- if (!l)
6514
+ if (!c)
6505
6515
  throw new R(
6506
6516
  `No filter provided and entity ${e}:${t} does not have a Filter sync configuration.`
6507
6517
  );
6508
- const u = wn(l), h = await i.getRepository(a).find({
6518
+ const u = wn(c), h = await i.getRepository(a).find({
6509
6519
  where: u
6510
6520
  }), p = h.map((f) => f.id), m = p.length;
6511
6521
  if (n?.dryRun)
@@ -6528,10 +6538,10 @@ async function Mi(r, e, t, n) {
6528
6538
  function wn(r) {
6529
6539
  return {
6530
6540
  combinator: r.combinator === "and" ? "or" : "and",
6531
- rules: r.rules.map((e) => "combinator" in e ? wn(e) : Oi(e))
6541
+ rules: r.rules.map((e) => "combinator" in e ? wn(e) : xi(e))
6532
6542
  };
6533
6543
  }
6534
- function Oi(r) {
6544
+ function xi(r) {
6535
6545
  const t = {
6536
6546
  "=": "!=",
6537
6547
  "!=": "=",
@@ -6559,7 +6569,7 @@ function Oi(r) {
6559
6569
  operator: t
6560
6570
  };
6561
6571
  }
6562
- const xi = async (r, e, t) => {
6572
+ const Ni = async (r, e, t) => {
6563
6573
  const { branchRepository: n, changeRepository: s } = await r.getLocalRepositories();
6564
6574
  if ((await n.find({
6565
6575
  where: {
@@ -6570,27 +6580,27 @@ const xi = async (r, e, t) => {
6570
6580
  })).length) throw new R(`Branch id (${e}) already exists`);
6571
6581
  let a, o;
6572
6582
  if (t) {
6573
- const l = (await s.find({
6583
+ const c = (await s.find({
6574
6584
  where: {
6575
6585
  combinator: "and",
6576
6586
  rules: [{ field: "id", operator: "=", value: t }]
6577
6587
  },
6578
6588
  limit: 1
6579
6589
  }))[0];
6580
- if (!l) throw new R(`Change ID (${t}) not found`);
6581
- o = l, a = (await n.find({
6590
+ if (!c) throw new R(`Change ID (${t}) not found`);
6591
+ o = c, a = (await n.find({
6582
6592
  where: {
6583
6593
  combinator: "and",
6584
- rules: [{ field: "id", operator: "=", value: l.branchId }]
6594
+ rules: [{ field: "id", operator: "=", value: c.branchId }]
6585
6595
  },
6586
6596
  limit: 1
6587
6597
  }))[0];
6588
6598
  } else
6589
- a = await r.getCurrentBranch(), a && (o = await Ni(r, a.id));
6599
+ a = await r.getCurrentBranch(), a && (o = await Pi(r, a.id));
6590
6600
  if (!a) throw new R("Source branch not found");
6591
- const c = new K();
6592
- return c.id = e, c.activated = !1, c.local = !0, c.remote = !1, c.fromChangeId = o?.id ?? null, c.parentId = a.id, await c.save(), c;
6593
- }, Ni = async (r, e) => {
6601
+ const l = new K();
6602
+ 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;
6603
+ }, Pi = async (r, e) => {
6594
6604
  const { changeRepository: t } = await r.getLocalRepositories();
6595
6605
  return (await t.find({
6596
6606
  where: {
@@ -6608,7 +6618,7 @@ const xi = async (r, e, t) => {
6608
6618
  limit: 1
6609
6619
  }))[0];
6610
6620
  };
6611
- async function Pi(r, e, t, n, s) {
6621
+ async function $i(r, e, t, n, s) {
6612
6622
  const { adapter: i } = await r.versionManager.getLocalRepositories(), a = i.getRepository(H), o = [
6613
6623
  { field: "namespace", operator: "=", value: e },
6614
6624
  { field: "entity", operator: "=", value: t },
@@ -6623,7 +6633,7 @@ async function Pi(r, e, t, n, s) {
6623
6633
  }
6624
6634
  })).length;
6625
6635
  }
6626
- async function $i(r, e, t) {
6636
+ async function Bi(r, e, t) {
6627
6637
  return (await bn(r, e, t)).pendingCount;
6628
6638
  }
6629
6639
  async function vn(r, e, t) {
@@ -6633,18 +6643,18 @@ async function vn(r, e, t) {
6633
6643
  });
6634
6644
  if (!n)
6635
6645
  throw new Error(`Entity not found: ${e}.${t}`);
6636
- const s = I(n), i = j(s, r.config.sync), o = (await r.versionManager.getCurrentBranch()).id, { adapter: c } = await r.versionManager.getLocalRepositories(), l = c.getRepository(z), d = {
6646
+ 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 = {
6637
6647
  combinator: "and",
6638
6648
  rules: [{ field: "id", operator: "=", value: `${e}:${t}:${o}` }]
6639
- }, h = await l.find({ where: d, limit: 1 }), p = h.length > 0 ? h[0] : null;
6649
+ }, h = await c.find({ where: d, limit: 1 }), p = h.length > 0 ? h[0] : null;
6640
6650
  let m = 0, f = 0;
6641
- return pi(s) && (m = await Pi(
6651
+ return fi(s) && (m = await $i(
6642
6652
  r,
6643
6653
  e,
6644
6654
  t,
6645
6655
  o,
6646
6656
  p?.lastPushedChangeId ?? null
6647
- )), dn(s) && (f = await $i(r, e, t)), {
6657
+ )), dn(s) && (f = await Bi(r, e, t)), {
6648
6658
  repository: { namespace: e, entity: t },
6649
6659
  branchId: o,
6650
6660
  syncType: i,
@@ -6657,16 +6667,16 @@ async function vn(r, e, t) {
6657
6667
  pullableCount: f
6658
6668
  };
6659
6669
  }
6660
- async function Bi(r, e) {
6670
+ async function Di(r, e) {
6661
6671
  const t = r.config.entities, n = [];
6662
6672
  for (const i of t) {
6663
- const a = I(i), o = a.namespace, c = a.name, l = await vn(r, o, c);
6664
- n.push(l);
6673
+ const a = I(i), o = a.namespace, l = a.name, c = await vn(r, o, l);
6674
+ n.push(c);
6665
6675
  }
6666
6676
  let s = n;
6667
6677
  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;
6668
6678
  }
6669
- const Di = (r) => {
6679
+ const Li = (r) => {
6670
6680
  const { branches: e, currentBranch: t, nextBranch: n } = r, s = r.currentChangeId ?? t.fromChangeId ?? 0, i = r.nextChangeId ?? n.fromChangeId ?? 0;
6671
6681
  if (s === i)
6672
6682
  return [];
@@ -6690,40 +6700,40 @@ const Di = (r) => {
6690
6700
  m.push(y), f = y;
6691
6701
  }
6692
6702
  return m;
6693
- }, c = o(t), l = o(n);
6703
+ }, l = o(t), c = o(n);
6694
6704
  let u = null, d = -1;
6695
- for (let p = 0; p < c.length; p++)
6696
- if (l.findIndex((f) => f.id === c[p].id) !== -1) {
6697
- u = c[p], d = p;
6705
+ for (let p = 0; p < l.length; p++)
6706
+ if (c.findIndex((f) => f.id === l[p].id) !== -1) {
6707
+ u = l[p], d = p;
6698
6708
  break;
6699
6709
  }
6700
6710
  const h = [];
6701
6711
  if (u) {
6702
6712
  for (let f = 0; f < d; f++) {
6703
- const y = c[f], g = f === 0 ? s : c[f - 1].fromChangeId ?? 0, _ = y.fromChangeId ?? 0;
6713
+ const y = l[f], g = f === 0 ? s : l[f - 1].fromChangeId ?? 0, _ = y.fromChangeId ?? 0;
6704
6714
  g !== _ && h.push({
6705
6715
  branch: y,
6706
6716
  fromChangeId: g,
6707
6717
  toChangeId: _
6708
6718
  });
6709
6719
  }
6710
- const p = l.findIndex((f) => f.id === u.id);
6720
+ const p = c.findIndex((f) => f.id === u.id);
6711
6721
  if (p === 0) {
6712
- const f = d === 0 ? s : c[d - 1].fromChangeId ?? 0, y = i;
6722
+ const f = d === 0 ? s : l[d - 1].fromChangeId ?? 0, y = i;
6713
6723
  f !== y && h.push({
6714
6724
  branch: u,
6715
6725
  fromChangeId: f,
6716
6726
  toChangeId: y
6717
6727
  });
6718
6728
  } else if (p > 0) {
6719
- const f = d === 0 ? s : c[d - 1].fromChangeId ?? 0, y = l[p - 1].fromChangeId ?? 0;
6729
+ const f = d === 0 ? s : l[d - 1].fromChangeId ?? 0, y = c[p - 1].fromChangeId ?? 0;
6720
6730
  f !== y && h.push({
6721
6731
  branch: u,
6722
6732
  fromChangeId: f,
6723
6733
  toChangeId: y
6724
6734
  });
6725
6735
  }
6726
- const m = l.slice(0, p).reverse();
6736
+ const m = c.slice(0, p).reverse();
6727
6737
  for (let f = 0; f < m.length; f++) {
6728
6738
  const y = m[f], g = y.fromChangeId ?? 0, _ = f === m.length - 1 ? i ?? 0 : m[f + 1].fromChangeId ?? 0;
6729
6739
  g !== _ && h.push({
@@ -6733,27 +6743,27 @@ const Di = (r) => {
6733
6743
  });
6734
6744
  }
6735
6745
  } else {
6736
- for (let _ = 0; _ < c.length; _++) {
6737
- const v = c[_], b = _ === 0 ? s : c[_ - 1].fromChangeId ?? 0, w = v.fromChangeId ?? 0;
6746
+ for (let _ = 0; _ < l.length; _++) {
6747
+ const v = l[_], b = _ === 0 ? s : l[_ - 1].fromChangeId ?? 0, w = v.fromChangeId ?? 0;
6738
6748
  b !== w && h.push({
6739
6749
  branch: v,
6740
6750
  fromChangeId: b,
6741
6751
  toChangeId: w
6742
6752
  });
6743
6753
  }
6744
- const p = c[c.length - 1], m = p.fromChangeId ?? 0;
6754
+ const p = l[l.length - 1], m = p.fromChangeId ?? 0;
6745
6755
  m !== 0 && h.push({
6746
6756
  branch: p,
6747
6757
  fromChangeId: m,
6748
6758
  toChangeId: 0
6749
6759
  });
6750
- const f = l[l.length - 1], y = l.length > 1 ? l[l.length - 2].fromChangeId ?? 0 : i ?? 0;
6760
+ const f = c[c.length - 1], y = c.length > 1 ? c[c.length - 2].fromChangeId ?? 0 : i ?? 0;
6751
6761
  y !== 0 && h.push({
6752
6762
  branch: f,
6753
6763
  fromChangeId: 0,
6754
6764
  toChangeId: y
6755
6765
  });
6756
- const g = l.slice(0, l.length - 1).reverse();
6766
+ const g = c.slice(0, c.length - 1).reverse();
6757
6767
  for (let _ = 0; _ < g.length; _++) {
6758
6768
  const v = g[_], b = v.fromChangeId ?? 0, w = _ === g.length - 1 ? i ?? 0 : g[_ + 1].fromChangeId ?? 0;
6759
6769
  b !== w && h.push({
@@ -6764,7 +6774,7 @@ const Di = (r) => {
6764
6774
  }
6765
6775
  }
6766
6776
  return h;
6767
- }, Li = async (r, e) => {
6777
+ }, Fi = async (r, e) => {
6768
6778
  const { branchRepository: t, changeRepository: n } = await r.getLocalRepositories(), s = await t.find({
6769
6779
  where: {
6770
6780
  combinator: "and",
@@ -6777,19 +6787,19 @@ const Di = (r) => {
6777
6787
  if (!a) throw new R(`Branch (${e}) not found`);
6778
6788
  if (i.id === a.id)
6779
6789
  throw new R("Cannot switch to the same branch");
6780
- const o = await Nt(n, i.id), c = await Nt(n, a.id), l = Di({
6790
+ const o = await Nt(n, i.id), l = await Nt(n, a.id), c = Li({
6781
6791
  branches: s,
6782
6792
  currentBranch: i,
6783
6793
  currentChangeId: o ? o.id : null,
6784
6794
  nextBranch: a,
6785
- nextChangeId: c ? c.id : null
6795
+ nextChangeId: l ? l.id : null
6786
6796
  }), u = {
6787
6797
  deletes: /* @__PURE__ */ new Map(),
6788
6798
  updates: /* @__PURE__ */ new Map(),
6789
6799
  inserts: /* @__PURE__ */ new Map()
6790
6800
  };
6791
- for (let d = 0; d < l.length; d++) {
6792
- const { branch: h, fromChangeId: p, toChangeId: m } = l[d], f = p < m, y = p > m, g = Math.min(p, m), _ = Math.max(p, m), v = {
6801
+ for (let d = 0; d < c.length; d++) {
6802
+ 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 = {
6793
6803
  where: {
6794
6804
  combinator: "and",
6795
6805
  rules: [
@@ -6802,10 +6812,10 @@ const Di = (r) => {
6802
6812
  };
6803
6813
  h.fromChangeId && g < h.fromChangeId && v.where.rules.push({ field: "id", operator: ">", value: h.fromChangeId });
6804
6814
  const b = await n.find(v);
6805
- y ? Ui(b, u) : f && Fi(b, u);
6815
+ y ? ji(b, u) : f && Ui(b, u);
6806
6816
  }
6807
6817
  return u;
6808
- }, Fi = (r, e) => be(r, !0, e), Ui = (r, e) => be(r, !1, e), be = (r, e, t = {
6818
+ }, Ui = (r, e) => be(r, !0, e), ji = (r, e) => be(r, !1, e), be = (r, e, t = {
6809
6819
  deletes: /* @__PURE__ */ new Map(),
6810
6820
  updates: /* @__PURE__ */ new Map(),
6811
6821
  inserts: /* @__PURE__ */ new Map()
@@ -6913,10 +6923,10 @@ function En(r) {
6913
6923
  ), t = [];
6914
6924
  return e.insert && t.push(`创建${e.insert}条`), e.update && t.push(`更新${e.update}条`), e.delete && t.push(`删除${e.delete}条`), `事务: ${t.join(", ")}`;
6915
6925
  }
6916
- function ji(r) {
6926
+ function Yi(r) {
6917
6927
  return r.type === "database" ? "database" : r.type === "repository" ? `${r.namespace}:${r.entity}` : `${r.namespace}:${r.entity}:${r.entityId}`;
6918
6928
  }
6919
- class Yi {
6929
+ class zi {
6920
6930
  constructor(e) {
6921
6931
  this.rxdb = e;
6922
6932
  const t = e.entityManager.getRepository(K).findOne({
@@ -6973,13 +6983,13 @@ class Yi {
6973
6983
  })
6974
6984
  );
6975
6985
  if (!i) return [];
6976
- const o = (await L(this.rxdb.localAdapter$)).getRepository(z), c = await o.find({
6986
+ const o = (await L(this.rxdb.localAdapter$)).getRepository(z), l = await o.find({
6977
6987
  where: {
6978
6988
  combinator: "and",
6979
6989
  rules: [{ field: "branchId", operator: "=", value: i.id }]
6980
6990
  }
6981
- }), l = /* @__PURE__ */ new Map();
6982
- for (const u of c) {
6991
+ }), c = /* @__PURE__ */ new Map();
6992
+ for (const u of l) {
6983
6993
  let d = null;
6984
6994
  try {
6985
6995
  const h = await o.find({
@@ -6993,10 +7003,10 @@ class Yi {
6993
7003
  } catch {
6994
7004
  d = null;
6995
7005
  }
6996
- d !== null && l.set(u.entity, d);
7006
+ d !== null && c.set(u.entity, d);
6997
7007
  }
6998
7008
  return n.filter((u) => u.changes.every((d) => {
6999
- const h = d.revertChangeId == null, p = d.remoteId == null, m = l.get(d.entity), f = m == null || d.id > m;
7009
+ const h = d.revertChangeId == null, p = d.remoteId == null, m = c.get(d.entity), f = m == null || d.id > m;
7000
7010
  return h && p && f;
7001
7011
  }));
7002
7012
  } catch (i) {
@@ -7232,8 +7242,8 @@ class Yi {
7232
7242
  if (e.length === 0) return;
7233
7243
  const t = e.flatMap((o) => o.changes), n = /* @__PURE__ */ new Date(), s = be([], !1), { adapter: i } = await this.rxdb.versionManager.getLocalRepositories();
7234
7244
  t.forEach((o) => {
7235
- const c = `${o.namespace}:RxDBChange:${o.id}`;
7236
- s.updates.set(c, {
7245
+ const l = `${o.namespace}:RxDBChange:${o.id}`;
7246
+ s.updates.set(l, {
7237
7247
  patch: {
7238
7248
  redoInvalidatedAt: n
7239
7249
  },
@@ -7312,7 +7322,7 @@ class Yi {
7312
7322
  entity: m.name
7313
7323
  };
7314
7324
  }
7315
- const n = ji(t);
7325
+ const n = Yi(t);
7316
7326
  if (this.history_cache) {
7317
7327
  const m = this.history_cache.get(n);
7318
7328
  if (m)
@@ -7336,12 +7346,12 @@ class Yi {
7336
7346
  return () => {
7337
7347
  y.unsubscribe();
7338
7348
  };
7339
- }), c = o(
7349
+ }), l = o(
7340
7350
  this.undoHistories$.pipe(
7341
7351
  $((m) => pe(m, t)),
7342
7352
  P({ bufferSize: 1, refCount: !0 })
7343
7353
  )
7344
- ), l = o(
7354
+ ), c = o(
7345
7355
  this.redoHistories$.pipe(
7346
7356
  $((m) => pe(m, t)),
7347
7357
  P({ bufferSize: 1, refCount: !0 })
@@ -7352,20 +7362,20 @@ class Yi {
7352
7362
  P({ bufferSize: 1, refCount: !0 })
7353
7363
  )
7354
7364
  ), d = o(
7355
- c.pipe(
7365
+ l.pipe(
7356
7366
  $((m) => m.length),
7357
7367
  P({ bufferSize: 1, refCount: !0 })
7358
7368
  )
7359
7369
  ), h = o(
7360
- l.pipe(
7370
+ c.pipe(
7361
7371
  $((m) => m.length),
7362
7372
  P({ bufferSize: 1, refCount: !0 })
7363
7373
  )
7364
7374
  ), p = {
7365
7375
  type: t.type,
7366
7376
  histories$: a,
7367
- undoHistories$: c,
7368
- redoHistories$: l,
7377
+ undoHistories$: l,
7378
+ redoHistories$: c,
7369
7379
  count$: u,
7370
7380
  undoCount$: d,
7371
7381
  redoCount$: h,
@@ -7404,12 +7414,12 @@ class Yi {
7404
7414
  rules: [{ field: "branchId", operator: "=", value: s.id }]
7405
7415
  }
7406
7416
  });
7407
- let c = 0;
7417
+ let l = 0;
7408
7418
  if (o.length > 0) {
7409
7419
  const u = o.map((d) => d.lastPushedChangeId).filter((d) => d !== null);
7410
- u.length > 0 && (c = Math.min(...u));
7420
+ u.length > 0 && (l = Math.min(...u));
7411
7421
  }
7412
- const l = await e.find({
7422
+ const c = await e.find({
7413
7423
  where: {
7414
7424
  combinator: "and",
7415
7425
  rules: [
@@ -7421,13 +7431,13 @@ class Yi {
7421
7431
  {
7422
7432
  field: "id",
7423
7433
  operator: ">",
7424
- value: c
7434
+ value: l
7425
7435
  }
7426
7436
  ]
7427
7437
  },
7428
7438
  orderBy: [{ field: "id", sort: "desc" }]
7429
7439
  });
7430
- return this.#a(l);
7440
+ return this.#a(c);
7431
7441
  }
7432
7442
  /**
7433
7443
  * 将变更记录转换为历史项
@@ -7455,13 +7465,13 @@ class Yi {
7455
7465
  * @returns 结构化的历史项,包含描述、类型、状态等信息
7456
7466
  */
7457
7467
  #c(e) {
7458
- const t = e[0], n = e.length, s = t.transactionId ?? null, i = t.createdAt, a = t.namespace, o = t.entity, c = s ? "TRANSACTION" : t.type, l = [c, t.entityId, i.getTime()].join(":"), u = e.some((h) => mt(h.revertChangeId) === !1), d = e.some((h) => mt(h.redoInvalidatedAt) === !1);
7468
+ 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);
7459
7469
  return {
7460
7470
  transactionId: s,
7461
7471
  changeId: Math.max(...e.map((h) => h.id)),
7462
- fingerprint: l,
7472
+ fingerprint: c,
7463
7473
  changes: e,
7464
- type: c,
7474
+ type: l,
7465
7475
  count: n,
7466
7476
  createdAt: i,
7467
7477
  description: En(e),
@@ -7488,29 +7498,29 @@ class Yi {
7488
7498
  async #u(e, t) {
7489
7499
  this.isUndoRedoInProgress = !0;
7490
7500
  try {
7491
- const n = t.flatMap((o) => o.changes).sort((o, c) => e === "undo" ? c.id - o.id : o.id - c.id), s = be(n, e === "redo");
7501
+ 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");
7492
7502
  if (e === "undo") {
7493
- const { adapter: o } = await this.rxdb.versionManager.getLocalRepositories(), c = await o.getRxDBChangeSequence(), l = /* @__PURE__ */ new Date();
7503
+ const { adapter: o } = await this.rxdb.versionManager.getLocalRepositories(), l = await o.getRxDBChangeSequence(), c = /* @__PURE__ */ new Date();
7494
7504
  n.forEach((u, d) => {
7495
7505
  const h = `${u.namespace}:RxDBChange:${u.id}`, p = s.updates.get(h) || { patch: {}, inversePatch: null };
7496
7506
  s.updates.set(h, {
7497
7507
  patch: {
7498
7508
  ...p.patch,
7499
- revertChangeId: c + d + 1,
7500
- revertChangedAt: l
7509
+ revertChangeId: l + d + 1,
7510
+ revertChangedAt: c
7501
7511
  },
7502
7512
  inversePatch: p.inversePatch
7503
7513
  });
7504
- }), s.updateRxDBChangeSequence = c + n.length;
7514
+ }), s.updateRxDBChangeSequence = l + n.length;
7505
7515
  } else
7506
7516
  n.forEach((o) => {
7507
- const c = `${o.namespace}:RxDBChange:${o.id}`, l = s.updates.get(c) || { patch: {}, inversePatch: null };
7508
- s.updates.set(c, {
7517
+ const l = `${o.namespace}:RxDBChange:${o.id}`, c = s.updates.get(l) || { patch: {}, inversePatch: null };
7518
+ s.updates.set(l, {
7509
7519
  patch: {
7510
- ...l.patch,
7520
+ ...c.patch,
7511
7521
  revertChangeId: null
7512
7522
  },
7513
- inversePatch: l.inversePatch
7523
+ inversePatch: c.inversePatch
7514
7524
  });
7515
7525
  });
7516
7526
  const { adapter: i } = await this.rxdb.versionManager.getLocalRepositories(), a = await this.rxdb.versionManager.getCurrentBranch();
@@ -7558,16 +7568,16 @@ class Yi {
7558
7568
  { field: "branchId", operator: "=", value: s.id },
7559
7569
  { field: "revertChangeId", operator: "=", value: null },
7560
7570
  { field: "remoteId", operator: "=", value: null }
7561
- ], o = i.map((l) => {
7571
+ ], o = i.map((c) => {
7562
7572
  const u = [
7563
- { field: "namespace", operator: "=", value: l.namespace },
7564
- { field: "entity", operator: "=", value: l.entity }
7573
+ { field: "namespace", operator: "=", value: c.namespace },
7574
+ { field: "entity", operator: "=", value: c.entity }
7565
7575
  ];
7566
- return l.lastPushedChangeId !== null && l.lastPushedChangeId !== void 0 && u.push({ field: "id", operator: ">", value: l.lastPushedChangeId }), {
7576
+ return c.lastPushedChangeId !== null && c.lastPushedChangeId !== void 0 && u.push({ field: "id", operator: ">", value: c.lastPushedChangeId }), {
7567
7577
  combinator: "and",
7568
7578
  rules: u
7569
7579
  };
7570
- }), c = await L(
7580
+ }), l = await L(
7571
7581
  H.count({
7572
7582
  where: {
7573
7583
  combinator: "and",
@@ -7581,7 +7591,7 @@ class Yi {
7581
7591
  }
7582
7592
  })
7583
7593
  );
7584
- this.#n.next(c);
7594
+ this.#n.next(l);
7585
7595
  } catch (e) {
7586
7596
  console.error("[#updatePushableCount] error", e), this.#n.next(0);
7587
7597
  }
@@ -7597,17 +7607,17 @@ async function Pt(r, e) {
7597
7607
  operation: "pull",
7598
7608
  repositories: e?.repositoryFilter?.map((d) => typeof d == "string" ? { namespace: "public", entity: d } : d)
7599
7609
  }, i = await r.bulkSync(s);
7600
- let a = 0, o = 0, c = 0, l = !1;
7610
+ let a = 0, o = 0, l = 0, c = !1;
7601
7611
  for (const d of i.results)
7602
7612
  if (d.success && d.result) {
7603
7613
  const h = d.result.pullResult;
7604
- a += h.pulled ?? 0, o += h.compacted ?? 0, c += h.applied ?? 0, h.hasMore && (l = !0);
7614
+ a += h.pulled ?? 0, o += h.compacted ?? 0, l += h.applied ?? 0, h.hasMore && (c = !0);
7605
7615
  }
7606
7616
  const u = {
7607
7617
  pulled: a,
7608
7618
  compacted: o,
7609
- applied: c,
7610
- hasMore: l
7619
+ applied: l,
7620
+ hasMore: c
7611
7621
  };
7612
7622
  return t.dispatchEvent(new zt("pull", u)), u;
7613
7623
  } catch (s) {
@@ -7624,25 +7634,25 @@ async function $t(r, e) {
7624
7634
  operation: "push",
7625
7635
  repositories: e?.repositoryFilter?.map((d) => typeof d == "string" ? { namespace: "public", entity: d } : d)
7626
7636
  }, i = await r.bulkSync(s);
7627
- let a = 0, o = 0, c = 0, l = 0;
7637
+ let a = 0, o = 0, l = 0, c = 0;
7628
7638
  for (const d of i.results)
7629
7639
  if (d.success && d.result) {
7630
7640
  const h = d.result.pushResult;
7631
- a += h.pushed ?? 0, o += h.failed ?? 0, c += h.compacted ?? 0, l += h.originalCount ?? 0;
7641
+ a += h.pushed ?? 0, o += h.failed ?? 0, l += h.compacted ?? 0, c += h.originalCount ?? 0;
7632
7642
  } else
7633
7643
  o++;
7634
7644
  const u = {
7635
7645
  pushed: a,
7636
7646
  failed: o,
7637
- compacted: c,
7638
- originalCount: l
7647
+ compacted: l,
7648
+ originalCount: c
7639
7649
  };
7640
7650
  return t.dispatchEvent(new zt("push", u)), u;
7641
7651
  } catch (s) {
7642
7652
  throw t.dispatchEvent(new Wt("push", s)), s;
7643
7653
  }
7644
7654
  }
7645
- const zi = async (r, e) => {
7655
+ const Wi = async (r, e) => {
7646
7656
  const { branchRepository: t, changeRepository: n, adapter: s } = await r.getLocalRepositories();
7647
7657
  if (e === "main")
7648
7658
  throw new R("Cannot remove main branch");
@@ -7664,7 +7674,7 @@ const zi = async (r, e) => {
7664
7674
  }
7665
7675
  });
7666
7676
  if (a.length > 0) {
7667
- const o = a.map((l) => l.id);
7677
+ const o = a.map((c) => c.id);
7668
7678
  if ((await t.find({
7669
7679
  where: {
7670
7680
  combinator: "and",
@@ -7679,9 +7689,9 @@ const zi = async (r, e) => {
7679
7689
  }
7680
7690
  await s.removeMany([...a, i]);
7681
7691
  };
7682
- class Wi {
7692
+ class ki {
7683
7693
  constructor(e) {
7684
- this.rxdb = e, this.historyManager = new Yi(this.rxdb);
7694
+ this.rxdb = e, this.historyManager = new zi(this.rxdb);
7685
7695
  }
7686
7696
  #e = [];
7687
7697
  /**
@@ -7728,14 +7738,14 @@ class Wi {
7728
7738
  * @param fromChangeId 从哪个 changeId 创建新分支
7729
7739
  */
7730
7740
  async createBranch(e, t) {
7731
- return xi(this, e, t);
7741
+ return Ni(this, e, t);
7732
7742
  }
7733
7743
  /**
7734
7744
  * 删除分支
7735
7745
  * @param branchId 分支 id
7736
7746
  */
7737
7747
  async removeBranch(e) {
7738
- return zi(this, e);
7748
+ return Wi(this, e);
7739
7749
  }
7740
7750
  // ============================================
7741
7751
  // Pull/Push 同步方法
@@ -7924,7 +7934,7 @@ class Wi {
7924
7934
  * ```
7925
7935
  */
7926
7936
  async cleanupExpired(e, t, n) {
7927
- return Mi(this, e, t, n);
7937
+ return Oi(this, e, t, n);
7928
7938
  }
7929
7939
  /**
7930
7940
  * Check for remote updates without downloading data (T040, US2)
@@ -7999,7 +8009,7 @@ class Wi {
7999
8009
  * ```
8000
8010
  */
8001
8011
  async getAllRepositorySyncStatus(e) {
8002
- return Bi(this.rxdb, e);
8012
+ return Di(this.rxdb, e);
8003
8013
  }
8004
8014
  /**
8005
8015
  * Bulk sync multiple repositories
@@ -8042,7 +8052,7 @@ class Wi {
8042
8052
  * ```
8043
8053
  */
8044
8054
  async bulkSync(e) {
8045
- return Si(this.rxdb, e);
8055
+ return Mi(this.rxdb, e);
8046
8056
  }
8047
8057
  /**
8048
8058
  * Get dependency graph for all repositories
@@ -8107,7 +8117,7 @@ class Wi {
8107
8117
  if ((await this.getCurrentBranch())?.id !== e)
8108
8118
  try {
8109
8119
  this.rxdb.dispatchEvent(new tr(e));
8110
- const { adapter: n } = await this.getLocalRepositories(), s = await Li(this, e), i = await n.switchBranch({
8120
+ const { adapter: n } = await this.getLocalRepositories(), s = await Fi(this, e), i = await n.switchBranch({
8111
8121
  branchId: e,
8112
8122
  actions: s
8113
8123
  });
@@ -8165,10 +8175,10 @@ class Wi {
8165
8175
  throw new R(`Cannot restore from non-DELETE change (type=${a.type})`);
8166
8176
  if (!a.inversePatch)
8167
8177
  throw new R(`RxDBChange ${t.changeId} has no inversePatch`);
8168
- const o = be([a], !1), c = await this.getCurrentBranch();
8169
- await s.switchBranch({ branchId: c.id, actions: o });
8170
- const l = e.constructor;
8171
- return (await s.getRepository(l).find({
8178
+ const o = be([a], !1), l = await this.getCurrentBranch();
8179
+ await s.switchBranch({ branchId: l.id, actions: o });
8180
+ const c = e.constructor;
8181
+ return (await s.getRepository(c).find({
8172
8182
  where: {
8173
8183
  combinator: "and",
8174
8184
  rules: [{ field: "id", operator: "=", value: a.entityId }]
@@ -8209,7 +8219,7 @@ class Wi {
8209
8219
  );
8210
8220
  }
8211
8221
  }
8212
- class ga {
8222
+ class _a {
8213
8223
  #e = new J("");
8214
8224
  #n = new J("");
8215
8225
  /**
@@ -8321,7 +8331,7 @@ class ga {
8321
8331
  * 获取 RxDB 版本号
8322
8332
  */
8323
8333
  get version() {
8324
- return ui;
8334
+ return di;
8325
8335
  }
8326
8336
  get config() {
8327
8337
  return this.#t;
@@ -8331,7 +8341,7 @@ class ga {
8331
8341
  * @param options - RxDB 配置选项
8332
8342
  */
8333
8343
  constructor(e) {
8334
- this.#t = e, this.schemaManager = new li(this), this.entityManager = new Ys(this), this.versionManager = new Wi(this), this.context = { ...this.#t.context }, this.#t.dbName = this.#t.dbName + "@" + this.version.replace(/\./g, "_"), $n(this.#t), globalThis.rxdb = this;
8344
+ this.#t = e, this.schemaManager = new ui(this), this.entityManager = new zs(this), this.versionManager = new ki(this), this.context = { ...this.#t.context }, this.#t.dbName = this.#t.dbName + "@" + this.version.replace(/\./g, "_"), $n(this.#t), globalThis.rxdb = this;
8335
8345
  }
8336
8346
  /**
8337
8347
  * 初始化 RxDB
@@ -8464,7 +8474,7 @@ class ga {
8464
8474
  * 设置统一的多 Tab 通信网关
8465
8475
  */
8466
8476
  #y() {
8467
- this.#c = new zs({
8477
+ this.#c = new Ws({
8468
8478
  dbName: this.#t.dbName,
8469
8479
  clientId: this.#d.clientId
8470
8480
  }), this.#c.init(
@@ -8526,21 +8536,21 @@ class ga {
8526
8536
  (await L(n.findAll({ where: { combinator: "and", rules: [] } }), {
8527
8537
  defaultValue: []
8528
8538
  })).forEach((o) => s.add(o.name));
8529
- const a = [...t].sort((o, c) => o.name.localeCompare(c.name));
8539
+ const a = [...t].sort((o, l) => o.name.localeCompare(l.name));
8530
8540
  for (const o of a) {
8531
8541
  if (s.has(o.name)) continue;
8532
8542
  try {
8533
8543
  await o.up();
8534
- } catch (l) {
8535
- throw console.error(`Migration failed: ${o.name}`, l), l;
8544
+ } catch (c) {
8545
+ throw console.error(`Migration failed: ${o.name}`, c), c;
8536
8546
  }
8537
- const c = new se();
8538
- c.name = o.name, c.executedAt = /* @__PURE__ */ new Date(), await c.save();
8547
+ const l = new se();
8548
+ l.name = o.name, l.executedAt = /* @__PURE__ */ new Date(), await l.save();
8539
8549
  }
8540
8550
  });
8541
8551
  }
8542
8552
  }
8543
- class _a {
8553
+ class ba {
8544
8554
  /**
8545
8555
  * 解决单个冲突
8546
8556
  *
@@ -8569,9 +8579,9 @@ class _a {
8569
8579
  export {
8570
8580
  Qn as CONFLICT_DETECTED_EVENT,
8571
8581
  Jn as CONFLICT_PENDING_EVENT,
8572
- sa as ConflictDetectedEvent,
8573
- ia as ConflictPendingEvent,
8574
- _r as ENTITY_BASE_METADATA_OPTIONS,
8582
+ ia as ConflictDetectedEvent,
8583
+ aa as ConflictPendingEvent,
8584
+ br as ENTITY_BASE_METADATA_OPTIONS,
8575
8585
  ne as ENTITY_LOCAL_CREATE_EVENT,
8576
8586
  Wn as ENTITY_LOCAL_NEW_EVENT,
8577
8587
  ce as ENTITY_LOCAL_REMOVE_EVENT,
@@ -8582,39 +8592,39 @@ export {
8582
8592
  ct as ENTITY_STATIC_TYPES,
8583
8593
  ie as Entity,
8584
8594
  Ie as EntityBase,
8585
- Gi as EntityLocalCreatedEvent,
8595
+ Qi as EntityLocalCreatedEvent,
8586
8596
  er as EntityLocalNewEvent,
8587
- Ji as EntityLocalRemovedEvent,
8588
- Qi as EntityLocalUpdatedEvent,
8589
- Xi as EntityRemoteCreatedEvent,
8590
- ea as EntityRemoteRemovedEvent,
8591
- Zi as EntityRemoteUpdatedEvent,
8592
- _a as LWWConflictResolver,
8597
+ Xi as EntityLocalRemovedEvent,
8598
+ Ji as EntityLocalUpdatedEvent,
8599
+ Zi as EntityRemoteCreatedEvent,
8600
+ ta as EntityRemoteRemovedEvent,
8601
+ ea as EntityRemoteUpdatedEvent,
8602
+ ba as LWWConflictResolver,
8593
8603
  et as NetworkOfflineError,
8594
8604
  k as OnDeleteAction,
8595
8605
  qt as OnUpdateAction,
8596
8606
  C as PropertyType,
8597
- ua as QueryCacheRepository,
8598
- ys as QueryTask,
8599
- Vi as REMOTE_CHANGES_PENDING_EVENT,
8607
+ da as QueryCacheRepository,
8608
+ ms as QueryTask,
8609
+ Gi as REMOTE_CHANGES_PENDING_EVENT,
8600
8610
  Xn as REPOSITORY_SYNC_BEGIN_EVENT,
8601
8611
  jt as REPOSITORY_SYNC_COMPLETE_EVENT,
8602
8612
  Zn as REPOSITORY_SYNC_ERROR_EVENT,
8603
8613
  T as RelationKind,
8604
8614
  sn as Repository,
8605
- $s as RepositoryBase,
8615
+ Bs as RepositoryBase,
8606
8616
  it as RepositorySyncBeginEvent,
8607
8617
  at as RepositorySyncCompleteEvent,
8608
8618
  ot as RepositorySyncErrorEvent,
8609
- ga as RxDB,
8619
+ _a as RxDB,
8610
8620
  an as RxDBAdapterBase,
8611
- da as RxDBAdapterLocalBase,
8612
- ha as RxDBAdapterRemoteBase,
8621
+ ha as RxDBAdapterLocalBase,
8622
+ pa as RxDBAdapterRemoteBase,
8613
8623
  K as RxDBBranch,
8614
8624
  H as RxDBChange,
8615
8625
  R as RxDBError,
8616
8626
  se as RxDBMigration,
8617
- pa as RxDBPluginBase,
8627
+ fa as RxDBPluginBase,
8618
8628
  z as RxDBSync,
8619
8629
  kn as SWITCH_BRANCH_BEGIN,
8620
8630
  Kn as SWITCH_BRANCH_COMMIT,
@@ -8629,47 +8639,47 @@ export {
8629
8639
  Yt as SyncBeginEvent,
8630
8640
  zt as SyncCompleteEvent,
8631
8641
  Wt as SyncErrorEvent,
8632
- ms as SyncStatus,
8642
+ gs as SyncStatus,
8633
8643
  fe as SyncType,
8634
8644
  tt as TRANSACTION_BEGIN,
8635
8645
  nt as TRANSACTION_COMMIT,
8636
8646
  rt as TRANSACTION_ROLLBACK,
8637
- vr as TREE_ADJACENCY_LIST_ENTITY_BASE_OPTIONS,
8638
- ta as TransactionBeginEvent,
8639
- na as TransactionCommitEvent,
8640
- ra as TransactionRollbackEvent,
8647
+ Er as TREE_ADJACENCY_LIST_ENTITY_BASE_OPTIONS,
8648
+ na as TransactionBeginEvent,
8649
+ ra as TransactionCommitEvent,
8650
+ sa as TransactionRollbackEvent,
8641
8651
  _t as TreeAdjacencyListEntityBase,
8642
- yr as TreeEntity,
8643
- ca as __decorateClass,
8644
- Mi as cleanupExpired,
8652
+ mr as TreeEntity,
8653
+ la as __decorateClass,
8654
+ Oi as cleanupExpired,
8645
8655
  un as compactChanges,
8646
- $r as diffMetadata,
8656
+ Br as diffMetadata,
8647
8657
  lr as fillDefaultValue,
8648
8658
  ur as fillInitValue,
8649
8659
  I as getEntityMetadata,
8650
8660
  Pe as getEntityMutations,
8651
8661
  O as getEntityStatus,
8652
- aa as getEntityType,
8662
+ oa as getEntityType,
8653
8663
  dr as getNeedRemoveEntities,
8654
8664
  gt as getNeedSaveEntities,
8655
8665
  Ze as getRxDBChangeKey,
8656
- hi as getSyncConfig,
8666
+ pi as getSyncConfig,
8657
8667
  j as getSyncType,
8658
- ya as getSyncableRepositories,
8659
- ma as groupBySyncType,
8660
- la as isEntityInternalName,
8661
- fi as isNoSync,
8668
+ ma as getSyncableRepositories,
8669
+ ga as groupBySyncType,
8670
+ ua as isEntityInternalName,
8671
+ yi as isNoSync,
8662
8672
  Vt as isRuleGroup,
8663
- oa as isRxDBEntity,
8673
+ ca as isRxDBEntity,
8664
8674
  dn as needsPull,
8665
- pi as needsPush,
8666
- fa as parseRxDBChangeKey,
8667
- xr as queryNeedRefreshCreate,
8668
- Nr as queryNeedRefreshRemove,
8669
- Pr as queryNeedRefreshUpdate,
8675
+ fi as needsPush,
8676
+ ya as parseRxDBChangeKey,
8677
+ Nr as queryNeedRefreshCreate,
8678
+ Pr as queryNeedRefreshRemove,
8679
+ $r as queryNeedRefreshUpdate,
8670
8680
  M as setSafeObjectKey,
8671
8681
  he as setSafeObjectKeyLazyInitOnce,
8672
8682
  cr as setSafeObjectWritableKey,
8673
- fr as transitionMetadata,
8683
+ yr as transitionMetadata,
8674
8684
  Ht as uuid
8675
8685
  };