@signaldb/oby 2.0.0-beta.2 → 2.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,1077 +1,24 @@
1
- import { createReactivityAdapter as At } from "@signaldb/core";
2
- const Ee = /* @__PURE__ */ Symbol("Cached"), te = /* @__PURE__ */ Symbol("Observable"), Je = /* @__PURE__ */ Symbol("Observable.Boolean"), Ye = /* @__PURE__ */ Symbol("Observable.Frozen"), we = /* @__PURE__ */ Symbol("Observable.Readable"), Oe = /* @__PURE__ */ Symbol("Observable.Writable"), X = /* @__PURE__ */ Symbol("Store"), Fe = /* @__PURE__ */ Symbol("Store.Keys"), Ve = /* @__PURE__ */ Symbol("Store.Observable"), ce = /* @__PURE__ */ Symbol("Store.Target"), Re = /* @__PURE__ */ Symbol("Store.Values"), _e = /* @__PURE__ */ Symbol("Store.Untracked"), q = /* @__PURE__ */ Symbol("Suspense"), ze = /* @__PURE__ */ Symbol("Uncached"), me = /* @__PURE__ */ Symbol("Untracked"), He = /* @__PURE__ */ Symbol("Untracked.Unwrapped"), dt = (e) => K(e) ? e : [e], pt = (e) => e instanceof Error ? e : typeof e == "string" ? new Error(e) : new Error("Unknown error"), { is: J } = Object, { isArray: K } = Array, bt = (e, t) => {
3
- if (e.length !== t.length)
4
- return !1;
5
- for (let s = 0, n = e.length; s < n; s++) {
6
- const r = e[s], i = t[s];
7
- if (!J(r, i))
8
- return !1;
9
- }
10
- return !0;
11
- }, E = (e) => typeof e == "function", Me = (e) => e !== null && typeof e == "object", St = (e) => typeof e == "symbol", xe = () => {
12
- }, Ge = () => !1;
13
- function gt() {
14
- if (arguments.length)
15
- throw new Error("A readonly Observable can not be updated");
16
- return this;
17
- }
18
- function yt() {
19
- if (arguments.length)
20
- throw new Error("A readonly Observable can not be updated");
21
- return this.get();
22
- }
23
- function Et(e) {
24
- return arguments.length ? E(e) ? this.C(e) : this.set(e) : this.get();
25
- }
26
- const P = (e) => {
27
- const t = gt.bind(e);
28
- return t[te] = !0, t[Ye] = !0, t;
29
- }, D = (e) => {
30
- const t = yt.bind(e);
31
- return t[te] = !0, t[we] = e, t;
32
- }, $e = (e) => {
33
- const t = Et.bind(e);
34
- return t[te] = !0, t[Oe] = e, t;
35
- }, Ke = 0, oe = 1, ue = 2, le = 3, je = P(!1), wt = P(!0), Te = new Proxy({}, new Proxy({}, { get() {
36
- throw new Error("Unavailable value");
37
- } })), We = function() {
38
- }, Se = (e, t) => {
39
- if (e instanceof Array)
40
- for (let s = 0, n = e.length; s < n; s++)
41
- t(e[s]);
42
- else e && t(e);
43
- }, re = (e, t) => {
44
- if (e instanceof Array)
45
- for (let s = e.length - 1; s >= 0; s--)
46
- t(e[s]);
47
- else e && t(e);
48
- }, se = (e, t, s) => {
49
- const n = e[t];
50
- n instanceof Array ? n.push(s) : n ? e[t] = [n, s] : e[t] = s;
51
- }, U = (e, t, s) => {
52
- const n = e[t];
53
- if (n instanceof Set)
54
- n.add(s);
55
- else if (n) {
56
- if (s !== n) {
57
- const r = /* @__PURE__ */ new Set();
58
- r.add(n), r.add(s), e[t] = r;
59
- }
60
- } else
61
- e[t] = s;
62
- }, v = (e, t, s) => {
63
- const n = e[t];
64
- n instanceof Set ? n.delete(s) : n === s && (e[t] = void 0);
65
- }, Z = (e, t) => {
66
- if (e instanceof Set)
67
- for (const s of e)
68
- t(s);
69
- else e && t(e);
70
- }, Ot = (e) => e.call(e), ge = (e) => e.Q(!0);
71
- class ne {
72
- constructor() {
73
- this.disposed = !1, this.B = void 0, this.S = void 0, this.D = void 0, this.K = void 0, this.T = void 0, this.U = void 0;
74
- }
75
- /* API */
76
- catch(t, s) {
77
- const { S: n } = this;
78
- if (n)
79
- return n(t), !0;
80
- if (this.parent?.catch(t, !0))
81
- return !0;
82
- if (s)
83
- return !1;
84
- throw t;
85
- }
86
- Q(t) {
87
- re(this.D, ge), re(this.K, ge), re(this.U, ge), re(this.B, Ot), this.B = void 0, this.disposed = t, this.S = void 0, this.K = void 0, this.U = void 0;
88
- }
89
- get(t) {
90
- return this.context?.[t];
91
- }
92
- E(t, s, n) {
93
- const r = A, i = H;
94
- ve(s), he(n);
95
- try {
96
- return t();
97
- } catch (c) {
98
- return this.catch(pt(c), !1), Te;
99
- } finally {
100
- ve(r), he(i);
101
- }
102
- }
103
- }
104
- class Xe extends ne {
105
- constructor() {
106
- super(...arguments), this.context = {};
107
- }
108
- }
109
- let F, Ze = new Xe(), H, A = Ze;
110
- const Ue = (e) => F = e, he = (e) => H = e, ve = (e) => A = e;
111
- let ie = 0, De = xe;
112
- const Rt = async (e) => {
113
- ie || Ue(new Promise((t) => De = t));
114
- try {
115
- return ie += 1, await e();
116
- } finally {
117
- ie -= 1, ie || (Ue(void 0), De());
118
- }
119
- }, ke = (e) => E(e) && Je in e, k = (e) => E(e) && (Ye in e || !!e[we]?.parent?.disposed), Be = (e) => E(e) && (me in e || He in e);
120
- let _t = class {
121
- constructor() {
122
- this.A1 = [], this.M = 0, this.A2 = !1, this.N = () => {
123
- if (!this.A2 && !this.M && this.A1.length)
124
- try {
125
- for (this.A2 = !0; ; ) {
126
- const t = this.A1;
127
- if (!t.length)
128
- break;
129
- this.A1 = [];
130
- for (let s = 0, n = t.length; s < n; s++)
131
- t[s].C();
132
- }
133
- } finally {
134
- this.A2 = !1;
135
- }
136
- }, this.E = (t) => {
137
- this.M += 1, t(), this.M -= 1, this.N();
138
- }, this.F = (t) => {
139
- this.A1.push(t);
140
- };
141
- }
142
- };
143
- const j = new _t();
144
- class T {
145
- /* CONSTRUCTOR */
146
- constructor(t, s, n) {
147
- this.K = /* @__PURE__ */ new Set(), this.value = t, n && (this.parent = n), s?.equals !== void 0 && (this.equals = s.equals || Ge);
148
- }
149
- /* API */
150
- get() {
151
- return this.parent?.disposed || (this.parent?.C(), H?.A.L(this)), this.value;
152
- }
153
- set(t) {
154
- const s = this.equals || J;
155
- return (this.value === We || !s(t, this.value)) && (this.value = t, j.M += 1, this.I(le), j.M -= 1, j.N()), t;
156
- }
157
- I(t) {
158
- for (const s of this.K)
159
- (s.J !== oe || s.A.has(this)) && (s.sync ? (s.J = Math.max(s.J, t), j.F(s)) : s.I(t));
160
- }
161
- C(t) {
162
- const s = t(this.value);
163
- return this.set(s);
164
- }
165
- }
166
- class mt {
167
- /* CONSTRUCTOR */
168
- constructor(t) {
169
- this.observer = t, this.A = [], this.P = 0;
170
- }
171
- /* API */
172
- Q(t) {
173
- if (t) {
174
- const { observer: s, A: n } = this;
175
- for (let r = 0; r < n.length; r++)
176
- n[r].K.delete(s);
177
- }
178
- this.P = 0;
179
- }
180
- R() {
181
- const { observer: t, A: s, P: n } = this, r = s.length;
182
- if (n < r) {
183
- for (let i = n; i < r; i++)
184
- s[i].K.delete(t);
185
- s.length = n;
186
- }
187
- }
188
- empty() {
189
- return !this.A.length;
190
- }
191
- has(t) {
192
- const s = this.A.indexOf(t);
193
- return s >= 0 && s < this.P;
194
- }
195
- L(t) {
196
- const { observer: s, A: n, P: r } = this, i = n.length;
197
- if (i > 0) {
198
- if (n[r] === t) {
199
- this.P += 1;
200
- return;
201
- }
202
- const c = n.indexOf(t);
203
- if (c >= 0 && c < r)
204
- return;
205
- r < i - 1 ? this.R() : r === i - 1 && n[r].K.delete(s);
206
- }
207
- t.K.add(s), n[this.P++] = t, r === 128 && (s.A = new Mt(s, n));
208
- }
209
- C() {
210
- const { A: t } = this;
211
- for (let s = 0, n = t.length; s < n; s++)
212
- t[s].parent?.C();
213
- }
214
- }
215
- class Mt {
216
- /* CONSTRUCTOR */
217
- constructor(t, s) {
218
- this.observer = t, this.A = new Set(s);
219
- }
220
- /* API */
221
- Q(t) {
222
- for (const s of this.A)
223
- s.K.delete(this.observer);
224
- }
225
- R() {
226
- }
227
- empty() {
228
- return !this.A.size;
229
- }
230
- has(t) {
231
- return this.A.has(t);
232
- }
233
- L(t) {
234
- const { observer: s, A: n } = this, r = n.size;
235
- t.K.add(s);
236
- const i = n.size;
237
- r !== i && n.add(t);
238
- }
239
- C() {
240
- for (const t of this.A)
241
- t.parent?.C();
242
- }
243
- }
244
- class Pe extends ne {
245
- /* CONSTRUCTOR */
246
- constructor() {
247
- super(), this.parent = A, this.context = A.context, this.J = le, this.A = new mt(this), A !== Ze && se(this.parent, "K", this);
248
- }
249
- /* API */
250
- Q(t) {
251
- this.A.Q(t), super.Q(t);
252
- }
253
- H(t) {
254
- this.Q(!1), this.J = oe;
255
- try {
256
- return this.E(t, this, this);
257
- } finally {
258
- this.A.R();
259
- }
260
- }
261
- run() {
262
- throw new Error("Abstract method");
263
- }
264
- I(t) {
265
- throw new Error("Abstract method");
266
- }
267
- C() {
268
- this.disposed || (this.J === ue && this.A.C(), this.J === le ? (this.J = oe, this.run(), this.J === oe ? this.J = Ke : this.C()) : this.J = Ke);
269
- }
270
- }
271
- class xt extends Pe {
272
- /* CONSTRUCTOR */
273
- constructor(t, s) {
274
- super(), this.fn = t, this.observable = new T(We, s, this), s?.sync === !0 && (this.sync = !0, this.C());
275
- }
276
- /* API */
277
- run() {
278
- const t = super.H(this.fn);
279
- !this.disposed && this.A.empty() && (this.disposed = !0), t !== Te && this.observable.set(t);
280
- }
281
- I(t) {
282
- const s = this.J;
283
- s >= t || (this.J = t, s !== ue && this.observable.I(ue));
284
- }
285
- }
286
- const B = (e, t) => {
287
- if (k(e))
288
- return e;
289
- if (Be(e))
290
- return P(e());
291
- {
292
- const s = new xt(e, t);
293
- return D(s.observable);
294
- }
295
- }, Ie = (e) => {
296
- if (E(e)) {
297
- if (k(e) || Be(e))
298
- return !!e();
299
- if (ke(e))
300
- return e;
301
- {
302
- const t = B(() => !!e());
303
- return t[Je] = !0, t;
304
- }
305
- } else
306
- return !!e;
307
- }, C = (e) => {
308
- se(A, "B", e);
309
- };
310
- class Tt extends ne {
311
- /* CONSTRUCTOR */
312
- constructor(t) {
313
- super(), this.parent = A, this.context = { ...A.context, ...t }, se(this.parent, "D", this);
314
- }
315
- /* API */
316
- E(t) {
317
- return super.E(t, this, void 0);
318
- }
319
- }
320
- function Bt(e, t) {
321
- return St(e) ? A.context[e] : new Tt(e).E(t || xe);
322
- }
323
- const Pt = () => {
324
- const e = new T(!1);
325
- return C(() => e.set(!0)), D(e);
326
- };
327
- class It {
328
- constructor() {
329
- this.A1 = [], this.A2 = !1, this.A3 = !1, this.N = () => {
330
- if (!this.A2 && this.A1.length)
331
- try {
332
- for (this.A2 = !0; ; ) {
333
- const t = this.A1;
334
- if (!t.length)
335
- break;
336
- this.A1 = [];
337
- for (let s = 0, n = t.length; s < n; s++)
338
- t[s].C();
339
- }
340
- } finally {
341
- this.A2 = !1;
342
- }
343
- }, this.queue = () => {
344
- this.A3 || (this.A3 = !0, this.resolve());
345
- }, this.resolve = () => {
346
- queueMicrotask(() => {
347
- queueMicrotask(() => {
348
- F ? F.finally(this.resolve) : (this.A3 = !1, this.N());
349
- });
350
- });
351
- }, this.F = (t) => {
352
- this.A1.push(t), this.queue();
353
- };
354
- }
355
- }
356
- const fe = new It();
357
- class et extends Pe {
358
- /* CONSTRUCTOR */
359
- constructor(t, s) {
360
- if (super(), this.fn = t, s?.suspense !== !1) {
361
- const n = this.get(q);
362
- n && (this.suspense = n);
363
- }
364
- s?.sync === !0 && (this.sync = !0), s?.sync === "init" ? (this.init = !0, this.C()) : this.F();
365
- }
366
- /* API */
367
- run() {
368
- const t = super.H(this.fn);
369
- E(t) && se(this, "B", t);
370
- }
371
- F() {
372
- this.suspense?.suspended || (this.sync ? this.C() : fe.F(this));
373
- }
374
- I(t) {
375
- const s = this.J;
376
- s >= t || (this.J = t, (!this.sync || s !== 2 && s !== 3) && this.F());
377
- }
378
- C() {
379
- this.suspense?.suspended || super.C();
380
- }
381
- }
382
- const Ae = (e, t) => {
383
- const s = new et(e, t);
384
- return () => s.Q(!0);
385
- };
386
- function S(e) {
387
- if (E(e))
388
- return He in e ? S(e()) : me in e ? P(S(e())) : te in e ? e : B(() => S(e()));
389
- if (e instanceof Array) {
390
- const t = new Array(e.length);
391
- for (let s = 0, n = t.length; s < n; s++)
392
- t[s] = S(e[s]);
393
- return t;
394
- } else
395
- return e;
396
- }
397
- class de extends ne {
398
- /* CONSTRUCTOR */
399
- constructor(t) {
400
- super(), this.parent = A, this.context = A.context, t && this.get(q) && (this.A0 = !0, U(this.parent, "T", this));
401
- }
402
- /* API */
403
- Q(t) {
404
- this.A0 && v(this.parent, "T", this), super.Q(t);
405
- }
406
- E(t) {
407
- const s = () => this.Q(!0), n = () => t(s);
408
- return super.E(n, this, void 0);
409
- }
410
- }
411
- const Nt = P(-1);
412
- let Lt = class extends de {
413
- };
414
- class Ct {
415
- /* CONSTRUCTOR */
416
- constructor(t) {
417
- this.parent = A, this.suspense = A.get(q), this.A5 = /* @__PURE__ */ new Map(), this.A6 = !1, this.A7 = 0, this.A8 = 0, this.A9 = 0, this.cleanup = () => {
418
- if (!this.A7 || this.A7 === this.A8)
419
- return;
420
- const { A5: s, A6: n } = this;
421
- s.size && (this.A9 ? s.forEach((r, i) => {
422
- r.A6 !== n && (r.Q(!0), s.delete(i));
423
- }) : (this.A5.forEach((r) => {
424
- r.Q(!0);
425
- }), this.A5 = /* @__PURE__ */ new Map()));
426
- }, this.Q = () => {
427
- this.suspense && v(this.parent, "T", this.T), this.A7 = this.A5.size, this.A8 = 0, this.A9 = 0, this.cleanup();
428
- }, this.AA = () => {
429
- this.A6 = !this.A6, this.A8 = 0, this.A9 = 0;
430
- }, this.O = (s) => {
431
- this.A9 = s.length, this.cleanup(), this.A7 = this.A9, this.A8 = 0;
432
- }, this.map = (s) => {
433
- this.AA();
434
- const { A5: n, A6: r, fn: i, AB: c } = this, u = new Array(s.length);
435
- let o = !0, l = !0, p = 0;
436
- for (let a = 0, d = s.length; a < d; a++) {
437
- const g = s[a], h = n.get(g);
438
- if (h && h.A6 !== r)
439
- l = !1, p += 1, h.A6 = r, h.index?.set(a), u[a] = h.G;
440
- else {
441
- o = !1;
442
- const w = new Lt(!1);
443
- h && C(() => w.Q(!0)), w.E(() => {
444
- let y = Nt;
445
- c && (w.index = new T(a), y = D(w.index));
446
- const _ = u[a] = S(i(g, y));
447
- w.A6 = r, w.G = _, h || n.set(g, w);
448
- });
449
- }
450
- }
451
- return this.A8 = p, this.O(s), o && (u[Ee] = !0), l && (u[ze] = !0), u;
452
- }, this.T = () => Array.from(this.A5.values()), this.fn = t, this.AB = t.length > 1, this.suspense && U(this.parent, "T", this.T);
453
- }
454
- }
455
- const Ne = (e) => E(e) && te in e;
456
- function V(e, t = !0) {
457
- return (t ? E : Ne)(e) ? e() : e;
458
- }
459
- class tt extends ne {
460
- /* CONSTRUCTOR */
461
- constructor() {
462
- super(), this.parent = A, this.context = { ...A.context, [q]: this }, se(this.parent, "U", this), this.suspended = A.get(q)?.suspended || 0;
463
- }
464
- /* API */
465
- A4(t) {
466
- if (!this.suspended && !t)
467
- return;
468
- const s = this.suspended, n = s + (t ? 1 : -1);
469
- if (this.suspended = n, !!s == !!n)
470
- return;
471
- this.observable?.set(!!n);
472
- const r = (o) => {
473
- Se(o.D, r), Se(o.K, i), Se(o.U, u), Z(o.T, c);
474
- }, i = (o) => {
475
- o instanceof et && (o.J === ue || o.J === le) && (o.init ? o.C() : o.F()), r(o);
476
- }, c = (o) => {
477
- E(o) ? o().forEach(r) : r(o);
478
- }, u = (o) => {
479
- o.A4(t);
480
- };
481
- r(this);
482
- }
483
- E(t) {
484
- return super.E(t, this, void 0);
485
- }
486
- }
487
- const st = (e, t) => {
488
- const s = new tt(), n = Ie(e);
489
- return Ae(() => s.A4(V(n)), { sync: !0 }), s.E(t);
490
- }, Kt = P(-1);
491
- class Ut extends de {
492
- }
493
- class vt {
494
- /* CONSTRUCTOR */
495
- constructor(t, s) {
496
- this.parent = A, this.suspense = A.get(q), this.A5 = /* @__PURE__ */ new Map(), this.AC = [], this.AD = 0, this.cleanup = () => {
497
- let n = 0, r = Math.max(0, this.pooled ? this.AD - this.AC.length : 0);
498
- this.A5.forEach((i) => {
499
- r > 0 && n++ < r ? (i.suspended?.set(!0), this.AC.push(i)) : i.Q(!0);
500
- });
501
- }, this.Q = () => {
502
- this.suspense && v(this.parent, "T", this.T), this.A5.forEach((n) => {
503
- n.Q(!0);
504
- }), this.AC.forEach((n) => {
505
- n.Q(!0);
506
- });
507
- }, this.map = (n) => {
508
- const { A5: r, fn: i, AB: c } = this, u = /* @__PURE__ */ new Map(), o = new Array(n.length), l = this.AC, p = this.pooled;
509
- let a = !0, d = !0, g = [];
510
- if (r.size)
511
- for (let h = 0, w = n.length; h < w; h++) {
512
- const y = n[h], _ = r.get(y);
513
- _ ? (d = !1, r.delete(y), u.set(y, _), _.index?.set(h), o[h] = _.G) : g.push(h);
514
- }
515
- else
516
- g = new Array(o.length);
517
- e: for (let h = 0, w = g.length; h < w; h++) {
518
- const y = g[h] || h, _ = n[y], Le = u.has(_);
519
- if (!Le)
520
- for (const [G, Q] of r.entries()) {
521
- r.delete(G), u.set(_, Q), Q.index?.set(y), Q.value?.set(_), o[y] = Q.G;
522
- continue e;
523
- }
524
- a = !1;
525
- let O;
526
- p && l.length ? (O = l.pop(), O.index?.set(y), O.value?.set(_), O.suspended?.set(!1), o[y] = O.G) : (O = new Ut(!1), O.E(() => {
527
- let G = Kt;
528
- c && (O.index = new T(y), G = D(O.index));
529
- const Q = O.value = new T(_), be = p ? new T(!1) : void 0, Ce = B(() => V(Q.get())), at = o[y] = be ? st(() => be.get(), () => S(i(Ce, G))) : S(i(Ce, G));
530
- O.value = Q, O.G = at, O.suspended = be;
531
- })), Le ? C(() => O.Q(!0)) : u.set(_, O);
532
- }
533
- return this.AD = Math.max(this.AD, o.length), this.cleanup(), this.A5 = u, a && (o[Ee] = !0), d && (o[ze] = !0), o;
534
- }, this.T = () => [...this.A5.values(), ...this.AC.values()], this.fn = t, this.AB = t.length > 1, this.pooled = s, this.suspense && U(this.parent, "T", this.T);
535
- }
536
- }
537
- const m = (e) => Me(e) && X in e;
538
- function I(e) {
539
- if (E(e)) {
540
- const t = H;
541
- if (t)
542
- try {
543
- return he(void 0), e();
544
- } finally {
545
- he(t);
546
- }
547
- else
548
- return e();
549
- } else
550
- return e;
551
- }
552
- function Dt(e, t, s = [], n) {
553
- if (K(e) && !m(e)) {
554
- const r = !!n?.unkeyed;
555
- return P(I(() => e.length ? e.map((i, c) => S(t(r && !Ne(i) ? P(i) : i, c))) : S(s)));
556
- } else {
557
- const { Q: r, map: i } = n?.unkeyed ? new vt(t, !!n.pooled) : new Ct(t);
558
- C(r);
559
- const c = B(() => V(e) ?? [], {
560
- equals: (u, o) => !!u && !!o && !u.length && !o.length && !m(u) && !m(o)
561
- });
562
- return B(() => {
563
- const u = c();
564
- return m(u) && u[Re], I(() => {
565
- const o = i(u);
566
- return o?.length ? o : S(s);
567
- });
568
- }, {
569
- equals: (u, o) => K(u) && !!u[Ee] && K(o) && bt(u, o)
570
- });
571
- }
572
- }
573
- const nt = (e) => (I(e), e), ye = (e, t, s) => {
574
- for (let n = 0, r = t.length; n < r; n++) {
575
- const i = t[n];
576
- if (i.length === 1)
577
- return i[0];
578
- if (J(i[0], e))
579
- return i[1];
580
- }
581
- return s;
582
- };
583
- function rt(e, t, s) {
584
- if (E(e) && !k(e) && !Be(e)) {
585
- if (ke(e))
586
- return B(() => S(ye(e(), t, s)));
587
- const r = nt(B(() => ye(e(), t, s)));
588
- return k(r) ? P(S(r())) : B(() => S(V(r)));
589
- } else {
590
- const r = ye(V(e), t, s);
591
- return P(S(r));
592
- }
593
- }
594
- const it = (e, t, s) => {
595
- const n = Ie(e);
596
- return rt(n, [[!0, t], [s]]);
597
- };
598
- function Qt(e, t, s) {
599
- return it(e, t, s);
600
- }
601
- const ot = () => !!F || fe.A3 || fe.A2 || j.A2;
602
- function ct(e, t) {
603
- return $e(new T(e, t));
604
- }
605
- const ut = () => {
606
- const e = A instanceof Xe, t = A instanceof de, s = A instanceof tt, n = A instanceof Pe;
607
- return { isSuperRoot: e, isRoot: t, isSuspense: s, isComputation: n };
608
- }, qt = (e) => E(e) && Oe in e, Jt = (e) => E(e) ? e[we] || e[Oe] || Te : e, Yt = (e) => qt(e) ? D(Jt(e)) : e, Ft = (e) => new de(!0).E(e);
609
- class Vt extends Map {
610
- constructor() {
611
- super(...arguments), this.disposed = !1;
612
- }
613
- }
614
- class zt extends T {
615
- constructor() {
616
- super(...arguments), this.AE = 1;
617
- }
618
- /* API */
619
- call() {
620
- this.AF.disposed || (this.AE -= 1, !this.AE && this.AF.delete(this.AG));
621
- }
622
- }
623
- const Ht = (e) => {
624
- if (e = nt(B(e)), k(e)) {
625
- const r = I(e);
626
- return (i) => i === r ? wt : je;
627
- }
628
- let t = new Vt(), s = I(e);
629
- return Ae(() => {
630
- const r = s, i = e();
631
- J(r, i) || (s = i, t.get(r)?.set(!1), t.get(i)?.set(!0));
632
- }, { suspense: !1, sync: !0 }), C(() => {
633
- t.disposed = !0;
634
- }), (r) => {
635
- let i = t.get(r);
636
- return i ? i.AE += 1 : (i = new zt(r === s), i.AF = t, i.AG = r, t.set(r, i)), C(i), D(i);
637
- };
638
- };
639
- class N extends Map {
640
- AH(t, s) {
641
- return super.set(t, s), s;
642
- }
643
- }
644
- class pe {
645
- constructor() {
646
- this.AE = 0;
647
- }
648
- listen() {
649
- this.AE += 1, C(this);
650
- }
651
- call() {
652
- this.AE -= 1, !this.AE && this.Q();
653
- }
654
- Q() {
655
- }
656
- }
657
- class Gt extends pe {
658
- constructor(t, s) {
659
- super(), this.parent = t, this.observable = s;
660
- }
661
- Q() {
662
- this.parent.keys = void 0;
663
- }
664
- }
665
- class $t extends pe {
666
- constructor(t, s) {
667
- super(), this.parent = t, this.observable = s;
668
- }
669
- Q() {
670
- this.parent.values = void 0;
671
- }
672
- }
673
- class jt extends pe {
674
- constructor(t, s, n) {
675
- super(), this.parent = t, this.key = s, this.observable = n;
676
- }
677
- Q() {
678
- this.parent.has?.delete(this.key);
679
- }
680
- }
681
- class Wt extends pe {
682
- constructor(t, s, n, r) {
683
- super(), this.parent = t, this.key = s, this.observable = n, this.AI = r;
684
- }
685
- Q() {
686
- this.parent.AJ?.delete(this.key);
687
- }
688
- }
689
- const R = {
690
- /* VARIABLES */
691
- AK: 0,
692
- AL: /* @__PURE__ */ new Set(),
693
- AM: /* @__PURE__ */ new Set(),
694
- /* API */
695
- AN: () => {
696
- const { AL: e, AM: t } = R, s = /* @__PURE__ */ new Set(), n = (r) => {
697
- s.has(r) || (s.add(r), Z(r.AO, n), Z(r.AP, (i) => {
698
- e.add(i);
699
- }));
700
- };
701
- return t.forEach(n), () => {
702
- e.forEach((r) => {
703
- r();
704
- });
705
- };
706
- },
707
- V: (e) => {
708
- R.AM.add(e), x.F();
709
- },
710
- reset: () => {
711
- R.AL = /* @__PURE__ */ new Set(), R.AM = /* @__PURE__ */ new Set();
712
- }
713
- }, b = {
714
- /* VARIABLES */
715
- AK: 0,
716
- AM: /* @__PURE__ */ new Map(),
717
- /* API */
718
- AN: () => {
719
- const { AM: e } = b;
720
- return () => {
721
- e.forEach((t, s) => {
722
- const n = Array.from(t);
723
- Z(s.AQ, (r) => {
724
- r(n);
725
- });
726
- });
727
- };
728
- },
729
- V: (e, t) => {
730
- const s = b.AM.get(e) || /* @__PURE__ */ new Set();
731
- s.add(t), b.AM.set(e, s), x.F();
732
- },
733
- AR: (e, t, s) => {
734
- if (t.AO) {
735
- const n = /* @__PURE__ */ new Set(), r = (i) => {
736
- n.has(i) || (n.add(i), Z(i.AO, (c) => {
737
- c.AO || b.V(c, i.store), r(c);
738
- }));
739
- };
740
- r(e || t);
741
- } else {
742
- const n = e?.store || I(() => t.store[s]);
743
- b.V(t, n);
744
- }
745
- },
746
- reset: () => {
747
- b.AM = /* @__PURE__ */ new Map();
748
- }
749
- }, x = {
750
- /* VARIABLES */
751
- AK: !1,
752
- /* API */
753
- N: () => {
754
- const e = R.AN(), t = b.AN();
755
- x.reset(), e(), t();
756
- },
757
- AS: () => {
758
- ot() ? F ? F.finally(x.AS) : setTimeout(x.AS, 0) : x.N();
759
- },
760
- reset: () => {
761
- x.AK = !1, R.reset(), b.reset();
762
- },
763
- F: () => {
764
- x.AK || (x.AK = !0, queueMicrotask(x.AS));
765
- }
766
- }, z = /* @__PURE__ */ new WeakMap(), Xt = /* @__PURE__ */ new Set([X, Fe, Ve, ce, Re]), Zt = /* @__PURE__ */ new Set(["__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__", "prototype", "constructor", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString", "toSource", "toString", "valueOf"]), lt = {
767
- /* API */
768
- get: (e, t) => {
769
- if (Xt.has(t)) {
770
- if (t === X)
771
- return !0;
772
- if (t === ce)
773
- return e;
774
- if (t === Fe) {
775
- if ($()) {
776
- const o = M(e);
777
- o.keys || (o.keys = Qe(o)), o.keys.listen(), o.keys.observable.get();
778
- }
779
- return;
780
- }
781
- if (t === Re) {
782
- if ($()) {
783
- const o = M(e);
784
- o.values || (o.values = es(o)), o.values.listen(), o.values.observable.get();
785
- }
786
- return;
787
- }
788
- if (t === Ve)
789
- return (o) => {
790
- o = typeof o == "number" ? String(o) : o;
791
- const l = M(e), p = l.AT?.get(o);
792
- if (p)
793
- return p.bind(l.store);
794
- l.AJ || (l.AJ = new N());
795
- const a = e[o], d = l.AJ.get(o) || l.AJ.AH(o, qe(l, o, a)), g = l.equals ? { equals: l.equals } : void 0;
796
- return d.observable || (d.observable = ee(l, a, g)), D(d.observable);
797
- };
798
- }
799
- if (Zt.has(t))
800
- return e[t];
801
- const s = M(e), n = s.AT?.get(t), r = n || e[t];
802
- s.AJ || (s.AJ = new N());
803
- const i = $(), c = W(r), u = i || c ? s.AJ.get(t) || s.AJ.AH(t, qe(s, t, r)) : void 0;
804
- if (u?.AI && U(u.AI, "AO", s), u && i) {
805
- const o = s.equals ? { equals: s.equals } : void 0;
806
- u.listen(), u.observable || (u.observable = ee(s, r, o)), u.observable.get();
807
- }
808
- return n ? n.call(s.store) : typeof r == "function" && r === Array.prototype[t] ? function() {
809
- return r.apply(s.store, arguments);
810
- } : u?.AI?.store || r;
811
- },
812
- set: (e, t, s) => {
813
- s = L(s);
814
- const n = M(e), r = n.AU?.get(t);
815
- if (r)
816
- r.call(n.store, s);
817
- else {
818
- const i = K(e), c = e[t], u = !!c || t in e, o = n.equals || J;
819
- if (u && o(s, c) && (t !== "length" || !i))
820
- return !0;
821
- const l = i && e.length;
822
- e[t] = s;
823
- const p = i && e.length;
824
- i && t !== "length" && l !== p && n.AJ?.get("length")?.observable?.set(p), n.values?.observable.set(0), u || (n.keys?.observable.set(0), n.has?.get(t)?.observable.set(!0));
825
- const a = n.AJ?.get(t);
826
- if (a?.AI && v(a.AI, "AO", n), a && (a.observable?.set(s), a.AI = W(s) ? z.get(s) || ae(s, t, n) : void 0), a?.AI && U(a.AI, "AO", n), b.AK && b.AR(a?.AI, n, t), R.AK && R.V(n), i && t === "length") {
827
- const d = Number(c), g = Number(s);
828
- for (let h = g; h < d; h++)
829
- h in e || lt.deleteProperty(e, `${h}`, !0);
830
- }
831
- }
832
- return !0;
833
- },
834
- deleteProperty: (e, t, s) => {
835
- const n = t in e;
836
- if (!s && !n)
837
- return !0;
838
- if (!Reflect.deleteProperty(e, t))
839
- return !1;
840
- const i = M(e);
841
- i.AT?.delete(t), i.AU?.delete(t), i.keys?.observable.set(0), i.values?.observable.set(0), i.has?.get(t)?.observable.set(!1);
842
- const c = i.AJ?.get(t);
843
- return b.AK && b.AR(c?.AI, i, t), c?.AI && v(c.AI, "AO", i), c && (c.observable?.set(void 0), c.AI = void 0), R.AK && R.V(i), !0;
844
- },
845
- defineProperty: (e, t, s) => {
846
- const n = M(e), r = n.equals || J, i = t in e, c = Reflect.getOwnPropertyDescriptor(e, t);
847
- if ("value" in s && m(s.value) && (s = { ...s, value: L(s.value) }), c && is(c, s, r))
848
- return !0;
849
- if (!Reflect.defineProperty(e, t, s))
850
- return !1;
851
- s.get ? s.get && (n.AT || (n.AT = new N()), n.AT.set(t, s.get)) : n.AT?.delete(t), s.set ? s.set && (n.AU || (n.AU = new N()), n.AU.set(t, s.set)) : n.AU?.delete(t), i !== !!s.enumerable && n.keys?.observable.set(0), n.has?.get(t)?.observable.set(!0);
852
- const o = n.AJ?.get(t);
853
- if (b.AK && b.AR(o?.AI, n, t), o?.AI && v(o.AI, "AO", n), o)
854
- if ("get" in s)
855
- o.observable?.set(s.get), o.AI = void 0;
856
- else {
857
- const l = s.value;
858
- o.observable?.set(l), o.AI = W(l) ? z.get(l) || ae(l, t, n) : void 0;
859
- }
860
- return o?.AI && U(o.AI, "AO", n), b.AK && b.AR(o?.AI, n, t), R.AK && R.V(n), !0;
861
- },
862
- has: (e, t) => {
863
- if (t === X || t === ce)
864
- return !0;
865
- const s = t in e;
866
- if ($()) {
867
- const n = M(e);
868
- n.has || (n.has = new N());
869
- const r = n.has.get(t) || n.has.AH(t, ts(n, t, s));
870
- r.listen(), r.observable.get();
871
- }
872
- return s;
873
- },
874
- ownKeys: (e) => {
875
- const t = Reflect.ownKeys(e);
876
- if ($()) {
877
- const s = M(e);
878
- s.keys || (s.keys = Qe(s)), s.keys.listen(), s.keys.observable.get();
879
- }
880
- return t;
881
- }
882
- }, kt = {
883
- /* API */
884
- has: (e, t) => t === _e ? !0 : t in e
885
- }, ae = (e, t, s, n) => {
886
- if (m(e))
887
- return M(L(e));
888
- const r = os(e, t, s) ? e : new Proxy(e, lt), i = ss(e), c = { AO: s, store: r };
889
- if (i) {
890
- const { AT: u, AU: o } = i;
891
- u && (c.AT = u), o && (c.AU = o);
892
- }
893
- return n === !1 ? c.equals = Ge : n ? c.equals = n : s?.equals && (c.equals = s.equals), z.set(e, c), c;
894
- }, M = (e) => {
895
- const t = z.get(e);
896
- if (!t)
897
- throw new Error("Impossible");
898
- return t;
899
- }, ht = (e) => M(L(e)), Qe = (e) => {
900
- const t = ee(e, 0, { equals: !1 });
901
- return new Gt(e, t);
902
- }, es = (e) => {
903
- const t = ee(e, 0, { equals: !1 });
904
- return new $t(e, t);
905
- }, ts = (e, t, s) => {
906
- const n = ee(e, s);
907
- return new jt(e, t, n);
908
- }, ee = (e, t, s) => new T(t, s), qe = (e, t, s) => {
909
- const r = W(s) ? z.get(s) || ae(s, t, e) : void 0, i = new Wt(e, t, void 0, r);
910
- return e.AJ || (e.AJ = new N()), e.AJ.set(t, i), i;
911
- }, ss = (e) => {
912
- if (K(e))
913
- return;
914
- let t, s;
915
- const n = Object.keys(e);
916
- for (let r = 0, i = n.length; r < i; r++) {
917
- const c = n[r], u = Object.getOwnPropertyDescriptor(e, c);
918
- if (!u)
919
- continue;
920
- const { get: o, set: l } = u;
921
- o && (t || (t = new N()), t.set(c, o)), l && (s || (s = new N()), s.set(c, l)), o && !l && (s || (s = new N()), s.set(c, cs));
922
- }
923
- if (!(!t && !s))
924
- return { AT: t, AU: s };
925
- }, ns = (e, t) => m(e) ? e : (z.get(e) || ae(e, void 0, void 0, t?.equals)).store, L = (e) => m(e) ? e[ce] : e, rs = (e) => !Me(e) || ft(e) ? e : new Proxy(e, kt), is = (e, t, s) => !!e.configurable == !!t.configurable && !!e.enumerable == !!t.enumerable && !!e.writable == !!t.writable && s(e.value, t.value) && e.get === t.get && e.set === t.set, os = (e, t, s) => {
926
- if (Object.isFrozen(e))
927
- return !0;
928
- if (!s || t === void 0)
929
- return !1;
930
- const n = Y.unwrap(s.store), r = Reflect.getOwnPropertyDescriptor(n, t);
931
- return !(r?.configurable || r?.writable);
932
- }, $ = () => !!H, W = (e) => {
933
- if (e === null || typeof e != "object")
934
- return !1;
935
- if (X in e)
936
- return !0;
937
- if (_e in e)
938
- return !1;
939
- if (K(e))
940
- return !0;
941
- const t = Object.getPrototypeOf(e);
942
- return t === null ? !0 : Object.getPrototypeOf(t) === null;
943
- }, ft = (e) => e === null || typeof e != "object" ? !1 : _e in e, cs = () => {
944
- throw new TypeError("Cannot set property value of #<Object> which has only a getter");
945
- }, Y = (e, t) => !Me(e) || ft(e) ? e : ns(e, t);
946
- Y.on = (e, t) => {
947
- const s = m(e) ? [e] : dt(e), n = s.filter(E), r = s.filter(m).map(ht);
948
- R.AK += 1;
949
- const i = n.map((c) => {
950
- let u = !1;
951
- return Ae(() => {
952
- u && (R.AL.add(t), x.F()), u = !0, c();
953
- }, { suspense: !1, sync: !0 });
954
- });
955
- return r.forEach((c) => {
956
- U(c, "AP", t);
957
- }), () => {
958
- R.AK -= 1, i.forEach((c) => {
959
- c();
960
- }), r.forEach((c) => {
961
- v(c, "AP", t);
962
- });
963
- };
964
- };
965
- Y._onRoots = (e, t) => {
966
- if (!m(e))
967
- return xe;
968
- const s = ht(e);
969
- if (s.AO)
970
- throw new Error("Only top-level stores are supported");
971
- return b.AK += 1, U(s, "AQ", t), () => {
972
- b.AK -= 1, v(s, "AQ", t);
973
- };
974
- };
975
- Y.reconcile = /* @__PURE__ */ (() => {
976
- const e = (r) => K(r) ? 1 : W(r) ? 2 : 0, t = (r, i) => {
977
- const c = L(r), u = L(i);
978
- s(r, i);
979
- const o = e(c), l = e(u);
980
- return (o === 1 || l === 1) && (r.length = i.length), r;
981
- }, s = (r, i) => {
982
- const c = L(r), u = L(i), o = Object.keys(c), l = Object.keys(u);
983
- for (let p = 0, a = l.length; p < a; p++) {
984
- const d = l[p], g = c[d], h = u[d];
985
- if (J(g, h))
986
- g === void 0 && !(d in c) && (r[d] = void 0);
987
- else {
988
- const w = e(g), y = e(h);
989
- w && w === y ? (s(r[d], h), w === 1 && (r[d].length = h.length)) : r[d] = h;
990
- }
991
- }
992
- for (let p = 0, a = o.length; p < a; p++) {
993
- const d = o[p];
994
- d in u || delete r[d];
995
- }
996
- return r;
997
- };
998
- return (r, i) => I(() => t(r, i));
999
- })();
1000
- Y.untrack = (e) => rs(e);
1001
- Y.unwrap = (e) => L(e);
1002
- const us = () => {
1003
- const e = A.get(q);
1004
- if (!e)
1005
- return je;
1006
- const t = e.observable || (e.observable = new T(!!e.suspended));
1007
- return D(t);
1008
- }, ls = () => {
1009
- fe.N();
1010
- }, hs = (e, t) => {
1011
- const s = ct();
1012
- return B(() => {
1013
- const n = s();
1014
- return n ? S(t({ error: n, reset: () => s(void 0) })) : (A.S = s, S(e));
1015
- });
1016
- };
1017
- function fs(e) {
1018
- const t = E(e) ? (...s) => I(() => e(...s)) : () => e;
1019
- return t[me] = !0, t;
1020
- }
1021
- const as = () => {
1022
- const e = A, t = H;
1023
- return (s) => e.E(() => s(), e, t);
1024
- };
1025
- function f(e, t) {
1026
- return $e(new T(e, t));
1027
- }
1028
- f.batch = Rt;
1029
- f.boolean = Ie;
1030
- f.cleanup = C;
1031
- f.context = Bt;
1032
- f.disposed = Pt;
1033
- f.effect = Ae;
1034
- f.for = Dt;
1035
- f.get = V;
1036
- f.if = Qt;
1037
- f.isBatching = ot;
1038
- f.isObservable = Ne;
1039
- f.isStore = m;
1040
- f.memo = B;
1041
- f.observable = ct;
1042
- f.owner = ut;
1043
- f.readonly = Yt;
1044
- f.resolve = S;
1045
- f.root = Ft;
1046
- f.selector = Ht;
1047
- f.store = Y;
1048
- f.suspended = us;
1049
- f.suspense = st;
1050
- f.switch = rt;
1051
- f.ternary = it;
1052
- f.tick = ls;
1053
- f.tryCatch = hs;
1054
- f.untrack = I;
1055
- f.untracked = fs;
1056
- f.with = as;
1057
- const bs = At({
1058
- create: () => {
1059
- const e = f(0);
1060
- return {
1061
- depend: () => {
1062
- e();
1063
- },
1064
- notify: () => {
1065
- e(I(() => e() + 1));
1066
- }
1067
- };
1068
- },
1069
- isInScope: () => !!ut(),
1070
- onDispose: (e) => {
1071
- C(e);
1072
- }
1
+ import e, { cleanup as t, owner as n, untrack as r } from "oby";
2
+ import { createReactivityAdapter as i } from "@signaldb/core";
3
+ //#region src/index.ts
4
+ var a = i({
5
+ create: () => {
6
+ let t = e(0);
7
+ return {
8
+ depend: () => {
9
+ t();
10
+ },
11
+ notify: () => {
12
+ t(r(() => t() + 1));
13
+ }
14
+ };
15
+ },
16
+ isInScope: () => !!n(),
17
+ onDispose: (e) => {
18
+ t(e);
19
+ }
1073
20
  });
1074
- export {
1075
- bs as default
1076
- };
1077
- //# sourceMappingURL=index.mjs.map
21
+ //#endregion
22
+ export { a as default };
23
+
24
+ //# sourceMappingURL=index.mjs.map