@hortiview/modulebase 1.0.1 → 1.0.2

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.
@@ -1,72 +1,157 @@
1
- import { R as v, r as m, a as c, d as b, e as C, f as S, t as F, c as g, C as d, n as q, g as A, i as D } from "./QueryClientProvider-CTj9TWgb.js";
2
- import * as p from "react";
3
- var w = class extends v {
4
- #i;
1
+ import { e as A, d as k, f as K, g as Q, R as T, r as E, a as P, i as M, j as N, k as G, t as j, c as H, C, n as _, l as x } from "./QueryClientProvider-Bak-4BVu.js";
2
+ import * as w from "react";
3
+ function B(t) {
4
+ return {
5
+ onFetch: (e, r) => {
6
+ const a = e.options, u = e.fetchOptions?.meta?.fetchMore?.direction, f = e.state.data?.pages || [], n = e.state.data?.pageParams || [];
7
+ let c = { pages: [], pageParams: [] }, s = 0;
8
+ const h = async () => {
9
+ let l = !1;
10
+ const p = (i) => {
11
+ Q(
12
+ i,
13
+ () => e.signal,
14
+ () => l = !0
15
+ );
16
+ }, R = A(e.options, e.fetchOptions), v = async (i, o, d) => {
17
+ if (l)
18
+ return Promise.reject(e.signal.reason);
19
+ if (o == null && i.pages.length)
20
+ return Promise.resolve(i);
21
+ const O = (() => {
22
+ const b = {
23
+ client: e.client,
24
+ queryKey: e.queryKey,
25
+ pageParam: o,
26
+ direction: d ? "backward" : "forward",
27
+ meta: e.options.meta
28
+ };
29
+ return p(b), b;
30
+ })(), I = await R(O), { maxPages: m } = e.options, F = d ? k : K;
31
+ return {
32
+ pages: F(i.pages, I, m),
33
+ pageParams: F(i.pageParams, o, m)
34
+ };
35
+ };
36
+ if (u && f.length) {
37
+ const i = u === "backward", o = i ? D : y, d = {
38
+ pages: f,
39
+ pageParams: n
40
+ }, g = o(a, d);
41
+ c = await v(d, g, i);
42
+ } else {
43
+ const i = t ?? f.length;
44
+ do {
45
+ const o = s === 0 ? n[0] ?? a.initialPageParam : y(a, c);
46
+ if (s > 0 && o == null)
47
+ break;
48
+ c = await v(c, o), s++;
49
+ } while (s < i);
50
+ }
51
+ return c;
52
+ };
53
+ e.options.persister ? e.fetchFn = () => e.options.persister?.(
54
+ h,
55
+ {
56
+ client: e.client,
57
+ queryKey: e.queryKey,
58
+ meta: e.options.meta,
59
+ signal: e.signal
60
+ },
61
+ r
62
+ ) : e.fetchFn = h;
63
+ }
64
+ };
65
+ }
66
+ function y(t, { pages: e, pageParams: r }) {
67
+ const a = e.length - 1;
68
+ return e.length > 0 ? t.getNextPageParam(
69
+ e[a],
70
+ e,
71
+ r[a],
72
+ r
73
+ ) : void 0;
74
+ }
75
+ function D(t, { pages: e, pageParams: r }) {
76
+ return e.length > 0 ? t.getPreviousPageParam?.(e[0], e, r[0], r) : void 0;
77
+ }
78
+ function W(t, e) {
79
+ return e ? y(t, e) != null : !1;
80
+ }
81
+ function z(t, e) {
82
+ return !e || !t.getPreviousPageParam ? !1 : D(t, e) != null;
83
+ }
84
+ var J = class extends T {
5
85
  #n;
6
- #e;
7
86
  #r;
8
- #t;
9
87
  #o;
88
+ #e;
10
89
  #a;
90
+ #t;
91
+ #u;
92
+ #i;
11
93
  constructor(t) {
12
- super(), this.#a = !1, this.#o = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.#r = t.client, this.#e = this.#r.getQueryCache(), this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.#i = f(this.options), this.state = t.state ?? this.#i, this.scheduleGc();
94
+ super(), this.#i = !1, this.#u = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.#a = t.client, this.#e = this.#a.getQueryCache(), this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.#r = q(this.options), this.state = t.state ?? this.#r, this.scheduleGc();
13
95
  }
14
96
  get meta() {
15
97
  return this.options.meta;
16
98
  }
99
+ get queryType() {
100
+ return this.#n;
101
+ }
17
102
  get promise() {
18
103
  return this.#t?.promise;
19
104
  }
20
105
  setOptions(t) {
21
- if (this.options = { ...this.#o, ...t }, this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
22
- const e = f(this.options);
106
+ if (this.options = { ...this.#u, ...t }, t?._type && (this.#n = t._type), this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
107
+ const e = q(this.options);
23
108
  e.data !== void 0 && (this.setState(
24
- l(e.data, e.dataUpdatedAt)
25
- ), this.#i = e);
109
+ S(e.data, e.dataUpdatedAt)
110
+ ), this.#r = e);
26
111
  }
27
112
  }
28
113
  optionalRemove() {
29
114
  !this.observers.length && this.state.fetchStatus === "idle" && this.#e.remove(this);
30
115
  }
31
116
  setData(t, e) {
32
- const i = m(this.state.data, t, this.options);
117
+ const r = E(this.state.data, t, this.options);
33
118
  return this.#s({
34
- data: i,
119
+ data: r,
35
120
  type: "success",
36
121
  dataUpdatedAt: e?.updatedAt,
37
122
  manual: e?.manual
38
- }), i;
123
+ }), r;
39
124
  }
40
- setState(t, e) {
41
- this.#s({ type: "setState", state: t, setStateOptions: e });
125
+ setState(t) {
126
+ this.#s({ type: "setState", state: t });
42
127
  }
43
128
  cancel(t) {
44
129
  const e = this.#t?.promise;
45
- return this.#t?.cancel(t), e ? e.then(c).catch(c) : Promise.resolve();
130
+ return this.#t?.cancel(t), e ? e.then(P).catch(P) : Promise.resolve();
46
131
  }
47
132
  destroy() {
48
133
  super.destroy(), this.cancel({ silent: !0 });
49
134
  }
50
135
  get resetState() {
51
- return this.#i;
136
+ return this.#r;
52
137
  }
53
138
  reset() {
54
139
  this.destroy(), this.setState(this.resetState);
55
140
  }
56
141
  isActive() {
57
142
  return this.observers.some(
58
- (t) => b(t.options.enabled, this) !== !1
143
+ (t) => M(t.options.enabled, this) !== !1
59
144
  );
60
145
  }
61
146
  isDisabled() {
62
- return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === C || !this.isFetched();
147
+ return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === N || !this.isFetched();
63
148
  }
64
149
  isFetched() {
65
150
  return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
66
151
  }
67
152
  isStatic() {
68
153
  return this.getObserversCount() > 0 ? this.observers.some(
69
- (t) => S(t.options.staleTime, this) === "static"
154
+ (t) => G(t.options.staleTime, this) === "static"
70
155
  ) : !1;
71
156
  }
72
157
  isStale() {
@@ -75,7 +160,7 @@ var w = class extends v {
75
160
  ) : this.state.data === void 0 || this.state.isInvalidated;
76
161
  }
77
162
  isStaleByTime(t = 0) {
78
- return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !F(this.state.dataUpdatedAt, t);
163
+ return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !j(this.state.dataUpdatedAt, t);
79
164
  }
80
165
  onFocus() {
81
166
  this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#t?.continue();
@@ -87,7 +172,7 @@ var w = class extends v {
87
172
  this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.#e.notify({ type: "observerAdded", query: this, observer: t }));
88
173
  }
89
174
  removeObserver(t) {
90
- this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#t && (this.#a || this.#h() ? this.#t.cancel({ revert: !0 }) : this.#t.cancelRetry()), this.scheduleGc()), this.#e.notify({ type: "observerRemoved", query: this, observer: t }));
175
+ this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#t && (this.#i || this.#h() ? this.#t.cancel({ revert: !0 }) : this.#t.cancelRetry()), this.scheduleGc()), this.#e.notify({ type: "observerRemoved", query: this, observer: t }));
91
176
  }
92
177
  getObserversCount() {
93
178
  return this.observers.length;
@@ -109,53 +194,55 @@ var w = class extends v {
109
194
  return this.#t.continueRetry(), this.#t.promise;
110
195
  }
111
196
  if (t && this.setOptions(t), !this.options.queryFn) {
112
- const s = this.observers.find((o) => o.options.queryFn);
197
+ const s = this.observers.find((h) => h.options.queryFn);
113
198
  s && this.setOptions(s.options);
114
199
  }
115
200
  process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
116
201
  "As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"
117
202
  ));
118
- const i = new AbortController(), r = (s) => {
203
+ const r = new AbortController(), a = (s) => {
119
204
  Object.defineProperty(s, "signal", {
120
205
  enumerable: !0,
121
- get: () => (this.#a = !0, i.signal)
206
+ get: () => (this.#i = !0, r.signal)
122
207
  });
123
- }, n = () => {
124
- const s = A(this.options, e), h = (() => {
125
- const u = {
126
- client: this.#r,
208
+ }, u = () => {
209
+ const s = A(this.options, e), l = (() => {
210
+ const p = {
211
+ client: this.#a,
127
212
  queryKey: this.queryKey,
128
213
  meta: this.meta
129
214
  };
130
- return r(u), u;
215
+ return a(p), p;
131
216
  })();
132
- return this.#a = !1, this.options.persister ? this.options.persister(
217
+ return this.#i = !1, this.options.persister ? this.options.persister(
133
218
  s,
134
- h,
219
+ l,
135
220
  this
136
- ) : s(h);
137
- }, a = (() => {
221
+ ) : s(l);
222
+ }, n = (() => {
138
223
  const s = {
139
224
  fetchOptions: e,
140
225
  options: this.options,
141
226
  queryKey: this.queryKey,
142
- client: this.#r,
227
+ client: this.#a,
143
228
  state: this.state,
144
- fetchFn: n
229
+ fetchFn: u
145
230
  };
146
- return r(s), s;
231
+ return a(s), s;
147
232
  })();
148
- this.options.behavior?.onFetch(a, this), this.#n = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== a.fetchOptions?.meta) && this.#s({ type: "fetch", meta: a.fetchOptions?.meta }), this.#t = g({
233
+ (this.#n === "infinite" ? B(
234
+ this.options.pages
235
+ ) : this.options.behavior)?.onFetch(n, this), this.#o = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== n.fetchOptions?.meta) && this.#s({ type: "fetch", meta: n.fetchOptions?.meta }), this.#t = H({
149
236
  initialPromise: e?.initialPromise,
150
- fn: a.fetchFn,
237
+ fn: n.fetchFn,
151
238
  onCancel: (s) => {
152
- s instanceof d && s.revert && this.setState({
153
- ...this.#n,
239
+ s instanceof C && s.revert && this.setState({
240
+ ...this.#o,
154
241
  fetchStatus: "idle"
155
- }), i.abort();
242
+ }), r.abort();
156
243
  },
157
- onFail: (s, o) => {
158
- this.#s({ type: "failed", failureCount: s, error: o });
244
+ onFail: (s, h) => {
245
+ this.#s({ type: "failed", failureCount: s, error: h });
159
246
  },
160
247
  onPause: () => {
161
248
  this.#s({ type: "pause" });
@@ -163,9 +250,9 @@ var w = class extends v {
163
250
  onContinue: () => {
164
251
  this.#s({ type: "continue" });
165
252
  },
166
- retry: a.options.retry,
167
- retryDelay: a.options.retryDelay,
168
- networkMode: a.options.networkMode,
253
+ retry: n.options.retry,
254
+ retryDelay: n.options.retryDelay,
255
+ networkMode: n.options.networkMode,
169
256
  canRun: () => !0
170
257
  });
171
258
  try {
@@ -180,7 +267,7 @@ var w = class extends v {
180
267
  this
181
268
  ), s;
182
269
  } catch (s) {
183
- if (s instanceof d) {
270
+ if (s instanceof C) {
184
271
  if (s.silent)
185
272
  return this.#t.promise;
186
273
  if (s.revert) {
@@ -205,51 +292,51 @@ var w = class extends v {
205
292
  }
206
293
  }
207
294
  #s(t) {
208
- const e = (i) => {
295
+ const e = (r) => {
209
296
  switch (t.type) {
210
297
  case "failed":
211
298
  return {
212
- ...i,
299
+ ...r,
213
300
  fetchFailureCount: t.failureCount,
214
301
  fetchFailureReason: t.error
215
302
  };
216
303
  case "pause":
217
304
  return {
218
- ...i,
305
+ ...r,
219
306
  fetchStatus: "paused"
220
307
  };
221
308
  case "continue":
222
309
  return {
223
- ...i,
310
+ ...r,
224
311
  fetchStatus: "fetching"
225
312
  };
226
313
  case "fetch":
227
314
  return {
228
- ...i,
229
- ...U(i.data, this.options),
315
+ ...r,
316
+ ...V(r.data, this.options),
230
317
  fetchMeta: t.meta ?? null
231
318
  };
232
319
  case "success":
233
- const r = {
234
- ...i,
235
- ...l(t.data, t.dataUpdatedAt),
236
- dataUpdateCount: i.dataUpdateCount + 1,
320
+ const a = {
321
+ ...r,
322
+ ...S(t.data, t.dataUpdatedAt),
323
+ dataUpdateCount: r.dataUpdateCount + 1,
237
324
  ...!t.manual && {
238
325
  fetchStatus: "idle",
239
326
  fetchFailureCount: 0,
240
327
  fetchFailureReason: null
241
328
  }
242
329
  };
243
- return this.#n = t.manual ? r : void 0, r;
330
+ return this.#o = t.manual ? a : void 0, a;
244
331
  case "error":
245
- const n = t.error;
332
+ const u = t.error;
246
333
  return {
247
- ...i,
248
- error: n,
249
- errorUpdateCount: i.errorUpdateCount + 1,
334
+ ...r,
335
+ error: u,
336
+ errorUpdateCount: r.errorUpdateCount + 1,
250
337
  errorUpdatedAt: Date.now(),
251
- fetchFailureCount: i.fetchFailureCount + 1,
252
- fetchFailureReason: n,
338
+ fetchFailureCount: r.fetchFailureCount + 1,
339
+ fetchFailureReason: u,
253
340
  fetchStatus: "idle",
254
341
  status: "error",
255
342
  // flag existing data as invalidated if we get a background error
@@ -258,35 +345,35 @@ var w = class extends v {
258
345
  };
259
346
  case "invalidate":
260
347
  return {
261
- ...i,
348
+ ...r,
262
349
  isInvalidated: !0
263
350
  };
264
351
  case "setState":
265
352
  return {
266
- ...i,
353
+ ...r,
267
354
  ...t.state
268
355
  };
269
356
  }
270
357
  };
271
- this.state = e(this.state), q.batch(() => {
272
- this.observers.forEach((i) => {
273
- i.onQueryUpdate();
358
+ this.state = e(this.state), _.batch(() => {
359
+ this.observers.forEach((r) => {
360
+ r.onQueryUpdate();
274
361
  }), this.#e.notify({ query: this, type: "updated", action: t });
275
362
  });
276
363
  }
277
364
  };
278
- function U(t, e) {
365
+ function V(t, e) {
279
366
  return {
280
367
  fetchFailureCount: 0,
281
368
  fetchFailureReason: null,
282
- fetchStatus: D(e.networkMode) ? "fetching" : "paused",
369
+ fetchStatus: x(e.networkMode) ? "fetching" : "paused",
283
370
  ...t === void 0 && {
284
371
  error: null,
285
372
  status: "pending"
286
373
  }
287
374
  };
288
375
  }
289
- function l(t, e) {
376
+ function S(t, e) {
290
377
  return {
291
378
  data: t,
292
379
  dataUpdatedAt: e ?? Date.now(),
@@ -295,12 +382,12 @@ function l(t, e) {
295
382
  status: "success"
296
383
  };
297
384
  }
298
- function f(t) {
299
- const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, i = e !== void 0, r = i ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
385
+ function q(t) {
386
+ const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, r = e !== void 0, a = r ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
300
387
  return {
301
388
  data: e,
302
389
  dataUpdateCount: 0,
303
- dataUpdatedAt: i ? r ?? Date.now() : 0,
390
+ dataUpdatedAt: r ? a ?? Date.now() : 0,
304
391
  error: null,
305
392
  errorUpdateCount: 0,
306
393
  errorUpdatedAt: 0,
@@ -308,14 +395,16 @@ function f(t) {
308
395
  fetchFailureReason: null,
309
396
  fetchMeta: null,
310
397
  isInvalidated: !1,
311
- status: i ? "success" : "pending",
398
+ status: r ? "success" : "pending",
312
399
  fetchStatus: "idle"
313
400
  };
314
401
  }
315
- var y = p.createContext(!1), x = () => p.useContext(y), I = y.Provider;
402
+ var U = w.createContext(!1), L = () => w.useContext(U), X = U.Provider;
316
403
  export {
317
- I,
318
- w as Q,
319
- U as f,
320
- x as u
404
+ X as I,
405
+ J as Q,
406
+ W as a,
407
+ V as f,
408
+ z as h,
409
+ L as u
321
410
  };