@hortiview/modulebase 1.0.0 → 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,66 +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-DyiNrPkn.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
  }
135
+ get resetState() {
136
+ return this.#r;
137
+ }
50
138
  reset() {
51
- this.destroy(), this.setState(this.#i);
139
+ this.destroy(), this.setState(this.resetState);
52
140
  }
53
141
  isActive() {
54
142
  return this.observers.some(
55
- (t) => b(t.options.enabled, this) !== !1
143
+ (t) => M(t.options.enabled, this) !== !1
56
144
  );
57
145
  }
58
146
  isDisabled() {
59
- return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === C || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
147
+ return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === N || !this.isFetched();
148
+ }
149
+ isFetched() {
150
+ return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
60
151
  }
61
152
  isStatic() {
62
153
  return this.getObserversCount() > 0 ? this.observers.some(
63
- (t) => S(t.options.staleTime, this) === "static"
154
+ (t) => G(t.options.staleTime, this) === "static"
64
155
  ) : !1;
65
156
  }
66
157
  isStale() {
@@ -69,7 +160,7 @@ var w = class extends v {
69
160
  ) : this.state.data === void 0 || this.state.isInvalidated;
70
161
  }
71
162
  isStaleByTime(t = 0) {
72
- 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);
73
164
  }
74
165
  onFocus() {
75
166
  this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#t?.continue();
@@ -81,11 +172,14 @@ var w = class extends v {
81
172
  this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.#e.notify({ type: "observerAdded", query: this, observer: t }));
82
173
  }
83
174
  removeObserver(t) {
84
- this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#t && (this.#a ? 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 }));
85
176
  }
86
177
  getObserversCount() {
87
178
  return this.observers.length;
88
179
  }
180
+ #h() {
181
+ return this.state.fetchStatus === "paused" && this.state.status === "pending";
182
+ }
89
183
  invalidate() {
90
184
  this.state.isInvalidated || this.#s({ type: "invalidate" });
91
185
  }
@@ -100,53 +194,55 @@ var w = class extends v {
100
194
  return this.#t.continueRetry(), this.#t.promise;
101
195
  }
102
196
  if (t && this.setOptions(t), !this.options.queryFn) {
103
- const s = this.observers.find((o) => o.options.queryFn);
197
+ const s = this.observers.find((h) => h.options.queryFn);
104
198
  s && this.setOptions(s.options);
105
199
  }
106
200
  process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
107
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']"
108
202
  ));
109
- const i = new AbortController(), r = (s) => {
203
+ const r = new AbortController(), a = (s) => {
110
204
  Object.defineProperty(s, "signal", {
111
205
  enumerable: !0,
112
- get: () => (this.#a = !0, i.signal)
206
+ get: () => (this.#i = !0, r.signal)
113
207
  });
114
- }, n = () => {
115
- const s = A(this.options, e), h = (() => {
116
- const u = {
117
- client: this.#r,
208
+ }, u = () => {
209
+ const s = A(this.options, e), l = (() => {
210
+ const p = {
211
+ client: this.#a,
118
212
  queryKey: this.queryKey,
119
213
  meta: this.meta
120
214
  };
121
- return r(u), u;
215
+ return a(p), p;
122
216
  })();
123
- return this.#a = !1, this.options.persister ? this.options.persister(
217
+ return this.#i = !1, this.options.persister ? this.options.persister(
124
218
  s,
125
- h,
219
+ l,
126
220
  this
127
- ) : s(h);
128
- }, a = (() => {
221
+ ) : s(l);
222
+ }, n = (() => {
129
223
  const s = {
130
224
  fetchOptions: e,
131
225
  options: this.options,
132
226
  queryKey: this.queryKey,
133
- client: this.#r,
227
+ client: this.#a,
134
228
  state: this.state,
135
- fetchFn: n
229
+ fetchFn: u
136
230
  };
137
- return r(s), s;
231
+ return a(s), s;
138
232
  })();
139
- 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({
140
236
  initialPromise: e?.initialPromise,
141
- fn: a.fetchFn,
237
+ fn: n.fetchFn,
142
238
  onCancel: (s) => {
143
- s instanceof d && s.revert && this.setState({
144
- ...this.#n,
239
+ s instanceof C && s.revert && this.setState({
240
+ ...this.#o,
145
241
  fetchStatus: "idle"
146
- }), i.abort();
242
+ }), r.abort();
147
243
  },
148
- onFail: (s, o) => {
149
- this.#s({ type: "failed", failureCount: s, error: o });
244
+ onFail: (s, h) => {
245
+ this.#s({ type: "failed", failureCount: s, error: h });
150
246
  },
151
247
  onPause: () => {
152
248
  this.#s({ type: "pause" });
@@ -154,9 +250,9 @@ var w = class extends v {
154
250
  onContinue: () => {
155
251
  this.#s({ type: "continue" });
156
252
  },
157
- retry: a.options.retry,
158
- retryDelay: a.options.retryDelay,
159
- networkMode: a.options.networkMode,
253
+ retry: n.options.retry,
254
+ retryDelay: n.options.retryDelay,
255
+ networkMode: n.options.networkMode,
160
256
  canRun: () => !0
161
257
  });
162
258
  try {
@@ -171,7 +267,7 @@ var w = class extends v {
171
267
  this
172
268
  ), s;
173
269
  } catch (s) {
174
- if (s instanceof d) {
270
+ if (s instanceof C) {
175
271
  if (s.silent)
176
272
  return this.#t.promise;
177
273
  if (s.revert) {
@@ -196,51 +292,51 @@ var w = class extends v {
196
292
  }
197
293
  }
198
294
  #s(t) {
199
- const e = (i) => {
295
+ const e = (r) => {
200
296
  switch (t.type) {
201
297
  case "failed":
202
298
  return {
203
- ...i,
299
+ ...r,
204
300
  fetchFailureCount: t.failureCount,
205
301
  fetchFailureReason: t.error
206
302
  };
207
303
  case "pause":
208
304
  return {
209
- ...i,
305
+ ...r,
210
306
  fetchStatus: "paused"
211
307
  };
212
308
  case "continue":
213
309
  return {
214
- ...i,
310
+ ...r,
215
311
  fetchStatus: "fetching"
216
312
  };
217
313
  case "fetch":
218
314
  return {
219
- ...i,
220
- ...U(i.data, this.options),
315
+ ...r,
316
+ ...V(r.data, this.options),
221
317
  fetchMeta: t.meta ?? null
222
318
  };
223
319
  case "success":
224
- const r = {
225
- ...i,
226
- ...l(t.data, t.dataUpdatedAt),
227
- dataUpdateCount: i.dataUpdateCount + 1,
320
+ const a = {
321
+ ...r,
322
+ ...S(t.data, t.dataUpdatedAt),
323
+ dataUpdateCount: r.dataUpdateCount + 1,
228
324
  ...!t.manual && {
229
325
  fetchStatus: "idle",
230
326
  fetchFailureCount: 0,
231
327
  fetchFailureReason: null
232
328
  }
233
329
  };
234
- return this.#n = t.manual ? r : void 0, r;
330
+ return this.#o = t.manual ? a : void 0, a;
235
331
  case "error":
236
- const n = t.error;
332
+ const u = t.error;
237
333
  return {
238
- ...i,
239
- error: n,
240
- errorUpdateCount: i.errorUpdateCount + 1,
334
+ ...r,
335
+ error: u,
336
+ errorUpdateCount: r.errorUpdateCount + 1,
241
337
  errorUpdatedAt: Date.now(),
242
- fetchFailureCount: i.fetchFailureCount + 1,
243
- fetchFailureReason: n,
338
+ fetchFailureCount: r.fetchFailureCount + 1,
339
+ fetchFailureReason: u,
244
340
  fetchStatus: "idle",
245
341
  status: "error",
246
342
  // flag existing data as invalidated if we get a background error
@@ -249,35 +345,35 @@ var w = class extends v {
249
345
  };
250
346
  case "invalidate":
251
347
  return {
252
- ...i,
348
+ ...r,
253
349
  isInvalidated: !0
254
350
  };
255
351
  case "setState":
256
352
  return {
257
- ...i,
353
+ ...r,
258
354
  ...t.state
259
355
  };
260
356
  }
261
357
  };
262
- this.state = e(this.state), q.batch(() => {
263
- this.observers.forEach((i) => {
264
- i.onQueryUpdate();
358
+ this.state = e(this.state), _.batch(() => {
359
+ this.observers.forEach((r) => {
360
+ r.onQueryUpdate();
265
361
  }), this.#e.notify({ query: this, type: "updated", action: t });
266
362
  });
267
363
  }
268
364
  };
269
- function U(t, e) {
365
+ function V(t, e) {
270
366
  return {
271
367
  fetchFailureCount: 0,
272
368
  fetchFailureReason: null,
273
- fetchStatus: D(e.networkMode) ? "fetching" : "paused",
369
+ fetchStatus: x(e.networkMode) ? "fetching" : "paused",
274
370
  ...t === void 0 && {
275
371
  error: null,
276
372
  status: "pending"
277
373
  }
278
374
  };
279
375
  }
280
- function l(t, e) {
376
+ function S(t, e) {
281
377
  return {
282
378
  data: t,
283
379
  dataUpdatedAt: e ?? Date.now(),
@@ -286,12 +382,12 @@ function l(t, e) {
286
382
  status: "success"
287
383
  };
288
384
  }
289
- function f(t) {
290
- 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;
291
387
  return {
292
388
  data: e,
293
389
  dataUpdateCount: 0,
294
- dataUpdatedAt: i ? r ?? Date.now() : 0,
390
+ dataUpdatedAt: r ? a ?? Date.now() : 0,
295
391
  error: null,
296
392
  errorUpdateCount: 0,
297
393
  errorUpdatedAt: 0,
@@ -299,14 +395,16 @@ function f(t) {
299
395
  fetchFailureReason: null,
300
396
  fetchMeta: null,
301
397
  isInvalidated: !1,
302
- status: i ? "success" : "pending",
398
+ status: r ? "success" : "pending",
303
399
  fetchStatus: "idle"
304
400
  };
305
401
  }
306
- 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;
307
403
  export {
308
- I,
309
- w as Q,
310
- U as f,
311
- 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
312
410
  };