fetchium 0.0.0 → 0.1.0

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 (127) hide show
  1. package/CHANGELOG.md +249 -0
  2. package/README.md +287 -0
  3. package/dist/cjs/development/QueryClient-CpmwggOn.js +2 -0
  4. package/dist/cjs/development/QueryClient-CpmwggOn.js.map +1 -0
  5. package/dist/cjs/development/index.js +2 -0
  6. package/dist/cjs/development/index.js.map +1 -0
  7. package/dist/cjs/development/package.json +3 -0
  8. package/dist/cjs/development/react/index.js +2 -0
  9. package/dist/cjs/development/react/index.js.map +1 -0
  10. package/dist/cjs/development/shared-Ct5zKrt4.js +2 -0
  11. package/dist/cjs/development/shared-Ct5zKrt4.js.map +1 -0
  12. package/dist/cjs/development/stores/async.js +2 -0
  13. package/dist/cjs/development/stores/async.js.map +1 -0
  14. package/dist/cjs/development/stores/sync.js +2 -0
  15. package/dist/cjs/development/stores/sync.js.map +1 -0
  16. package/dist/cjs/development/subscriptions/polling.js +2 -0
  17. package/dist/cjs/development/subscriptions/polling.js.map +1 -0
  18. package/dist/cjs/production/QueryClient-qi3bR0eD.js +2 -0
  19. package/dist/cjs/production/QueryClient-qi3bR0eD.js.map +1 -0
  20. package/dist/cjs/production/index.js +2 -0
  21. package/dist/cjs/production/index.js.map +1 -0
  22. package/dist/cjs/production/package.json +3 -0
  23. package/dist/cjs/production/react/index.js +2 -0
  24. package/dist/cjs/production/react/index.js.map +1 -0
  25. package/dist/cjs/production/shared-Ct5zKrt4.js +2 -0
  26. package/dist/cjs/production/shared-Ct5zKrt4.js.map +1 -0
  27. package/dist/cjs/production/stores/async.js +2 -0
  28. package/dist/cjs/production/stores/async.js.map +1 -0
  29. package/dist/cjs/production/stores/sync.js +2 -0
  30. package/dist/cjs/production/stores/sync.js.map +1 -0
  31. package/dist/cjs/production/subscriptions/polling.js +2 -0
  32. package/dist/cjs/production/subscriptions/polling.js.map +1 -0
  33. package/dist/esm/ConstraintMatcher.d.ts +42 -0
  34. package/dist/esm/ConstraintMatcher.d.ts.map +1 -0
  35. package/dist/esm/EntityInstance.d.ts +38 -0
  36. package/dist/esm/EntityInstance.d.ts.map +1 -0
  37. package/dist/esm/EntityStore.d.ts +14 -0
  38. package/dist/esm/EntityStore.d.ts.map +1 -0
  39. package/dist/esm/GcManager.d.ts +38 -0
  40. package/dist/esm/GcManager.d.ts.map +1 -0
  41. package/dist/esm/LiveCollection.d.ts +86 -0
  42. package/dist/esm/LiveCollection.d.ts.map +1 -0
  43. package/dist/esm/MutationResult.d.ts +23 -0
  44. package/dist/esm/MutationResult.d.ts.map +1 -0
  45. package/dist/esm/NetworkManager.d.ts +62 -0
  46. package/dist/esm/NetworkManager.d.ts.map +1 -0
  47. package/dist/esm/QueryClient.d.ts +76 -0
  48. package/dist/esm/QueryClient.d.ts.map +1 -0
  49. package/dist/esm/QueryResult.d.ts +67 -0
  50. package/dist/esm/QueryResult.d.ts.map +1 -0
  51. package/dist/esm/applyEntities.d.ts +12 -0
  52. package/dist/esm/applyEntities.d.ts.map +1 -0
  53. package/dist/esm/development/QueryClient-DRZtPKFD.js +2568 -0
  54. package/dist/esm/development/QueryClient-DRZtPKFD.js.map +1 -0
  55. package/dist/esm/development/index.js +103 -0
  56. package/dist/esm/development/index.js.map +1 -0
  57. package/dist/esm/development/react/index.js +40 -0
  58. package/dist/esm/development/react/index.js.map +1 -0
  59. package/dist/esm/development/shared-Dq2yW78d.js +15 -0
  60. package/dist/esm/development/shared-Dq2yW78d.js.map +1 -0
  61. package/dist/esm/development/stores/async.js +214 -0
  62. package/dist/esm/development/stores/async.js.map +1 -0
  63. package/dist/esm/development/stores/sync.js +149 -0
  64. package/dist/esm/development/stores/sync.js.map +1 -0
  65. package/dist/esm/development/subscriptions/polling.js +25 -0
  66. package/dist/esm/development/subscriptions/polling.js.map +1 -0
  67. package/dist/esm/errors.d.ts +4 -0
  68. package/dist/esm/errors.d.ts.map +1 -0
  69. package/dist/esm/fieldRef.d.ts +15 -0
  70. package/dist/esm/fieldRef.d.ts.map +1 -0
  71. package/dist/esm/index.d.ts +14 -0
  72. package/dist/esm/index.d.ts.map +1 -0
  73. package/dist/esm/mutation.d.ts +47 -0
  74. package/dist/esm/mutation.d.ts.map +1 -0
  75. package/dist/esm/parseEntities.d.ts +44 -0
  76. package/dist/esm/parseEntities.d.ts.map +1 -0
  77. package/dist/esm/production/QueryClient-BP0Z1rQV.js +2453 -0
  78. package/dist/esm/production/QueryClient-BP0Z1rQV.js.map +1 -0
  79. package/dist/esm/production/index.js +103 -0
  80. package/dist/esm/production/index.js.map +1 -0
  81. package/dist/esm/production/react/index.js +40 -0
  82. package/dist/esm/production/react/index.js.map +1 -0
  83. package/dist/esm/production/shared-Dq2yW78d.js +15 -0
  84. package/dist/esm/production/shared-Dq2yW78d.js.map +1 -0
  85. package/dist/esm/production/stores/async.js +214 -0
  86. package/dist/esm/production/stores/async.js.map +1 -0
  87. package/dist/esm/production/stores/sync.js +149 -0
  88. package/dist/esm/production/stores/sync.js.map +1 -0
  89. package/dist/esm/production/subscriptions/polling.js +25 -0
  90. package/dist/esm/production/subscriptions/polling.js.map +1 -0
  91. package/dist/esm/proxy.d.ts +20 -0
  92. package/dist/esm/proxy.d.ts.map +1 -0
  93. package/dist/esm/proxyId.d.ts +8 -0
  94. package/dist/esm/proxyId.d.ts.map +1 -0
  95. package/dist/esm/query-types.d.ts +62 -0
  96. package/dist/esm/query-types.d.ts.map +1 -0
  97. package/dist/esm/query.d.ts +86 -0
  98. package/dist/esm/query.d.ts.map +1 -0
  99. package/dist/esm/react/index.d.ts +2 -0
  100. package/dist/esm/react/index.d.ts.map +1 -0
  101. package/dist/esm/react/use-query.d.ts +5 -0
  102. package/dist/esm/react/use-query.d.ts.map +1 -0
  103. package/dist/esm/retry.d.ts +4 -0
  104. package/dist/esm/retry.d.ts.map +1 -0
  105. package/dist/esm/stores/async.d.ts +80 -0
  106. package/dist/esm/stores/async.d.ts.map +1 -0
  107. package/dist/esm/stores/shared.d.ts +12 -0
  108. package/dist/esm/stores/shared.d.ts.map +1 -0
  109. package/dist/esm/stores/sync.d.ts +41 -0
  110. package/dist/esm/stores/sync.d.ts.map +1 -0
  111. package/dist/esm/subscriptions/polling.d.ts +6 -0
  112. package/dist/esm/subscriptions/polling.d.ts.map +1 -0
  113. package/dist/esm/type-utils.d.ts +16 -0
  114. package/dist/esm/type-utils.d.ts.map +1 -0
  115. package/dist/esm/typeDefs.d.ts +86 -0
  116. package/dist/esm/typeDefs.d.ts.map +1 -0
  117. package/dist/esm/types.d.ts +272 -0
  118. package/dist/esm/types.d.ts.map +1 -0
  119. package/dist/esm/utils.d.ts +38 -0
  120. package/dist/esm/utils.d.ts.map +1 -0
  121. package/index.d.ts +1 -0
  122. package/package.json +134 -5
  123. package/stores/async.d.ts +1 -0
  124. package/stores/async.js +15 -0
  125. package/stores/sync.d.ts +1 -0
  126. package/stores/sync.js +15 -0
  127. package/index.js +0 -1
@@ -0,0 +1,2453 @@
1
+ import { notifier as at, relay as It, setScopeOwner as pe, reactiveMethod as ge, signal as Mt, context as Tt, getContext as ve, task as _e, reactiveSignal as me, isSignal as Ee } from "signalium";
2
+ import { registerCustomHash as we, hashValue as A } from "signalium/utils";
3
+ import { D as Ft } from "./shared-Dq2yW78d.js";
4
+ var q = /* @__PURE__ */ ((i) => (i.Always = "always", i.Online = "online", i.OfflineFirst = "offlineFirst", i))(q || {}), u = /* @__PURE__ */ ((i) => (i[i.UNDEFINED = 1] = "UNDEFINED", i[i.NULL = 2] = "NULL", i[i.NUMBER = 4] = "NUMBER", i[i.STRING = 8] = "STRING", i[i.BOOLEAN = 16] = "BOOLEAN", i[i.OBJECT = 32] = "OBJECT", i[i.ARRAY = 64] = "ARRAY", i[i.ID = 128] = "ID", i[i.RECORD = 256] = "RECORD", i[i.UNION = 512] = "UNION", i[i.ENTITY = 1024] = "ENTITY", i[i.HAS_FORMAT = 4096] = "HAS_FORMAT", i[i.IS_EAGER_FORMAT = 8192] = "IS_EAGER_FORMAT", i[i.PARSE_RESULT = 16384] = "PARSE_RESULT", i[i.LIVE = 32768] = "LIVE", i))(u || {});
5
+ const B = /* @__PURE__ */ Symbol("array"), Q = /* @__PURE__ */ Symbol("record"), kt = /* @__PURE__ */ Symbol("QUERY_ID");
6
+ var ct = /* @__PURE__ */ ((i) => (i[i.Array = 0] = "Array", i[i.Value = 1] = "Value", i))(ct || {});
7
+ class U {
8
+ type;
9
+ entityDefs;
10
+ constraintFieldRefs;
11
+ sort;
12
+ valueType;
13
+ onCreate;
14
+ onUpdate;
15
+ onDelete;
16
+ constructor(t, e, n, s, r, o, a, c) {
17
+ this.type = t, this.entityDefs = e, this.constraintFieldRefs = n, this.sort = s, this.valueType = r, this.onCreate = o, this.onUpdate = a, this.onDelete = c;
18
+ }
19
+ static array(t, e, n) {
20
+ return new U(
21
+ 0,
22
+ t,
23
+ e,
24
+ n,
25
+ void 0,
26
+ void 0,
27
+ void 0,
28
+ void 0
29
+ );
30
+ }
31
+ static value(t, e, n, s, r, o) {
32
+ return new U(
33
+ 1,
34
+ t,
35
+ e,
36
+ void 0,
37
+ n,
38
+ s,
39
+ r,
40
+ o
41
+ );
42
+ }
43
+ }
44
+ const O = /* @__PURE__ */ new WeakMap();
45
+ function F(i) {
46
+ return O.get(i);
47
+ }
48
+ var W = /* @__PURE__ */ ((i) => (i[i.Query = 0] = "Query", i[i.Entity = 1] = "Entity", i))(W || {});
49
+ class be {
50
+ constructor(t, e, n) {
51
+ this._onEvict = e, this._intervalId = setInterval(this._tick, t * 6e4 * n);
52
+ }
53
+ _currentFlush = /* @__PURE__ */ new Map();
54
+ _nextFlush = /* @__PURE__ */ new Map();
55
+ _intervalId;
56
+ schedule(t, e) {
57
+ this._nextFlush.set(t, e);
58
+ }
59
+ cancel(t) {
60
+ this._currentFlush.delete(t), this._nextFlush.delete(t);
61
+ }
62
+ _tick = () => {
63
+ const { _currentFlush: t, _nextFlush: e, _onEvict: n } = this;
64
+ for (const [s, r] of t)
65
+ n(s, r);
66
+ this._currentFlush = e, this._nextFlush = /* @__PURE__ */ new Map();
67
+ };
68
+ destroy() {
69
+ clearInterval(this._intervalId);
70
+ }
71
+ }
72
+ class Ce {
73
+ _buckets = /* @__PURE__ */ new Map();
74
+ _nextTickEntries = /* @__PURE__ */ new Map();
75
+ _nextTickScheduled = !1;
76
+ _onEvict;
77
+ _multiplier;
78
+ constructor(t, e = 1) {
79
+ this._onEvict = t, this._multiplier = e;
80
+ }
81
+ schedule(t, e, n) {
82
+ if (e === 1 / 0) return;
83
+ if (e === 0) {
84
+ const { _nextTickEntries: o } = this;
85
+ o.set(t, n), this._nextTickScheduled || (this._nextTickScheduled = !0, setTimeout(this._flushNextTick, 0));
86
+ return;
87
+ }
88
+ const { _buckets: s } = this;
89
+ let r = s.get(e);
90
+ r || (r = new be(e, this._onEvict, this._multiplier), s.set(e, r)), r.schedule(t, n);
91
+ }
92
+ cancel(t, e) {
93
+ if (e !== 1 / 0) {
94
+ if (e === 0) {
95
+ this._nextTickEntries.delete(t);
96
+ return;
97
+ }
98
+ this._buckets.get(e)?.cancel(t);
99
+ }
100
+ }
101
+ _flushNextTick = () => {
102
+ const { _nextTickEntries: t, _onEvict: e } = this;
103
+ this._nextTickScheduled = !1;
104
+ for (const [n, s] of t)
105
+ e(n, s);
106
+ t.clear();
107
+ };
108
+ destroy() {
109
+ const { _buckets: t, _nextTickEntries: e } = this;
110
+ for (const n of t.values())
111
+ n.destroy();
112
+ t.clear(), e.clear();
113
+ }
114
+ }
115
+ class xe {
116
+ schedule(t, e, n) {
117
+ }
118
+ cancel(t, e) {
119
+ }
120
+ destroy() {
121
+ }
122
+ }
123
+ const Y = /* @__PURE__ */ Symbol("fieldRef"), M = /* @__PURE__ */ Symbol("fieldRefPath"), ft = /* @__PURE__ */ Symbol("DEFINITION_TARGET"), G = /* @__PURE__ */ Symbol("CANCEL_PROXY"), Re = /\[([^\]]+)\]/g;
124
+ function Pt(i) {
125
+ const t = {
126
+ [Y]: !0,
127
+ [M]: i
128
+ };
129
+ return new Proxy(t, Oe);
130
+ }
131
+ const Oe = {
132
+ get(i, t) {
133
+ if (t === Y) return !0;
134
+ if (t === M) return i[M];
135
+ if (t === Symbol.toPrimitive || t === "toString" || t === "valueOf") {
136
+ const n = i[M];
137
+ return () => `[${n.join(".")}]`;
138
+ }
139
+ if (typeof t == "symbol") return;
140
+ const e = i[M];
141
+ return Pt([...e, t]);
142
+ },
143
+ has(i, t) {
144
+ return t === Y || t === M;
145
+ }
146
+ };
147
+ function Lt(i) {
148
+ return typeof i == "object" && i !== null && i[Y] === !0;
149
+ }
150
+ function jt(i) {
151
+ return i[M];
152
+ }
153
+ function qt(i) {
154
+ return new Proxy(i, {
155
+ set(t, e, n) {
156
+ return t[e] = n, !0;
157
+ },
158
+ get(t, e) {
159
+ return e === ft ? t : e === G ? () => {
160
+ } : typeof e == "symbol" ? t[e] : Pt([e]);
161
+ }
162
+ });
163
+ }
164
+ function Se(i) {
165
+ const t = i[ft];
166
+ i[G]();
167
+ const e = {};
168
+ for (const r of Object.getOwnPropertyNames(t))
169
+ e[r] = t[r];
170
+ const n = {};
171
+ let s = Object.getPrototypeOf(t);
172
+ for (; s && s !== Object.prototype; ) {
173
+ for (const r of Object.getOwnPropertyNames(s)) {
174
+ if (r === "constructor") continue;
175
+ const o = Object.getOwnPropertyDescriptor(s, r);
176
+ typeof o.value == "function" && !(r in n) && (n[r] = o.value);
177
+ }
178
+ s = Object.getPrototypeOf(s);
179
+ }
180
+ return { fields: e, methods: n };
181
+ }
182
+ function ut(i, t) {
183
+ let e = t;
184
+ for (const n of i) {
185
+ if (e == null) return;
186
+ e = e[n];
187
+ }
188
+ return e;
189
+ }
190
+ function Ne(i, t) {
191
+ return i.replace(Re, (e, n) => {
192
+ const s = n.split("."), r = ut(s, t);
193
+ return r != null ? encodeURIComponent(String(r)) : "";
194
+ });
195
+ }
196
+ function P(i, t) {
197
+ if (Lt(i))
198
+ return ut(jt(i), t);
199
+ if (typeof i == "string")
200
+ return Ne(i, t);
201
+ if (Array.isArray(i))
202
+ return i.map((e) => P(e, t));
203
+ if (typeof i == "object" && i !== null && Object.getPrototypeOf(i) === Object.prototype) {
204
+ const e = {};
205
+ for (const n of Object.keys(i))
206
+ e[n] = P(i[n], t);
207
+ return e;
208
+ }
209
+ return i;
210
+ }
211
+ function et(i, t, e) {
212
+ const n = i.fields, s = i.methods, r = { params: t }, o = {};
213
+ for (const [a, c] of Object.entries(n))
214
+ o[a] = P(c, r);
215
+ o.params = t, o.context = e;
216
+ for (const [a, c] of Object.entries(s))
217
+ o[a] = c.bind(o);
218
+ return o;
219
+ }
220
+ class Ut {
221
+ static cache;
222
+ constructor() {
223
+ return qt(this);
224
+ }
225
+ }
226
+ const Vt = Object.entries, it = Object.keys;
227
+ function Et(i) {
228
+ return typeof i == "number" ? i | u.UNDEFINED : i instanceof _ ? (i.mask & u.UNDEFINED) !== 0 ? i : _.cloneWith(i, u.UNDEFINED) : i;
229
+ }
230
+ function De(i) {
231
+ return i instanceof _ && (i.mask & u.OBJECT) !== 0 && (i.mask & (u.ENTITY | u.ARRAY | u.UNION | u.RECORD | u.LIVE)) === 0;
232
+ }
233
+ function Kt(i, t, e) {
234
+ const n = /* @__PURE__ */ new Set();
235
+ for (const r of i)
236
+ if (r !== void 0)
237
+ for (const o of Object.keys(r))
238
+ n.add(o);
239
+ const s = {};
240
+ for (const r of n) {
241
+ let o = 0, a;
242
+ const c = [];
243
+ let f = !0;
244
+ for (const l of i) {
245
+ const d = l?.[r];
246
+ d !== void 0 ? (o++, a === void 0 && (a = d), De(d) ? c.push(d.shape) : (f = !1, c.push(void 0))) : (f = !1, c.push(void 0));
247
+ }
248
+ if (f && o > 0) {
249
+ const l = Kt(c, t), d = new _(u.OBJECT, l);
250
+ s[r] = o < t ? Et(d) : d;
251
+ } else
252
+ s[r] = o < t ? Et(a) : a;
253
+ }
254
+ return s;
255
+ }
256
+ class _ {
257
+ mask;
258
+ shape;
259
+ typenameField = void 0;
260
+ typenameValue = void 0;
261
+ idField = void 0;
262
+ values = void 0;
263
+ /**
264
+ * Methods object for entity definitions.
265
+ * Shared across all proxies, but each proxy binds its own reactive method wrappers.
266
+ */
267
+ _methods = void 0;
268
+ /**
269
+ * Entity configuration including stream options.
270
+ */
271
+ _entityConfig = void 0;
272
+ /**
273
+ * The original Entity class for this definition.
274
+ * Used by createEntityProxy to set the proxy prototype so `instanceof` works.
275
+ */
276
+ _entityClass = void 0;
277
+ /**
278
+ * Entity cache options (e.g. gcTime for in-memory eviction).
279
+ */
280
+ _entityCache = void 0;
281
+ /**
282
+ * Live collection configuration (shared by LiveArray and LiveValue).
283
+ */
284
+ _liveConfig = void 0;
285
+ constructor(t, e, n, s, r, o) {
286
+ this.mask = t, this.shape = e, this.values = n, this.typenameField = s, this.typenameValue = r, this.idField = o;
287
+ }
288
+ static merge(t) {
289
+ if (t.length === 1) return t[0];
290
+ const e = t.length, n = t.map((c) => c.shape);
291
+ t[0].typenameValue;
292
+ const s = Kt(n, e);
293
+ let r, o, a;
294
+ for (const c of t) {
295
+ if (r === void 0 && c.idField !== void 0)
296
+ r = c.idField;
297
+ else if (r !== void 0 && c.idField !== void 0 && c.idField !== r)
298
+ throw new Error(
299
+ `[fetchium] Entity typename '${c.typenameValue}' has conflicting id fields: '${String(r)}' vs '${String(c.idField)}'`
300
+ );
301
+ o === void 0 && (o = c.typenameField), a === void 0 && (a = c.typenameValue);
302
+ }
303
+ return new _(
304
+ u.ENTITY | u.OBJECT,
305
+ s,
306
+ void 0,
307
+ o,
308
+ a,
309
+ r
310
+ );
311
+ }
312
+ static cloneWith(t, e) {
313
+ const n = new _(
314
+ e | t.mask,
315
+ t.shape,
316
+ t.values,
317
+ t.typenameField,
318
+ t.typenameValue,
319
+ t.idField
320
+ );
321
+ return n._methods = t._methods, n._entityConfig = t._entityConfig, n._entityClass = t._entityClass, n._entityCache = t._entityCache, n._liveConfig = t._liveConfig, n;
322
+ }
323
+ }
324
+ class H extends Set {
325
+ lowercaseMap;
326
+ // lowercase -> canonical (strings only)
327
+ constructor(t) {
328
+ super(t), this.lowercaseMap = /* @__PURE__ */ new Map();
329
+ for (const e of t)
330
+ if (typeof e == "string") {
331
+ const n = e.toLowerCase(), s = this.lowercaseMap.get(n);
332
+ if (s !== void 0)
333
+ throw new Error(
334
+ `Case-insensitive enum cannot have multiple values with the same lowercase form: '${s}' and '${e}' both become '${n}'`
335
+ );
336
+ this.lowercaseMap.set(n, e);
337
+ }
338
+ }
339
+ /**
340
+ * Check if a value exists in the set (case-insensitively for strings).
341
+ * Used for backwards compatibility with Set-based checks.
342
+ */
343
+ has(t) {
344
+ return this.get(t) !== void 0;
345
+ }
346
+ /**
347
+ * Get the canonical value for a given input.
348
+ * For strings, performs case-insensitive lookup and returns the canonical casing.
349
+ * For numbers/booleans, performs exact match.
350
+ * Returns undefined if no match is found.
351
+ */
352
+ get(t) {
353
+ if (typeof t == "string")
354
+ return this.lowercaseMap.get(t.toLowerCase());
355
+ if (super.has(t))
356
+ return t;
357
+ }
358
+ }
359
+ const Ae = 1128875347;
360
+ we(H, (i) => {
361
+ let t = Ae;
362
+ for (const e of i)
363
+ t += A(e);
364
+ return t >>> 0;
365
+ });
366
+ function dt(i, t) {
367
+ return new _(i, t);
368
+ }
369
+ function Ie(i) {
370
+ return dt(u.ARRAY, i);
371
+ }
372
+ function Me(i) {
373
+ return dt(u.RECORD | u.OBJECT, i);
374
+ }
375
+ function Te(i) {
376
+ return dt(u.PARSE_RESULT, i);
377
+ }
378
+ function $t(i, t) {
379
+ let e = i, n, s, r;
380
+ for (const [o, a] of Vt(t))
381
+ switch (typeof a) {
382
+ case "number":
383
+ if ((a & u.ID) !== 0) {
384
+ if (n !== void 0)
385
+ throw new Error(`Duplicate id field: ${o}`);
386
+ n = o;
387
+ }
388
+ break;
389
+ case "string":
390
+ if (s !== void 0 && s !== o)
391
+ throw new Error(`Duplicate typename field: ${o}`);
392
+ s = o, r = a;
393
+ break;
394
+ case "object":
395
+ if (a instanceof H || a instanceof Set)
396
+ break;
397
+ a.mask & u.LIVE && (e |= u.LIVE);
398
+ break;
399
+ }
400
+ return new _(e, t, void 0, s, r, n);
401
+ }
402
+ function Fe(i) {
403
+ return $t(u.OBJECT, i);
404
+ }
405
+ function wt(i, t, e) {
406
+ const n = i.mask;
407
+ if ((n & u.UNION) !== 0) {
408
+ const s = i;
409
+ if (s.typenameField !== void 0) {
410
+ if (e !== void 0 && e !== s.typenameField)
411
+ throw new Error(
412
+ `Union typename field conflict: Cannot merge unions with different typename fields ('${e}' vs '${s.typenameField}')`
413
+ );
414
+ e = s.typenameField;
415
+ }
416
+ const r = s.shape;
417
+ if (r !== void 0)
418
+ for (const o of [...it(r), B, Q]) {
419
+ const a = r[o];
420
+ if (t[o] !== void 0 && t[o] !== a)
421
+ throw new Error(
422
+ `Union merge conflict: Duplicate typename value '${String(o)}' found when merging nested unions (${String(t[o])} vs ${String(a)})`
423
+ );
424
+ t[o] = a;
425
+ }
426
+ } else if ((n & u.ARRAY) !== 0) {
427
+ if (t[B] !== void 0)
428
+ throw new Error("Array shape already defined");
429
+ t[B] = i.shape;
430
+ } else if ((n & u.RECORD) !== 0) {
431
+ if (t[Q] !== void 0)
432
+ throw new Error("Record shape already defined");
433
+ t[Q] = i.shape;
434
+ } else {
435
+ const s = i.typenameField, r = i.typenameValue;
436
+ if (r === void 0)
437
+ throw new Error(
438
+ "Object definitions must have a typename to be in a union with other objects, records, or arrays"
439
+ );
440
+ if (e !== void 0 && s !== e)
441
+ throw new Error("Object definitions must have the same typename field to be in the same union");
442
+ e = s, t[r] = i;
443
+ }
444
+ return e;
445
+ }
446
+ function lt(...i) {
447
+ const t = i;
448
+ let e = 0, n = 0, s, r, o, a, c = 0;
449
+ for (const l of t) {
450
+ if (typeof l == "number") {
451
+ e |= l;
452
+ continue;
453
+ }
454
+ if (l instanceof Set) {
455
+ if (r === void 0)
456
+ r = new Set(l);
457
+ else
458
+ for (const d of l)
459
+ r.add(d);
460
+ continue;
461
+ }
462
+ if (n++, c |= l.mask, n === 1) {
463
+ s = l;
464
+ continue;
465
+ }
466
+ n === 2 && (o = /* @__PURE__ */ Object.create(null), a = wt(s, o, a)), a = wt(l, o, a);
467
+ }
468
+ if (n === 0)
469
+ return r === void 0 ? e : e === 0 ? r : new _(e | u.UNION, void 0, r);
470
+ if (n === 1)
471
+ return _.cloneWith(s, e);
472
+ const f = e | c | u.UNION;
473
+ return new _(f, o, r, a);
474
+ }
475
+ function ht(i, t, e) {
476
+ const n = i;
477
+ if (typeof n == "number")
478
+ return n | t;
479
+ if (n instanceof Set)
480
+ return lt(i, t);
481
+ let s = e.get(n);
482
+ return s === void 0 && (s = _.cloneWith(n, t), e.set(n, s)), s;
483
+ }
484
+ const ke = /* @__PURE__ */ new WeakMap(), Pe = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap();
485
+ function je(i) {
486
+ return ht(i, u.UNDEFINED | u.NULL, Le);
487
+ }
488
+ function qe(i) {
489
+ return ht(i, u.UNDEFINED, ke);
490
+ }
491
+ function Ue(i) {
492
+ return ht(i, u.NULL, Pe);
493
+ }
494
+ function Ve(i) {
495
+ return i;
496
+ }
497
+ function Ke(i) {
498
+ return /* @__PURE__ */ new Set([i]);
499
+ }
500
+ const Bt = ((...i) => new Set(i));
501
+ Bt.caseInsensitive = (...i) => new H(i);
502
+ const Qt = 16;
503
+ let $e = 0;
504
+ const nt = [], Yt = [], Gt = /* @__PURE__ */ new Map(), z = /* @__PURE__ */ new WeakSet();
505
+ class V {
506
+ _raw;
507
+ _formatted;
508
+ _parsed;
509
+ _formatId;
510
+ constructor(t, e, n) {
511
+ this._raw = t, this._formatId = e, n ? (this._formatted = nt[e](t), this._parsed = !0) : this._parsed = !1, z.add(this);
512
+ }
513
+ getValue() {
514
+ return this._parsed || (this._formatted = nt[this._formatId](this._raw), this._parsed = !0), this._formatted;
515
+ }
516
+ toJSON() {
517
+ return this._parsed ? Yt[this._formatId](this._formatted) : this._raw;
518
+ }
519
+ }
520
+ function Be(i) {
521
+ const t = Gt.get(i);
522
+ if (t === void 0)
523
+ throw new Error(`Format ${i} not registered`);
524
+ return t;
525
+ }
526
+ function Wt(i, t, e, n, s) {
527
+ const r = $e++;
528
+ nt[r] = e, Yt[r] = n;
529
+ const o = s?.eager ?? !0, c = r << Qt | t | u.HAS_FORMAT | (o ? u.IS_EAGER_FORMAT : 0);
530
+ Gt.set(i, c);
531
+ }
532
+ Wt(
533
+ "date",
534
+ u.STRING,
535
+ (i) => {
536
+ const t = i.match(/^(\d{4})-(\d{2})-(\d{2})$/);
537
+ if (!t)
538
+ throw new Error(`Invalid date string: ${i}. Expected YYYY-MM-DD format.`);
539
+ const [, e, n, s] = t, r = new Date(Date.UTC(parseInt(e, 10), parseInt(n, 10) - 1, parseInt(s, 10)));
540
+ if (isNaN(r.getTime()))
541
+ throw new Error(`Invalid date string: ${i}`);
542
+ return r;
543
+ },
544
+ (i) => {
545
+ const t = i.getUTCFullYear(), e = String(i.getUTCMonth() + 1).padStart(2, "0"), n = String(i.getUTCDate()).padStart(2, "0");
546
+ return `${t}-${e}-${n}`;
547
+ }
548
+ );
549
+ Wt(
550
+ "date-time",
551
+ u.STRING,
552
+ (i) => {
553
+ const t = new Date(i);
554
+ if (isNaN(t.getTime()))
555
+ throw new Error(`Invalid date-time string: ${i}`);
556
+ return t;
557
+ },
558
+ (i) => i.toISOString()
559
+ );
560
+ const bt = /* @__PURE__ */ new WeakMap();
561
+ function L(i) {
562
+ let t = bt.get(i);
563
+ if (t === void 0) {
564
+ const e = new i(), n = e[ft] ?? e;
565
+ e[G] && e[G]();
566
+ const s = {};
567
+ for (const [f, l] of Vt(n))
568
+ s[f] = l;
569
+ const r = Object.getPrototypeOf(i.prototype);
570
+ if (r != null) {
571
+ const f = r.constructor;
572
+ if (f !== Ut && typeof f == "function") {
573
+ const d = L(f).shape;
574
+ for (const y of it(d))
575
+ if (y in s && s[y] !== d[y])
576
+ throw new Error(`Cannot extend: field '${y}' already exists in type definition`);
577
+ }
578
+ }
579
+ const o = {}, a = i.prototype;
580
+ for (const f of Object.getOwnPropertyNames(a))
581
+ f !== "constructor" && typeof a[f] == "function" && (o[f] = a[f]);
582
+ t = $t(u.ENTITY | u.OBJECT, s), t._entityClass = i, it(o).length > 0 && (t._methods = o), typeof o.__subscribe == "function" && (t._entityConfig = { hasSubscribe: !0 });
583
+ const c = i;
584
+ c.cache && (t._entityCache = c.cache), bt.set(i, t);
585
+ }
586
+ return t;
587
+ }
588
+ function Qe(i) {
589
+ return L(i);
590
+ }
591
+ function Ht(i, t) {
592
+ if (t == null) return;
593
+ const e = /* @__PURE__ */ new Map();
594
+ if (Array.isArray(t))
595
+ for (const n of t) {
596
+ const [s, r] = n, a = L(s).typenameValue;
597
+ if (a === void 0) continue;
598
+ const c = [];
599
+ for (const [f, l] of Object.entries(r))
600
+ c.push([f, l]);
601
+ c.length > 0 && e.set(a, c);
602
+ }
603
+ else {
604
+ const s = Object.entries(t);
605
+ if (s.length === 0) return;
606
+ const r = s.map(([o, a]) => [o, a]);
607
+ for (const o of i) {
608
+ const a = o.typenameValue;
609
+ a !== void 0 && e.set(a, r);
610
+ }
611
+ }
612
+ return e.size > 0 ? e : void 0;
613
+ }
614
+ function zt(i) {
615
+ return Array.isArray(i) ? i.map((t) => L(t)) : [L(i)];
616
+ }
617
+ function Ye(i, t) {
618
+ const e = zt(i), n = e.length === 1 ? e[0] : lt(...e.map((o) => o)), s = u.ARRAY | u.LIVE, r = new _(s, n);
619
+ return r._liveConfig = U.array(
620
+ e,
621
+ Ht(e, t?.constraints),
622
+ t?.sort
623
+ ), r;
624
+ }
625
+ function Ge(i, t, e) {
626
+ const n = zt(t), s = i, r = u.LIVE, o = new _(r, void 0);
627
+ return o._liveConfig = U.value(
628
+ n,
629
+ Ht(n, e?.constraints),
630
+ s,
631
+ e.onCreate,
632
+ e.onUpdate,
633
+ e.onDelete
634
+ ), o;
635
+ }
636
+ const We = {
637
+ format: Be,
638
+ typename: Ve,
639
+ const: Ke,
640
+ enum: Bt,
641
+ id: u.ID | u.STRING | u.NUMBER,
642
+ string: u.STRING,
643
+ number: u.NUMBER,
644
+ boolean: u.BOOLEAN,
645
+ null: u.NULL,
646
+ undefined: u.UNDEFINED,
647
+ array: Ie,
648
+ object: Fe,
649
+ record: Me,
650
+ union: lt,
651
+ nullish: je,
652
+ optional: qe,
653
+ nullable: Ue,
654
+ result: Te,
655
+ entity: Qe,
656
+ liveArray: Ye,
657
+ liveValue: Ge
658
+ };
659
+ function j(i, t, e) {
660
+ return new TypeError(`Validation error at ${i}`);
661
+ }
662
+ const Jt = Array.isArray;
663
+ function Ct(i) {
664
+ if (i === null) return u.NULL;
665
+ switch (typeof i) {
666
+ case "number":
667
+ return u.NUMBER;
668
+ case "string":
669
+ return u.STRING;
670
+ case "boolean":
671
+ return u.BOOLEAN;
672
+ case "undefined":
673
+ return u.UNDEFINED;
674
+ case "object":
675
+ return Jt(i) ? u.ARRAY : u.OBJECT;
676
+ default:
677
+ throw new Error(`Invalid type: ${typeof i}`);
678
+ }
679
+ }
680
+ function Ri(i) {
681
+ return k(i);
682
+ }
683
+ function k(i) {
684
+ if (i === null || typeof i != "object")
685
+ return i;
686
+ if (Jt(i))
687
+ return i.map((e) => k(e));
688
+ if (i instanceof Date)
689
+ return new Date(i.getTime());
690
+ if (i instanceof Map) {
691
+ const e = /* @__PURE__ */ new Map();
692
+ for (const [n, s] of i)
693
+ e.set(k(n), k(s));
694
+ return e;
695
+ }
696
+ if (i instanceof Set) {
697
+ const e = /* @__PURE__ */ new Set();
698
+ for (const n of i)
699
+ e.add(k(n));
700
+ return e;
701
+ }
702
+ const t = {};
703
+ for (const e of Object.keys(i))
704
+ t[e] = k(i[e]);
705
+ return t;
706
+ }
707
+ const yt = Object.entries, He = () => {
708
+ };
709
+ class st {
710
+ queryClient = void 0;
711
+ preloadedEntities = void 0;
712
+ warn = He;
713
+ /** When true, missing optional fields on existing entities are set to
714
+ * undefined. False for mutation events (truly partial payloads). */
715
+ isPartialEvent = !1;
716
+ seen = void 0;
717
+ seenByKey = void 0;
718
+ reset(t, e, n, s = !1) {
719
+ this.queryClient = t, this.preloadedEntities = e, this.warn = n, this.isPartialEvent = s, t !== void 0 && (this.seen === void 0 ? (this.seen = /* @__PURE__ */ new Map(), this.seenByKey = /* @__PURE__ */ new Map()) : (this.seen.clear(), this.seenByKey.clear()));
720
+ }
721
+ }
722
+ function Xt(i, t, e) {
723
+ return T(i, t, e, "");
724
+ }
725
+ function ze(i, t, e) {
726
+ return pt(i, t, e);
727
+ }
728
+ function xt(i, t, e, n) {
729
+ const s = i >> Qt;
730
+ if ((i & u.IS_EAGER_FORMAT) !== 0)
731
+ try {
732
+ return new V(t, s, !0);
733
+ } catch (o) {
734
+ if ((i & u.UNDEFINED) !== 0) {
735
+ e.warn("Invalid formatted value for optional type, defaulting to undefined", {
736
+ value: t,
737
+ path: n,
738
+ error: o instanceof Error ? o.message : String(o)
739
+ });
740
+ return;
741
+ }
742
+ throw o;
743
+ }
744
+ return new V(t, s, !1);
745
+ }
746
+ function T(i, t, e, n) {
747
+ const s = t;
748
+ if (s instanceof H) {
749
+ const c = s.get(i);
750
+ if (c === void 0) throw j(n);
751
+ return c;
752
+ }
753
+ if (s instanceof Set) {
754
+ if (!s.has(i)) throw j(n);
755
+ return i;
756
+ }
757
+ if (typeof s == "string") {
758
+ if (i == null) return s;
759
+ if (i !== s) throw j(n);
760
+ return i;
761
+ }
762
+ if (typeof s == "number") {
763
+ const c = Ct(i);
764
+ if ((s & c) === 0) {
765
+ if ((s & u.UNDEFINED) !== 0) {
766
+ e.warn("Invalid value for optional type, defaulting to undefined", { value: i, path: n });
767
+ return;
768
+ }
769
+ throw j(n);
770
+ }
771
+ return (s & u.HAS_FORMAT) !== 0 && i !== null && i !== void 0 ? xt(s, i, e, n) : i;
772
+ }
773
+ const r = s.mask, o = s._liveConfig;
774
+ if (o !== void 0 && o.type === ct.Value)
775
+ return o.valueType !== void 0 ? T(i, o.valueType, e, n) : i;
776
+ if ((r & u.PARSE_RESULT) !== 0)
777
+ try {
778
+ return { success: !0, value: T(i, s.shape, e, n) };
779
+ } catch (c) {
780
+ return { success: !1, error: c instanceof Error ? c : new Error(String(c)) };
781
+ }
782
+ const a = Ct(i);
783
+ if ((r & a) === 0 && !s.values?.has(i)) {
784
+ if ((r & u.UNDEFINED) !== 0) {
785
+ e.warn("Invalid value for optional type, defaulting to undefined", { value: i, path: n });
786
+ return;
787
+ }
788
+ throw j(n);
789
+ }
790
+ return a < u.OBJECT ? (r & u.HAS_FORMAT) !== 0 && i !== null && i !== void 0 ? xt(r, i, e, n) : i : (r & u.UNION) !== 0 ? Je(a, i, s, e, n) : a === u.ARRAY ? Zt(i, s.shape, e, n) : (r & u.RECORD) !== 0 ? te(i, s.shape, e, n) : (r & u.ENTITY) !== 0 && e.queryClient !== void 0 ? pt(i, s, e) : ee(i, s, e, n);
791
+ }
792
+ function Je(i, t, e, n, s) {
793
+ if (i === u.ARRAY) {
794
+ const r = e.shape[B];
795
+ return r === void 0 || typeof r == "number" ? t : Zt(t, r, n, s);
796
+ } else {
797
+ const r = e.typenameField, o = r ? t[r] : void 0;
798
+ if (o === void 0 || typeof o != "string") {
799
+ const c = e.shape[Q];
800
+ if (c === void 0)
801
+ throw new Error(
802
+ `Typename field '${r}' is required for union discrimination but was not found in the data`
803
+ );
804
+ return te(t, c, n, s);
805
+ }
806
+ const a = e.shape[o];
807
+ if (a === void 0 || typeof a == "number")
808
+ throw new Error(`Unknown typename '${o}' in union`);
809
+ return a.mask & u.ENTITY && n.queryClient !== void 0 ? pt(t, a, n) : ee(t, a, n, s);
810
+ }
811
+ }
812
+ function Zt(i, t, e, n) {
813
+ const s = [];
814
+ for (let r = 0; r < i.length; r++)
815
+ try {
816
+ s.push(T(i[r], t, e, `${n}[${r}]`));
817
+ } catch (o) {
818
+ e.warn("Failed to parse array item, filtering out", {
819
+ index: r,
820
+ value: i[r],
821
+ error: o instanceof Error ? o.message : String(o)
822
+ });
823
+ }
824
+ return s;
825
+ }
826
+ function te(i, t, e, n) {
827
+ for (const [s, r] of yt(i))
828
+ i[s] = T(r, t, e, `${n}["${s}"]`);
829
+ return i;
830
+ }
831
+ function ee(i, t, e, n) {
832
+ if (O.has(i))
833
+ return i;
834
+ const s = t.shape;
835
+ for (const [r, o] of yt(s))
836
+ i[r] = T(i[r], o, e, `${n}.${r}`);
837
+ return i;
838
+ }
839
+ function pt(i, t, e) {
840
+ const n = e.queryClient, s = e.preloadedEntities;
841
+ let r, o;
842
+ if (s !== void 0)
843
+ r = i.__entityRef, o = r;
844
+ else {
845
+ const p = i[t.idField];
846
+ if (p == null || typeof p != "string" && typeof p != "number")
847
+ throw new Error(`Entity id must be a string or number: ${t.typenameValue} (got ${typeof p})`);
848
+ o = p, r = A([t.typenameValue, o]);
849
+ }
850
+ const a = e.seenByKey.get(r);
851
+ if (a !== void 0)
852
+ return a.data;
853
+ if (s !== void 0) {
854
+ const g = n.entityMap.getEntity(r)?.data ?? s.get(r);
855
+ if (g === void 0)
856
+ throw new Error(`Cached entity ${r} not found in preloaded map`);
857
+ i = g;
858
+ }
859
+ const c = {};
860
+ typeof t.idField == "symbol" && (c[t.idField] = o);
861
+ const f = n.entityMap.getEntity(r), l = e.isPartialEvent && f !== void 0, d = {
862
+ key: r,
863
+ shape: t,
864
+ data: c,
865
+ rawKeys: l ? new Set(Object.keys(i)) : void 0
866
+ };
867
+ e.seen.set(c, d), e.seenByKey.set(r, d);
868
+ const y = `[[${t.typenameValue}:${o}]]`, v = t.shape;
869
+ for (const [p, g] of yt(v))
870
+ l && !(p in i) || (c[p] = T(i[p], g, e, `${y}.${p}`));
871
+ return c;
872
+ }
873
+ function Xe(i, t) {
874
+ return Ze(i, t.shape, t.typenameField);
875
+ }
876
+ function Ze(i, t, e) {
877
+ if (t === void 0) return !0;
878
+ for (const n of Object.keys(t)) {
879
+ if (n === e) continue;
880
+ const s = t[n];
881
+ if (s instanceof _) {
882
+ if ((s.mask & u.UNDEFINED) !== 0) continue;
883
+ if (!(n in i) || i[n] === void 0) return !1;
884
+ } else if (typeof s == "number") {
885
+ if ((s & u.UNDEFINED) !== 0) continue;
886
+ if (!(n in i) || i[n] === void 0) return !1;
887
+ } else if (!(n in i) || i[n] === void 0) return !1;
888
+ }
889
+ return !0;
890
+ }
891
+ const ti = Object.prototype, $ = /* @__PURE__ */ new WeakMap();
892
+ function D(i) {
893
+ if (typeof i != "object" || i === null) return i;
894
+ if (z.has(i)) return D(i.getValue());
895
+ if (O.has(i)) return i;
896
+ if (Array.isArray(i)) {
897
+ let t = $.get(i);
898
+ return t === void 0 && (t = new Proxy(i, ei), $.set(i, t)), t;
899
+ }
900
+ if (Object.getPrototypeOf(i) === ti) {
901
+ let t = $.get(i);
902
+ return t === void 0 && (t = new Proxy(i, ii), $.set(i, t)), t;
903
+ }
904
+ return i;
905
+ }
906
+ const ei = {
907
+ get(i, t, e) {
908
+ if (typeof t == "string") {
909
+ const n = Number(t);
910
+ if (Number.isInteger(n) && n >= 0 && n < i.length)
911
+ return D(i[n]);
912
+ }
913
+ return Reflect.get(i, t, e);
914
+ },
915
+ set() {
916
+ return !1;
917
+ },
918
+ deleteProperty() {
919
+ return !1;
920
+ }
921
+ }, ii = {
922
+ get(i, t, e) {
923
+ return typeof t == "string" ? D(i[t]) : Reflect.get(i, t, e);
924
+ },
925
+ set() {
926
+ return !1;
927
+ },
928
+ deleteProperty() {
929
+ return !1;
930
+ },
931
+ has(i, t) {
932
+ return t in i;
933
+ },
934
+ ownKeys(i) {
935
+ return Reflect.ownKeys(i);
936
+ },
937
+ getOwnPropertyDescriptor(i, t) {
938
+ return Object.getOwnPropertyDescriptor(i, t);
939
+ }
940
+ };
941
+ class ni {
942
+ _notifier;
943
+ _queryClient;
944
+ _proxies = /* @__PURE__ */ new Map();
945
+ key;
946
+ typename;
947
+ id;
948
+ idField;
949
+ data;
950
+ refCount = 0;
951
+ entityRefs;
952
+ liveCollections = [];
953
+ satisfiedDefs = /* @__PURE__ */ new WeakSet();
954
+ parseId = -1;
955
+ _entityCache;
956
+ _extraMethods;
957
+ _extraGetters;
958
+ constructor(t, e, n, s, r, o) {
959
+ this._notifier = at(), this._queryClient = o, this.key = t, this.typename = e, this.id = n, this.idField = s, this.data = r, this.entityRefs = void 0;
960
+ }
961
+ retain() {
962
+ this.refCount++;
963
+ const t = this._entityCache?.gcTime;
964
+ t !== void 0 && this._queryClient.gcManager.cancel(this.key, t);
965
+ }
966
+ release() {
967
+ if (--this.refCount > 0 || this.refCount < 0)
968
+ return;
969
+ const t = this._entityCache?.gcTime;
970
+ t !== void 0 ? this._queryClient.gcManager.schedule(this.key, t, W.Entity) : this.evict();
971
+ }
972
+ evict() {
973
+ const t = this.liveCollections.slice();
974
+ this.liveCollections.length = 0;
975
+ for (const n of t) n.destroy();
976
+ this._queryClient.entityMap.remove(this.key);
977
+ const e = this.entityRefs;
978
+ if (this.entityRefs = void 0, e)
979
+ for (const n of e.keys()) n.release();
980
+ }
981
+ setChildRefs(t, e) {
982
+ const n = this.entityRefs;
983
+ if (t !== void 0 && t.size > 0)
984
+ for (const s of t.keys())
985
+ (n === void 0 || !n.has(s)) && s.retain();
986
+ if (n !== void 0 && n.size > 0)
987
+ for (const s of n.keys())
988
+ (t === void 0 || !t.has(s)) && s.release();
989
+ this.entityRefs = t, e && this.save();
990
+ }
991
+ addChildRef(t) {
992
+ this.entityRefs === void 0 && (this.entityRefs = /* @__PURE__ */ new Map());
993
+ const e = this.entityRefs.get(t) ?? 0;
994
+ this.entityRefs.set(t, e + 1), e === 0 && t.retain(), this.save();
995
+ }
996
+ removeChildRef(t) {
997
+ if (this.entityRefs === void 0) return;
998
+ const e = this.entityRefs.get(t);
999
+ e !== void 0 && (e <= 1 ? (this.entityRefs.delete(t), t.release()) : this.entityRefs.set(t, e - 1), this.save());
1000
+ }
1001
+ getProxy(t) {
1002
+ const e = t;
1003
+ let n = this._proxies.get(e);
1004
+ return n === void 0 && (n = ri(this, this.key, t, this._notifier, this._queryClient), this._proxies.set(e, n)), n;
1005
+ }
1006
+ get proxy() {
1007
+ return this._proxies.values().next().value;
1008
+ }
1009
+ satisfiesDef(t) {
1010
+ return this.satisfiedDefs.has(t) ? !0 : Xe(this.data, t) ? (this.satisfiedDefs.add(t), !0) : !1;
1011
+ }
1012
+ save() {
1013
+ this._queryClient.entityMap.save(this);
1014
+ }
1015
+ notify() {
1016
+ this._notifier.notify();
1017
+ }
1018
+ consume() {
1019
+ this._notifier.consume();
1020
+ }
1021
+ }
1022
+ function si(i, t, e) {
1023
+ const n = [];
1024
+ for (const s of i) {
1025
+ if (typeof s != "object" || s === null) continue;
1026
+ const r = O.get(s);
1027
+ if (r === void 0) continue;
1028
+ const o = e.entityMap.getEntity(r);
1029
+ o !== void 0 && o.satisfiesDef(t) && n.push(s);
1030
+ }
1031
+ return n;
1032
+ }
1033
+ function ri(i, t, e, n, s) {
1034
+ const r = e.shape ?? {}, o = e, a = o._methods, c = o._entityClass, f = o._entityConfig, l = c ? c.prototype : Ut.prototype;
1035
+ e.typenameField;
1036
+ const d = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), v = () => ({ __entityRef: t });
1037
+ let p;
1038
+ f?.hasSubscribe && a && "__subscribe" in a && (p = It((w) => {
1039
+ const h = (b) => {
1040
+ b.__eventSource = t, s.applyMutationEvent(b);
1041
+ }, m = a.__subscribe.call(g, h);
1042
+ return w.value = g, m;
1043
+ }));
1044
+ let g;
1045
+ const E = Object.keys(r);
1046
+ if (E.includes("__typename") || E.push("__typename"), a)
1047
+ for (const w of Object.keys(a))
1048
+ E.includes(w) || E.push(w);
1049
+ let S, C = E;
1050
+ function I() {
1051
+ const w = i._extraMethods;
1052
+ if (w !== S) {
1053
+ if (S = w, C = E.slice(), w !== void 0)
1054
+ for (const m of Object.keys(w))
1055
+ C.includes(m) || C.push(m);
1056
+ const h = i._extraGetters;
1057
+ if (h !== void 0)
1058
+ for (const m of Object.keys(h))
1059
+ C.includes(m) || C.push(m);
1060
+ }
1061
+ return C;
1062
+ }
1063
+ const x = {
1064
+ getPrototypeOf() {
1065
+ return l;
1066
+ },
1067
+ get(w, h) {
1068
+ if (typeof h == "symbol") return;
1069
+ if (h === "toJSON") return v;
1070
+ if (h === "__context") return s.getContext();
1071
+ if (h === "__typename") return i.typename;
1072
+ if (p?.value, n.consume(), typeof h == "string") {
1073
+ const b = i._extraGetters;
1074
+ if (b !== void 0 && h in b)
1075
+ return b[h]();
1076
+ const N = i._extraMethods;
1077
+ if (N !== void 0 && h in N) {
1078
+ let R = d.get(h);
1079
+ return R || (R = N[h].bind(g), d.set(h, R)), R;
1080
+ }
1081
+ if (a && h in a) {
1082
+ let R = d.get(h);
1083
+ return R || (R = ge(g, a[h].bind(g)), d.set(h, R)), R;
1084
+ }
1085
+ }
1086
+ const m = i.data[h];
1087
+ if (typeof m == "object" && m !== null && z.has(m))
1088
+ return D(m.getValue());
1089
+ if (Array.isArray(m) && typeof h == "string") {
1090
+ const b = r[h];
1091
+ if (b instanceof _ && (b.mask & u.ARRAY) !== 0) {
1092
+ const N = b.shape;
1093
+ if (N instanceof _ && (N.mask & u.ENTITY) !== 0) {
1094
+ const R = N.typenameValue;
1095
+ if (R !== void 0) {
1096
+ const _t = s.getEntityDefsForTypename(R);
1097
+ if (_t !== void 0 && _t.length > 1) {
1098
+ const X = y.get(h);
1099
+ if (X !== void 0 && X.source === m)
1100
+ return D(X.filtered);
1101
+ const mt = si(m, N, s);
1102
+ return y.set(h, { source: m, filtered: mt }), D(mt);
1103
+ }
1104
+ }
1105
+ }
1106
+ }
1107
+ return D(m);
1108
+ }
1109
+ return D(m);
1110
+ },
1111
+ set() {
1112
+ return !1;
1113
+ },
1114
+ has(w, h) {
1115
+ if (h === "__typename") return !0;
1116
+ if (typeof h == "string") {
1117
+ const m = i._extraGetters;
1118
+ if (m && h in m) return !0;
1119
+ const b = i._extraMethods;
1120
+ if (b && h in b || a && h in a) return !0;
1121
+ }
1122
+ return h in r;
1123
+ },
1124
+ ownKeys() {
1125
+ return I();
1126
+ },
1127
+ getOwnPropertyDescriptor(w, h) {
1128
+ if (h === "__typename")
1129
+ return { enumerable: !0, configurable: !0, value: i.typename, writable: !1 };
1130
+ if (h in r)
1131
+ return { enumerable: !0, configurable: !0, value: x.get(w, h, g), writable: !1 };
1132
+ if (typeof h == "string") {
1133
+ const m = i._extraGetters;
1134
+ if (m && h in m)
1135
+ return { enumerable: !0, configurable: !0, value: x.get(w, h, g), writable: !1 };
1136
+ const b = i._extraMethods;
1137
+ if (b && h in b)
1138
+ return { enumerable: !0, configurable: !0, value: x.get(w, h, g), writable: !1 };
1139
+ if (a && h in a)
1140
+ return { enumerable: !1, configurable: !0, value: x.get(w, h, g), writable: !1 };
1141
+ }
1142
+ }
1143
+ };
1144
+ return g = new Proxy({}, x), O.set(g, t), pe(g, s), g;
1145
+ }
1146
+ class oi {
1147
+ instances = /* @__PURE__ */ new Map();
1148
+ persistEntity;
1149
+ constructor(t) {
1150
+ this.persistEntity = t;
1151
+ }
1152
+ hasEntity(t) {
1153
+ return this.instances.has(t);
1154
+ }
1155
+ getEntity(t) {
1156
+ return this.instances.get(t);
1157
+ }
1158
+ getOrCreateEntity(t, e, n, s) {
1159
+ let r = this.instances.get(t);
1160
+ if (r === void 0) {
1161
+ const o = n.idField;
1162
+ if (o === void 0)
1163
+ throw new Error(`Entity id field is required ${n.typenameValue}`);
1164
+ const a = e[o];
1165
+ if (typeof a != "string" && typeof a != "number")
1166
+ throw new Error(`Entity id must be string or number: ${n.typenameValue}`);
1167
+ const c = n;
1168
+ r = new ni(t, n.typenameValue, a, o, e, s), r._entityCache = c._entityCache, this.instances.set(t, r);
1169
+ }
1170
+ return r.parseId = s.currentParseId, r;
1171
+ }
1172
+ remove(t) {
1173
+ this.instances.delete(t);
1174
+ }
1175
+ save(t) {
1176
+ let e;
1177
+ if (t.entityRefs) {
1178
+ e = /* @__PURE__ */ new Set();
1179
+ for (const n of t.entityRefs.keys()) e.add(n.key);
1180
+ }
1181
+ this.persistEntity(t.key, t.data, e);
1182
+ }
1183
+ }
1184
+ class ie {
1185
+ onlineSignal;
1186
+ manualOverride = void 0;
1187
+ eventListenersAttached = !1;
1188
+ constructor(t) {
1189
+ const e = t ?? this.detectOnlineStatus();
1190
+ this.onlineSignal = Mt(e), this.canAttachListeners() && this.attachEventListeners();
1191
+ }
1192
+ /**
1193
+ * Returns true if the network is currently online
1194
+ */
1195
+ get isOnline() {
1196
+ return this.manualOverride !== void 0 ? this.manualOverride : this.onlineSignal.value;
1197
+ }
1198
+ /**
1199
+ * Manually set the network status (useful for testing)
1200
+ */
1201
+ setNetworkStatus(t) {
1202
+ this.manualOverride = t, this.onlineSignal.value = t;
1203
+ }
1204
+ /**
1205
+ * Clear manual override and return to automatic detection
1206
+ */
1207
+ clearManualOverride() {
1208
+ this.manualOverride = void 0, this.onlineSignal.value = this.detectOnlineStatus();
1209
+ }
1210
+ /**
1211
+ * Get the reactive signal for online status
1212
+ * This allows reactive functions to depend on network status
1213
+ */
1214
+ getOnlineSignal() {
1215
+ return this.onlineSignal;
1216
+ }
1217
+ /**
1218
+ * Detect current online status from the environment
1219
+ */
1220
+ detectOnlineStatus() {
1221
+ return typeof navigator < "u" && "onLine" in navigator ? navigator.onLine : !0;
1222
+ }
1223
+ /**
1224
+ * Check if we can attach event listeners (browser or React Native)
1225
+ */
1226
+ canAttachListeners() {
1227
+ return typeof window < "u" && typeof window.addEventListener == "function";
1228
+ }
1229
+ /**
1230
+ * Remove event listeners and clean up resources.
1231
+ */
1232
+ destroy() {
1233
+ this.eventListenersAttached && this.handleOnline && this.handleOffline && (window.removeEventListener("online", this.handleOnline), window.removeEventListener("offline", this.handleOffline), this.eventListenersAttached = !1);
1234
+ }
1235
+ handleOnline = void 0;
1236
+ handleOffline = void 0;
1237
+ /**
1238
+ * Attach event listeners for online/offline events
1239
+ */
1240
+ attachEventListeners() {
1241
+ this.eventListenersAttached || (this.handleOnline = () => {
1242
+ this.manualOverride === void 0 && (this.onlineSignal.value = !0);
1243
+ }, this.handleOffline = () => {
1244
+ this.manualOverride === void 0 && (this.onlineSignal.value = !1);
1245
+ }, window.addEventListener("online", this.handleOnline), window.addEventListener("offline", this.handleOffline), this.eventListenersAttached = !0);
1246
+ }
1247
+ }
1248
+ class ne {
1249
+ static onlineSignal = Mt(!0);
1250
+ get isOnline() {
1251
+ return !0;
1252
+ }
1253
+ setNetworkStatus(t) {
1254
+ }
1255
+ clearManualOverride() {
1256
+ }
1257
+ getOnlineSignal() {
1258
+ return ne.onlineSignal;
1259
+ }
1260
+ destroy() {
1261
+ }
1262
+ }
1263
+ const ai = new ie(), Oi = Tt(ai);
1264
+ function gt(i, t = typeof window > "u") {
1265
+ let e;
1266
+ i === !1 ? e = 0 : i === void 0 || i === !0 ? e = t ? 0 : 3 : typeof i == "number" ? e = i : e = i.retries;
1267
+ const n = typeof i == "object" && i.retryDelay ? i.retryDelay : (s) => 1e3 * Math.pow(2, s);
1268
+ return { retries: e, retryDelay: n };
1269
+ }
1270
+ class ci {
1271
+ static cache;
1272
+ params;
1273
+ config;
1274
+ constructor() {
1275
+ return qt(this);
1276
+ }
1277
+ }
1278
+ class Si extends ci {
1279
+ method = "GET";
1280
+ path;
1281
+ searchParams;
1282
+ body;
1283
+ headers;
1284
+ requestOptions;
1285
+ loadNext;
1286
+ getStorageKey() {
1287
+ return `${this.method ?? "GET"}:${this.path ?? ""}`;
1288
+ }
1289
+ async send() {
1290
+ return this.executeRequest();
1291
+ }
1292
+ resolveLoadNext() {
1293
+ const e = (this.getLoadNext ? this.getLoadNext() : void 0) ?? this.rawLoadNext;
1294
+ if (e === void 0) return;
1295
+ const n = {
1296
+ params: this.params ?? {},
1297
+ result: this.resultData
1298
+ };
1299
+ return {
1300
+ url: e.url !== void 0 ? P(e.url, n) : void 0,
1301
+ searchParams: e.searchParams !== void 0 ? P(e.searchParams, n) : void 0
1302
+ };
1303
+ }
1304
+ hasNext() {
1305
+ const t = this.resolveLoadNext();
1306
+ if (t === void 0) return !1;
1307
+ if (t.url !== void 0 && t.url !== null)
1308
+ return !0;
1309
+ if (t.searchParams !== void 0) {
1310
+ const e = Object.keys(t.searchParams);
1311
+ if (e.length === 0) return !1;
1312
+ for (const n of e)
1313
+ if (t.searchParams[n] === void 0 || t.searchParams[n] === null)
1314
+ return !1;
1315
+ return !0;
1316
+ }
1317
+ return !1;
1318
+ }
1319
+ async sendNext() {
1320
+ const t = this.resolveLoadNext();
1321
+ if (t === void 0)
1322
+ throw new Error("loadNext is not configured for this query");
1323
+ return this.executeRequest(t);
1324
+ }
1325
+ async executeRequest(t) {
1326
+ const e = t?.url ?? (this.getPath ? this.getPath() : this.path), n = this.getMethod ? this.getMethod() : this.method, s = this.getSearchParams ? this.getSearchParams() : this.searchParams, r = t?.searchParams ? { ...s, ...t.searchParams } : s, o = this.getBody ? this.getBody() : this.body, a = this.getRequestOptions ? this.getRequestOptions() : this.requestOptions;
1327
+ if (!e)
1328
+ throw new Error("RESTQuery requires a path. Define `path` as a field or override `getPath()`.");
1329
+ let c = e;
1330
+ if (r) {
1331
+ const S = new URLSearchParams();
1332
+ for (const I in r) {
1333
+ const x = r[I];
1334
+ x != null && S.append(I, String(x));
1335
+ }
1336
+ const C = S.toString();
1337
+ C && (c += "?" + C);
1338
+ }
1339
+ const f = Dt(a?.baseUrl) ?? Dt(this.context.baseUrl), l = f ? `${f}${c}` : c, { baseUrl: d, signal: y, ...v } = a ?? {}, g = o || this.headers ? {
1340
+ ...o ? { "Content-Type": "application/json" } : void 0,
1341
+ ...this.headers
1342
+ } : void 0, E = await this.context.fetch(l, {
1343
+ method: n,
1344
+ headers: g,
1345
+ body: o ? JSON.stringify(o) : void 0,
1346
+ signal: this.signal,
1347
+ ...v
1348
+ });
1349
+ return this.response = E, E.json();
1350
+ }
1351
+ }
1352
+ const Rt = /* @__PURE__ */ new WeakMap();
1353
+ class J {
1354
+ constructor(t, e) {
1355
+ this.captured = e, this.statics = t;
1356
+ }
1357
+ statics;
1358
+ createExecutionContext(t, e) {
1359
+ return et(this.captured, t, e);
1360
+ }
1361
+ resolveOptions(t) {
1362
+ const { methods: e } = this.captured, n = e.getConfig ? e.getConfig.call(t) : t.config, s = gt(n?.retry);
1363
+ return { config: n, retryConfig: s };
1364
+ }
1365
+ static for(t) {
1366
+ let e = Rt.get(t);
1367
+ if (e !== void 0)
1368
+ return e;
1369
+ const n = new t(), s = Se(n), r = String(s.methods.getStorageKey.call(s.fields)), o = s.fields.result, a = o instanceof _ ? o : We.object(o), c = (a.mask & u.ENTITY) !== 0, f = t.cache, l = s.fields.loadNext, d = typeof s.methods.sendNext == "function", y = c ? a : new _(
1370
+ u.ENTITY | u.OBJECT,
1371
+ a.shape,
1372
+ void 0,
1373
+ void 0,
1374
+ r,
1375
+ // typenameValue — unique per query class
1376
+ kt
1377
+ // idField — symbol, injected onto payload before parse
1378
+ );
1379
+ return e = new J(
1380
+ { id: r, shape: y, cache: f, rawLoadNext: l, hasSendNext: d, isEntityResult: c },
1381
+ s
1382
+ ), Rt.set(t, e), e;
1383
+ }
1384
+ }
1385
+ const Ni = (i, t) => {
1386
+ const e = J.for(i);
1387
+ return vt(e, t);
1388
+ };
1389
+ function Di(i, ...t) {
1390
+ const e = J.for(i), n = ve(wi);
1391
+ if (n === void 0)
1392
+ throw new Error("QueryClient not found");
1393
+ const s = t[0];
1394
+ return n.getQuery(e, s);
1395
+ }
1396
+ function se(i, t) {
1397
+ return new Promise((e, n) => {
1398
+ if (t?.aborted) {
1399
+ n(t.reason);
1400
+ return;
1401
+ }
1402
+ const s = setTimeout(e, i);
1403
+ t?.addEventListener(
1404
+ "abort",
1405
+ () => {
1406
+ clearTimeout(s), n(t.reason);
1407
+ },
1408
+ { once: !0 }
1409
+ );
1410
+ });
1411
+ }
1412
+ async function rt(i, t, e) {
1413
+ const n = Math.max(0, t.retries);
1414
+ let s;
1415
+ for (let r = 0; r <= n; r++) {
1416
+ e?.throwIfAborted();
1417
+ try {
1418
+ return await i();
1419
+ } catch (o) {
1420
+ if (s = o, r >= n) throw o;
1421
+ await se(t.retryDelay(r), e);
1422
+ }
1423
+ }
1424
+ throw s;
1425
+ }
1426
+ class fi {
1427
+ def;
1428
+ queryKey;
1429
+ storageKey = -1;
1430
+ /** The public-facing ReactivePromise returned to consumers. */
1431
+ relay;
1432
+ queryClient;
1433
+ initialized = !1;
1434
+ updatedAt = void 0;
1435
+ params = void 0;
1436
+ unsubscribe = void 0;
1437
+ _relayState = void 0;
1438
+ wasPaused = !1;
1439
+ currentParams = void 0;
1440
+ debounceTimer = void 0;
1441
+ /** Resolved per-instance options (depend on actual params). */
1442
+ config = void 0;
1443
+ retryConfig = gt(void 0);
1444
+ /** The raw fetch Response from the most recent successful fetch. */
1445
+ _lastResponse = void 0;
1446
+ /** Controller for aborting in-flight fetches and retry waits. */
1447
+ _abortController = void 0;
1448
+ /** Cached execution context, recreated only when storageKey (params) changes. */
1449
+ _executionCtx = void 0;
1450
+ _executionCtxKey = -1;
1451
+ /** Root entity that holds parsed data, proxy, child refs, and bindings.
1452
+ * For entity results, this is undefined until the first apply discovers it. */
1453
+ rootEntity;
1454
+ /** Extra methods (__refetch, __loadNext) attached to the root entity proxy. */
1455
+ _extraMethods = {};
1456
+ /** Query id injected as QUERY_ID on non-entity payloads. */
1457
+ _queryId = 0;
1458
+ get key() {
1459
+ return this.queryKey;
1460
+ }
1461
+ get relayState() {
1462
+ return this._relayState;
1463
+ }
1464
+ constructor(t, e, n, s) {
1465
+ this.def = t, this.queryClient = e, this.queryKey = n, this.params = s, this._extraMethods = { __refetch: this.refetch }, t.statics.hasSendNext && (this._extraMethods.__loadNext = this.loadNext);
1466
+ const r = At(s);
1467
+ this._queryId = r !== void 0 ? A(r) : 0, this.relay = It(
1468
+ (o) => {
1469
+ this._relayState = o;
1470
+ const a = () => {
1471
+ clearTimeout(this.debounceTimer), this.debounceTimer = void 0, this._abortController?.abort(), this._abortController = void 0, this._loadNextAbort?.abort(), this._loadNextAbort = void 0, this._loadNextPromise = void 0, this.unsubscribe?.(), this.unsubscribe = void 0;
1472
+ const f = this.config?.gcTime ?? Ft;
1473
+ this.queryClient.gcManager.schedule(this.queryKey, f, W.Query);
1474
+ }, c = (f = !1) => {
1475
+ const { wasPaused: l, isPaused: d, initialized: y } = this;
1476
+ if (this.wasPaused = d, d && !l && y) {
1477
+ a();
1478
+ return;
1479
+ }
1480
+ const v = At(this.params), p = vt(this.def, v), g = p !== this.storageKey;
1481
+ g && (this.currentParams = v, this.storageKey = p), this.getOrCreateExecutionContext(), this.initialized ? l || f ? (this.queryClient.activateQuery(this), f && this.updatedAt !== void 0 && this.setupSubscription(), (this.config?.refreshStaleOnReconnect ?? !0) && this.isStale && this.runDebounced()) : g && (this.setupSubscription(), this.runDebounced()) : (this.queryClient.activateQuery(this), this.initialize());
1482
+ };
1483
+ return c(!0), {
1484
+ update: c,
1485
+ deactivate: a
1486
+ };
1487
+ },
1488
+ { desc: `Query(${t.statics.id})` }
1489
+ );
1490
+ }
1491
+ /** Apply raw data (fresh or cached) to the root entity and return the proxy. */
1492
+ applyData(t, e, n = !1, s) {
1493
+ const r = this.def;
1494
+ return this.rootEntity = this.queryClient.parseAndApplyRootEntity(
1495
+ t,
1496
+ this._queryId,
1497
+ r.statics.shape,
1498
+ e,
1499
+ n,
1500
+ s
1501
+ ), this.rootEntity._extraMethods === void 0 && (this.rootEntity._extraMethods = this._extraMethods, this.rootEntity._extraGetters = {
1502
+ __hasNext: () => this.hasNext,
1503
+ __isLoadingNext: () => this._loadNextPromise !== void 0
1504
+ }), this.rootEntity.getProxy(r.statics.shape);
1505
+ }
1506
+ /** Save query metadata (the __entityRef pointer, updatedAt, ref set). */
1507
+ saveQueryMetadata() {
1508
+ if (this.rootEntity === void 0 || this.updatedAt === void 0) return;
1509
+ const t = new Map(this.rootEntity.entityRefs ?? []);
1510
+ t.set(this.rootEntity, 1), this.queryClient.saveQueryData(
1511
+ this.def,
1512
+ this.storageKey,
1513
+ { __entityRef: this.rootEntity.key },
1514
+ this.updatedAt,
1515
+ t
1516
+ );
1517
+ }
1518
+ async initialize() {
1519
+ const t = this.queryClient, e = this.relayState;
1520
+ this.initialized = !0;
1521
+ let n;
1522
+ try {
1523
+ n = await t.loadCachedQuery(this.def, this.storageKey), n !== void 0 && (this.updatedAt = n.updatedAt, e.value = this.applyData(n.value, !1, !1, n.preloadedEntities));
1524
+ } catch (s) {
1525
+ t.store.deleteQuery(this.storageKey), t.getContext().log?.warn?.("Failed to initialize query, the query cache may be corrupted or invalid", s);
1526
+ }
1527
+ if (!this.isPaused)
1528
+ try {
1529
+ if (n !== void 0 && this.setupSubscription(), n === void 0 || this.isStale) {
1530
+ if (await se(0), this.isPaused) return;
1531
+ this.runQueryImmediately();
1532
+ }
1533
+ } catch (s) {
1534
+ e.setError(s);
1535
+ }
1536
+ }
1537
+ setupSubscription() {
1538
+ this.unsubscribe?.(), this.unsubscribe = void 0;
1539
+ const t = this.config?.subscribe;
1540
+ if (!t) return;
1541
+ const e = this._executionCtx;
1542
+ this.unsubscribe = t.call(e, (n) => {
1543
+ n.__eventSource = this.queryKey, this.queryClient.applyMutationEvent(n);
1544
+ });
1545
+ }
1546
+ getOrCreateExecutionContext() {
1547
+ return (this._executionCtx === void 0 || this._executionCtxKey !== this.storageKey) && (this._executionCtxKey = this.storageKey, this._executionCtx = this.def.createExecutionContext(
1548
+ this.currentParams ?? {},
1549
+ this.queryClient.getContext()
1550
+ ), this._executionCtx.refetch = () => this.refetch(), this._executionCtx.rawLoadNext = this.def.statics.rawLoadNext), this._executionCtx.response = this._lastResponse, this.resolveAndApplyOptions(), this._executionCtx;
1551
+ }
1552
+ resolveAndApplyOptions() {
1553
+ const t = this.def.resolveOptions(this._executionCtx);
1554
+ this.config = t.config, this.retryConfig = t.retryConfig;
1555
+ }
1556
+ async runQuery() {
1557
+ const t = this.def;
1558
+ if (this.isPaused)
1559
+ throw new Error("Query is paused due to network status");
1560
+ const e = this.getOrCreateExecutionContext(), { send: n } = t.captured.methods, s = this._abortController?.signal;
1561
+ return e.signal = s, rt(
1562
+ async () => {
1563
+ const r = await n.call(e);
1564
+ this._lastResponse = e.response, this._executionCtx.response = this._lastResponse, this.resolveAndApplyOptions(), this.updatedAt = Date.now();
1565
+ const o = this.applyData(r, !0);
1566
+ return this.saveQueryMetadata(), this.unsubscribe === void 0 && this.setupSubscription(), o;
1567
+ },
1568
+ this.retryConfig,
1569
+ s
1570
+ );
1571
+ }
1572
+ runQueryImmediately() {
1573
+ this._abortController?.abort(), this._abortController = new AbortController(), this._loadNextAbort?.abort(), this._loadNextAbort = void 0, this._loadNextPromise = void 0, this.relayState.setPromise(this.runQuery());
1574
+ }
1575
+ runDebounced() {
1576
+ if (this.relayState.isPending) return;
1577
+ const t = this.config?.debounce ?? 0;
1578
+ clearTimeout(this.debounceTimer), this.debounceTimer = setTimeout(() => {
1579
+ this.debounceTimer = void 0, this.runQueryImmediately();
1580
+ }, t);
1581
+ }
1582
+ // ======================================================
1583
+ // Public methods
1584
+ // ======================================================
1585
+ refetch = () => this.relayState.isPending ? this.relay : (this.runQueryImmediately(), this.relay);
1586
+ /** In-flight loadNext promise for deduplication. */
1587
+ _loadNextPromise = void 0;
1588
+ /** Controller for aborting in-flight loadNext requests. */
1589
+ _loadNextAbort = void 0;
1590
+ loadNext = () => {
1591
+ if (this.updatedAt === void 0)
1592
+ throw new Error("Cannot call __loadNext before initial data has loaded");
1593
+ return this._loadNextPromise !== void 0 ? this._loadNextPromise : (queueMicrotask(() => this.rootEntity?.notify()), this._loadNextPromise = this.runLoadNext().then(
1594
+ (t) => (this._loadNextPromise = void 0, this.rootEntity?.notify(), t),
1595
+ (t) => {
1596
+ throw this._loadNextPromise = void 0, this.rootEntity?.notify(), t;
1597
+ }
1598
+ ), this._loadNextPromise);
1599
+ };
1600
+ get hasNext() {
1601
+ if (this.rootEntity === void 0 || !this._executionCtx) return !1;
1602
+ const t = this.def.captured.methods.hasNext;
1603
+ return t ? (this._executionCtx.resultData = this.rootEntity.data, t.call(this._executionCtx)) : !1;
1604
+ }
1605
+ async runLoadNext() {
1606
+ const t = this.def;
1607
+ this._loadNextAbort = new AbortController();
1608
+ const e = this._loadNextAbort.signal, n = this.getOrCreateExecutionContext();
1609
+ n.signal = e, n.resultData = this.rootEntity.data;
1610
+ const s = t.captured.methods.sendNext;
1611
+ return rt(
1612
+ async () => {
1613
+ const r = await s.call(n);
1614
+ this._lastResponse = n.response, this._executionCtx.response = this._lastResponse, this.resolveAndApplyOptions(), this.updatedAt = Date.now();
1615
+ const o = this.applyData(r, !0, !0);
1616
+ return this.saveQueryMetadata(), o;
1617
+ },
1618
+ this.retryConfig,
1619
+ e
1620
+ );
1621
+ }
1622
+ // ======================================================
1623
+ // Internal computed properties
1624
+ // ======================================================
1625
+ get isStale() {
1626
+ if (this.updatedAt === void 0)
1627
+ return !0;
1628
+ const t = this.config?.staleTime ?? 0;
1629
+ return Date.now() - this.updatedAt >= t;
1630
+ }
1631
+ get isPaused() {
1632
+ const t = this.config?.networkMode ?? q.Online;
1633
+ if (t === q.Always)
1634
+ return !1;
1635
+ const e = this.queryClient.networkManager.getOnlineSignal().value;
1636
+ switch (t) {
1637
+ case q.Online:
1638
+ return !e;
1639
+ case q.OfflineFirst:
1640
+ return !e && this.updatedAt === void 0;
1641
+ default:
1642
+ return !1;
1643
+ }
1644
+ }
1645
+ }
1646
+ class ui {
1647
+ def;
1648
+ queryClient;
1649
+ _lastResponse;
1650
+ _inFlight = !1;
1651
+ task;
1652
+ constructor(t, e) {
1653
+ this.def = t, this.queryClient = e, this.task = this.createTask();
1654
+ }
1655
+ createTask() {
1656
+ return _e(
1657
+ async (t) => {
1658
+ if (this._inFlight)
1659
+ throw new Error("A mutation is already in progress. Await the previous call before starting a new one.");
1660
+ this._inFlight = !0;
1661
+ try {
1662
+ const e = await this.executeWithRetry(t), n = this.validateResponse(e);
1663
+ return this.processEffects(t, n), n;
1664
+ } finally {
1665
+ this._inFlight = !1;
1666
+ }
1667
+ },
1668
+ { desc: `Mutation(${this.def.id})` }
1669
+ );
1670
+ }
1671
+ validateResponse(t) {
1672
+ const e = this.def.responseShape;
1673
+ if (!(e instanceof _))
1674
+ return t;
1675
+ const n = this.queryClient.getContext().log?.warn ?? (() => {
1676
+ }), s = new st();
1677
+ return s.reset(void 0, void 0, n), Xt(t, e, s);
1678
+ }
1679
+ // ======================================================
1680
+ // Effects processing
1681
+ // ======================================================
1682
+ processEffects(t, e) {
1683
+ let n;
1684
+ if (this.def.hasGetEffects) {
1685
+ const r = et(
1686
+ this.def.captured,
1687
+ t ?? {},
1688
+ this.queryClient.getContext()
1689
+ );
1690
+ r.result = e, r.response = this._lastResponse, n = r.getEffects();
1691
+ } else if (this.def.effects !== void 0) {
1692
+ const r = { params: t, result: e };
1693
+ n = P(this.def.effects, r);
1694
+ }
1695
+ if (n === void 0) return;
1696
+ const s = this.queryClient;
1697
+ Z(n.creates, "create", s), Z(n.updates, "update", s), Z(n.deletes, "delete", s);
1698
+ }
1699
+ // ======================================================
1700
+ // Retry logic
1701
+ // ======================================================
1702
+ executeWithRetry(t) {
1703
+ const e = gt(this.def.config?.retry, !0);
1704
+ return rt(async () => {
1705
+ const n = et(
1706
+ this.def.captured,
1707
+ t ?? {},
1708
+ this.queryClient.getContext()
1709
+ ), s = await this.def.captured.methods.send.call(n);
1710
+ return this._lastResponse = n.response, s;
1711
+ }, e);
1712
+ }
1713
+ }
1714
+ function di(i) {
1715
+ return typeof i == "string" ? i : L(i).typenameValue;
1716
+ }
1717
+ function Z(i, t, e) {
1718
+ if (i)
1719
+ for (const [n, s] of i) {
1720
+ const r = di(n);
1721
+ r !== void 0 && e.applyMutationEvent({ type: t, typename: r, data: s });
1722
+ }
1723
+ }
1724
+ const re = "__eventSource";
1725
+ function oe(i) {
1726
+ return { field: i, segments: i.indexOf(".") !== -1 ? i.split(".") : void 0 };
1727
+ }
1728
+ function li(i) {
1729
+ return i.map(oe);
1730
+ }
1731
+ function hi(i, t) {
1732
+ if (t.segments === void 0) return i[t.field];
1733
+ let e = i;
1734
+ for (const n of t.segments) {
1735
+ if (e == null) return;
1736
+ e = e[n];
1737
+ }
1738
+ return e;
1739
+ }
1740
+ function ae(i, t) {
1741
+ const e = [];
1742
+ for (let n = 0; n < t.length; n++) {
1743
+ const s = t[n], r = hi(i, s);
1744
+ if (r === void 0) return;
1745
+ e.push(s.field, r);
1746
+ }
1747
+ return A(e);
1748
+ }
1749
+ function yi(i, t) {
1750
+ if (i === void 0) return;
1751
+ const e = /* @__PURE__ */ new Map();
1752
+ for (const [n, s] of i) {
1753
+ const r = s.slice().sort((c, f) => c[0] < f[0] ? -1 : c[0] > f[0] ? 1 : 0), o = [];
1754
+ let a = !0;
1755
+ for (const [c, f] of r) {
1756
+ let l;
1757
+ if (Lt(f)) {
1758
+ const d = jt(f);
1759
+ l = ut(d, t);
1760
+ } else
1761
+ l = f;
1762
+ if (l === void 0) {
1763
+ a = !1;
1764
+ break;
1765
+ }
1766
+ o.push(c, l);
1767
+ }
1768
+ a && e.set(n, A(o));
1769
+ }
1770
+ return e.size > 0 ? e : void 0;
1771
+ }
1772
+ function Ot(i, t) {
1773
+ const e = i.get(t);
1774
+ if (e !== void 0)
1775
+ return e.map(([n]) => n).sort();
1776
+ }
1777
+ class pi {
1778
+ fields;
1779
+ fieldPaths;
1780
+ _bindings = /* @__PURE__ */ new Map();
1781
+ constructor(t) {
1782
+ this.fields = t, this.fieldPaths = t.map(oe);
1783
+ }
1784
+ register(t, e) {
1785
+ let n = this._bindings.get(t);
1786
+ n === void 0 && (n = /* @__PURE__ */ new Set(), this._bindings.set(t, n)), n.add(e);
1787
+ }
1788
+ unregister(t, e) {
1789
+ const n = this._bindings.get(t);
1790
+ n !== void 0 && (n.delete(e), n.size === 0 && this._bindings.delete(t));
1791
+ }
1792
+ getMatching(t) {
1793
+ return this._bindings.get(t);
1794
+ }
1795
+ get isEmpty() {
1796
+ return this._bindings.size === 0;
1797
+ }
1798
+ }
1799
+ function St(i) {
1800
+ return A(i);
1801
+ }
1802
+ class gi {
1803
+ _groups = /* @__PURE__ */ new Map();
1804
+ getOrCreateGroup(t) {
1805
+ const e = St(t);
1806
+ let n = this._groups.get(e);
1807
+ return n === void 0 && (n = new pi(t), this._groups.set(e, n)), n;
1808
+ }
1809
+ register(t, e, n) {
1810
+ this.getOrCreateGroup(e).register(t, n);
1811
+ }
1812
+ unregister(t, e, n) {
1813
+ const s = St(e), r = this._groups.get(s);
1814
+ r !== void 0 && (r.unregister(t, n), r.isEmpty && this._groups.delete(s));
1815
+ }
1816
+ registerBinding(t, e) {
1817
+ const n = t._constraintHashes.get(e);
1818
+ if (n === void 0) return;
1819
+ const s = Ot(t._constraintFieldRefs, e);
1820
+ s !== void 0 && this.register(n, s, t);
1821
+ }
1822
+ unregisterBinding(t, e) {
1823
+ const n = t._constraintHashes.get(e);
1824
+ if (n === void 0) return;
1825
+ const s = Ot(t._constraintFieldRefs, e);
1826
+ s !== void 0 && this.unregister(n, s, t);
1827
+ }
1828
+ routeEvent(t, e, n, s, r, o) {
1829
+ for (const a of this._groups.values()) {
1830
+ const c = ae(e, a.fieldPaths);
1831
+ if (c === void 0) continue;
1832
+ const f = a.getMatching(c);
1833
+ if (f !== void 0)
1834
+ for (const l of f)
1835
+ l.onEvent(t, n, s, r, o);
1836
+ }
1837
+ }
1838
+ }
1839
+ function Nt(i) {
1840
+ const t = /* @__PURE__ */ new Set();
1841
+ for (const e of i)
1842
+ if (typeof e == "object" && e !== null) {
1843
+ const n = F(e);
1844
+ n !== void 0 && t.add(n);
1845
+ }
1846
+ return t;
1847
+ }
1848
+ class ce {
1849
+ _queryClient;
1850
+ _parent;
1851
+ _constraintHashes;
1852
+ _entityDefsByTypename;
1853
+ _constraintFieldRefs;
1854
+ instance;
1855
+ constructor(t, e, n, s, r, o) {
1856
+ this._queryClient = n, this._parent = s, this._constraintHashes = r, this._constraintFieldRefs = e, this.instance = o, this._entityDefsByTypename = /* @__PURE__ */ new Map();
1857
+ for (const a of t)
1858
+ a.typenameValue !== void 0 && this._entityDefsByTypename.set(a.typenameValue, a);
1859
+ z.add(this);
1860
+ }
1861
+ getValue() {
1862
+ return this.instance.getValue();
1863
+ }
1864
+ toJSON() {
1865
+ return this.instance.getRawValue();
1866
+ }
1867
+ reset(t) {
1868
+ this.instance.reset(t);
1869
+ }
1870
+ append(t) {
1871
+ this.instance.append(t);
1872
+ }
1873
+ /**
1874
+ * Handle an entity event. The entity has already been created/updated at the
1875
+ * root level by applyMutationEvent. The binding just checks if the entity's
1876
+ * current data satisfies this binding's shape and forwards to the instance.
1877
+ */
1878
+ onEvent(t, e, n, s, r) {
1879
+ const o = this._entityDefsByTypename.get(t);
1880
+ if (o === void 0) return;
1881
+ const a = this._queryClient.entityMap.getEntity(e);
1882
+ if (n === "delete") {
1883
+ const f = a !== void 0 ? a.getProxy(o) : r;
1884
+ f !== void 0 && (this.instance.onEvent(e, f, r ?? a?.data ?? {}, "delete"), s?.());
1885
+ return;
1886
+ }
1887
+ if (a === void 0 || !a.satisfiesDef(o)) return;
1888
+ s?.();
1889
+ const c = a.getProxy(o);
1890
+ this.instance.onEvent(e, c, a.data, n);
1891
+ }
1892
+ destroy() {
1893
+ this._queryClient.unregisterLiveCollection(this);
1894
+ const t = this._parent.liveCollections, e = t.indexOf(this);
1895
+ e !== -1 && t.splice(e, 1);
1896
+ }
1897
+ }
1898
+ class vi {
1899
+ _notifier;
1900
+ _items;
1901
+ _keys;
1902
+ _outputSignal;
1903
+ _queryClient;
1904
+ _parent;
1905
+ constructor(t, e, n, s, r, o) {
1906
+ this._notifier = at(), this._items = n, this._keys = Nt(n), this._queryClient = t, this._parent = e;
1907
+ const a = s !== void 0 && r !== void 0, c = o !== void 0;
1908
+ (a || c) && (this._outputSignal = me(() => {
1909
+ this._notifier.consume();
1910
+ let f = this._items;
1911
+ if (a) {
1912
+ const l = [];
1913
+ for (const d of f) {
1914
+ if (typeof d != "object" || d === null) {
1915
+ l.push(d);
1916
+ continue;
1917
+ }
1918
+ const y = F(d);
1919
+ if (y === void 0) {
1920
+ l.push(d);
1921
+ continue;
1922
+ }
1923
+ const v = t.entityMap.getEntity(y);
1924
+ if (v === void 0) {
1925
+ l.push(d);
1926
+ continue;
1927
+ }
1928
+ v.consume(), ae(v.data, s) === r && l.push(d);
1929
+ }
1930
+ f = l;
1931
+ }
1932
+ return c && (f = (f === this._items ? f.slice() : f).sort(o)), f;
1933
+ }));
1934
+ }
1935
+ onEvent(t, e, n, s) {
1936
+ switch (s) {
1937
+ case "create":
1938
+ this.add(t, e);
1939
+ break;
1940
+ case "update":
1941
+ !this.has(t) && e !== void 0 && this.add(t, e);
1942
+ break;
1943
+ case "delete":
1944
+ this.remove(t);
1945
+ break;
1946
+ }
1947
+ }
1948
+ getValue() {
1949
+ return this._outputSignal !== void 0 ? this._outputSignal.value : (this._notifier.consume(), this._items);
1950
+ }
1951
+ getRawValue() {
1952
+ return this._items;
1953
+ }
1954
+ add(t, e) {
1955
+ if (this._keys.has(t)) return !1;
1956
+ this._keys.add(t), this._items.push(e);
1957
+ const n = this._queryClient.entityMap.getEntity(t);
1958
+ return n !== void 0 && (this._parent.addChildRef(n), n.save()), this._notifier.notify(), !0;
1959
+ }
1960
+ remove(t) {
1961
+ if (!this._keys.has(t)) return !1;
1962
+ this._keys.delete(t);
1963
+ const e = this._findIndex(t);
1964
+ e !== -1 && this._items.splice(e, 1);
1965
+ const n = this._queryClient.entityMap.getEntity(t);
1966
+ return n !== void 0 && this._parent.removeChildRef(n), this._notifier.notify(), !0;
1967
+ }
1968
+ has(t) {
1969
+ return this._keys.has(t);
1970
+ }
1971
+ reset(t) {
1972
+ const e = this._items, n = Array.isArray(t) ? t : [];
1973
+ this._items = n, this._keys = Nt(n);
1974
+ for (const s of n)
1975
+ if (typeof s == "object" && s !== null) {
1976
+ const r = F(s);
1977
+ if (r !== void 0) {
1978
+ const o = this._queryClient.entityMap.getEntity(r);
1979
+ o !== void 0 && this._parent.addChildRef(o);
1980
+ }
1981
+ }
1982
+ for (const s of e)
1983
+ if (typeof s == "object" && s !== null) {
1984
+ const r = F(s);
1985
+ if (r !== void 0) {
1986
+ const o = this._queryClient.entityMap.getEntity(r);
1987
+ o !== void 0 && this._parent.removeChildRef(o);
1988
+ }
1989
+ }
1990
+ this._notifier.notify();
1991
+ }
1992
+ append(t) {
1993
+ if (Array.isArray(t))
1994
+ for (const e of t) {
1995
+ if (typeof e != "object" || e === null) continue;
1996
+ const n = F(e);
1997
+ n !== void 0 && this.add(n, e);
1998
+ }
1999
+ }
2000
+ _findIndex(t) {
2001
+ for (let e = 0; e < this._items.length; e++) {
2002
+ const n = this._items[e];
2003
+ if (typeof n == "object" && n !== null && F(n) === t)
2004
+ return e;
2005
+ }
2006
+ return -1;
2007
+ }
2008
+ }
2009
+ class _i {
2010
+ _notifier;
2011
+ _value;
2012
+ _createdKeys;
2013
+ _deletedKeys;
2014
+ _queryClient;
2015
+ _parent;
2016
+ _onCreate;
2017
+ _onUpdate;
2018
+ _onDelete;
2019
+ constructor(t, e, n, s, r, o) {
2020
+ this._notifier = at(), this._value = n, this._createdKeys = /* @__PURE__ */ new Set(), this._deletedKeys = /* @__PURE__ */ new Set(), this._queryClient = t, this._parent = e, this._onCreate = s, this._onUpdate = r, this._onDelete = o;
2021
+ }
2022
+ onEvent(t, e, n, s) {
2023
+ switch (s) {
2024
+ case "create":
2025
+ if (this._createdKeys.has(t)) return;
2026
+ this._createdKeys.add(t), this._value = this._onCreate(this._value, e);
2027
+ break;
2028
+ case "update":
2029
+ this._value = this._onUpdate(this._value, e ?? n);
2030
+ break;
2031
+ case "delete":
2032
+ if (this._deletedKeys.has(t)) return;
2033
+ this._deletedKeys.add(t), this._value = this._onDelete(this._value, e ?? n);
2034
+ break;
2035
+ }
2036
+ this._notifier.notify();
2037
+ }
2038
+ getValue() {
2039
+ return this._notifier.consume(), this._value;
2040
+ }
2041
+ getRawValue() {
2042
+ return this._value;
2043
+ }
2044
+ reset(t) {
2045
+ this._value = t, this._createdKeys.clear(), this._deletedKeys.clear(), this._notifier.notify();
2046
+ }
2047
+ append(t) {
2048
+ }
2049
+ }
2050
+ function fe(i, t, e, n, s) {
2051
+ let r = i.constraintFieldRefs;
2052
+ if (r === void 0) {
2053
+ r = /* @__PURE__ */ new Map();
2054
+ for (const f of i.entityDefs) {
2055
+ const l = f.typenameValue;
2056
+ l !== void 0 && r.set(l, [[re, e.key]]);
2057
+ }
2058
+ }
2059
+ const o = yi(r, n) ?? /* @__PURE__ */ new Map();
2060
+ let a;
2061
+ if (i.type === ct.Array) {
2062
+ let f, l;
2063
+ if (i.constraintFieldRefs !== void 0 && o.size > 0 && o.size === 1)
2064
+ for (const [d] of i.constraintFieldRefs) {
2065
+ const y = o.get(d);
2066
+ if (y !== void 0) {
2067
+ l = y;
2068
+ const v = i.constraintFieldRefs.get(d);
2069
+ v !== void 0 && (f = li(v.map(([p]) => p)));
2070
+ break;
2071
+ }
2072
+ }
2073
+ a = new vi(
2074
+ s,
2075
+ e,
2076
+ Array.isArray(t) ? t : [],
2077
+ f,
2078
+ l,
2079
+ i.sort
2080
+ );
2081
+ } else
2082
+ a = new _i(
2083
+ s,
2084
+ e,
2085
+ t,
2086
+ i.onCreate,
2087
+ i.onUpdate,
2088
+ i.onDelete
2089
+ );
2090
+ const c = new ce(
2091
+ i.entityDefs,
2092
+ r,
2093
+ s,
2094
+ e,
2095
+ o,
2096
+ a
2097
+ );
2098
+ return e.liveCollections.push(c), s.registerLiveCollection(c), c;
2099
+ }
2100
+ const ue = Object.entries, de = Object.prototype;
2101
+ function tt(i, t, e, n = !1) {
2102
+ const s = i.queryClient;
2103
+ s.currentParseId++;
2104
+ const r = i.seen, o = /* @__PURE__ */ new Map();
2105
+ return { data: K(t, r, s, e, o, n), entityRefs: o };
2106
+ }
2107
+ function K(i, t, e, n, s, r) {
2108
+ if (typeof i != "object" || i === null) return i;
2109
+ const o = t.get(i);
2110
+ if (o !== void 0)
2111
+ return mi(o, t, e, n, s, r);
2112
+ if (Array.isArray(i)) {
2113
+ for (let a = 0; a < i.length; a++) {
2114
+ const c = i[a];
2115
+ typeof c == "object" && c !== null && !(c instanceof V) && !O.has(c) && (i[a] = K(c, t, e, n, s, r));
2116
+ }
2117
+ return i;
2118
+ }
2119
+ if (Object.getPrototypeOf(i) === de && !O.has(i)) {
2120
+ const a = i;
2121
+ for (const c of Object.keys(a)) {
2122
+ const f = a[c];
2123
+ typeof f == "object" && f !== null && !(f instanceof V) && !O.has(f) && (a[c] = K(f, t, e, n, s, r));
2124
+ }
2125
+ }
2126
+ return i;
2127
+ }
2128
+ function le(i) {
2129
+ return typeof i == "object" && i !== null && !(i instanceof V) && !O.has(i);
2130
+ }
2131
+ function mi(i, t, e, n, s, r) {
2132
+ const { key: o, data: a, shape: c, rawKeys: f } = i, l = c.shape, d = e.prepareEntity(o, a, c), y = d.data, v = y !== a, p = v && f !== void 0 && d.entityRefs !== void 0 ? new Map(d.entityRefs) : /* @__PURE__ */ new Map();
2133
+ if (v ? (he(
2134
+ l,
2135
+ a,
2136
+ y,
2137
+ f,
2138
+ d,
2139
+ y,
2140
+ t,
2141
+ e,
2142
+ n,
2143
+ p,
2144
+ r
2145
+ ), d.notify()) : ye(l, a, d, a, t, e, n, p, r), r && d.liveCollections.length > 0)
2146
+ for (const E of d.liveCollections) {
2147
+ const S = E.instance.getRawValue();
2148
+ if (Array.isArray(S))
2149
+ for (const C of S) {
2150
+ if (typeof C != "object" || C === null) continue;
2151
+ const I = O.get(C);
2152
+ if (I === void 0) continue;
2153
+ const x = e.entityMap.getEntity(I);
2154
+ x !== void 0 && p.set(x, (p.get(x) ?? 0) + 1);
2155
+ }
2156
+ }
2157
+ d.setChildRefs(p.size > 0 ? p : void 0, n);
2158
+ const g = d.getProxy(c);
2159
+ return s.set(d, (s.get(d) ?? 0) + 1), g;
2160
+ }
2161
+ function he(i, t, e, n, s, r, o, a, c, f, l) {
2162
+ for (const [d, y] of ue(i))
2163
+ if (!(n !== void 0 && !n.has(d)))
2164
+ if (le(t[d]) && (t[d] = K(t[d], o, a, c, f, l)), y instanceof _ && y._liveConfig !== void 0) {
2165
+ const v = e[d];
2166
+ v instanceof ce ? l ? v.append(t[d]) : v.reset(t[d]) : e[d] = fe(
2167
+ y._liveConfig,
2168
+ t[d],
2169
+ s,
2170
+ r,
2171
+ a
2172
+ );
2173
+ } else {
2174
+ const v = t[d], p = e[d];
2175
+ if (ot(v) && ot(p)) {
2176
+ const g = y instanceof _ && y.shape !== void 0 ? y.shape : void 0;
2177
+ if (g !== void 0)
2178
+ he(
2179
+ g,
2180
+ v,
2181
+ p,
2182
+ void 0,
2183
+ s,
2184
+ r,
2185
+ o,
2186
+ a,
2187
+ c,
2188
+ f,
2189
+ l
2190
+ );
2191
+ else
2192
+ for (const E of Object.keys(v))
2193
+ p[E] = v[E];
2194
+ e[d] = p;
2195
+ } else
2196
+ e[d] = v;
2197
+ }
2198
+ }
2199
+ function ye(i, t, e, n, s, r, o, a, c) {
2200
+ for (const [f, l] of ue(i))
2201
+ if (f in t)
2202
+ if (le(t[f]) && (t[f] = K(t[f], s, r, o, a, c)), l instanceof _ && l._liveConfig !== void 0)
2203
+ t[f] = fe(
2204
+ l._liveConfig,
2205
+ t[f],
2206
+ e,
2207
+ n,
2208
+ r
2209
+ );
2210
+ else {
2211
+ const d = t[f];
2212
+ if (ot(d)) {
2213
+ const y = l instanceof _ && l.shape !== void 0 ? l.shape : void 0;
2214
+ y !== void 0 && ye(y, d, e, n, s, r, o, a, c);
2215
+ }
2216
+ }
2217
+ }
2218
+ function ot(i) {
2219
+ return typeof i == "object" && i !== null && !Array.isArray(i) && Object.getPrototypeOf(i) === de && !O.has(i);
2220
+ }
2221
+ function Dt(i) {
2222
+ if (i !== void 0)
2223
+ return typeof i == "string" ? i : typeof i == "function" ? i() : i.value;
2224
+ }
2225
+ function Ei(i) {
2226
+ return Ee(i);
2227
+ }
2228
+ function At(i) {
2229
+ if (i === void 0)
2230
+ return;
2231
+ const t = {};
2232
+ for (const [e, n] of Object.entries(i))
2233
+ Ei(n) ? t[e] = n.value : t[e] = n;
2234
+ return t;
2235
+ }
2236
+ const vt = (i, t) => A([i.statics.id, t]);
2237
+ class Ai {
2238
+ constructor(t, e = { fetch, log: console }, n, s) {
2239
+ this.context = e, this.isServer = typeof window > "u", this.store = t, this.gcManager = s ?? (this.isServer ? new xe() : new Ce(this.handleEviction, this.context.evictionMultiplier)), this.networkManager = n ?? new ie(), this.entityMap = new oi((r, o, a) => this.store.saveEntity(r, o, a)), this.store.purgeStaleQueries?.();
2240
+ }
2241
+ entityMap;
2242
+ queryInstances = /* @__PURE__ */ new Map();
2243
+ mutationInstances = /* @__PURE__ */ new Map();
2244
+ gcManager;
2245
+ networkManager;
2246
+ isServer;
2247
+ store;
2248
+ currentParseId = 0;
2249
+ typenameRegistry = /* @__PURE__ */ new Map();
2250
+ constraintRegistry = /* @__PURE__ */ new Map();
2251
+ mergedDefCache = /* @__PURE__ */ new Map();
2252
+ getContext() {
2253
+ return this.context;
2254
+ }
2255
+ // ======================================================
2256
+ // Typename Registry (per-client)
2257
+ // ======================================================
2258
+ registerEntityDef(t) {
2259
+ const e = t.typenameValue;
2260
+ if (e === void 0 || t._entityClass === void 0) return;
2261
+ const n = this.typenameRegistry.get(e);
2262
+ if (n !== void 0) {
2263
+ if (n.indexOf(t) !== -1) return;
2264
+ n.push(t), this.mergedDefCache.delete(e), this.getMergedDef(e);
2265
+ } else
2266
+ this.typenameRegistry.set(e, [t]);
2267
+ }
2268
+ getEntityDefsForTypename(t) {
2269
+ return this.typenameRegistry.get(t);
2270
+ }
2271
+ getMergedDef(t) {
2272
+ let e = this.mergedDefCache.get(t);
2273
+ if (e !== void 0) return e;
2274
+ const n = this.typenameRegistry.get(t);
2275
+ if (n !== void 0)
2276
+ return e = _.merge(n), this.mergedDefCache.set(t, e), e;
2277
+ }
2278
+ saveQueryData(t, e, n, s, r) {
2279
+ const o = r !== void 0 && r.size > 0 ? new Set([...r.keys()].map((a) => a.key)) : void 0;
2280
+ this.store.saveQuery(t, e, n, s, o);
2281
+ }
2282
+ activateQuery(t) {
2283
+ const { def: e, queryKey: n, storageKey: s, config: r } = t;
2284
+ this.store.activateQuery(e, s);
2285
+ const o = r?.gcTime ?? Ft;
2286
+ this.gcManager.cancel(n, o);
2287
+ }
2288
+ loadCachedQuery(t, e) {
2289
+ return this.store.loadQuery(t, e);
2290
+ }
2291
+ /**
2292
+ * Loads a query from the document store and returns a QueryResult
2293
+ * that triggers fetches and prepopulates with cached data
2294
+ */
2295
+ getQuery(t, e) {
2296
+ const n = vt(t, e);
2297
+ let s = this.queryInstances.get(n);
2298
+ return s === void 0 && (s = new fi(t, this, n, e), this.queryInstances.set(n, s)), s.relay;
2299
+ }
2300
+ /**
2301
+ * Gets or creates a MutationResult for the given mutation definition.
2302
+ * Mutations are cached by their definition ID.
2303
+ */
2304
+ getMutation(t) {
2305
+ const e = t.id;
2306
+ let n = this.mutationInstances.get(e);
2307
+ return n === void 0 && (n = new ui(t, this), this.mutationInstances.set(e, n)), n.task;
2308
+ }
2309
+ /**
2310
+ * Parse data: validates, formats, produces parsed entity data objects.
2311
+ * Does NOT touch the entity store. Call applyRefs() after to commit entities.
2312
+ */
2313
+ parseData(t, e, n) {
2314
+ const s = this.context.log?.warn ?? (() => {
2315
+ }), r = new st();
2316
+ return r.reset(this, n, s), { data: Xt(t, e, r), ctx: r };
2317
+ }
2318
+ /**
2319
+ * Apply entities from parseData() via a single depth-first walk: creates/
2320
+ * updates EntityInstances, replaces parsed data with proxies, counts child
2321
+ * refs. Returns the reified data and root-level entity refs.
2322
+ */
2323
+ applyRefs(t, e = !0, n = !1) {
2324
+ return tt(t.ctx, t.data, e, n);
2325
+ }
2326
+ /**
2327
+ * Parse and apply data as a root entity. For non-entity results, injects
2328
+ * QUERY_ID onto the payload. Returns the root EntityInstance (created or
2329
+ * found in the store by the standard entity pipeline).
2330
+ */
2331
+ parseAndApplyRootEntity(t, e, n, s, r = !1, o) {
2332
+ typeof n.idField == "symbol" && typeof t == "object" && t !== null && !("__entityRef" in t) && (t[kt] = e);
2333
+ const a = this.parseData(t, n, o), c = tt(a.ctx, a.data, s, r), f = O.get(c.data);
2334
+ return this.entityMap.getEntity(f);
2335
+ }
2336
+ prepareEntity(t, e, n) {
2337
+ return this.registerEntityDef(n), this.entityMap.getOrCreateEntity(t, e, n, this);
2338
+ }
2339
+ // ======================================================
2340
+ // Mutation Events
2341
+ // ======================================================
2342
+ applyMutationEvent(t) {
2343
+ const { type: e, typename: n } = t, s = this.getMergedDef(n);
2344
+ if (s === void 0) return;
2345
+ const r = s.idField;
2346
+ if (r === void 0 || typeof r == "symbol") return;
2347
+ const o = t.data, a = t.id !== void 0 ? t.id : e === "delete" && (typeof o == "string" || typeof o == "number") ? o : o[r];
2348
+ if (a === void 0) return;
2349
+ const c = A([n, a]), f = t.__eventSource, l = typeof o == "object" && o !== null ? o : {}, d = this.entityMap.getEntity(c);
2350
+ if (e === "delete") {
2351
+ const g = d !== void 0 ? d.data : l;
2352
+ this.routeEvent(n, g, c, e, f, void 0, g);
2353
+ return;
2354
+ }
2355
+ try {
2356
+ const g = this.context.log?.warn ?? (() => {
2357
+ }), E = new st();
2358
+ E.reset(
2359
+ this,
2360
+ void 0,
2361
+ g,
2362
+ /* isPartialEvent */
2363
+ !0
2364
+ );
2365
+ const S = ze(l, s, E);
2366
+ tt(E, S, !0);
2367
+ } catch (g) {
2368
+ if (this.context.log?.warn?.("Failed to apply mutation event", g), d === void 0) {
2369
+ const E = this.entityMap.getEntity(c);
2370
+ E !== void 0 && E.evict();
2371
+ }
2372
+ return;
2373
+ }
2374
+ const y = this.entityMap.getEntity(c);
2375
+ if (y === void 0) return;
2376
+ this.entityMap.save(y);
2377
+ const v = d === void 0;
2378
+ let p = !1;
2379
+ this.routeEvent(n, y.data, c, e, f, () => {
2380
+ p = !0;
2381
+ }), v && !p && y.evict();
2382
+ }
2383
+ // ======================================================
2384
+ // In-Memory GC
2385
+ // ======================================================
2386
+ handleEviction = (t, e) => {
2387
+ if (e === W.Query) {
2388
+ const s = this.queryInstances.get(t);
2389
+ if (s === void 0) return;
2390
+ s.rootEntity?.evict(), this.queryInstances.delete(t);
2391
+ return;
2392
+ }
2393
+ const n = this.entityMap.getEntity(t);
2394
+ n !== void 0 && n.evict();
2395
+ };
2396
+ // ======================================================
2397
+ // Constraint Registry (Live Collections)
2398
+ // ======================================================
2399
+ getOrCreateMatcher(t) {
2400
+ let e = this.constraintRegistry.get(t);
2401
+ return e === void 0 && (e = new gi(), this.constraintRegistry.set(t, e)), e;
2402
+ }
2403
+ registerLiveCollection(t) {
2404
+ for (const [e, n] of t._entityDefsByTypename)
2405
+ this.registerEntityDef(n), this.getOrCreateMatcher(e).registerBinding(t, e);
2406
+ }
2407
+ unregisterLiveCollection(t) {
2408
+ for (const e of t._entityDefsByTypename.keys()) {
2409
+ const n = this.constraintRegistry.get(e);
2410
+ n !== void 0 && n.unregisterBinding(t, e);
2411
+ }
2412
+ }
2413
+ routeEvent(t, e, n, s, r, o, a) {
2414
+ const c = this.constraintRegistry.get(t);
2415
+ if (c === void 0) return;
2416
+ const f = r !== void 0 ? { ...e, [re]: r } : e;
2417
+ c.routeEvent(t, f, n, s, o, a);
2418
+ }
2419
+ destroy() {
2420
+ this.gcManager.destroy(), this.networkManager.destroy(), this.queryInstances.clear(), this.mutationInstances.clear(), this.constraintRegistry.clear(), this.typenameRegistry.clear(), this.mergedDefCache.clear();
2421
+ }
2422
+ }
2423
+ const wi = Tt(void 0);
2424
+ export {
2425
+ B as A,
2426
+ Ut as E,
2427
+ Ce as G,
2428
+ ct as L,
2429
+ u as M,
2430
+ ie as N,
2431
+ wi as Q,
2432
+ Si as R,
2433
+ _ as V,
2434
+ Ai as a,
2435
+ Wt as b,
2436
+ qt as c,
2437
+ ci as d,
2438
+ Se as e,
2439
+ Di as f,
2440
+ Ri as g,
2441
+ ne as h,
2442
+ ai as i,
2443
+ Oi as j,
2444
+ xe as k,
2445
+ q as l,
2446
+ Q as m,
2447
+ kt as n,
2448
+ U as o,
2449
+ Ni as q,
2450
+ Dt as r,
2451
+ We as t
2452
+ };
2453
+ //# sourceMappingURL=QueryClient-BP0Z1rQV.js.map