@hortiview/modulebase 1.1.0 → 1.1.1-alpha.3d69639d.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.
@@ -1,237 +0,0 @@
1
- import { R as r, c as u, n as h } from "./QueryClientProvider-Bak-4BVu.js";
2
- var l = class extends r {
3
- #o;
4
- #e;
5
- #t;
6
- #i;
7
- constructor(t) {
8
- super(), this.#o = t.client, this.mutationId = t.mutationId, this.#t = t.mutationCache, this.#e = [], this.state = t.state || c(), this.setOptions(t.options), this.scheduleGc();
9
- }
10
- setOptions(t) {
11
- this.options = t, this.updateGcTime(this.options.gcTime);
12
- }
13
- get meta() {
14
- return this.options.meta;
15
- }
16
- addObserver(t) {
17
- this.#e.includes(t) || (this.#e.push(t), this.clearGcTimeout(), this.#t.notify({
18
- type: "observerAdded",
19
- mutation: this,
20
- observer: t
21
- }));
22
- }
23
- removeObserver(t) {
24
- this.#e = this.#e.filter((o) => o !== t), this.scheduleGc(), this.#t.notify({
25
- type: "observerRemoved",
26
- mutation: this,
27
- observer: t
28
- });
29
- }
30
- optionalRemove() {
31
- this.#e.length || (this.state.status === "pending" ? this.scheduleGc() : this.#t.remove(this));
32
- }
33
- continue() {
34
- return this.#i?.continue() ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
35
- this.execute(this.state.variables);
36
- }
37
- async execute(t) {
38
- const o = () => {
39
- this.#s({ type: "continue" });
40
- }, e = {
41
- client: this.#o,
42
- meta: this.options.meta,
43
- mutationKey: this.options.mutationKey
44
- };
45
- this.#i = u({
46
- fn: () => this.options.mutationFn ? this.options.mutationFn(t, e) : Promise.reject(new Error("No mutationFn found")),
47
- onFail: (s, i) => {
48
- this.#s({ type: "failed", failureCount: s, error: i });
49
- },
50
- onPause: () => {
51
- this.#s({ type: "pause" });
52
- },
53
- onContinue: o,
54
- retry: this.options.retry ?? 0,
55
- retryDelay: this.options.retryDelay,
56
- networkMode: this.options.networkMode,
57
- canRun: () => this.#t.canRun(this)
58
- });
59
- const a = this.state.status === "pending", n = !this.#i.canStart();
60
- try {
61
- if (a)
62
- o();
63
- else {
64
- this.#s({ type: "pending", variables: t, isPaused: n }), this.#t.config.onMutate && await this.#t.config.onMutate(
65
- t,
66
- this,
67
- e
68
- );
69
- const i = await this.options.onMutate?.(
70
- t,
71
- e
72
- );
73
- i !== this.state.context && this.#s({
74
- type: "pending",
75
- context: i,
76
- variables: t,
77
- isPaused: n
78
- });
79
- }
80
- const s = await this.#i.start();
81
- return await this.#t.config.onSuccess?.(
82
- s,
83
- t,
84
- this.state.context,
85
- this,
86
- e
87
- ), await this.options.onSuccess?.(
88
- s,
89
- t,
90
- this.state.context,
91
- e
92
- ), await this.#t.config.onSettled?.(
93
- s,
94
- null,
95
- this.state.variables,
96
- this.state.context,
97
- this,
98
- e
99
- ), await this.options.onSettled?.(
100
- s,
101
- null,
102
- t,
103
- this.state.context,
104
- e
105
- ), this.#s({ type: "success", data: s }), s;
106
- } catch (s) {
107
- try {
108
- await this.#t.config.onError?.(
109
- s,
110
- t,
111
- this.state.context,
112
- this,
113
- e
114
- );
115
- } catch (i) {
116
- Promise.reject(i);
117
- }
118
- try {
119
- await this.options.onError?.(
120
- s,
121
- t,
122
- this.state.context,
123
- e
124
- );
125
- } catch (i) {
126
- Promise.reject(i);
127
- }
128
- try {
129
- await this.#t.config.onSettled?.(
130
- void 0,
131
- s,
132
- this.state.variables,
133
- this.state.context,
134
- this,
135
- e
136
- );
137
- } catch (i) {
138
- Promise.reject(i);
139
- }
140
- try {
141
- await this.options.onSettled?.(
142
- void 0,
143
- s,
144
- t,
145
- this.state.context,
146
- e
147
- );
148
- } catch (i) {
149
- Promise.reject(i);
150
- }
151
- throw this.#s({ type: "error", error: s }), s;
152
- } finally {
153
- this.#t.runNext(this);
154
- }
155
- }
156
- #s(t) {
157
- const o = (e) => {
158
- switch (t.type) {
159
- case "failed":
160
- return {
161
- ...e,
162
- failureCount: t.failureCount,
163
- failureReason: t.error
164
- };
165
- case "pause":
166
- return {
167
- ...e,
168
- isPaused: !0
169
- };
170
- case "continue":
171
- return {
172
- ...e,
173
- isPaused: !1
174
- };
175
- case "pending":
176
- return {
177
- ...e,
178
- context: t.context,
179
- data: void 0,
180
- failureCount: 0,
181
- failureReason: null,
182
- error: null,
183
- isPaused: t.isPaused,
184
- status: "pending",
185
- variables: t.variables,
186
- submittedAt: Date.now()
187
- };
188
- case "success":
189
- return {
190
- ...e,
191
- data: t.data,
192
- failureCount: 0,
193
- failureReason: null,
194
- error: null,
195
- status: "success",
196
- isPaused: !1
197
- };
198
- case "error":
199
- return {
200
- ...e,
201
- data: void 0,
202
- error: t.error,
203
- failureCount: e.failureCount + 1,
204
- failureReason: t.error,
205
- isPaused: !1,
206
- status: "error"
207
- };
208
- }
209
- };
210
- this.state = o(this.state), h.batch(() => {
211
- this.#e.forEach((e) => {
212
- e.onMutationUpdate(t);
213
- }), this.#t.notify({
214
- mutation: this,
215
- type: "updated",
216
- action: t
217
- });
218
- });
219
- }
220
- };
221
- function c() {
222
- return {
223
- context: void 0,
224
- data: void 0,
225
- error: null,
226
- failureCount: 0,
227
- failureReason: null,
228
- isPaused: !1,
229
- status: "idle",
230
- variables: void 0,
231
- submittedAt: 0
232
- };
233
- }
234
- export {
235
- l as M,
236
- c as g
237
- };
@@ -1 +0,0 @@
1
-