@aiao/rxdb 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/{RxDB.d.ts → dist/RxDB.d.ts} +39 -11
  3. package/dist/RxDB.d.ts.map +1 -0
  4. package/{RxDBError.d.ts → dist/RxDBError.d.ts} +2 -0
  5. package/dist/RxDBError.d.ts.map +1 -0
  6. package/{entity → dist/entity}/@Entity.d.ts +4 -9
  7. package/dist/entity/@Entity.d.ts.map +1 -0
  8. package/{entity → dist/entity}/@TreeEntity.d.ts +5 -4
  9. package/dist/entity/@TreeEntity.d.ts.map +1 -0
  10. package/{entity → dist/entity}/EntityBase.d.ts +4 -1
  11. package/dist/entity/EntityBase.d.ts.map +1 -0
  12. package/{entity → dist/entity}/EntityManager.d.ts +33 -9
  13. package/dist/entity/EntityManager.d.ts.map +1 -0
  14. package/{entity → dist/entity}/EntityStatus.d.ts +26 -19
  15. package/dist/entity/EntityStatus.d.ts.map +1 -0
  16. package/dist/entity/TreeEntityBase.d.ts +15 -0
  17. package/dist/entity/TreeEntityBase.d.ts.map +1 -0
  18. package/{entity → dist/entity}/entity-metadata-options.interface.d.ts +67 -72
  19. package/dist/entity/entity-metadata-options.interface.d.ts.map +1 -0
  20. package/{entity → dist/entity}/entity-metadata.interface.d.ts +5 -14
  21. package/dist/entity/entity-metadata.interface.d.ts.map +1 -0
  22. package/{entity → dist/entity}/entity.interface.d.ts +10 -1
  23. package/dist/entity/entity.interface.d.ts.map +1 -0
  24. package/{entity → dist/entity}/entity.utils.d.ts +9 -2
  25. package/dist/entity/entity.utils.d.ts.map +1 -0
  26. package/{entity → dist/entity}/entity_proxy_helper.d.ts +3 -2
  27. package/dist/entity/entity_proxy_helper.d.ts.map +1 -0
  28. package/{entity → dist/entity}/entity_relation_helper.d.ts +4 -3
  29. package/dist/entity/entity_relation_helper.d.ts.map +1 -0
  30. package/{entity → dist/entity}/generate_many_to_many_entity.d.ts +5 -4
  31. package/dist/entity/generate_many_to_many_entity.d.ts.map +1 -0
  32. package/{entity → dist/entity}/transition-metadata.d.ts +6 -5
  33. package/dist/entity/transition-metadata.d.ts.map +1 -0
  34. package/dist/index.d.ts +38 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +3386 -0
  37. package/{repository → dist/repository}/Repository.d.ts +14 -20
  38. package/dist/repository/Repository.d.ts.map +1 -0
  39. package/{repository → dist/repository}/RepositoryBase.d.ts +6 -5
  40. package/dist/repository/RepositoryBase.d.ts.map +1 -0
  41. package/dist/repository/TreeRepository.d.ts +29 -0
  42. package/dist/repository/TreeRepository.d.ts.map +1 -0
  43. package/dist/repository/query-options.interface.d.ts +47 -0
  44. package/dist/repository/query-options.interface.d.ts.map +1 -0
  45. package/{repository → dist/repository}/query.interface.d.ts +18 -10
  46. package/dist/repository/query.interface.d.ts.map +1 -0
  47. package/dist/repository/query.utils.d.ts +27 -0
  48. package/dist/repository/query.utils.d.ts.map +1 -0
  49. package/dist/repository/relation-query.interface.d.ts +63 -0
  50. package/dist/repository/relation-query.interface.d.ts.map +1 -0
  51. package/{repository → dist/repository}/repository.interface.d.ts +9 -18
  52. package/dist/repository/repository.interface.d.ts.map +1 -0
  53. package/dist/repository/tree-repository.interface.d.ts +66 -0
  54. package/dist/repository/tree-repository.interface.d.ts.map +1 -0
  55. package/{rxdb-adapter.d.ts → dist/rxdb-adapter.d.ts} +30 -6
  56. package/dist/rxdb-adapter.d.ts.map +1 -0
  57. package/{rxdb-events.d.ts → dist/rxdb-events.d.ts} +9 -82
  58. package/dist/rxdb-events.d.ts.map +1 -0
  59. package/{rxdb-plugin.d.ts → dist/rxdb-plugin.d.ts} +2 -1
  60. package/dist/rxdb-plugin.d.ts.map +1 -0
  61. package/{rxdb-utils.d.ts → dist/rxdb-utils.d.ts} +15 -3
  62. package/dist/rxdb-utils.d.ts.map +1 -0
  63. package/{rxdb.interface.d.ts → dist/rxdb.interface.d.ts} +3 -10
  64. package/dist/rxdb.interface.d.ts.map +1 -0
  65. package/{rxdb.private.d.ts → dist/rxdb.private.d.ts} +14 -14
  66. package/dist/rxdb.private.d.ts.map +1 -0
  67. package/{schema → dist/schema}/SchemaManager.d.ts +8 -4
  68. package/dist/schema/SchemaManager.d.ts.map +1 -0
  69. package/dist/system/VersionManager.d.ts +35 -0
  70. package/dist/system/VersionManager.d.ts.map +1 -0
  71. package/dist/system/branch.d.ts +17 -0
  72. package/dist/system/branch.d.ts.map +1 -0
  73. package/dist/system/change.d.ts +78 -0
  74. package/dist/system/change.d.ts.map +1 -0
  75. package/dist/system/migration.d.ts +27 -0
  76. package/dist/system/migration.d.ts.map +1 -0
  77. package/dist/system/types.d.ts +335 -0
  78. package/dist/system/types.d.ts.map +1 -0
  79. package/package.json +26 -12
  80. package/entity/TreeEntityBase.d.ts +0 -7
  81. package/index.d.ts +0 -26
  82. package/index.js +0 -1779
  83. package/repository/TreeRepository.d.ts +0 -28
  84. package/repository/query-options.interface.d.ts +0 -53
  85. package/repository/query.utils.d.ts +0 -19
  86. package/repository/tree-query-options.interface.d.ts +0 -9
  87. package/repository/tree-repository.interface.d.ts +0 -26
  88. package/system/change.d.ts +0 -13
  89. package/system/migration.d.ts +0 -9
package/dist/index.js ADDED
@@ -0,0 +1,3386 @@
1
+ const g = [];
2
+ for (let t = 0; t < 256; ++t)
3
+ g.push((t + 256).toString(16).slice(1));
4
+ function bt(t, e = 0) {
5
+ return (g[t[e + 0]] + g[t[e + 1]] + g[t[e + 2]] + g[t[e + 3]] + "-" + g[t[e + 4]] + g[t[e + 5]] + "-" + g[t[e + 6]] + g[t[e + 7]] + "-" + g[t[e + 8]] + g[t[e + 9]] + "-" + g[t[e + 10]] + g[t[e + 11]] + g[t[e + 12]] + g[t[e + 13]] + g[t[e + 14]] + g[t[e + 15]]).toLowerCase();
6
+ }
7
+ let ue;
8
+ const _t = new Uint8Array(16);
9
+ function Et() {
10
+ if (!ue) {
11
+ if (typeof crypto > "u" || !crypto.getRandomValues)
12
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
13
+ ue = crypto.getRandomValues.bind(crypto);
14
+ }
15
+ return ue(_t);
16
+ }
17
+ const le = {};
18
+ function gt(t, e, n) {
19
+ let r;
20
+ {
21
+ const i = Date.now(), o = Et();
22
+ wt(le, i, o), r = Ot(o, le.msecs, le.seq, e, n);
23
+ }
24
+ return bt(r);
25
+ }
26
+ function wt(t, e, n) {
27
+ return t.msecs ??= -1 / 0, t.seq ??= 0, e > t.msecs ? (t.seq = n[6] << 23 | n[7] << 16 | n[8] << 8 | n[9], t.msecs = e) : (t.seq = t.seq + 1 | 0, t.seq === 0 && t.msecs++), t;
28
+ }
29
+ function Ot(t, e, n, r, i = 0) {
30
+ if (t.length < 16)
31
+ throw new Error("Random bytes length must be >= 16");
32
+ if (!r)
33
+ r = new Uint8Array(16), i = 0;
34
+ else if (i < 0 || i + 16 > r.length)
35
+ throw new RangeError(`UUID byte range ${i}:${i + 15} is out of buffer bounds`);
36
+ return e ??= Date.now(), n ??= t[6] * 127 << 24 | t[7] << 16 | t[8] << 8 | t[9], r[i++] = e / 1099511627776 & 255, r[i++] = e / 4294967296 & 255, r[i++] = e / 16777216 & 255, r[i++] = e / 65536 & 255, r[i++] = e / 256 & 255, r[i++] = e & 255, r[i++] = 112 | n >>> 28 & 15, r[i++] = n >>> 20 & 255, r[i++] = 128 | n >>> 14 & 63, r[i++] = n >>> 6 & 255, r[i++] = n << 2 & 255 | t[10] & 3, r[i++] = t[11], r[i++] = t[12], r[i++] = t[13], r[i++] = t[14], r[i++] = t[15], r;
37
+ }
38
+ class se {
39
+ constructor(e) {
40
+ this.entities = e;
41
+ }
42
+ }
43
+ const At = "ENTITY_NEW";
44
+ class St extends se {
45
+ type = At;
46
+ }
47
+ const xt = "ENTITY_CREATE";
48
+ class Tt extends se {
49
+ type = xt;
50
+ }
51
+ const Rt = "ENTITY_UPDATE";
52
+ class Mt extends se {
53
+ type = Rt;
54
+ }
55
+ const It = "ENTITY_REMOVE";
56
+ class Nt extends se {
57
+ type = It;
58
+ }
59
+ const Ee = "TRANSACTION_BEGIN", ge = "TRANSACTION_COMMIT", we = "TRANSACTION_ROLLBACK";
60
+ class vr {
61
+ type = Ee;
62
+ }
63
+ class mr {
64
+ type = ge;
65
+ }
66
+ class br {
67
+ type = we;
68
+ }
69
+ const Fe = "DATABASE_DELETE", Pt = "DATABASE_INSERT", jt = "DATABASE_UPDATE";
70
+ class Oe {
71
+ constructor(e, n) {
72
+ this.EntityType = e, this.data = n;
73
+ }
74
+ }
75
+ class _r extends Oe {
76
+ type = Fe;
77
+ }
78
+ class Er extends Oe {
79
+ type = Pt;
80
+ }
81
+ class gr extends Oe {
82
+ type = jt;
83
+ }
84
+ const Ve = Symbol("ɵProxy"), he = Symbol("ɵMetadata"), We = Symbol("ɵStatus"), ze = Symbol("ɵEntityManager"), Ke = Symbol("ɵEntityDeleteCheck"), F = Symbol("ɵUpdateBy"), Bt = "SYSTEM", Ct = "USER", Dt = (t, e) => e.sync.local?.adapter === t, $t = (t) => [Ee, ge, we].includes(t.type), N = (t) => t[he] || t.constructor[he], w = (t) => t[We], wr = (t) => t && !!w(t), Or = (t) => `${t.id}-${t.updatedAt && t.updatedAt.getTime()}`, Ar = (t, e, n, r) => {
85
+ let i = r > 1 ? void 0 : r ? Object.getOwnPropertyDescriptor(e, n) : e;
86
+ for (let o = t.length - 1, s; o >= 0; o--)
87
+ (s = t[o]) && (i = s(i) || i);
88
+ return i;
89
+ }, Yt = () => gt();
90
+ class S extends Error {
91
+ constructor(e) {
92
+ super(e), this.name = "RxDBError", Object.setPrototypeOf(this, S.prototype);
93
+ }
94
+ }
95
+ var pe = function(t, e) {
96
+ return pe = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, r) {
97
+ n.__proto__ = r;
98
+ } || function(n, r) {
99
+ for (var i in r) Object.prototype.hasOwnProperty.call(r, i) && (n[i] = r[i]);
100
+ }, pe(t, e);
101
+ };
102
+ function P(t, e) {
103
+ if (typeof e != "function" && e !== null)
104
+ throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
105
+ pe(t, e);
106
+ function n() {
107
+ this.constructor = t;
108
+ }
109
+ t.prototype = e === null ? Object.create(e) : (n.prototype = e.prototype, new n());
110
+ }
111
+ function kt(t, e, n, r) {
112
+ function i(o) {
113
+ return o instanceof n ? o : new n(function(s) {
114
+ s(o);
115
+ });
116
+ }
117
+ return new (n || (n = Promise))(function(o, s) {
118
+ function a(l) {
119
+ try {
120
+ u(r.next(l));
121
+ } catch (f) {
122
+ s(f);
123
+ }
124
+ }
125
+ function c(l) {
126
+ try {
127
+ u(r.throw(l));
128
+ } catch (f) {
129
+ s(f);
130
+ }
131
+ }
132
+ function u(l) {
133
+ l.done ? o(l.value) : i(l.value).then(a, c);
134
+ }
135
+ u((r = r.apply(t, e || [])).next());
136
+ });
137
+ }
138
+ function Ge(t, e) {
139
+ var n = { label: 0, sent: function() {
140
+ if (o[0] & 1) throw o[1];
141
+ return o[1];
142
+ }, trys: [], ops: [] }, r, i, o, s = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
143
+ return s.next = a(0), s.throw = a(1), s.return = a(2), typeof Symbol == "function" && (s[Symbol.iterator] = function() {
144
+ return this;
145
+ }), s;
146
+ function a(u) {
147
+ return function(l) {
148
+ return c([u, l]);
149
+ };
150
+ }
151
+ function c(u) {
152
+ if (r) throw new TypeError("Generator is already executing.");
153
+ for (; s && (s = 0, u[0] && (n = 0)), n; ) try {
154
+ if (r = 1, i && (o = u[0] & 2 ? i.return : u[0] ? i.throw || ((o = i.return) && o.call(i), 0) : i.next) && !(o = o.call(i, u[1])).done) return o;
155
+ switch (i = 0, o && (u = [u[0] & 2, o.value]), u[0]) {
156
+ case 0:
157
+ case 1:
158
+ o = u;
159
+ break;
160
+ case 4:
161
+ return n.label++, { value: u[1], done: !1 };
162
+ case 5:
163
+ n.label++, i = u[1], u = [0];
164
+ continue;
165
+ case 7:
166
+ u = n.ops.pop(), n.trys.pop();
167
+ continue;
168
+ default:
169
+ if (o = n.trys, !(o = o.length > 0 && o[o.length - 1]) && (u[0] === 6 || u[0] === 2)) {
170
+ n = 0;
171
+ continue;
172
+ }
173
+ if (u[0] === 3 && (!o || u[1] > o[0] && u[1] < o[3])) {
174
+ n.label = u[1];
175
+ break;
176
+ }
177
+ if (u[0] === 6 && n.label < o[1]) {
178
+ n.label = o[1], o = u;
179
+ break;
180
+ }
181
+ if (o && n.label < o[2]) {
182
+ n.label = o[2], n.ops.push(u);
183
+ break;
184
+ }
185
+ o[2] && n.ops.pop(), n.trys.pop();
186
+ continue;
187
+ }
188
+ u = e.call(t, n);
189
+ } catch (l) {
190
+ u = [6, l], i = 0;
191
+ } finally {
192
+ r = o = 0;
193
+ }
194
+ if (u[0] & 5) throw u[1];
195
+ return { value: u[0] ? u[1] : void 0, done: !0 };
196
+ }
197
+ }
198
+ function D(t) {
199
+ var e = typeof Symbol == "function" && Symbol.iterator, n = e && t[e], r = 0;
200
+ if (n) return n.call(t);
201
+ if (t && typeof t.length == "number") return {
202
+ next: function() {
203
+ return t && r >= t.length && (t = void 0), { value: t && t[r++], done: !t };
204
+ }
205
+ };
206
+ throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
207
+ }
208
+ function V(t, e) {
209
+ var n = typeof Symbol == "function" && t[Symbol.iterator];
210
+ if (!n) return t;
211
+ var r = n.call(t), i, o = [], s;
212
+ try {
213
+ for (; (e === void 0 || e-- > 0) && !(i = r.next()).done; ) o.push(i.value);
214
+ } catch (a) {
215
+ s = { error: a };
216
+ } finally {
217
+ try {
218
+ i && !i.done && (n = r.return) && n.call(r);
219
+ } finally {
220
+ if (s) throw s.error;
221
+ }
222
+ }
223
+ return o;
224
+ }
225
+ function W(t, e, n) {
226
+ if (n || arguments.length === 2) for (var r = 0, i = e.length, o; r < i; r++)
227
+ (o || !(r in e)) && (o || (o = Array.prototype.slice.call(e, 0, r)), o[r] = e[r]);
228
+ return t.concat(o || Array.prototype.slice.call(e));
229
+ }
230
+ function C(t) {
231
+ return this instanceof C ? (this.v = t, this) : new C(t);
232
+ }
233
+ function Lt(t, e, n) {
234
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
235
+ var r = n.apply(t, e || []), i, o = [];
236
+ return i = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), a("next"), a("throw"), a("return", s), i[Symbol.asyncIterator] = function() {
237
+ return this;
238
+ }, i;
239
+ function s(d) {
240
+ return function(m) {
241
+ return Promise.resolve(m).then(d, f);
242
+ };
243
+ }
244
+ function a(d, m) {
245
+ r[d] && (i[d] = function(_) {
246
+ return new Promise(function(B, k) {
247
+ o.push([d, _, B, k]) > 1 || c(d, _);
248
+ });
249
+ }, m && (i[d] = m(i[d])));
250
+ }
251
+ function c(d, m) {
252
+ try {
253
+ u(r[d](m));
254
+ } catch (_) {
255
+ h(o[0][3], _);
256
+ }
257
+ }
258
+ function u(d) {
259
+ d.value instanceof C ? Promise.resolve(d.value.v).then(l, f) : h(o[0][2], d);
260
+ }
261
+ function l(d) {
262
+ c("next", d);
263
+ }
264
+ function f(d) {
265
+ c("throw", d);
266
+ }
267
+ function h(d, m) {
268
+ d(m), o.shift(), o.length && c(o[0][0], o[0][1]);
269
+ }
270
+ }
271
+ function Ut(t) {
272
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
273
+ var e = t[Symbol.asyncIterator], n;
274
+ return e ? e.call(t) : (t = typeof D == "function" ? D(t) : t[Symbol.iterator](), n = {}, r("next"), r("throw"), r("return"), n[Symbol.asyncIterator] = function() {
275
+ return this;
276
+ }, n);
277
+ function r(o) {
278
+ n[o] = t[o] && function(s) {
279
+ return new Promise(function(a, c) {
280
+ s = t[o](s), i(a, c, s.done, s.value);
281
+ });
282
+ };
283
+ }
284
+ function i(o, s, a, c) {
285
+ Promise.resolve(c).then(function(u) {
286
+ o({ value: u, done: a });
287
+ }, s);
288
+ }
289
+ }
290
+ function E(t) {
291
+ return typeof t == "function";
292
+ }
293
+ function Ae(t) {
294
+ var e = function(r) {
295
+ Error.call(r), r.stack = new Error().stack;
296
+ }, n = t(e);
297
+ return n.prototype = Object.create(Error.prototype), n.prototype.constructor = n, n;
298
+ }
299
+ var fe = Ae(function(t) {
300
+ return function(n) {
301
+ t(this), this.message = n ? n.length + ` errors occurred during unsubscription:
302
+ ` + n.map(function(r, i) {
303
+ return i + 1 + ") " + r.toString();
304
+ }).join(`
305
+ `) : "", this.name = "UnsubscriptionError", this.errors = n;
306
+ };
307
+ });
308
+ function ye(t, e) {
309
+ if (t) {
310
+ var n = t.indexOf(e);
311
+ 0 <= n && t.splice(n, 1);
312
+ }
313
+ }
314
+ var ae = (function() {
315
+ function t(e) {
316
+ this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
317
+ }
318
+ return t.prototype.unsubscribe = function() {
319
+ var e, n, r, i, o;
320
+ if (!this.closed) {
321
+ this.closed = !0;
322
+ var s = this._parentage;
323
+ if (s)
324
+ if (this._parentage = null, Array.isArray(s))
325
+ try {
326
+ for (var a = D(s), c = a.next(); !c.done; c = a.next()) {
327
+ var u = c.value;
328
+ u.remove(this);
329
+ }
330
+ } catch (_) {
331
+ e = { error: _ };
332
+ } finally {
333
+ try {
334
+ c && !c.done && (n = a.return) && n.call(a);
335
+ } finally {
336
+ if (e) throw e.error;
337
+ }
338
+ }
339
+ else
340
+ s.remove(this);
341
+ var l = this.initialTeardown;
342
+ if (E(l))
343
+ try {
344
+ l();
345
+ } catch (_) {
346
+ o = _ instanceof fe ? _.errors : [_];
347
+ }
348
+ var f = this._finalizers;
349
+ if (f) {
350
+ this._finalizers = null;
351
+ try {
352
+ for (var h = D(f), d = h.next(); !d.done; d = h.next()) {
353
+ var m = d.value;
354
+ try {
355
+ Ie(m);
356
+ } catch (_) {
357
+ o = o ?? [], _ instanceof fe ? o = W(W([], V(o)), V(_.errors)) : o.push(_);
358
+ }
359
+ }
360
+ } catch (_) {
361
+ r = { error: _ };
362
+ } finally {
363
+ try {
364
+ d && !d.done && (i = h.return) && i.call(h);
365
+ } finally {
366
+ if (r) throw r.error;
367
+ }
368
+ }
369
+ }
370
+ if (o)
371
+ throw new fe(o);
372
+ }
373
+ }, t.prototype.add = function(e) {
374
+ var n;
375
+ if (e && e !== this)
376
+ if (this.closed)
377
+ Ie(e);
378
+ else {
379
+ if (e instanceof t) {
380
+ if (e.closed || e._hasParent(this))
381
+ return;
382
+ e._addParent(this);
383
+ }
384
+ (this._finalizers = (n = this._finalizers) !== null && n !== void 0 ? n : []).push(e);
385
+ }
386
+ }, t.prototype._hasParent = function(e) {
387
+ var n = this._parentage;
388
+ return n === e || Array.isArray(n) && n.includes(e);
389
+ }, t.prototype._addParent = function(e) {
390
+ var n = this._parentage;
391
+ this._parentage = Array.isArray(n) ? (n.push(e), n) : n ? [n, e] : e;
392
+ }, t.prototype._removeParent = function(e) {
393
+ var n = this._parentage;
394
+ n === e ? this._parentage = null : Array.isArray(n) && ye(n, e);
395
+ }, t.prototype.remove = function(e) {
396
+ var n = this._finalizers;
397
+ n && ye(n, e), e instanceof t && e._removeParent(this);
398
+ }, t.EMPTY = (function() {
399
+ var e = new t();
400
+ return e.closed = !0, e;
401
+ })(), t;
402
+ })(), qe = ae.EMPTY;
403
+ function Je(t) {
404
+ return t instanceof ae || t && "closed" in t && E(t.remove) && E(t.add) && E(t.unsubscribe);
405
+ }
406
+ function Ie(t) {
407
+ E(t) ? t() : t.unsubscribe();
408
+ }
409
+ var Ft = {
410
+ Promise: void 0
411
+ }, Vt = {
412
+ setTimeout: function(t, e) {
413
+ for (var n = [], r = 2; r < arguments.length; r++)
414
+ n[r - 2] = arguments[r];
415
+ return setTimeout.apply(void 0, W([t, e], V(n)));
416
+ },
417
+ clearTimeout: function(t) {
418
+ return clearTimeout(t);
419
+ },
420
+ delegate: void 0
421
+ };
422
+ function He(t) {
423
+ Vt.setTimeout(function() {
424
+ throw t;
425
+ });
426
+ }
427
+ function Ne() {
428
+ }
429
+ function ee(t) {
430
+ t();
431
+ }
432
+ var Se = (function(t) {
433
+ P(e, t);
434
+ function e(n) {
435
+ var r = t.call(this) || this;
436
+ return r.isStopped = !1, n ? (r.destination = n, Je(n) && n.add(r)) : r.destination = Kt, r;
437
+ }
438
+ return e.create = function(n, r, i) {
439
+ return new $(n, r, i);
440
+ }, e.prototype.next = function(n) {
441
+ this.isStopped || this._next(n);
442
+ }, e.prototype.error = function(n) {
443
+ this.isStopped || (this.isStopped = !0, this._error(n));
444
+ }, e.prototype.complete = function() {
445
+ this.isStopped || (this.isStopped = !0, this._complete());
446
+ }, e.prototype.unsubscribe = function() {
447
+ this.closed || (this.isStopped = !0, t.prototype.unsubscribe.call(this), this.destination = null);
448
+ }, e.prototype._next = function(n) {
449
+ this.destination.next(n);
450
+ }, e.prototype._error = function(n) {
451
+ try {
452
+ this.destination.error(n);
453
+ } finally {
454
+ this.unsubscribe();
455
+ }
456
+ }, e.prototype._complete = function() {
457
+ try {
458
+ this.destination.complete();
459
+ } finally {
460
+ this.unsubscribe();
461
+ }
462
+ }, e;
463
+ })(ae), Wt = (function() {
464
+ function t(e) {
465
+ this.partialObserver = e;
466
+ }
467
+ return t.prototype.next = function(e) {
468
+ var n = this.partialObserver;
469
+ if (n.next)
470
+ try {
471
+ n.next(e);
472
+ } catch (r) {
473
+ Q(r);
474
+ }
475
+ }, t.prototype.error = function(e) {
476
+ var n = this.partialObserver;
477
+ if (n.error)
478
+ try {
479
+ n.error(e);
480
+ } catch (r) {
481
+ Q(r);
482
+ }
483
+ else
484
+ Q(e);
485
+ }, t.prototype.complete = function() {
486
+ var e = this.partialObserver;
487
+ if (e.complete)
488
+ try {
489
+ e.complete();
490
+ } catch (n) {
491
+ Q(n);
492
+ }
493
+ }, t;
494
+ })(), $ = (function(t) {
495
+ P(e, t);
496
+ function e(n, r, i) {
497
+ var o = t.call(this) || this, s;
498
+ return E(n) || !n ? s = {
499
+ next: n ?? void 0,
500
+ error: r ?? void 0,
501
+ complete: i ?? void 0
502
+ } : s = n, o.destination = new Wt(s), o;
503
+ }
504
+ return e;
505
+ })(Se);
506
+ function Q(t) {
507
+ He(t);
508
+ }
509
+ function zt(t) {
510
+ throw t;
511
+ }
512
+ var Kt = {
513
+ closed: !0,
514
+ next: Ne,
515
+ error: zt,
516
+ complete: Ne
517
+ }, xe = (function() {
518
+ return typeof Symbol == "function" && Symbol.observable || "@@observable";
519
+ })();
520
+ function q(t) {
521
+ return t;
522
+ }
523
+ function Gt(t) {
524
+ return t.length === 0 ? q : t.length === 1 ? t[0] : function(n) {
525
+ return t.reduce(function(r, i) {
526
+ return i(r);
527
+ }, n);
528
+ };
529
+ }
530
+ var O = (function() {
531
+ function t(e) {
532
+ e && (this._subscribe = e);
533
+ }
534
+ return t.prototype.lift = function(e) {
535
+ var n = new t();
536
+ return n.source = this, n.operator = e, n;
537
+ }, t.prototype.subscribe = function(e, n, r) {
538
+ var i = this, o = Jt(e) ? e : new $(e, n, r);
539
+ return ee(function() {
540
+ var s = i, a = s.operator, c = s.source;
541
+ o.add(a ? a.call(o, c) : c ? i._subscribe(o) : i._trySubscribe(o));
542
+ }), o;
543
+ }, t.prototype._trySubscribe = function(e) {
544
+ try {
545
+ return this._subscribe(e);
546
+ } catch (n) {
547
+ e.error(n);
548
+ }
549
+ }, t.prototype.forEach = function(e, n) {
550
+ var r = this;
551
+ return n = Pe(n), new n(function(i, o) {
552
+ var s = new $({
553
+ next: function(a) {
554
+ try {
555
+ e(a);
556
+ } catch (c) {
557
+ o(c), s.unsubscribe();
558
+ }
559
+ },
560
+ error: o,
561
+ complete: i
562
+ });
563
+ r.subscribe(s);
564
+ });
565
+ }, t.prototype._subscribe = function(e) {
566
+ var n;
567
+ return (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(e);
568
+ }, t.prototype[xe] = function() {
569
+ return this;
570
+ }, t.prototype.pipe = function() {
571
+ for (var e = [], n = 0; n < arguments.length; n++)
572
+ e[n] = arguments[n];
573
+ return Gt(e)(this);
574
+ }, t.prototype.toPromise = function(e) {
575
+ var n = this;
576
+ return e = Pe(e), new e(function(r, i) {
577
+ var o;
578
+ n.subscribe(function(s) {
579
+ return o = s;
580
+ }, function(s) {
581
+ return i(s);
582
+ }, function() {
583
+ return r(o);
584
+ });
585
+ });
586
+ }, t.create = function(e) {
587
+ return new t(e);
588
+ }, t;
589
+ })();
590
+ function Pe(t) {
591
+ var e;
592
+ return (e = t ?? Ft.Promise) !== null && e !== void 0 ? e : Promise;
593
+ }
594
+ function qt(t) {
595
+ return t && E(t.next) && E(t.error) && E(t.complete);
596
+ }
597
+ function Jt(t) {
598
+ return t && t instanceof Se || qt(t) && Je(t);
599
+ }
600
+ function Ht(t) {
601
+ return E(t?.lift);
602
+ }
603
+ function I(t) {
604
+ return function(e) {
605
+ if (Ht(e))
606
+ return e.lift(function(n) {
607
+ try {
608
+ return t(n, this);
609
+ } catch (r) {
610
+ this.error(r);
611
+ }
612
+ });
613
+ throw new TypeError("Unable to lift unknown Observable type");
614
+ };
615
+ }
616
+ function M(t, e, n, r, i) {
617
+ return new Zt(t, e, n, r, i);
618
+ }
619
+ var Zt = (function(t) {
620
+ P(e, t);
621
+ function e(n, r, i, o, s, a) {
622
+ var c = t.call(this, n) || this;
623
+ return c.onFinalize = s, c.shouldUnsubscribe = a, c._next = r ? function(u) {
624
+ try {
625
+ r(u);
626
+ } catch (l) {
627
+ n.error(l);
628
+ }
629
+ } : t.prototype._next, c._error = o ? function(u) {
630
+ try {
631
+ o(u);
632
+ } catch (l) {
633
+ n.error(l);
634
+ } finally {
635
+ this.unsubscribe();
636
+ }
637
+ } : t.prototype._error, c._complete = i ? function() {
638
+ try {
639
+ i();
640
+ } catch (u) {
641
+ n.error(u);
642
+ } finally {
643
+ this.unsubscribe();
644
+ }
645
+ } : t.prototype._complete, c;
646
+ }
647
+ return e.prototype.unsubscribe = function() {
648
+ var n;
649
+ if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
650
+ var r = this.closed;
651
+ t.prototype.unsubscribe.call(this), !r && ((n = this.onFinalize) === null || n === void 0 || n.call(this));
652
+ }
653
+ }, e;
654
+ })(Se), Qt = Ae(function(t) {
655
+ return function() {
656
+ t(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
657
+ };
658
+ }), J = (function(t) {
659
+ P(e, t);
660
+ function e() {
661
+ var n = t.call(this) || this;
662
+ return n.closed = !1, n.currentObservers = null, n.observers = [], n.isStopped = !1, n.hasError = !1, n.thrownError = null, n;
663
+ }
664
+ return e.prototype.lift = function(n) {
665
+ var r = new je(this, this);
666
+ return r.operator = n, r;
667
+ }, e.prototype._throwIfClosed = function() {
668
+ if (this.closed)
669
+ throw new Qt();
670
+ }, e.prototype.next = function(n) {
671
+ var r = this;
672
+ ee(function() {
673
+ var i, o;
674
+ if (r._throwIfClosed(), !r.isStopped) {
675
+ r.currentObservers || (r.currentObservers = Array.from(r.observers));
676
+ try {
677
+ for (var s = D(r.currentObservers), a = s.next(); !a.done; a = s.next()) {
678
+ var c = a.value;
679
+ c.next(n);
680
+ }
681
+ } catch (u) {
682
+ i = { error: u };
683
+ } finally {
684
+ try {
685
+ a && !a.done && (o = s.return) && o.call(s);
686
+ } finally {
687
+ if (i) throw i.error;
688
+ }
689
+ }
690
+ }
691
+ });
692
+ }, e.prototype.error = function(n) {
693
+ var r = this;
694
+ ee(function() {
695
+ if (r._throwIfClosed(), !r.isStopped) {
696
+ r.hasError = r.isStopped = !0, r.thrownError = n;
697
+ for (var i = r.observers; i.length; )
698
+ i.shift().error(n);
699
+ }
700
+ });
701
+ }, e.prototype.complete = function() {
702
+ var n = this;
703
+ ee(function() {
704
+ if (n._throwIfClosed(), !n.isStopped) {
705
+ n.isStopped = !0;
706
+ for (var r = n.observers; r.length; )
707
+ r.shift().complete();
708
+ }
709
+ });
710
+ }, e.prototype.unsubscribe = function() {
711
+ this.isStopped = this.closed = !0, this.observers = this.currentObservers = null;
712
+ }, Object.defineProperty(e.prototype, "observed", {
713
+ get: function() {
714
+ var n;
715
+ return ((n = this.observers) === null || n === void 0 ? void 0 : n.length) > 0;
716
+ },
717
+ enumerable: !1,
718
+ configurable: !0
719
+ }), e.prototype._trySubscribe = function(n) {
720
+ return this._throwIfClosed(), t.prototype._trySubscribe.call(this, n);
721
+ }, e.prototype._subscribe = function(n) {
722
+ return this._throwIfClosed(), this._checkFinalizedStatuses(n), this._innerSubscribe(n);
723
+ }, e.prototype._innerSubscribe = function(n) {
724
+ var r = this, i = this, o = i.hasError, s = i.isStopped, a = i.observers;
725
+ return o || s ? qe : (this.currentObservers = null, a.push(n), new ae(function() {
726
+ r.currentObservers = null, ye(a, n);
727
+ }));
728
+ }, e.prototype._checkFinalizedStatuses = function(n) {
729
+ var r = this, i = r.hasError, o = r.thrownError, s = r.isStopped;
730
+ i ? n.error(o) : s && n.complete();
731
+ }, e.prototype.asObservable = function() {
732
+ var n = new O();
733
+ return n.source = this, n;
734
+ }, e.create = function(n, r) {
735
+ return new je(n, r);
736
+ }, e;
737
+ })(O), je = (function(t) {
738
+ P(e, t);
739
+ function e(n, r) {
740
+ var i = t.call(this) || this;
741
+ return i.destination = n, i.source = r, i;
742
+ }
743
+ return e.prototype.next = function(n) {
744
+ var r, i;
745
+ (i = (r = this.destination) === null || r === void 0 ? void 0 : r.next) === null || i === void 0 || i.call(r, n);
746
+ }, e.prototype.error = function(n) {
747
+ var r, i;
748
+ (i = (r = this.destination) === null || r === void 0 ? void 0 : r.error) === null || i === void 0 || i.call(r, n);
749
+ }, e.prototype.complete = function() {
750
+ var n, r;
751
+ (r = (n = this.destination) === null || n === void 0 ? void 0 : n.complete) === null || r === void 0 || r.call(n);
752
+ }, e.prototype._subscribe = function(n) {
753
+ var r, i;
754
+ return (i = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(n)) !== null && i !== void 0 ? i : qe;
755
+ }, e;
756
+ })(J), z = (function(t) {
757
+ P(e, t);
758
+ function e(n) {
759
+ var r = t.call(this) || this;
760
+ return r._value = n, r;
761
+ }
762
+ return Object.defineProperty(e.prototype, "value", {
763
+ get: function() {
764
+ return this.getValue();
765
+ },
766
+ enumerable: !1,
767
+ configurable: !0
768
+ }), e.prototype._subscribe = function(n) {
769
+ var r = t.prototype._subscribe.call(this, n);
770
+ return !r.closed && n.next(this._value), r;
771
+ }, e.prototype.getValue = function() {
772
+ var n = this, r = n.hasError, i = n.thrownError, o = n._value;
773
+ if (r)
774
+ throw i;
775
+ return this._throwIfClosed(), o;
776
+ }, e.prototype.next = function(n) {
777
+ t.prototype.next.call(this, this._value = n);
778
+ }, e;
779
+ })(J), Ze = {
780
+ now: function() {
781
+ return (Ze.delegate || Date).now();
782
+ },
783
+ delegate: void 0
784
+ }, Xt = (function(t) {
785
+ P(e, t);
786
+ function e(n, r, i) {
787
+ n === void 0 && (n = 1 / 0), r === void 0 && (r = 1 / 0), i === void 0 && (i = Ze);
788
+ var o = t.call(this) || this;
789
+ return o._bufferSize = n, o._windowTime = r, o._timestampProvider = i, o._buffer = [], o._infiniteTimeWindow = !0, o._infiniteTimeWindow = r === 1 / 0, o._bufferSize = Math.max(1, n), o._windowTime = Math.max(1, r), o;
790
+ }
791
+ return e.prototype.next = function(n) {
792
+ var r = this, i = r.isStopped, o = r._buffer, s = r._infiniteTimeWindow, a = r._timestampProvider, c = r._windowTime;
793
+ i || (o.push(n), !s && o.push(a.now() + c)), this._trimBuffer(), t.prototype.next.call(this, n);
794
+ }, e.prototype._subscribe = function(n) {
795
+ this._throwIfClosed(), this._trimBuffer();
796
+ for (var r = this._innerSubscribe(n), i = this, o = i._infiniteTimeWindow, s = i._buffer, a = s.slice(), c = 0; c < a.length && !n.closed; c += o ? 1 : 2)
797
+ n.next(a[c]);
798
+ return this._checkFinalizedStatuses(n), r;
799
+ }, e.prototype._trimBuffer = function() {
800
+ var n = this, r = n._bufferSize, i = n._timestampProvider, o = n._buffer, s = n._infiniteTimeWindow, a = (s ? 1 : 2) * r;
801
+ if (r < 1 / 0 && a < o.length && o.splice(0, o.length - a), !s) {
802
+ for (var c = i.now(), u = 0, l = 1; l < o.length && o[l] <= c; l += 2)
803
+ u = l;
804
+ u && o.splice(0, u + 1);
805
+ }
806
+ }, e;
807
+ })(J);
808
+ function en(t) {
809
+ return t && E(t.schedule);
810
+ }
811
+ function Qe(t) {
812
+ return t[t.length - 1];
813
+ }
814
+ function tn(t) {
815
+ return E(Qe(t)) ? t.pop() : void 0;
816
+ }
817
+ function Xe(t) {
818
+ return en(Qe(t)) ? t.pop() : void 0;
819
+ }
820
+ var et = (function(t) {
821
+ return t && typeof t.length == "number" && typeof t != "function";
822
+ });
823
+ function tt(t) {
824
+ return E(t?.then);
825
+ }
826
+ function nt(t) {
827
+ return E(t[xe]);
828
+ }
829
+ function rt(t) {
830
+ return Symbol.asyncIterator && E(t?.[Symbol.asyncIterator]);
831
+ }
832
+ function it(t) {
833
+ return new TypeError("You provided " + (t !== null && typeof t == "object" ? "an invalid object" : "'" + t + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
834
+ }
835
+ function nn() {
836
+ return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
837
+ }
838
+ var ot = nn();
839
+ function st(t) {
840
+ return E(t?.[ot]);
841
+ }
842
+ function at(t) {
843
+ return Lt(this, arguments, function() {
844
+ var n, r, i, o;
845
+ return Ge(this, function(s) {
846
+ switch (s.label) {
847
+ case 0:
848
+ n = t.getReader(), s.label = 1;
849
+ case 1:
850
+ s.trys.push([1, , 9, 10]), s.label = 2;
851
+ case 2:
852
+ return [4, C(n.read())];
853
+ case 3:
854
+ return r = s.sent(), i = r.value, o = r.done, o ? [4, C(void 0)] : [3, 5];
855
+ case 4:
856
+ return [2, s.sent()];
857
+ case 5:
858
+ return [4, C(i)];
859
+ case 6:
860
+ return [4, s.sent()];
861
+ case 7:
862
+ return s.sent(), [3, 2];
863
+ case 8:
864
+ return [3, 10];
865
+ case 9:
866
+ return n.releaseLock(), [7];
867
+ case 10:
868
+ return [2];
869
+ }
870
+ });
871
+ });
872
+ }
873
+ function ct(t) {
874
+ return E(t?.getReader);
875
+ }
876
+ function j(t) {
877
+ if (t instanceof O)
878
+ return t;
879
+ if (t != null) {
880
+ if (nt(t))
881
+ return rn(t);
882
+ if (et(t))
883
+ return on(t);
884
+ if (tt(t))
885
+ return sn(t);
886
+ if (rt(t))
887
+ return ut(t);
888
+ if (st(t))
889
+ return an(t);
890
+ if (ct(t))
891
+ return cn(t);
892
+ }
893
+ throw it(t);
894
+ }
895
+ function rn(t) {
896
+ return new O(function(e) {
897
+ var n = t[xe]();
898
+ if (E(n.subscribe))
899
+ return n.subscribe(e);
900
+ throw new TypeError("Provided object does not correctly implement Symbol.observable");
901
+ });
902
+ }
903
+ function on(t) {
904
+ return new O(function(e) {
905
+ for (var n = 0; n < t.length && !e.closed; n++)
906
+ e.next(t[n]);
907
+ e.complete();
908
+ });
909
+ }
910
+ function sn(t) {
911
+ return new O(function(e) {
912
+ t.then(function(n) {
913
+ e.closed || (e.next(n), e.complete());
914
+ }, function(n) {
915
+ return e.error(n);
916
+ }).then(null, He);
917
+ });
918
+ }
919
+ function an(t) {
920
+ return new O(function(e) {
921
+ var n, r;
922
+ try {
923
+ for (var i = D(t), o = i.next(); !o.done; o = i.next()) {
924
+ var s = o.value;
925
+ if (e.next(s), e.closed)
926
+ return;
927
+ }
928
+ } catch (a) {
929
+ n = { error: a };
930
+ } finally {
931
+ try {
932
+ o && !o.done && (r = i.return) && r.call(i);
933
+ } finally {
934
+ if (n) throw n.error;
935
+ }
936
+ }
937
+ e.complete();
938
+ });
939
+ }
940
+ function ut(t) {
941
+ return new O(function(e) {
942
+ un(t, e).catch(function(n) {
943
+ return e.error(n);
944
+ });
945
+ });
946
+ }
947
+ function cn(t) {
948
+ return ut(at(t));
949
+ }
950
+ function un(t, e) {
951
+ var n, r, i, o;
952
+ return kt(this, void 0, void 0, function() {
953
+ var s, a;
954
+ return Ge(this, function(c) {
955
+ switch (c.label) {
956
+ case 0:
957
+ c.trys.push([0, 5, 6, 11]), n = Ut(t), c.label = 1;
958
+ case 1:
959
+ return [4, n.next()];
960
+ case 2:
961
+ if (r = c.sent(), !!r.done) return [3, 4];
962
+ if (s = r.value, e.next(s), e.closed)
963
+ return [2];
964
+ c.label = 3;
965
+ case 3:
966
+ return [3, 1];
967
+ case 4:
968
+ return [3, 11];
969
+ case 5:
970
+ return a = c.sent(), i = { error: a }, [3, 11];
971
+ case 6:
972
+ return c.trys.push([6, , 9, 10]), r && !r.done && (o = n.return) ? [4, o.call(n)] : [3, 8];
973
+ case 7:
974
+ c.sent(), c.label = 8;
975
+ case 8:
976
+ return [3, 10];
977
+ case 9:
978
+ if (i) throw i.error;
979
+ return [7];
980
+ case 10:
981
+ return [7];
982
+ case 11:
983
+ return e.complete(), [2];
984
+ }
985
+ });
986
+ });
987
+ }
988
+ function R(t, e, n, r, i) {
989
+ r === void 0 && (r = 0), i === void 0 && (i = !1);
990
+ var o = e.schedule(function() {
991
+ n(), i ? t.add(this.schedule(null, r)) : this.unsubscribe();
992
+ }, r);
993
+ if (t.add(o), !i)
994
+ return o;
995
+ }
996
+ function lt(t, e) {
997
+ return e === void 0 && (e = 0), I(function(n, r) {
998
+ n.subscribe(M(r, function(i) {
999
+ return R(r, t, function() {
1000
+ return r.next(i);
1001
+ }, e);
1002
+ }, function() {
1003
+ return R(r, t, function() {
1004
+ return r.complete();
1005
+ }, e);
1006
+ }, function(i) {
1007
+ return R(r, t, function() {
1008
+ return r.error(i);
1009
+ }, e);
1010
+ }));
1011
+ });
1012
+ }
1013
+ function ft(t, e) {
1014
+ return e === void 0 && (e = 0), I(function(n, r) {
1015
+ r.add(t.schedule(function() {
1016
+ return n.subscribe(r);
1017
+ }, e));
1018
+ });
1019
+ }
1020
+ function ln(t, e) {
1021
+ return j(t).pipe(ft(e), lt(e));
1022
+ }
1023
+ function fn(t, e) {
1024
+ return j(t).pipe(ft(e), lt(e));
1025
+ }
1026
+ function dn(t, e) {
1027
+ return new O(function(n) {
1028
+ var r = 0;
1029
+ return e.schedule(function() {
1030
+ r === t.length ? n.complete() : (n.next(t[r++]), n.closed || this.schedule());
1031
+ });
1032
+ });
1033
+ }
1034
+ function hn(t, e) {
1035
+ return new O(function(n) {
1036
+ var r;
1037
+ return R(n, e, function() {
1038
+ r = t[ot](), R(n, e, function() {
1039
+ var i, o, s;
1040
+ try {
1041
+ i = r.next(), o = i.value, s = i.done;
1042
+ } catch (a) {
1043
+ n.error(a);
1044
+ return;
1045
+ }
1046
+ s ? n.complete() : n.next(o);
1047
+ }, 0, !0);
1048
+ }), function() {
1049
+ return E(r?.return) && r.return();
1050
+ };
1051
+ });
1052
+ }
1053
+ function dt(t, e) {
1054
+ if (!t)
1055
+ throw new Error("Iterable cannot be null");
1056
+ return new O(function(n) {
1057
+ R(n, e, function() {
1058
+ var r = t[Symbol.asyncIterator]();
1059
+ R(n, e, function() {
1060
+ r.next().then(function(i) {
1061
+ i.done ? n.complete() : n.next(i.value);
1062
+ });
1063
+ }, 0, !0);
1064
+ });
1065
+ });
1066
+ }
1067
+ function pn(t, e) {
1068
+ return dt(at(t), e);
1069
+ }
1070
+ function yn(t, e) {
1071
+ if (t != null) {
1072
+ if (nt(t))
1073
+ return ln(t, e);
1074
+ if (et(t))
1075
+ return dn(t, e);
1076
+ if (tt(t))
1077
+ return fn(t, e);
1078
+ if (rt(t))
1079
+ return dt(t, e);
1080
+ if (st(t))
1081
+ return hn(t, e);
1082
+ if (ct(t))
1083
+ return pn(t, e);
1084
+ }
1085
+ throw it(t);
1086
+ }
1087
+ function Te(t, e) {
1088
+ return e ? yn(t, e) : j(t);
1089
+ }
1090
+ function ve() {
1091
+ for (var t = [], e = 0; e < arguments.length; e++)
1092
+ t[e] = arguments[e];
1093
+ var n = Xe(t);
1094
+ return Te(t, n);
1095
+ }
1096
+ var vn = Ae(function(t) {
1097
+ return function() {
1098
+ t(this), this.name = "EmptyError", this.message = "no elements in sequence";
1099
+ };
1100
+ });
1101
+ function T(t, e) {
1102
+ return new Promise(function(n, r) {
1103
+ var i = new $({
1104
+ next: function(o) {
1105
+ n(o), i.unsubscribe();
1106
+ },
1107
+ error: r,
1108
+ complete: function() {
1109
+ r(new vn());
1110
+ }
1111
+ });
1112
+ t.subscribe(i);
1113
+ });
1114
+ }
1115
+ function K(t, e) {
1116
+ return I(function(n, r) {
1117
+ var i = 0;
1118
+ n.subscribe(M(r, function(o) {
1119
+ r.next(t.call(e, o, i++));
1120
+ }));
1121
+ });
1122
+ }
1123
+ var mn = Array.isArray;
1124
+ function bn(t, e) {
1125
+ return mn(e) ? t.apply(void 0, W([], V(e))) : t(e);
1126
+ }
1127
+ function _n(t) {
1128
+ return K(function(e) {
1129
+ return bn(t, e);
1130
+ });
1131
+ }
1132
+ var En = Array.isArray, gn = Object.getPrototypeOf, wn = Object.prototype, On = Object.keys;
1133
+ function An(t) {
1134
+ if (t.length === 1) {
1135
+ var e = t[0];
1136
+ if (En(e))
1137
+ return { args: e, keys: null };
1138
+ if (Sn(e)) {
1139
+ var n = On(e);
1140
+ return {
1141
+ args: n.map(function(r) {
1142
+ return e[r];
1143
+ }),
1144
+ keys: n
1145
+ };
1146
+ }
1147
+ }
1148
+ return { args: t, keys: null };
1149
+ }
1150
+ function Sn(t) {
1151
+ return t && typeof t == "object" && gn(t) === wn;
1152
+ }
1153
+ function xn(t, e) {
1154
+ return t.reduce(function(n, r, i) {
1155
+ return n[r] = e[i], n;
1156
+ }, {});
1157
+ }
1158
+ function Be() {
1159
+ for (var t = [], e = 0; e < arguments.length; e++)
1160
+ t[e] = arguments[e];
1161
+ var n = Xe(t), r = tn(t), i = An(t), o = i.args, s = i.keys;
1162
+ if (o.length === 0)
1163
+ return Te([], n);
1164
+ var a = new O(Tn(o, n, s ? function(c) {
1165
+ return xn(s, c);
1166
+ } : q));
1167
+ return r ? a.pipe(_n(r)) : a;
1168
+ }
1169
+ function Tn(t, e, n) {
1170
+ return n === void 0 && (n = q), function(r) {
1171
+ Ce(e, function() {
1172
+ for (var i = t.length, o = new Array(i), s = i, a = i, c = function(l) {
1173
+ Ce(e, function() {
1174
+ var f = Te(t[l], e), h = !1;
1175
+ f.subscribe(M(r, function(d) {
1176
+ o[l] = d, h || (h = !0, a--), a || r.next(n(o.slice()));
1177
+ }, function() {
1178
+ --s || r.complete();
1179
+ }));
1180
+ }, r);
1181
+ }, u = 0; u < i; u++)
1182
+ c(u);
1183
+ }, r);
1184
+ };
1185
+ }
1186
+ function Ce(t, e, n) {
1187
+ t ? R(n, t, e) : e();
1188
+ }
1189
+ function De(t) {
1190
+ return new O(function(e) {
1191
+ j(t()).subscribe(e);
1192
+ });
1193
+ }
1194
+ function te(t, e) {
1195
+ return I(function(n, r) {
1196
+ var i = 0;
1197
+ n.subscribe(M(r, function(o) {
1198
+ return t.call(e, o, i++) && r.next(o);
1199
+ }));
1200
+ });
1201
+ }
1202
+ function G(t, e) {
1203
+ return e === void 0 && (e = q), t = t ?? Rn, I(function(n, r) {
1204
+ var i, o = !0;
1205
+ n.subscribe(M(r, function(s) {
1206
+ var a = e(s);
1207
+ (o || !t(i, a)) && (o = !1, i = a, r.next(s));
1208
+ }));
1209
+ });
1210
+ }
1211
+ function Rn(t, e) {
1212
+ return t === e;
1213
+ }
1214
+ function Mn(t) {
1215
+ t === void 0 && (t = {});
1216
+ var e = t.connector, n = e === void 0 ? function() {
1217
+ return new J();
1218
+ } : e, r = t.resetOnError, i = r === void 0 ? !0 : r, o = t.resetOnComplete, s = o === void 0 ? !0 : o, a = t.resetOnRefCountZero, c = a === void 0 ? !0 : a;
1219
+ return function(u) {
1220
+ var l, f, h, d = 0, m = !1, _ = !1, B = function() {
1221
+ f?.unsubscribe(), f = void 0;
1222
+ }, k = function() {
1223
+ B(), l = h = void 0, m = _ = !1;
1224
+ }, mt = function() {
1225
+ var L = l;
1226
+ k(), L?.unsubscribe();
1227
+ };
1228
+ return I(function(L, Me) {
1229
+ d++, !_ && !m && B();
1230
+ var H = h = h ?? n();
1231
+ Me.add(function() {
1232
+ d--, d === 0 && !_ && !m && (f = de(mt, c));
1233
+ }), H.subscribe(Me), !l && d > 0 && (l = new $({
1234
+ next: function(Z) {
1235
+ return H.next(Z);
1236
+ },
1237
+ error: function(Z) {
1238
+ _ = !0, B(), f = de(k, i, Z), H.error(Z);
1239
+ },
1240
+ complete: function() {
1241
+ m = !0, B(), f = de(k, s), H.complete();
1242
+ }
1243
+ }), j(L).subscribe(l));
1244
+ })(u);
1245
+ };
1246
+ }
1247
+ function de(t, e) {
1248
+ for (var n = [], r = 2; r < arguments.length; r++)
1249
+ n[r - 2] = arguments[r];
1250
+ if (e === !0) {
1251
+ t();
1252
+ return;
1253
+ }
1254
+ if (e !== !1) {
1255
+ var i = new $({
1256
+ next: function() {
1257
+ i.unsubscribe(), t();
1258
+ }
1259
+ });
1260
+ return j(e.apply(void 0, W([], V(n)))).subscribe(i);
1261
+ }
1262
+ }
1263
+ function x(t, e, n) {
1264
+ var r, i = !1;
1265
+ return r = t, Mn({
1266
+ connector: function() {
1267
+ return new Xt(r, e, n);
1268
+ },
1269
+ resetOnError: !0,
1270
+ resetOnComplete: !1,
1271
+ resetOnRefCountZero: i
1272
+ });
1273
+ }
1274
+ function y(t, e) {
1275
+ return I(function(n, r) {
1276
+ var i = null, o = 0, s = !1, a = function() {
1277
+ return s && !i && r.complete();
1278
+ };
1279
+ n.subscribe(M(r, function(c) {
1280
+ i?.unsubscribe();
1281
+ var u = 0, l = o++;
1282
+ j(t(c, l)).subscribe(i = M(r, function(f) {
1283
+ return r.next(e ? e(c, f, l, u++) : f);
1284
+ }, function() {
1285
+ i = null, a();
1286
+ }));
1287
+ }, function() {
1288
+ s = !0, a();
1289
+ }));
1290
+ });
1291
+ }
1292
+ function A(t, e, n) {
1293
+ var r = E(t) || e || n ? { next: t, error: e, complete: n } : t;
1294
+ return r ? I(function(i, o) {
1295
+ var s;
1296
+ (s = r.subscribe) === null || s === void 0 || s.call(r);
1297
+ var a = !0;
1298
+ i.subscribe(M(o, function(c) {
1299
+ var u;
1300
+ (u = r.next) === null || u === void 0 || u.call(r, c), o.next(c);
1301
+ }, function() {
1302
+ var c;
1303
+ a = !1, (c = r.complete) === null || c === void 0 || c.call(r), o.complete();
1304
+ }, function(c) {
1305
+ var u;
1306
+ a = !1, (u = r.error) === null || u === void 0 || u.call(r, c), o.error(c);
1307
+ }, function() {
1308
+ var c, u;
1309
+ a && ((c = r.unsubscribe) === null || c === void 0 || c.call(r)), (u = r.finalize) === null || u === void 0 || u.call(r);
1310
+ }));
1311
+ }) : q;
1312
+ }
1313
+ const In = Array.isArray, ce = (t) => !!(t && t.constructor && t.call && t.apply), Nn = (t) => t && t.constructor === Symbol, Pn = (t) => !!t && t.constructor === Object, jn = (t) => !(!t || !t.then || !ce(t.then)), $e = (t) => t instanceof Uint8Array, Bn = (t, e = [], n = []) => {
1314
+ const r = [...t];
1315
+ return r.sort((i, o) => {
1316
+ for (let s = 0; s < e.length; s++) {
1317
+ const a = e[s], c = n[s] || "asc", u = i[a], l = o[a];
1318
+ if (u == null && l == null) continue;
1319
+ if (u == null) return c === "desc" ? 1 : -1;
1320
+ if (l == null) return c === "desc" ? -1 : 1;
1321
+ let f = 0;
1322
+ if (u < l ? f = -1 : u > l && (f = 1), c === "desc" && (f = -f), f !== 0)
1323
+ return f;
1324
+ }
1325
+ return 0;
1326
+ }), r;
1327
+ };
1328
+ new TextDecoder();
1329
+ const ht = (t) => {
1330
+ for (const e of Object.getOwnPropertyNames(t)) {
1331
+ const n = t[e];
1332
+ !Pn(n) && !ce(n) || n === null || ht(n);
1333
+ }
1334
+ return Object.isFrozen(t) ? t : Object.freeze(t);
1335
+ }, Cn = (t, e, n) => {
1336
+ const r = (o) => String.prototype.split.call(e, o).filter(Boolean).reduce((s, a) => s != null ? s[a] : s, t), i = r(/[,[\]]+?/) || r(/[,[\].]+?/);
1337
+ return i === void 0 || i === t ? n : i;
1338
+ };
1339
+ function Dn(t, e) {
1340
+ return t.length !== e.length ? !1 : t.every((n, r) => n === e[r]);
1341
+ }
1342
+ const ne = (t, e) => {
1343
+ if (t === e || Object.is(t, e)) return !0;
1344
+ if (t && e && typeof t == "object" && typeof e == "object") {
1345
+ if (t.constructor !== e.constructor) return !1;
1346
+ let n, r;
1347
+ if (Array.isArray(t)) {
1348
+ if (n = t.length, n != e.length) return !1;
1349
+ for (r = n; r-- !== 0; ) if (!ne(t[r], e[r])) return !1;
1350
+ return !0;
1351
+ }
1352
+ if ($e(t) && $e(e)) return Dn(t, e);
1353
+ if (t.constructor === RegExp) return t.source === e.source && t.flags === e.flags;
1354
+ if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === e.valueOf();
1355
+ if (t.toString !== Object.prototype.toString) return t.toString() === e.toString();
1356
+ const i = Object.keys(t);
1357
+ if (n = i.length, n !== Object.keys(e).length) return !1;
1358
+ for (r = n; r-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(e, i[r])) return !1;
1359
+ for (r = n; r-- !== 0; ) {
1360
+ const o = i[r];
1361
+ if (!ne(t[o], e[o])) return !1;
1362
+ }
1363
+ return !0;
1364
+ }
1365
+ return t !== t && e !== e;
1366
+ };
1367
+ function $n(t, e) {
1368
+ return Object.keys(t).filter((n) => !e(t[n], n)).reduce((n, r) => (n[r] = t[r], n), {});
1369
+ }
1370
+ const Yn = [
1371
+ "id",
1372
+ "createdAt",
1373
+ "updatedAt",
1374
+ "removedAt",
1375
+ "createdBy",
1376
+ "updatedBy",
1377
+ "removedBy"
1378
+ ], kn = ["rev"], Sr = (t) => !!(Yn.includes(t) || kn.includes(t) || t.startsWith("_")), b = (t, e, n) => Object.defineProperty(t, e, {
1379
+ value: n,
1380
+ enumerable: !1,
1381
+ configurable: !1,
1382
+ writable: !1
1383
+ }), Ye = (t, e, n) => Object.defineProperty(t, e, {
1384
+ value: n,
1385
+ enumerable: !1,
1386
+ configurable: !1,
1387
+ writable: !0
1388
+ }), U = (t, e, n) => {
1389
+ let r;
1390
+ const i = {
1391
+ get: () => (r = n(), i.get = () => r, r),
1392
+ enumerable: !1,
1393
+ configurable: !1
1394
+ };
1395
+ return Object.defineProperty(t, e, i);
1396
+ }, Ln = (t, e) => {
1397
+ const n = {};
1398
+ let r = !1;
1399
+ t.defaultValueProperties.forEach((i) => {
1400
+ e[i.name] === void 0 && (r = !0, ce(i.default) ? n[i.name] = i.default() : n[i.name] = i.default);
1401
+ }), r && Object.assign(e, n);
1402
+ }, Un = (t, e, n) => {
1403
+ const { propertyMap: r, foreignKeyNames: i } = N(e);
1404
+ Object.keys(n).forEach((o) => {
1405
+ r.has(o) ? t.propertyMap.get(o)?.readonly !== !0 && (e[o] = n[o]) : i.includes(o) && (e[o] = n[o]);
1406
+ });
1407
+ }, ke = (t) => {
1408
+ const e = /* @__PURE__ */ new Set(), n = (i) => {
1409
+ const s = w(i).getNeedSaveRelationEntities();
1410
+ s.length && r(s);
1411
+ }, r = (i) => i.filter((o) => !e.has(o)).forEach((o) => {
1412
+ e.add(o), n(o);
1413
+ });
1414
+ return r(t), Array.from(e).filter((i) => w(i).modified);
1415
+ };
1416
+ var p = /* @__PURE__ */ ((t) => (t.uuid = "uuid", t.string = "string", t.number = "number", t.integer = "integer", t.boolean = "boolean", t.date = "date", t.stringArray = "stringArray", t.numberArray = "numberArray", t.valueObject = "valueObject", t.json = "json", t))(p || {}), v = /* @__PURE__ */ ((t) => (t.ONE_TO_ONE = "1:1", t.ONE_TO_MANY = "1:m", t.MANY_TO_ONE = "m:1", t.MANY_TO_MANY = "m:n", t))(v || {}), Fn = /* @__PURE__ */ ((t) => (t.Full = "full", t.Filter = "filter", t.None = "None", t))(Fn || {});
1417
+ const Vn = (t, e) => {
1418
+ const n = [];
1419
+ n.push(t);
1420
+ const r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = { ...t };
1421
+ if (s.repository = s.repository || "Repository", s.namespace = s.namespace || "public", s.properties = s.properties || [], s.relations = s.relations || [], s.indexes = s.indexes || [], e) {
1422
+ if (ce(e)) {
1423
+ let c = e, u = t;
1424
+ for (; c !== Object.prototype && u; )
1425
+ c = Object.getPrototypeOf(c), u = N(c), u && n.push(u);
1426
+ } else In(e) ? n.push(...e) : n.push(e);
1427
+ const a = n.map((c) => c.name);
1428
+ a.shift(), s.extends = a;
1429
+ }
1430
+ return s.extends = s.extends || [], s.displayName || (s.displayName = s.name), n.reverse().forEach((a) => {
1431
+ a.namespace = a.namespace || "public", a.properties?.forEach((c) => {
1432
+ r.set(c.name, c);
1433
+ }), a.relations?.forEach((c) => {
1434
+ if (c.mappedNamespace = c.mappedNamespace || "public", c.mappedEntity === a.name && c.mappedNamespace === a.namespace) {
1435
+ const u = { ...c };
1436
+ u.mappedEntity = s.name, u.mappedNamespace = s.namespace, i.set(c.name, u);
1437
+ } else
1438
+ i.set(c.name, c);
1439
+ }), a.indexes?.forEach((c) => o.set(c.name, c));
1440
+ }), b(s, "propertyMap", r), b(s, "relationMap", i), b(s, "indexMap", o), U(
1441
+ s,
1442
+ "defaultValueProperties",
1443
+ () => Array.from(r.values()).filter((a) => a.default !== void 0)
1444
+ ), U(
1445
+ s,
1446
+ "foreignKeyRelations",
1447
+ () => Array.from(s.relationMap.values()).filter(
1448
+ (a) => a.kind === v.MANY_TO_ONE || a.kind === v.ONE_TO_ONE
1449
+ )
1450
+ ), U(s, "foreignKeyRelationMap", () => {
1451
+ const a = /* @__PURE__ */ new Map();
1452
+ return s.foreignKeyRelations.forEach((c) => a.set(c.name, c)), a;
1453
+ }), U(s, "foreignKeyNames", () => s.foreignKeyRelations.map((a) => `${a.name}Id`)), b(
1454
+ s,
1455
+ "isForeignKey",
1456
+ (a) => a && a.endsWith("Id") && s.foreignKeyNames.includes(a)
1457
+ ), s;
1458
+ }, Y = (t) => (e) => {
1459
+ const n = Vn(t, e);
1460
+ if (b(e, he, n), t.abstract) return e;
1461
+ const r = e;
1462
+ return class extends r {
1463
+ /**
1464
+ * 实体构造函数
1465
+ * 处理实体初始化、默认值填充和代理包装
1466
+ *
1467
+ * 构造函数执行以下步骤:
1468
+ * 1. 调用原始类的构造函数
1469
+ * 2. 获取实体管理器
1470
+ * 3. 填充默认值(基于元数据中定义的默认值)
1471
+ * 4. 填充初始值(如果提供了初始化数据)
1472
+ * 5. 创建并返回实体代理(用于变更跟踪)
1473
+ */
1474
+ constructor(i) {
1475
+ super(i);
1476
+ const o = this[ze];
1477
+ if (!o) throw new S("need init rxdb");
1478
+ return Ln(n, this), i && Un(n, this, i), o[Ve](this);
1479
+ }
1480
+ };
1481
+ };
1482
+ var Wn = Object.getOwnPropertyDescriptor, zn = (t, e, n, r) => {
1483
+ for (var i = r > 1 ? void 0 : r ? Wn(e, n) : e, o = t.length - 1, s; o >= 0; o--)
1484
+ (s = t[o]) && (i = s(i) || i);
1485
+ return i;
1486
+ };
1487
+ const me = {
1488
+ name: "EntityBase",
1489
+ abstract: !0,
1490
+ // 标记为抽象类,不会直接创建此类的实例
1491
+ properties: [
1492
+ {
1493
+ name: "id",
1494
+ type: p.uuid,
1495
+ primary: !0,
1496
+ // 主键
1497
+ unique: !0,
1498
+ // 唯一索引
1499
+ readonly: !0,
1500
+ // 创建后不可修改
1501
+ default: () => Yt()
1502
+ // 默认生成 UUID
1503
+ },
1504
+ {
1505
+ name: "createdAt",
1506
+ type: p.date,
1507
+ readonly: !0,
1508
+ default: () => /* @__PURE__ */ new Date()
1509
+ },
1510
+ {
1511
+ name: "updatedAt",
1512
+ type: p.date,
1513
+ readonly: !0,
1514
+ default: () => /* @__PURE__ */ new Date()
1515
+ },
1516
+ {
1517
+ name: "removedAt",
1518
+ type: p.date,
1519
+ readonly: !0,
1520
+ nullable: !0
1521
+ },
1522
+ {
1523
+ name: "createdBy",
1524
+ type: p.string,
1525
+ readonly: !0,
1526
+ nullable: !0
1527
+ },
1528
+ {
1529
+ name: "updatedBy",
1530
+ type: p.string,
1531
+ readonly: !0,
1532
+ nullable: !0
1533
+ },
1534
+ {
1535
+ name: "removedBy",
1536
+ type: p.string,
1537
+ readonly: !0,
1538
+ nullable: !0
1539
+ }
1540
+ ]
1541
+ };
1542
+ let re = class {
1543
+ /**
1544
+ * 实体唯一标识符
1545
+ * 自动生成的UUID,作为主键
1546
+ */
1547
+ id;
1548
+ /**
1549
+ * 创建时间
1550
+ * 实体创建时自动设置为当前时间
1551
+ */
1552
+ createdAt;
1553
+ /**
1554
+ * 更新时间
1555
+ * 实体创建或更新时自动设置为当前时间
1556
+ */
1557
+ updatedAt;
1558
+ /**
1559
+ * 删除时间
1560
+ * 实体被软删除时设置为当前时间,否则为null
1561
+ */
1562
+ removedAt;
1563
+ /**
1564
+ * 创建者ID
1565
+ * 记录创建此实体的用户ID
1566
+ */
1567
+ createdBy;
1568
+ /**
1569
+ * 更新者ID
1570
+ * 记录最后更新此实体的用户ID
1571
+ */
1572
+ updatedBy;
1573
+ /**
1574
+ * 删除者ID
1575
+ * 记录删除此实体的用户ID
1576
+ */
1577
+ removedBy;
1578
+ /**
1579
+ * 实体基类构造函数
1580
+ * 子类会通过 Entity 装饰器增强此构造函数
1581
+ *
1582
+ * @param initData - 可选的初始化数据
1583
+ */
1584
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1585
+ constructor(t) {
1586
+ }
1587
+ };
1588
+ re = zn([
1589
+ Y(me)
1590
+ ], re);
1591
+ var Kn = Object.getOwnPropertyDescriptor, Gn = (t, e, n, r) => {
1592
+ for (var i = r > 1 ? void 0 : r ? Kn(e, n) : e, o = t.length - 1, s; o >= 0; o--)
1593
+ (s = t[o]) && (i = s(i) || i);
1594
+ return i;
1595
+ };
1596
+ const pt = {
1597
+ name: "TreeAdjacencyListEntityBase",
1598
+ abstract: !0,
1599
+ // 标记为抽象类,不会直接创建此类的实例
1600
+ relations: [
1601
+ {
1602
+ name: "children",
1603
+ // 子节点关系名称
1604
+ kind: v.ONE_TO_MANY,
1605
+ // 一对多关系
1606
+ mappedEntity: "TreeAdjacencyListEntityBase",
1607
+ // 关联到同一实体类型
1608
+ mappedProperty: "parent"
1609
+ // 映射到子实体的 parent 属性
1610
+ },
1611
+ {
1612
+ name: "parent",
1613
+ // 父节点关系名称
1614
+ kind: v.MANY_TO_ONE,
1615
+ // 多对一关系
1616
+ mappedEntity: "TreeAdjacencyListEntityBase",
1617
+ // 关联到同一实体类型
1618
+ nullable: !0
1619
+ // 允许根节点没有父节点
1620
+ }
1621
+ ]
1622
+ };
1623
+ let Le = class extends re {
1624
+ parentId;
1625
+ };
1626
+ Le = Gn([
1627
+ Y(pt)
1628
+ ], Le);
1629
+ const qn = (t) => {
1630
+ const e = t.features || {};
1631
+ return Y({
1632
+ ...t,
1633
+ features: {
1634
+ ...e,
1635
+ treeType: e.treeType || "adjacency-list"
1636
+ },
1637
+ repository: t.repository || "TreeRepository"
1638
+ });
1639
+ }, Re = Symbol("ɵEntityStaticTypes"), Jn = (t) => !!t.combinator, Hn = (t, e) => {
1640
+ const n = e[t.field], { operator: r, value: i } = t;
1641
+ switch (r) {
1642
+ case "in":
1643
+ return i.includes(n);
1644
+ case "notIn":
1645
+ return i.includes(n) === !1;
1646
+ case "between":
1647
+ return n >= i[0] && n <= i[1];
1648
+ case "notBetween":
1649
+ return n < i[0] || n > i[1];
1650
+ case "contains":
1651
+ return `${n}`.includes(`${i}`);
1652
+ case "notContain":
1653
+ return `${n}`.includes(`${i}`) === !1;
1654
+ case "beginWith":
1655
+ return `${n}`.startsWith(`${i}`);
1656
+ case "notBeginWith":
1657
+ return `${n}`.startsWith(`${i}`) === !1;
1658
+ case "endWith":
1659
+ return `${n}`.endsWith(`${i}`);
1660
+ case "notEndWith":
1661
+ return `${n}`.endsWith(`${i}`) === !1;
1662
+ case "=":
1663
+ return ne(i, n);
1664
+ case "!=":
1665
+ return ne(i, n) === !1;
1666
+ case ">":
1667
+ return n > i;
1668
+ case ">=":
1669
+ return n >= i;
1670
+ case "<":
1671
+ return n < i;
1672
+ case "<=":
1673
+ return n <= i;
1674
+ default:
1675
+ throw new S(`Unknown operator: ${r}`);
1676
+ }
1677
+ }, be = (t, e) => {
1678
+ if (Jn(t)) {
1679
+ const { combinator: n, rules: r } = t;
1680
+ return n === "and" ? r.every((i) => be(i, e)) : r.some((i) => be(i, e));
1681
+ } else
1682
+ return Hn(t, e);
1683
+ }, xr = (t, e) => be(e, t), Zn = (t, e, n) => {
1684
+ const { field: r, sort: i } = n, o = Cn(t, r);
1685
+ if (i === "asc") {
1686
+ if (e.some((c) => o < Reflect.get(c, r))) return !0;
1687
+ if (e.every((c) => o > Reflect.get(c, r))) return !1;
1688
+ } else {
1689
+ if (e.some((c) => o > Reflect.get(c, r))) return !0;
1690
+ if (e.every((c) => o < Reflect.get(c, r))) return !1;
1691
+ }
1692
+ }, Tr = (t, e, n) => {
1693
+ if (!n || !n || n.length === 0 || e.length === 0) return !0;
1694
+ for (let r = 0; r < n.length; r++) {
1695
+ const i = n[r], o = Zn(t, e, i);
1696
+ if (o === void 0) {
1697
+ const { field: s } = i, a = Reflect.get(t, s);
1698
+ e = e.filter((c) => Reflect.get(c, s) === a);
1699
+ } else
1700
+ return o;
1701
+ }
1702
+ }, Rr = (t, e) => {
1703
+ const n = [], r = [];
1704
+ return e.forEach((i) => {
1705
+ n.push(i.field), r.push(i.sort);
1706
+ }), Bn(t, n, r);
1707
+ };
1708
+ var Qn = /* @__PURE__ */ ((t) => (t.Synced = "Synced", t.Syncing = "Syncing", t.Never = "Never", t))(Qn || {});
1709
+ class Mr {
1710
+ constructor(e, n) {
1711
+ this.rxdb = e, this.EntityClass = n;
1712
+ }
1713
+ /**
1714
+ * 获取实体实例
1715
+ * @param data 实体数据
1716
+ */
1717
+ createEntityRef(e) {
1718
+ return this.rxdb.entityManager.createEntityRef(this.EntityClass, e);
1719
+ }
1720
+ /**
1721
+ * 获取实体实例
1722
+ * @param id 实体的 ID
1723
+ */
1724
+ getEntityRef(e) {
1725
+ return this.rxdb.entityManager.getEntityRef(this.EntityClass, e);
1726
+ }
1727
+ /**
1728
+ * 获取实体实例
1729
+ * @param id 实体的 ID
1730
+ */
1731
+ hasEntityRef(e) {
1732
+ return this.rxdb.entityManager.hasEntityRef(this.EntityClass, e);
1733
+ }
1734
+ /**
1735
+ * 更新实体
1736
+ */
1737
+ updateEntity(e, n) {
1738
+ e[F] = Bt;
1739
+ const r = w(e);
1740
+ r.origin = { ...n }, Object.assign(e, n), e[F] = null;
1741
+ }
1742
+ }
1743
+ class yt {
1744
+ constructor(e) {
1745
+ this.rxdb = e;
1746
+ }
1747
+ }
1748
+ class Ir extends yt {
1749
+ }
1750
+ class Nr extends yt {
1751
+ }
1752
+ class Pr {
1753
+ constructor(e) {
1754
+ this.rxdb = e;
1755
+ }
1756
+ }
1757
+ class vt {
1758
+ constructor(e, n) {
1759
+ this.rxdb = e, this.EntityType = n;
1760
+ const r = N(n);
1761
+ this.sync = r.sync || e.options.sync;
1762
+ const { local: i, remote: o } = this.sync;
1763
+ i && this.localAdapterSub.next(i.adapter), o && this.remoteAdapterSub.next(o.adapter);
1764
+ }
1765
+ /**
1766
+ * 本地适配器
1767
+ */
1768
+ localAdapterSub = new z("");
1769
+ localAdapter$ = this.localAdapterSub.asObservable().pipe(
1770
+ te(Boolean),
1771
+ G(),
1772
+ y((e) => this.rxdb.getAdapter(e)),
1773
+ x(1)
1774
+ );
1775
+ /**
1776
+ * 本地仓库
1777
+ */
1778
+ local$ = this.localAdapter$.pipe(
1779
+ K((e) => e.getRepository(this.EntityType)),
1780
+ x(1)
1781
+ );
1782
+ /**
1783
+ * 远程适配器
1784
+ */
1785
+ remoteAdapterSub = new z("");
1786
+ remoteAdapter$ = this.remoteAdapterSub.asObservable().pipe(
1787
+ te(Boolean),
1788
+ G(),
1789
+ y((e) => this.rxdb.getAdapter(e)),
1790
+ x(1)
1791
+ );
1792
+ /**
1793
+ * 远程仓库
1794
+ */
1795
+ remote$ = this.remoteAdapter$.pipe(
1796
+ K((e) => e.getRepository(this.EntityType)),
1797
+ x(1)
1798
+ );
1799
+ /**
1800
+ * 同步配置
1801
+ * TODO: 待实现同步功能
1802
+ */
1803
+ sync;
1804
+ /**
1805
+ * 根据 id 获取实体
1806
+ * @param id
1807
+ * @param options
1808
+ */
1809
+ get(e) {
1810
+ return this.local$.pipe(
1811
+ y((n) => n.get(e)),
1812
+ A(this._setLocalEntityStatus)
1813
+ );
1814
+ }
1815
+ /**
1816
+ * 查找一个实体
1817
+ * @param where
1818
+ * @param options
1819
+ */
1820
+ findOne(e) {
1821
+ return this.local$.pipe(
1822
+ y((n) => n.findOne(e)),
1823
+ A((n) => n && this._setLocalEntityStatus(n))
1824
+ );
1825
+ }
1826
+ /**
1827
+ * 查找一个实体,查不到就抛出错误
1828
+ * @param where
1829
+ * @param options
1830
+ */
1831
+ findOneOrFail(e) {
1832
+ return this.local$.pipe(
1833
+ y((n) => n.findOneOrFail(e)),
1834
+ A(this._setLocalEntityStatus)
1835
+ );
1836
+ }
1837
+ /**
1838
+ * 查询多个实体
1839
+ * @param where
1840
+ * @param options
1841
+ */
1842
+ find(e) {
1843
+ return this.local$.pipe(
1844
+ y((n) => n.find(e)),
1845
+ A(this._setLocalEntitiesStatus)
1846
+ );
1847
+ }
1848
+ /**
1849
+ * 查询所有实体
1850
+ * @param where
1851
+ * @param options
1852
+ */
1853
+ findAll(e) {
1854
+ return this.local$.pipe(
1855
+ y((n) => n.findAll(e)),
1856
+ A(this._setLocalEntitiesStatus)
1857
+ );
1858
+ }
1859
+ /**
1860
+ * 查询实体数量
1861
+ * @param where
1862
+ * @param options
1863
+ */
1864
+ count(e) {
1865
+ return this.local$.pipe(y((n) => n.count(e)));
1866
+ }
1867
+ /**
1868
+ * 事务保存
1869
+ * @param entities 需要保存的实体
1870
+ */
1871
+ async saveMany(e) {
1872
+ return (await T(this.localAdapter$)).transaction(async () => {
1873
+ for (let r = 0; r < e.length; r++) {
1874
+ const i = e[r], o = w(i);
1875
+ o.modified && (o.local ? await this.rxdb.entityManager.update(i) : await this.rxdb.entityManager.create(i));
1876
+ }
1877
+ return e;
1878
+ });
1879
+ }
1880
+ /**
1881
+ * 创建实体
1882
+ * @param entity
1883
+ */
1884
+ create(e) {
1885
+ const n = this.local$.pipe(
1886
+ y((r) => r.create(e)),
1887
+ A(this._setLocalEntityStatus)
1888
+ );
1889
+ return T(n);
1890
+ }
1891
+ /**
1892
+ * 更新实体
1893
+ * @param entity
1894
+ * @param patch
1895
+ */
1896
+ update(e, n) {
1897
+ const r = this.local$.pipe(
1898
+ y((i) => i.update(e, n)),
1899
+ A(this._setLocalEntityStatus)
1900
+ );
1901
+ return T(r);
1902
+ }
1903
+ /**
1904
+ * 删除实体
1905
+ * @param entity
1906
+ */
1907
+ remove(e) {
1908
+ const n = this.local$.pipe(y((r) => r.remove(e)));
1909
+ return T(n);
1910
+ }
1911
+ /**
1912
+ * 设置状态 local
1913
+ */
1914
+ _setLocalEntityStatus = (e) => w(e).local = !0;
1915
+ _setLocalEntitiesStatus = (e) => e.forEach(this._setLocalEntityStatus);
1916
+ }
1917
+ class Xn extends vt {
1918
+ findRoot(e) {
1919
+ return this.local$.pipe(
1920
+ y((n) => n.findRoot(e)),
1921
+ A(this._setLocalEntitiesStatus)
1922
+ );
1923
+ }
1924
+ countRoot(e) {
1925
+ return this.local$.pipe(y((n) => n.countRoot(e)));
1926
+ }
1927
+ /**
1928
+ * 查询子孙
1929
+ */
1930
+ findDescendants(e) {
1931
+ return this.local$.pipe(
1932
+ y((n) => n.findDescendants(e)),
1933
+ A(this._setLocalEntitiesStatus)
1934
+ );
1935
+ }
1936
+ /**
1937
+ * 查询子孙数量
1938
+ */
1939
+ countDescendants(e) {
1940
+ return this.local$.pipe(y((n) => n.countDescendants(e)));
1941
+ }
1942
+ /**
1943
+ * 查询祖先
1944
+ */
1945
+ findAncestors(e) {
1946
+ return this.local$.pipe(
1947
+ y((n) => n.findAncestors(e)),
1948
+ A(this._setLocalEntitiesStatus)
1949
+ );
1950
+ }
1951
+ /**
1952
+ * 查询祖先数量
1953
+ */
1954
+ countAncestors(e) {
1955
+ return this.local$.pipe(y((n) => n.countAncestors(e)));
1956
+ }
1957
+ }
1958
+ const er = (t) => {
1959
+ const e = w(t), n = t;
1960
+ let r = [];
1961
+ const i = () => {
1962
+ let a = {}, c = {}, u = null;
1963
+ const l = () => {
1964
+ u && (e.addEntityPatch(c, a, u), u = null, a = {}, c = {});
1965
+ };
1966
+ r.forEach(({ prop: f, value: h, oldValue: d, updatedBy: m }) => {
1967
+ a[f] = a[f] ?? d, c[f] = h, u === null ? u = m : u !== m && l();
1968
+ }), l(), r = [], n[F] = null;
1969
+ };
1970
+ let o;
1971
+ const s = {
1972
+ // get: (target, prop, receiver) => {
1973
+ // const value = Reflect.get(target, prop, receiver);
1974
+ // return value;
1975
+ // },
1976
+ /**
1977
+ * 拦截属性设置操作
1978
+ * 当属性值发生变化时,记录变更并安排检查
1979
+ */
1980
+ set: (a, c, u, l) => {
1981
+ if (a[c] === u) return !0;
1982
+ if (Nn(c) === !1) {
1983
+ const f = a[F] || Ct;
1984
+ r.push({ updatedBy: f, prop: c, value: u, oldValue: a[c] }), e.modified = !0, clearTimeout(o), o = setTimeout(() => i(), 0);
1985
+ }
1986
+ return Reflect.set(a, c, u, l);
1987
+ }
1988
+ };
1989
+ return new Proxy(t, s);
1990
+ }, tr = (t, e, n) => {
1991
+ const r = n.rxdb.schemaManager.getEntityType(t.mappedEntity, t.mappedNamespace);
1992
+ if (!r) throw new S(`mapped entity not found: ${t.mappedEntity}`);
1993
+ const i = t.name + "Id", o = t.name + "$";
1994
+ let s;
1995
+ switch (t.kind) {
1996
+ /**
1997
+ * 多对一, 一对一关系处理
1998
+ * 创建一个可观察对象,通过外键ID获取关联实体
1999
+ * 提供set和remove方法操作关系
2000
+ */
2001
+ case v.MANY_TO_ONE:
2002
+ case v.ONE_TO_ONE:
2003
+ s = function() {
2004
+ const a = this, c = w(a), u = new z(a[i]), l = u.asObservable().pipe(
2005
+ y((f) => f ? n.getRepository(r).get(f) : ve(null)),
2006
+ x(1)
2007
+ );
2008
+ return b(l, "set", (f) => {
2009
+ f || l.remove(), Reflect.get(a, i) != f.id && (c.addRelationEntity(t, f), u.next(f.id), Reflect.set(a, i, f.id));
2010
+ }), b(l, "remove", () => {
2011
+ Reflect.get(a, i) != null && (u.next(null), c.removeRelationEntity(t, e), Reflect.set(a, i, null));
2012
+ }), Object.freeze(l);
2013
+ };
2014
+ break;
2015
+ /**
2016
+ * 一对多关系处理
2017
+ * 创建一个可观察对象,查询所有关联到当前实体的实体集合
2018
+ * 提供add和remove方法操作关系集合
2019
+ */
2020
+ case v.ONE_TO_MANY:
2021
+ s = function() {
2022
+ const a = t.mappedProperty + "Id", c = t.mappedProperty + "$", u = this, l = w(u), f = n.getRepository(r).findAll({
2023
+ where: {
2024
+ combinator: "and",
2025
+ rules: [
2026
+ {
2027
+ field: a,
2028
+ operator: "=",
2029
+ value: u.id
2030
+ }
2031
+ ]
2032
+ }
2033
+ }), h = n.getRepository(r).count({
2034
+ where: {
2035
+ combinator: "and",
2036
+ rules: [
2037
+ {
2038
+ field: a,
2039
+ operator: "=",
2040
+ value: u.id
2041
+ }
2042
+ ]
2043
+ }
2044
+ });
2045
+ return b(f, "count$", h), b(f, "add", (...d) => {
2046
+ d.forEach((m) => {
2047
+ l.addRelationEntity(t, m), m[c].set(u);
2048
+ });
2049
+ }), b(f, "remove", (...d) => {
2050
+ d.forEach((m) => {
2051
+ l.removeRelationEntity(t, m), m[c].remove();
2052
+ });
2053
+ }), Object.freeze(f);
2054
+ };
2055
+ break;
2056
+ /**
2057
+ * 多对多关系处理
2058
+ * 通过中间表(junction entity)实现多对多关系
2059
+ * 创建一个可观察对象,查询通过中间表关联到当前实体的实体集合
2060
+ * 提供add和remove方法操作关系集合
2061
+ */
2062
+ case v.MANY_TO_MANY:
2063
+ s = function() {
2064
+ const a = this, c = w(a), u = t.name + "Id";
2065
+ if (!t.junctionEntityType) throw new S("junction entity not found");
2066
+ const l = n.getRepository(t.junctionEntityType).findAll({
2067
+ where: {
2068
+ combinator: "and",
2069
+ rules: [
2070
+ {
2071
+ field: t.mappedProperty + "Id",
2072
+ operator: "=",
2073
+ value: a.id
2074
+ }
2075
+ ]
2076
+ }
2077
+ }).pipe(
2078
+ y((h) => {
2079
+ const d = h.map((m) => m[u]);
2080
+ return n.getRepository(r).findAll({
2081
+ where: {
2082
+ combinator: "and",
2083
+ rules: [
2084
+ {
2085
+ field: "id",
2086
+ operator: "in",
2087
+ value: d
2088
+ }
2089
+ ]
2090
+ }
2091
+ });
2092
+ })
2093
+ ), f = n.getRepository(t.junctionEntityType).count({
2094
+ where: {
2095
+ combinator: "and",
2096
+ rules: [
2097
+ {
2098
+ field: t.mappedProperty + "Id",
2099
+ operator: "=",
2100
+ value: a.id
2101
+ }
2102
+ ]
2103
+ }
2104
+ });
2105
+ return b(l, "count$", f), b(l, "add", (...h) => {
2106
+ h.forEach((d) => c.addRelationEntity(t, d));
2107
+ }), b(l, "remove", (...h) => {
2108
+ h.forEach((d) => {
2109
+ c.removeRelationEntity(t, d);
2110
+ });
2111
+ }), Object.freeze(l);
2112
+ };
2113
+ break;
2114
+ }
2115
+ Object.defineProperty(e.prototype, o, {
2116
+ get: s,
2117
+ enumerable: !1,
2118
+ configurable: !1
2119
+ });
2120
+ };
2121
+ class nr {
2122
+ /**
2123
+ * 创建实体状态实例
2124
+ *
2125
+ * @constructor
2126
+ * @param rxdb - RxDB 实例
2127
+ * @param data - 实体状态初始数据
2128
+ */
2129
+ constructor(e, n) {
2130
+ this.rxdb = e, b(this, "target", n.target), this._local = n.local || !1, this._remote = n.remote || !1, this._modified = n.modified || !1, this._origin = { ...n.target }, this._patches = n.patches || [], [
2131
+ "_rowId",
2132
+ "_local",
2133
+ "_modified",
2134
+ "_origin",
2135
+ "_patches",
2136
+ "_remote",
2137
+ "_removed",
2138
+ "_snapshots",
2139
+ "patches$",
2140
+ "rxdb"
2141
+ ].forEach(
2142
+ (r) => Object.defineProperty(this, r, {
2143
+ enumerable: !1,
2144
+ configurable: !1
2145
+ })
2146
+ );
2147
+ }
2148
+ /**
2149
+ * 按关系类型存储关联实体
2150
+ * 用于跟踪和管理实体的各种关系
2151
+ */
2152
+ #e = /* @__PURE__ */ new Map();
2153
+ /**
2154
+ * 实体变更记录的可观察对象
2155
+ * 用于发布实体变更通知
2156
+ */
2157
+ #t = new J();
2158
+ /**
2159
+ * 实体状态快照数组
2160
+ * 用于存储实体在不同时间点的完整状态
2161
+ */
2162
+ #r = [];
2163
+ /**
2164
+ * 标识实体是否存在于远程数据库
2165
+ */
2166
+ _remote;
2167
+ /**
2168
+ * 标识实体是否存在于本地数据库
2169
+ */
2170
+ _local;
2171
+ /**
2172
+ * 标识实体是否已被修改
2173
+ */
2174
+ _modified;
2175
+ /**
2176
+ * 标识实体是否已被删除
2177
+ */
2178
+ _removed = !1;
2179
+ /**
2180
+ * 实体在数据库中的行ID
2181
+ */
2182
+ _rowId;
2183
+ /**
2184
+ * 实体变更记录数组
2185
+ */
2186
+ _patches;
2187
+ /**
2188
+ * 实体变更缓存
2189
+ */
2190
+ _patch_cache;
2191
+ /**
2192
+ * 实体原始数据
2193
+ * 用于比较变更和恢复
2194
+ */
2195
+ _origin;
2196
+ /**
2197
+ * 实体原始对象
2198
+ */
2199
+ target;
2200
+ /**
2201
+ * 实体代理对象
2202
+ * 用于拦截并记录对象的属性访问和修改
2203
+ */
2204
+ proxyTarget;
2205
+ /**
2206
+ * 实体变更记录的可观察流
2207
+ * 用于订阅实体变更
2208
+ */
2209
+ patches$ = this.#t.asObservable().pipe(x(1));
2210
+ /**
2211
+ * 是否已修改
2212
+ */
2213
+ get modified() {
2214
+ return this._modified;
2215
+ }
2216
+ set modified(e) {
2217
+ this._modified = e, this._patch_cache = void 0;
2218
+ }
2219
+ /**
2220
+ * 是否已删除
2221
+ */
2222
+ get removed() {
2223
+ return this._removed;
2224
+ }
2225
+ set removed(e) {
2226
+ this._removed = e;
2227
+ }
2228
+ /**
2229
+ * 是否是远程数据
2230
+ */
2231
+ get remote() {
2232
+ return this._remote;
2233
+ }
2234
+ set remote(e) {
2235
+ this._remote = e;
2236
+ }
2237
+ /**
2238
+ * 是否是本地数据
2239
+ */
2240
+ get local() {
2241
+ return this._local;
2242
+ }
2243
+ set local(e) {
2244
+ this._local = e;
2245
+ }
2246
+ /**
2247
+ * 获取所有变化
2248
+ */
2249
+ get patch() {
2250
+ return this._patch_cache || (this._patch_cache = $n(this.proxyTarget, (e, n) => e === this.origin[n])), this._patch_cache;
2251
+ }
2252
+ /**
2253
+ * 获取变化
2254
+ */
2255
+ get patches() {
2256
+ return this._patches;
2257
+ }
2258
+ /**
2259
+ * 设置原始值
2260
+ */
2261
+ set origin(e) {
2262
+ this._origin = e;
2263
+ }
2264
+ get origin() {
2265
+ return this._origin;
2266
+ }
2267
+ /**
2268
+ * 设置 rowId
2269
+ */
2270
+ set rowId(e) {
2271
+ this._rowId !== e && (this._rowId = e, this.rxdb.entityManager.updateEntityRowId(this.proxyTarget, e));
2272
+ }
2273
+ get rowId() {
2274
+ return this._rowId;
2275
+ }
2276
+ /**
2277
+ * 重置实体状态
2278
+ */
2279
+ reset() {
2280
+ Object.assign(this.proxyTarget, this.origin);
2281
+ }
2282
+ /**
2283
+ * 添加实体变更记录
2284
+ * 记录实体的变更并发布变更事件
2285
+ *
2286
+ * @param patch - 变更内容
2287
+ * @param inversePatch - 逆向变更内容,用于撤销操作
2288
+ * @param updatedBy - 更新者信息
2289
+ * @param recordAt - 记录时间戳
2290
+ */
2291
+ addEntityPatch(e, n, r, i = /* @__PURE__ */ new Date()) {
2292
+ const o = { patch: e, inversePatch: n, recordAt: i, timeStamp: performance.now(), updatedBy: r };
2293
+ this._patches.length === 0 && this.#r.push(Object.freeze(structuredClone(this.origin))), U(o, "snapshot", () => {
2294
+ const s = this._patches.findIndex((u) => u === o), a = this.#r[s];
2295
+ if (a) return a;
2296
+ let c;
2297
+ for (let u = 0; u <= s; u++) {
2298
+ const l = this.#r[u];
2299
+ l ? c = l : (c = Object.freeze({ ...c, ...o.patch }), this.#r[u] = c);
2300
+ }
2301
+ return c;
2302
+ }), this._patches.push(o), this.#t.next(this._patches);
2303
+ }
2304
+ /**
2305
+ * 获取需要保存的关联实体
2306
+ * 根据关系类型的优先级排序,返回需要保存的实体数组
2307
+ *
2308
+ * @returns 需要保存的实体数组
2309
+ */
2310
+ getNeedSaveRelationEntities() {
2311
+ const e = /* @__PURE__ */ new Set([this.proxyTarget]);
2312
+ return this.#e.forEach(
2313
+ (n) => n.forEach((r) => {
2314
+ w(r).modified === !0 && e.add(r);
2315
+ })
2316
+ ), Array.from(e);
2317
+ }
2318
+ /**
2319
+ * 添加关系实体
2320
+ * 根据关系类型处理实体间的关联
2321
+ *
2322
+ * @param relation - 关系元数据
2323
+ * @param entity - 要关联的实体
2324
+ */
2325
+ addRelationEntity(e, n) {
2326
+ const r = this.getRelationCache(e.kind);
2327
+ switch (e.kind) {
2328
+ case v.MANY_TO_MANY:
2329
+ {
2330
+ const i = e.junctionEntityType, o = e.name + "Id", s = e.mappedProperty + "Id", a = (f) => f instanceof i && f[o] === n.id && f[s] === this.target.id;
2331
+ if (Array.from(r.values()).find(a)) return;
2332
+ const u = w(n).getRelationCache(v.MANY_TO_MANY);
2333
+ let l = Array.from(u.values()).find(a);
2334
+ l || (l = new i({
2335
+ [o]: n.id,
2336
+ [s]: this.target.id
2337
+ })), r.add(n), r.add(l), u.add(this.proxyTarget), u.add(l);
2338
+ }
2339
+ break;
2340
+ default:
2341
+ r.add(n);
2342
+ }
2343
+ }
2344
+ /**
2345
+ * 删除关系实体
2346
+ * 根据关系类型移除实体间的关联
2347
+ *
2348
+ * @param relation - 关系元数据
2349
+ * @param entity - 要移除关联的实体
2350
+ */
2351
+ removeRelationEntity(e, n) {
2352
+ const r = this.getRelationCache(e.kind);
2353
+ switch (e.kind) {
2354
+ case v.MANY_TO_MANY:
2355
+ {
2356
+ const i = e.junctionEntityType, o = e.name + "Id", s = e.mappedProperty + "Id", a = Array.from(r.values()).find(
2357
+ (c) => c instanceof i && c[o] === this.target.id && c[s] === n.id
2358
+ );
2359
+ a && r.delete(a);
2360
+ }
2361
+ break;
2362
+ }
2363
+ r.delete(n);
2364
+ }
2365
+ /**
2366
+ * 获取指定关系类型的实体缓存
2367
+ * 如果缓存不存在则创建新的缓存
2368
+ *
2369
+ * @param kind - 关系类型
2370
+ */
2371
+ getRelationCache(e) {
2372
+ let n = this.#e.get(e);
2373
+ return n ? this.#e.get(e) : (n = /* @__PURE__ */ new Set(), this.#e.set(e, n), n);
2374
+ }
2375
+ }
2376
+ class rr {
2377
+ /**
2378
+ * 创建实体管理器实例
2379
+ *
2380
+ * 构造函数会:
2381
+ * 1. 为所有注册的实体类型添加静态和实例方法
2382
+ * 2. 设置实体关系处理
2383
+ * 3. 配置实体代理和删除检查
2384
+ *
2385
+ * @param rxdb - RxDB实例,提供数据库访问和事件分发
2386
+ */
2387
+ constructor(e) {
2388
+ this.rxdb = e, this.rxdb.options.entities.forEach((n) => {
2389
+ const r = N(n);
2390
+ b(n.prototype, ze, this);
2391
+ let i = ["get", "findOneOrFail", "find", "findOne", "findAll", "count"];
2392
+ r.repository === "TreeRepository" && (i = [
2393
+ ...i,
2394
+ "findRoot",
2395
+ "countRoot",
2396
+ "findDescendants",
2397
+ "countDescendants",
2398
+ "findAncestors",
2399
+ "countAncestors"
2400
+ ]), i.forEach(
2401
+ (o) => b(
2402
+ n,
2403
+ o,
2404
+ (s) => this.#i(n)[o](s)
2405
+ )
2406
+ ), Object.keys(Ue).forEach(
2407
+ (o) => b(n.prototype, o, Ue[o](this, n))
2408
+ ), r.relationMap.forEach((o) => tr(o, n, this));
2409
+ }), b(this, Ve, (n) => {
2410
+ const r = this.#a(n, { local: !1, remote: !1, modified: !0 });
2411
+ this.addEntityCache(r);
2412
+ const i = new St([r]);
2413
+ return this.rxdb.dispatchEvent(i), r;
2414
+ }), b(this, Ke, (n) => {
2415
+ const { EntityType: r, data: i } = n;
2416
+ i.rowIds.forEach((o) => {
2417
+ const a = this.#s(r).get(o), c = a && this.#n(r).get(a);
2418
+ if (c) {
2419
+ const u = w(c);
2420
+ u.removed = !0;
2421
+ }
2422
+ });
2423
+ });
2424
+ }
2425
+ /**
2426
+ * 实体仓库映射
2427
+ * 存储每个实体类型对应的仓库实例
2428
+ */
2429
+ #e = /* @__PURE__ */ new Map();
2430
+ /**
2431
+ * 实体缓存映射
2432
+ * 按实体类型存储实体实例,键为实体ID
2433
+ * 用于实现实体标识映射和缓存
2434
+ */
2435
+ #t = /* @__PURE__ */ new Map();
2436
+ /**
2437
+ * 行ID映射
2438
+ * 存储数据库行ID到实体UUID的映射关系
2439
+ * 用于在数据库操作中快速查找实体
2440
+ */
2441
+ #r = /* @__PURE__ */ new Map();
2442
+ /**
2443
+ * 创建实体引用
2444
+ * 根据提供的数据创建或获取实体实例,并设置其状态
2445
+ * 如果实体已存在于缓存中,则返回缓存的实例
2446
+ *
2447
+ * @template T 实体类型
2448
+ * @param EntityType - 实体类型
2449
+ * @param data - 实体数据,必须包含id
2450
+ * @param [status] - 可选的实体状态配置
2451
+ * @returns 创建或获取的实体实例
2452
+ */
2453
+ createEntityRef(e, n, r) {
2454
+ const i = this.#n(e);
2455
+ if (i.has(n.id) === !1) {
2456
+ const o = Object.create(e.prototype);
2457
+ Object.assign(o, n);
2458
+ const s = this.#a(o, r);
2459
+ i.set(o.id, s);
2460
+ }
2461
+ return i.get(n.id);
2462
+ }
2463
+ /**
2464
+ * 获取实体引用
2465
+ * 从缓存中获取指定ID的实体实例
2466
+ *
2467
+ * @template T 实体类型
2468
+ * @param EntityType - 实体类型
2469
+ * @param id - 实体ID
2470
+ * @returns 实体实例,如果不存在则返回undefined
2471
+ */
2472
+ getEntityRef(e, n) {
2473
+ return this.#n(e)?.get(n);
2474
+ }
2475
+ /**
2476
+ * 根据数据库行ID获取实体
2477
+ * @param EntityType
2478
+ * @param rowId
2479
+ * @returns
2480
+ */
2481
+ getEntityByRowId(e, n) {
2482
+ const r = this.#r.get(e)?.get(n);
2483
+ return r && this.#n(e).get(r);
2484
+ }
2485
+ /**
2486
+ * 检查实体是否在缓存中
2487
+ * 判断指定ID的实体是否已在缓存中初始化
2488
+ *
2489
+ * @template T 实体类型
2490
+ * @param EntityType - 实体类型
2491
+ * @param id - 实体ID
2492
+ * @returns 如果实体在缓存中存在则返回true
2493
+ */
2494
+ hasEntityRef(e, n) {
2495
+ return this.#n(e)?.has(n) === !0;
2496
+ }
2497
+ /**
2498
+ * 添加实体到缓存
2499
+ * 将实体实例添加到对应类型的缓存映射中
2500
+ *
2501
+ * @template T 实体类型
2502
+ * @param entity - 要缓存的实体实例
2503
+ */
2504
+ addEntityCache(e) {
2505
+ this.#n(e.constructor)?.set(e.id, e);
2506
+ }
2507
+ /**
2508
+ * 从缓存中删除实体
2509
+ * 将实体实例从缓存映射中移除
2510
+ *
2511
+ * @template T 实体类型
2512
+ * @param entity - 要移除的实体实例
2513
+ */
2514
+ removeEntityCache(e) {
2515
+ this.#n(e.constructor)?.delete(e.id);
2516
+ }
2517
+ /**
2518
+ * 更新实体的行ID映射
2519
+ * 建立数据库行ID到实体UUID的映射关系
2520
+ *
2521
+ * @template T 实体类型
2522
+ * @param entity - 实体实例
2523
+ * @param rowId - 数据库行ID
2524
+ */
2525
+ updateEntityRowId(e, n) {
2526
+ this.#s(e.constructor).set(n, e.id);
2527
+ }
2528
+ /**
2529
+ * 保存实体
2530
+ * 根据实体状态决定是创建新实体还是更新现有实体
2531
+ * 如果有关联实体需要保存,会使用事务进行批量保存
2532
+ *
2533
+ * @template T 实体类型
2534
+ * @param data - 要保存的实体实例
2535
+ * @returns 保存后的实体实例
2536
+ */
2537
+ async save(e) {
2538
+ const n = ke([e]);
2539
+ if (n.length === 1) {
2540
+ const r = n[0];
2541
+ w(r).local ? await this.update(r) : await this.create(r);
2542
+ } else n.length > 1 && await this.saveMany(n);
2543
+ return e;
2544
+ }
2545
+ /**
2546
+ * 批量保存
2547
+ * @param entities
2548
+ * @returns
2549
+ */
2550
+ async saveMany(e) {
2551
+ const n = ke(e);
2552
+ return (await T(this.#o())).saveMany(n);
2553
+ }
2554
+ /**
2555
+ * 删除实体
2556
+ * 从数据库中删除实体,并分发相关事件
2557
+ *
2558
+ * @template T 实体类型
2559
+ * @param data - 要删除的实体实例
2560
+ * @returns 删除后的实体实例
2561
+ * @throws 如果删除失败,抛出错误
2562
+ */
2563
+ async remove(e) {
2564
+ const n = e.constructor, r = await this.#i(n).remove(e);
2565
+ return this.rxdb.dispatchEvent(new Nt([r])), r;
2566
+ }
2567
+ /**
2568
+ * 重置实体
2569
+ */
2570
+ async reset(e) {
2571
+ const n = w(e);
2572
+ n.modified && n.reset();
2573
+ }
2574
+ /**
2575
+ * 批量删除
2576
+ * @param entities
2577
+ * @returns
2578
+ */
2579
+ async removeMany(e) {
2580
+ if (e.length === 1)
2581
+ await this.remove(e[0]);
2582
+ else if (e.length > 1)
2583
+ return (await T(this.#o())).transaction(async () => {
2584
+ for (let r = 0; r < e.length; r++) {
2585
+ const i = e[r];
2586
+ await this.remove(i);
2587
+ }
2588
+ });
2589
+ }
2590
+ /**
2591
+ * 创建实体
2592
+ * 在数据库中创建新实体,并分发相关事件
2593
+ *
2594
+ * @template T 实体类型
2595
+ * @param data - 要创建的实体实例
2596
+ * @returns 创建后的实体实例
2597
+ * @throws 如果创建失败,抛出错误
2598
+ */
2599
+ async create(e) {
2600
+ const n = e.constructor, r = await this.#i(n).create(e);
2601
+ return this.rxdb.dispatchEvent(new Tt([r])), r;
2602
+ }
2603
+ /**
2604
+ * 更新实体
2605
+ * 在数据库中更新实体,只更新已修改的属性,并分发相关事件
2606
+ *
2607
+ * @template T 实体类型
2608
+ * @param data - 要更新的实体实例
2609
+ * @returns 更新后的实体实例
2610
+ * @throws 如果更新失败,抛出错误
2611
+ */
2612
+ async update(e) {
2613
+ const n = e.constructor, r = w(e);
2614
+ if (r.modified) {
2615
+ const i = await this.#i(n).update(e, r.patch);
2616
+ return this.rxdb.dispatchEvent(new Mt([i])), i;
2617
+ }
2618
+ return e;
2619
+ }
2620
+ /**
2621
+ * 获取实体仓库
2622
+ * 获取指定实体类型的仓库实例
2623
+ *
2624
+ * @template T 实体类型
2625
+ * @param EntityType - 实体类型
2626
+ * @returns 实体仓库实例
2627
+ */
2628
+ getRepository(e) {
2629
+ return this.#i(e);
2630
+ }
2631
+ /**
2632
+ * 获取本地适配器
2633
+ * 当前只考虑,有且只有一个本地适配器的场景,未来再扩展
2634
+ * @returns
2635
+ */
2636
+ #o() {
2637
+ const { local: e } = this.rxdb.options.sync;
2638
+ return this.rxdb.getAdapter(e.adapter);
2639
+ }
2640
+ /**
2641
+ * 获取或创建实体仓库
2642
+ * 根据实体元数据中的repository配置创建对应类型的仓库
2643
+ *
2644
+ * @template T 实体类型
2645
+ * @template RT 仓库类型
2646
+ * @param EntityType - 实体类型
2647
+ * @returns 实体仓库实例
2648
+ * @throws {RxDBError} 如果仓库类型无效
2649
+ */
2650
+ #i(e) {
2651
+ if (!this.#e.has(e)) {
2652
+ const n = N(e);
2653
+ if (!n) throw new S("meta not found");
2654
+ let r;
2655
+ switch (n.repository) {
2656
+ case "Repository":
2657
+ r = new vt(this.rxdb, e);
2658
+ break;
2659
+ case "TreeRepository":
2660
+ r = new Xn(this.rxdb, e);
2661
+ break;
2662
+ default:
2663
+ throw new S("repository must be 'Repository' or 'TreeRepository'");
2664
+ }
2665
+ return this.#e.set(e, r), r;
2666
+ }
2667
+ return this.#e.get(e);
2668
+ }
2669
+ /**
2670
+ * 获取实体缓存映射
2671
+ * 获取指定实体类型的缓存映射,如果不存在则创建
2672
+ *
2673
+ * @template T 实体类型
2674
+ * @param EntityType - 实体类型
2675
+ * @returns 实体缓存映射
2676
+ */
2677
+ #n(e) {
2678
+ return this.#t.has(e) === !1 && this.#t.set(e, /* @__PURE__ */ new Map()), this.#t.get(e);
2679
+ }
2680
+ /**
2681
+ * 获取行ID缓存映射
2682
+ * 获取指定实体类型的行ID映射,如果不存在则创建
2683
+ *
2684
+ * @template T 实体类型
2685
+ * @param EntityType - 实体类型
2686
+ * @returns 行ID到UUID的映射
2687
+ */
2688
+ #s(e) {
2689
+ return this.#r.has(e) === !1 && this.#r.set(e, /* @__PURE__ */ new Map()), this.#r.get(e);
2690
+ }
2691
+ /**
2692
+ * 初始化实体
2693
+ * 设置实体的状态和代理,使其可以跟踪变更
2694
+ *
2695
+ * @template T 实体类型
2696
+ * @param entity - 要初始化的实体实例
2697
+ * @param [status] - 可选的实体状态配置
2698
+ * @returns 初始化后的代理实体实例
2699
+ */
2700
+ #a(e, n) {
2701
+ Ye(e, F, "");
2702
+ const r = new nr(this.rxdb, { target: e, ...n });
2703
+ Ye(e, We, r);
2704
+ const i = er(e);
2705
+ return b(r, "proxyTarget", i), i;
2706
+ }
2707
+ }
2708
+ const Ue = {
2709
+ save: (t) => function() {
2710
+ return t.save(this);
2711
+ },
2712
+ remove: (t) => function() {
2713
+ return t.remove(this);
2714
+ },
2715
+ reset: (t) => function() {
2716
+ return t.reset(this);
2717
+ }
2718
+ }, ir = (t) => {
2719
+ const [{ metadata: e, relation: n }, { metadata: r, relation: i }] = t, o = Array.from(/* @__PURE__ */ new Set([e.namespace, r.namespace])).sort().join("_") || void 0;
2720
+ return {
2721
+ name: Array.from(/* @__PURE__ */ new Set([e.name, r.name])).sort().join("_"),
2722
+ namespace: o,
2723
+ relations: [
2724
+ {
2725
+ name: n.name,
2726
+ kind: v.MANY_TO_ONE,
2727
+ mappedNamespace: r.namespace,
2728
+ mappedEntity: r.name
2729
+ },
2730
+ {
2731
+ name: i.name,
2732
+ kind: v.MANY_TO_ONE,
2733
+ mappedNamespace: e.namespace,
2734
+ mappedEntity: e.name
2735
+ }
2736
+ ]
2737
+ };
2738
+ };
2739
+ var or = Object.getOwnPropertyDescriptor, sr = (t, e, n, r) => {
2740
+ for (var i = r > 1 ? void 0 : r ? or(e, n) : e, o = t.length - 1, s; o >= 0; o--)
2741
+ (s = t[o]) && (i = s(i) || i);
2742
+ return i;
2743
+ };
2744
+ let ie = class {
2745
+ id;
2746
+ activated;
2747
+ local;
2748
+ remote;
2749
+ [Re];
2750
+ save() {
2751
+ return Promise.resolve(this);
2752
+ }
2753
+ delete() {
2754
+ return Promise.resolve(this);
2755
+ }
2756
+ };
2757
+ ie = sr([
2758
+ Y({
2759
+ name: "RxDBBranch",
2760
+ log: !1,
2761
+ properties: [
2762
+ {
2763
+ name: "id",
2764
+ type: p.string,
2765
+ primary: !0,
2766
+ unique: !0
2767
+ },
2768
+ {
2769
+ name: "activated",
2770
+ type: p.boolean,
2771
+ default: !1
2772
+ },
2773
+ {
2774
+ name: "local",
2775
+ type: p.boolean,
2776
+ default: !0
2777
+ },
2778
+ {
2779
+ name: "remote",
2780
+ type: p.boolean,
2781
+ default: !1
2782
+ }
2783
+ ],
2784
+ relations: [
2785
+ {
2786
+ name: "changes",
2787
+ kind: v.ONE_TO_MANY,
2788
+ mappedEntity: "RxDBChange",
2789
+ mappedProperty: "branch"
2790
+ }
2791
+ ]
2792
+ })
2793
+ ], ie);
2794
+ var ar = Object.getOwnPropertyDescriptor, cr = (t, e, n, r) => {
2795
+ for (var i = r > 1 ? void 0 : r ? ar(e, n) : e, o = t.length - 1, s; o >= 0; o--)
2796
+ (s = t[o]) && (i = s(i) || i);
2797
+ return i;
2798
+ };
2799
+ let _e = class {
2800
+ /**
2801
+ * id
2802
+ */
2803
+ id;
2804
+ /**
2805
+ * 变更类型
2806
+ */
2807
+ type;
2808
+ /**
2809
+ * 实体所属的命名空间
2810
+ */
2811
+ namespace;
2812
+ /**
2813
+ * 发生变更的实体类型名称
2814
+ */
2815
+ entity;
2816
+ /**
2817
+ * 发生变更的实体唯一标识符
2818
+ */
2819
+ entityId;
2820
+ /**
2821
+ * 反向补丁数据,用于撤销此次变更
2822
+ * 包含恢复到变更前状态所需的字段和值
2823
+ */
2824
+ inversePatch;
2825
+ /**
2826
+ * 正向补丁数据,包含此次变更的具体内容
2827
+ * 记录了哪些字段被修改以及修改后的值
2828
+ */
2829
+ patch;
2830
+ /**
2831
+ * 变更发生的时间戳
2832
+ */
2833
+ createdAt;
2834
+ /**
2835
+ * 变更更新
2836
+ */
2837
+ updatedAt;
2838
+ /**
2839
+ * 撤销此次变更的 id
2840
+ * 用于跟踪变更的回滚
2841
+ * @example
2842
+ * 数据库有 3 条记录 1,2,3
2843
+ * 3 被还原,那么 3 的 revertChangeId 就是 4
2844
+ * 如何这个时候有条新记录,那么数据库共有4条记录,分别是 1,2,3,5
2845
+ */
2846
+ revertChangeId;
2847
+ /**
2848
+ * 撤销此次变更的时间戳
2849
+ */
2850
+ /**
2851
+ * 变更所属的事务
2852
+ */
2853
+ transactionId;
2854
+ /**
2855
+ * 撤销此次变更的时间
2856
+ */
2857
+ revertChangedAt;
2858
+ /**
2859
+ * 变更所属的分支
2860
+ */
2861
+ branchId;
2862
+ /**
2863
+ * 变更父级
2864
+ */
2865
+ parentId;
2866
+ [Re];
2867
+ };
2868
+ _e = cr([
2869
+ qn({
2870
+ name: "RxDBChange",
2871
+ log: !1,
2872
+ // 此实体本身不记录变更日志,避免递归记录
2873
+ properties: [
2874
+ {
2875
+ name: "id",
2876
+ type: p.integer,
2877
+ primary: !0
2878
+ },
2879
+ {
2880
+ name: "type",
2881
+ type: p.string,
2882
+ readonly: !0
2883
+ },
2884
+ {
2885
+ name: "transactionId",
2886
+ type: p.uuid,
2887
+ nullable: !0
2888
+ },
2889
+ {
2890
+ name: "namespace",
2891
+ type: p.string,
2892
+ readonly: !0,
2893
+ nullable: !0
2894
+ },
2895
+ {
2896
+ name: "entity",
2897
+ type: p.string,
2898
+ readonly: !0,
2899
+ nullable: !0
2900
+ },
2901
+ {
2902
+ name: "entityId",
2903
+ type: p.uuid,
2904
+ readonly: !0,
2905
+ nullable: !0
2906
+ },
2907
+ {
2908
+ name: "inversePatch",
2909
+ type: p.json,
2910
+ readonly: !0,
2911
+ nullable: !0
2912
+ },
2913
+ {
2914
+ name: "patch",
2915
+ type: p.json,
2916
+ readonly: !0,
2917
+ nullable: !0
2918
+ },
2919
+ {
2920
+ name: "createdAt",
2921
+ type: p.date,
2922
+ default: "CURRENT_TIMESTAMP",
2923
+ readonly: !0,
2924
+ nullable: !0
2925
+ },
2926
+ {
2927
+ name: "updatedAt",
2928
+ type: p.date,
2929
+ default: "CURRENT_TIMESTAMP",
2930
+ readonly: !0,
2931
+ nullable: !0
2932
+ },
2933
+ {
2934
+ name: "revertChangedAt",
2935
+ type: p.date,
2936
+ nullable: !0
2937
+ },
2938
+ {
2939
+ name: "revertChangeId",
2940
+ type: p.integer,
2941
+ nullable: !0
2942
+ }
2943
+ ],
2944
+ relations: [
2945
+ {
2946
+ name: "children",
2947
+ kind: v.ONE_TO_MANY,
2948
+ mappedEntity: "RxDBChange",
2949
+ mappedProperty: "parent"
2950
+ },
2951
+ {
2952
+ name: "parent",
2953
+ kind: v.MANY_TO_ONE,
2954
+ mappedEntity: "RxDBChange",
2955
+ nullable: !0
2956
+ },
2957
+ {
2958
+ name: "branch",
2959
+ kind: v.MANY_TO_ONE,
2960
+ mappedEntity: "RxDBBranch",
2961
+ nullable: !0
2962
+ }
2963
+ ]
2964
+ })
2965
+ ], _e);
2966
+ var ur = Object.getOwnPropertyDescriptor, lr = (t, e, n, r) => {
2967
+ for (var i = r > 1 ? void 0 : r ? ur(e, n) : e, o = t.length - 1, s; o >= 0; o--)
2968
+ (s = t[o]) && (i = s(i) || i);
2969
+ return i;
2970
+ };
2971
+ let oe = class {
2972
+ /**
2973
+ * 迁移记录的唯一标识符
2974
+ */
2975
+ id;
2976
+ /**
2977
+ * 迁移脚本的唯一名称或标识符
2978
+ * 通常包含版本号或描述性名称,用于识别具体的迁移操作
2979
+ */
2980
+ name;
2981
+ /**
2982
+ * 迁移脚本的执行时间戳
2983
+ * 默认为执行时的当前时间
2984
+ */
2985
+ executedAt;
2986
+ [Re];
2987
+ };
2988
+ oe = lr([
2989
+ Y({
2990
+ name: "RxDBMigration",
2991
+ log: !1,
2992
+ properties: [
2993
+ {
2994
+ name: "id",
2995
+ type: p.integer,
2996
+ primary: !0
2997
+ },
2998
+ {
2999
+ name: "name",
3000
+ type: p.string,
3001
+ readonly: !0
3002
+ },
3003
+ {
3004
+ name: "executedAt",
3005
+ type: p.date,
3006
+ readonly: !0,
3007
+ default: () => /* @__PURE__ */ new Date()
3008
+ }
3009
+ ]
3010
+ })
3011
+ ], oe);
3012
+ var fr = Object.getOwnPropertyDescriptor, dr = (t, e, n, r) => {
3013
+ for (var i = r > 1 ? void 0 : r ? fr(e, n) : e, o = t.length - 1, s; o >= 0; o--)
3014
+ (s = t[o]) && (i = s(i) || i);
3015
+ return i;
3016
+ };
3017
+ const X = (t, e) => e + ":" + t;
3018
+ class hr {
3019
+ constructor(e) {
3020
+ this.rxdb = e;
3021
+ const { entities: n } = this.rxdb.options;
3022
+ n.push(ie, _e, oe), new Set(n).forEach((r) => {
3023
+ const i = N(r), { name: o, namespace: s } = i, a = X(o, s);
3024
+ this.#e.set(a, i), this.#t.set(a, r);
3025
+ }), this.#e.forEach((r) => {
3026
+ const { relations: i } = r;
3027
+ i.forEach((o) => {
3028
+ if (o.kind === v.MANY_TO_MANY) {
3029
+ const s = o, a = this.findMappedRelation(r, s);
3030
+ if (!a) throw new S("mapped relation not found");
3031
+ const c = ir([
3032
+ { metadata: r, relation: s },
3033
+ a
3034
+ ]), u = X(c.name, c.namespace);
3035
+ if (this.#e.has(u) === !1) {
3036
+ let l = class extends re {
3037
+ };
3038
+ l = dr([
3039
+ Y(c)
3040
+ ], l);
3041
+ const f = N(l);
3042
+ this.#e.set(u, f), this.#t.set(u, l), n.push(l);
3043
+ }
3044
+ o.junctionEntityType = this.#t.get(u);
3045
+ }
3046
+ });
3047
+ }), this.#e.forEach((r, i) => {
3048
+ const { name: o, namespace: s } = r;
3049
+ let a = e;
3050
+ s && Object.hasOwn(a, s) === !1 && (b(a, s, {}), a = a[s]), b(a, o, this.#t.get(i));
3051
+ }), Object.freeze(this);
3052
+ }
3053
+ #e = /* @__PURE__ */ new Map();
3054
+ #t = /* @__PURE__ */ new Map();
3055
+ /**
3056
+ * 查找当前关系属性的映射关系
3057
+ * @param relation 当前关系属性
3058
+ */
3059
+ findMappedRelation(e, n) {
3060
+ for (const r of this.#e.values())
3061
+ if (r.relations && r.name === n.mappedEntity && r.namespace === n.mappedNamespace) {
3062
+ let i;
3063
+ switch (n.kind) {
3064
+ case v.MANY_TO_MANY:
3065
+ i = (s) => s.kind === v.MANY_TO_MANY && s.name === n.mappedProperty && s.mappedProperty === n.name;
3066
+ break;
3067
+ case v.ONE_TO_MANY:
3068
+ i = (s) => s.kind === v.MANY_TO_ONE && s.name === n.mappedProperty;
3069
+ break;
3070
+ case v.MANY_TO_ONE:
3071
+ i = (s) => s.kind === v.ONE_TO_MANY && s.mappedProperty === n.name;
3072
+ break;
3073
+ case v.ONE_TO_ONE:
3074
+ i = (s) => s.kind === v.ONE_TO_ONE && s.mappedEntity === e.name;
3075
+ break;
3076
+ }
3077
+ const o = r.relations.find(i);
3078
+ if (o)
3079
+ return {
3080
+ metadata: r,
3081
+ relation: o
3082
+ };
3083
+ }
3084
+ }
3085
+ /**
3086
+ * 通过查询条件的字段找出关系数组
3087
+ * @param field 查询条件的字段
3088
+ */
3089
+ getFieldRelations(e, n) {
3090
+ if (n.includes(".") === !1) throw new S(`field '${n}' 必须是关属性查询`);
3091
+ const r = [], i = n.split("."), o = i.length - 1;
3092
+ let s = e, a, c = !1, u = "";
3093
+ return i.length === 2 && i[1] == "id" && (c = s.foreignKeyRelationMap.has(i[0]), u = i[0] + "Id"), i.forEach((l, f) => {
3094
+ if (f === o) {
3095
+ if (s.propertyMap.has(l) === !1) throw new S(`property '${l}' not found`);
3096
+ a = s.propertyMap.get(l);
3097
+ } else {
3098
+ if (s.relationMap.has(l) === !1) throw new S(`relation '${l}' not found`);
3099
+ const h = s.relationMap.get(l);
3100
+ r.push({ relation: h, metadata: s }), s = this.getEntityMetadata(h.mappedEntity, h.mappedNamespace);
3101
+ }
3102
+ }), {
3103
+ property: a,
3104
+ propertyName: u || a.name,
3105
+ isForeignKey: c,
3106
+ relations: r
3107
+ };
3108
+ }
3109
+ /**
3110
+ * 获取实体元数据
3111
+ */
3112
+ getEntityMetadata(e, n) {
3113
+ const r = X(e, n);
3114
+ return this.#e.get(r);
3115
+ }
3116
+ /**
3117
+ * 获取实体元数据
3118
+ */
3119
+ getEntityType(e, n) {
3120
+ const r = X(e, n);
3121
+ return this.#t.get(r);
3122
+ }
3123
+ }
3124
+ class pr {
3125
+ constructor(e) {
3126
+ this.rxdb = e;
3127
+ const n = e.options.sync, { local: r } = n;
3128
+ r && this.localAdapterSub.next(r.adapter);
3129
+ }
3130
+ #e;
3131
+ #t;
3132
+ /**
3133
+ * 本地适配器
3134
+ */
3135
+ localAdapterSub = new z("");
3136
+ localAdapter$ = this.localAdapterSub.asObservable().pipe(
3137
+ te(Boolean),
3138
+ G(),
3139
+ y((e) => this.rxdb.getAdapter(e)),
3140
+ x(1)
3141
+ );
3142
+ /**
3143
+ * 创建新分支
3144
+ * @param branchId 分支 id
3145
+ * @param fromChangeId 从哪个 changeId 创建新分支
3146
+ */
3147
+ createBranch(e, n) {
3148
+ return this.#t || (this.#t = T(
3149
+ this.localAdapter$.pipe(
3150
+ y((r) => r.createBranch(e, n)),
3151
+ A(() => this.#t = void 0)
3152
+ )
3153
+ )), this.#t;
3154
+ }
3155
+ /**
3156
+ * 切换分支
3157
+ * @param branchId
3158
+ */
3159
+ switchBranch(e) {
3160
+ return this.#e || (this.#e = T(
3161
+ this.localAdapter$.pipe(
3162
+ y((n) => n.switchBranch(e)),
3163
+ A(() => this.#e = void 0)
3164
+ )
3165
+ )), this.#e;
3166
+ }
3167
+ /**
3168
+ * 恢复某个实体
3169
+ * @param entity
3170
+ * @param options
3171
+ */
3172
+ restoreEntity(e, n) {
3173
+ throw new Error("Method not implemented.");
3174
+ }
3175
+ }
3176
+ class jr {
3177
+ // 插件
3178
+ #e = /* @__PURE__ */ new WeakSet();
3179
+ // events
3180
+ #t = /* @__PURE__ */ new Map();
3181
+ #r = [];
3182
+ #o = !1;
3183
+ // 适配器
3184
+ #i = /* @__PURE__ */ new Map();
3185
+ #n = /* @__PURE__ */ new Map();
3186
+ #s = new z(0);
3187
+ #a = this.#s.asObservable().pipe(G(), x(1));
3188
+ // 上下文
3189
+ #u = {};
3190
+ /**
3191
+ * Schema 管理
3192
+ */
3193
+ schemaManager;
3194
+ /**
3195
+ * Entity 管理
3196
+ */
3197
+ entityManager;
3198
+ /**
3199
+ * 版本管理
3200
+ */
3201
+ versionManager;
3202
+ /**
3203
+ * 设置环境上下文
3204
+ */
3205
+ get context() {
3206
+ return this.#u;
3207
+ }
3208
+ set context(e) {
3209
+ this.#u = e;
3210
+ }
3211
+ options;
3212
+ constructor(e) {
3213
+ this.options = Object.freeze(e), this.schemaManager = new hr(this), this.entityManager = new rr(this), this.versionManager = new pr(this), this.context = { ...this.options.context }, this.addEventListener(Ee, () => {
3214
+ this.#o = !0;
3215
+ }), this.addEventListener(ge, () => {
3216
+ this.#o = !1, this.#r.forEach((r) => this.dispatchEvent(r)), this.#r = [];
3217
+ }), this.addEventListener(we, () => {
3218
+ this.#o = !1, this.#r = [];
3219
+ });
3220
+ const n = this.entityManager;
3221
+ this.addEventListener(Fe, (r) => n[Ke](r)), ht(this.options);
3222
+ }
3223
+ /**
3224
+ * 注册适配器
3225
+ */
3226
+ adapter(e, n) {
3227
+ return this.#i.set(e, n), this.#s.next(this.#i.size), this;
3228
+ }
3229
+ /**
3230
+ * 获取适配器
3231
+ */
3232
+ getAdapter(e) {
3233
+ return this.#n.has(e) ? this.#n.get(e) : this.#a.pipe(
3234
+ K(() => this.#i.get(e)),
3235
+ te(Boolean),
3236
+ G(),
3237
+ y((n) => {
3238
+ if (!this.#n.has(e)) {
3239
+ const r = n(this);
3240
+ jn(r) ? this.#n.set(e, De(() => r).pipe(x(1))) : this.#n.set(e, ve(r).pipe(x(1)));
3241
+ }
3242
+ return this.#n.get(e);
3243
+ })
3244
+ );
3245
+ }
3246
+ /**
3247
+ * 安装插件
3248
+ */
3249
+ use(e, n) {
3250
+ if (this.#e.has(e))
3251
+ console.warn("plugin already installed");
3252
+ else {
3253
+ this.#e.add(e);
3254
+ const r = e(this, n);
3255
+ this[r.name] = r;
3256
+ }
3257
+ return this;
3258
+ }
3259
+ /**
3260
+ * 连接适配器
3261
+ */
3262
+ connect(e) {
3263
+ return this.getAdapter(e).pipe(
3264
+ y((n) => n.connect()),
3265
+ y((n) => Dt(e, this.options) ? De(async () => {
3266
+ if (!await n.isTableExisted(oe)) {
3267
+ const i = new ie();
3268
+ i.id = "main", i.activated = !0, await n.createTables(this.options.entities, [i]);
3269
+ }
3270
+ }).pipe(K(() => n)) : ve(n))
3271
+ );
3272
+ }
3273
+ /**
3274
+ * 断开适配器
3275
+ * @param adapterName 适配器注册名称
3276
+ */
3277
+ disconnect(e) {
3278
+ return this.getAdapter(e).pipe(y((n) => n.disconnect()));
3279
+ }
3280
+ /**
3281
+ * 断开所有适配器
3282
+ */
3283
+ disconnectAll() {
3284
+ return Be(Array.from(this.#n.values())).pipe(
3285
+ y((e) => Be(e.map((n) => n.disconnect())))
3286
+ );
3287
+ }
3288
+ /**
3289
+ * 监听事件
3290
+ * @param type
3291
+ * @param listener
3292
+ */
3293
+ addEventListener(e, n) {
3294
+ this.#c(e).add(n);
3295
+ }
3296
+ /**
3297
+ * 移除事件
3298
+ * @param type
3299
+ * @param listener
3300
+ */
3301
+ removeEventListener(e, n) {
3302
+ this.#c(e).delete(n);
3303
+ }
3304
+ /**
3305
+ * 派发事件
3306
+ * @param event
3307
+ */
3308
+ dispatchEvent(e) {
3309
+ this.#o && $t(e) === !1 ? this.#r.push(e) : this.#c(e.type).forEach((n) => n.call(this, e));
3310
+ }
3311
+ #c(e) {
3312
+ if (this.#t.has(e))
3313
+ return this.#t.get(e);
3314
+ {
3315
+ const r = /* @__PURE__ */ new Set();
3316
+ return this.#t.set(e, r), r;
3317
+ }
3318
+ }
3319
+ }
3320
+ const yr = {
3321
+ EntityBase: [me],
3322
+ TreeAdjacencyListEntityBase: [pt, me]
3323
+ }, Br = (t) => yr[t];
3324
+ export {
3325
+ Fe as DATABASE_DELETE,
3326
+ Pt as DATABASE_INSERT,
3327
+ jt as DATABASE_UPDATE,
3328
+ me as ENTITY_BASE_METADATA_OPTIONS,
3329
+ xt as ENTITY_CREATE_EVENT,
3330
+ yr as ENTITY_METADATA_MAP,
3331
+ At as ENTITY_NEW_EVENT,
3332
+ It as ENTITY_REMOVE_EVENT,
3333
+ Re as ENTITY_STATIC_TYPES,
3334
+ Rt as ENTITY_UPDATE_EVENT,
3335
+ Y as Entity,
3336
+ re as EntityBase,
3337
+ Tt as EntityCreateEvent,
3338
+ St as EntityNewEvent,
3339
+ Nt as EntityRemoveEvent,
3340
+ Mt as EntityUpdateEvent,
3341
+ p as PropertyType,
3342
+ v as RelationKind,
3343
+ Mr as RepositoryBase,
3344
+ jr as RxDB,
3345
+ yt as RxDBAdapterBase,
3346
+ _r as RxDBAdapterDeleteChangeEvent,
3347
+ Er as RxDBAdapterInsertChangeEvent,
3348
+ Ir as RxDBAdapterLocalBase,
3349
+ Nr as RxDBAdapterRemoteBase,
3350
+ gr as RxDBAdapterUpdateChangeEvent,
3351
+ ie as RxDBBranch,
3352
+ _e as RxDBChange,
3353
+ S as RxDBError,
3354
+ oe as RxDBMigration,
3355
+ Pr as RxDBPluginBase,
3356
+ Qn as SyncStatus,
3357
+ Fn as SyncType,
3358
+ Ee as TRANSACTION_BEGIN,
3359
+ ge as TRANSACTION_COMMIT,
3360
+ we as TRANSACTION_ROLLBACK,
3361
+ pt as TREE_ADJACENCY_LIST_ENTITY_BASE_OPTIONS,
3362
+ vr as TransactionBeginEvent,
3363
+ mr as TransactionCommitEvent,
3364
+ br as TransactionRollbackEvent,
3365
+ Le as TreeAdjacencyListEntityBase,
3366
+ qn as TreeEntity,
3367
+ Ar as __decorateClass,
3368
+ Rr as calculateOrderBy,
3369
+ Ln as fillDefaultValue,
3370
+ Un as fillInitValue,
3371
+ Or as getEntityFingerprint,
3372
+ N as getEntityMetadata,
3373
+ Br as getEntityMetadataOptions,
3374
+ w as getEntityStatus,
3375
+ ke as getNeedSaveEntities,
3376
+ Tr as isEntityEffectOrderBy,
3377
+ Sr as isEntityInternalName,
3378
+ xr as isEntityMatchWhere,
3379
+ Jn as isRuleGroup,
3380
+ wr as isRxDBEntity,
3381
+ b as setSafeObjectKey,
3382
+ U as setSafeObjectKeyLazyInitOnce,
3383
+ Ye as setSafeObjectWritableKey,
3384
+ Vn as transitionMetadata,
3385
+ Yt as uuid
3386
+ };