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