@effect-app/vue 2.52.4 → 2.52.5
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 -0
- package/dist/experimental/commander.d.ts +120 -0
- package/dist/experimental/commander.d.ts.map +1 -0
- package/dist/experimental/commander.js +206 -0
- package/dist/experimental/confirm.d.ts +12 -0
- package/dist/experimental/confirm.d.ts.map +1 -0
- package/dist/experimental/confirm.js +14 -0
- package/dist/experimental/intl.d.ts +32 -0
- package/dist/experimental/intl.d.ts.map +1 -0
- package/dist/experimental/intl.js +4 -0
- package/dist/experimental/makeExperimental.d.ts +59 -26
- package/dist/experimental/makeExperimental.d.ts.map +1 -1
- package/dist/experimental/makeExperimental.js +8 -16
- package/dist/experimental/toast.d.ts +54 -0
- package/dist/experimental/toast.d.ts.map +1 -0
- package/dist/experimental/toast.js +4 -0
- package/dist/experimental/withToast.d.ts +17 -0
- package/dist/experimental/withToast.d.ts.map +1 -0
- package/dist/experimental/withToast.js +36 -0
- package/dist/makeClient.js +6 -6
- package/dist/makeIntl.d.ts +1 -1
- package/dist/makeIntl.d.ts.map +1 -1
- package/dist/makeIntl.js +9 -4
- package/package.json +19 -11
- package/src/experimental/commander.ts +567 -0
- package/src/experimental/confirm.ts +20 -0
- package/src/experimental/intl.ts +5 -0
- package/src/experimental/makeExperimental.ts +7 -25
- package/src/experimental/toast.ts +14 -0
- package/src/experimental/withToast.ts +58 -0
- package/src/makeClient.ts +5 -5
- package/src/makeIntl.ts +8 -3
- package/test/Mutation.test.ts +21 -41
- package/test/dist/stubs.d.ts +58 -21
- package/test/dist/stubs.d.ts.map +1 -1
- package/test/dist/stubs.js +28 -22
- package/test/stubs.ts +65 -61
- package/dist/experimental/useCommand.d.ts +0 -75
- package/dist/experimental/useCommand.d.ts.map +0 -1
- package/dist/experimental/useCommand.js +0 -198
- package/dist/experimental/useConfirm.d.ts +0 -7
- package/dist/experimental/useConfirm.d.ts.map +0 -1
- package/dist/experimental/useConfirm.js +0 -9
- package/dist/experimental/useWithToast.d.ts +0 -23
- package/dist/experimental/useWithToast.d.ts.map +0 -1
- package/dist/experimental/useWithToast.js +0 -31
- package/src/experimental/useCommand.ts +0 -564
- package/src/experimental/useConfirm.ts +0 -17
- package/src/experimental/useWithToast.ts +0 -65
|
@@ -1,564 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { asResult, type MakeIntlReturn, reportRuntimeError } from "@effect-app/vue"
|
|
3
|
-
import { reportMessage } from "@effect-app/vue/errorReporter"
|
|
4
|
-
import { type Result } from "@effect-atom/atom/Result"
|
|
5
|
-
import { Cause, Context, Effect, type Exit, flow, Match, Option, Runtime, S } from "effect-app"
|
|
6
|
-
import { SupportedErrors } from "effect-app/client"
|
|
7
|
-
import { OperationFailure, OperationSuccess } from "effect-app/Operations"
|
|
8
|
-
import { type RuntimeFiber } from "effect/Fiber"
|
|
9
|
-
import { type NoInfer } from "effect/Types"
|
|
10
|
-
import { type YieldWrap } from "effect/Utils"
|
|
11
|
-
import { computed, type ComputedRef } from "vue"
|
|
12
|
-
import { type makeUseConfirm } from "./useConfirm.js"
|
|
13
|
-
import { type makeUseWithToast } from "./useWithToast.js"
|
|
14
|
-
|
|
15
|
-
export const DefaultIntl = {
|
|
16
|
-
de: {
|
|
17
|
-
"handle.confirmation": "{action} bestätigen?",
|
|
18
|
-
"handle.waiting": "{action} wird ausgeführt...",
|
|
19
|
-
"handle.success": "{action} erfolgreich",
|
|
20
|
-
"handle.with_errors": "{action} fehlgeschlagen",
|
|
21
|
-
"handle.with_warnings": "{action} erfolgreich, mit Warnungen",
|
|
22
|
-
"handle.error_response":
|
|
23
|
-
"Die Anfrage war nicht erfolgreich:\n{error}\nWir wurden benachrichtigt und werden das Problem in Kürze beheben.",
|
|
24
|
-
"handle.response_error": "Die Antwort konnte nicht verarbeitet werden:\n{error}",
|
|
25
|
-
"handle.request_error": "Die Anfrage konnte nicht gesendet werden:\n{error}",
|
|
26
|
-
"handle.unexpected_error2": "{action} unerwarteter Fehler, probieren sie es in kurze nochmals."
|
|
27
|
-
},
|
|
28
|
-
en: {
|
|
29
|
-
"handle.confirmation": "Confirm {action}?",
|
|
30
|
-
"handle.waiting": "{action} executing...",
|
|
31
|
-
"handle.success": "{action} Success",
|
|
32
|
-
"handle.with_errors": "{action} Failed",
|
|
33
|
-
"handle.with_warnings": "{action}, with warnings",
|
|
34
|
-
"handle.error_response":
|
|
35
|
-
"There was an error in processing the response:\n{error}\nWe have been notified and will fix the problem shortly.",
|
|
36
|
-
"handle.request_error": "There was an error in the request:\n{error}",
|
|
37
|
-
"handle.response_error": "The request was not successful:\n{error}",
|
|
38
|
-
"handle.unexpected_error2": "{action} unexpected error, please try again shortly."
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class CommandContext extends Context.Tag("CommandContext")<
|
|
43
|
-
CommandContext,
|
|
44
|
-
{ action: string }
|
|
45
|
-
>() {}
|
|
46
|
-
|
|
47
|
-
export interface CommandProps<A, E> {
|
|
48
|
-
action: string
|
|
49
|
-
result: Result<A, E>
|
|
50
|
-
waiting: boolean
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const makeUseCommand = <Locale extends string, RT>(
|
|
54
|
-
// NOTE: underscores to not collide with auto exports in nuxt apps
|
|
55
|
-
_useIntl: MakeIntlReturn<Locale>["useIntl"],
|
|
56
|
-
_useConfirm: ReturnType<typeof makeUseConfirm>,
|
|
57
|
-
_useWithToast: ReturnType<typeof makeUseWithToast>,
|
|
58
|
-
runtime: Runtime.Runtime<RT>
|
|
59
|
-
) =>
|
|
60
|
-
() => {
|
|
61
|
-
const withToast = _useWithToast()
|
|
62
|
-
const { intl } = _useIntl()
|
|
63
|
-
const { confirmOrInterrupt } = _useConfirm()
|
|
64
|
-
|
|
65
|
-
const runFork = Runtime.runFork(runtime)
|
|
66
|
-
|
|
67
|
-
type CommandOut<Args extends Array<any>, A, E> = ComputedRef<
|
|
68
|
-
((...a: Args) => RuntimeFiber<Exit.Exit<A, E>, never>) & CommandProps<A, E>
|
|
69
|
-
>
|
|
70
|
-
|
|
71
|
-
type CommandOutHelper<Args extends Array<any>, Eff extends Effect.Effect<any, any, any>> = CommandOut<
|
|
72
|
-
Args,
|
|
73
|
-
Effect.Effect.Success<Eff>,
|
|
74
|
-
Effect.Effect.Error<Eff>
|
|
75
|
-
>
|
|
76
|
-
|
|
77
|
-
type Gen = {
|
|
78
|
-
<Eff extends YieldWrap<Effect.Effect<any, any, RT | CommandContext>>, AEff, Args extends Array<any>>(
|
|
79
|
-
body: (...args: Args) => Generator<Eff, AEff, never>
|
|
80
|
-
): CommandOut<
|
|
81
|
-
Args,
|
|
82
|
-
AEff,
|
|
83
|
-
[Eff] extends [never] ? never
|
|
84
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
85
|
-
: never
|
|
86
|
-
>
|
|
87
|
-
<
|
|
88
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
89
|
-
AEff,
|
|
90
|
-
Args extends Array<any>,
|
|
91
|
-
A extends Effect.Effect<any, any, RT | CommandContext>
|
|
92
|
-
>(
|
|
93
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
94
|
-
a: (
|
|
95
|
-
_: Effect.Effect<
|
|
96
|
-
AEff,
|
|
97
|
-
[Eff] extends [never] ? never
|
|
98
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
99
|
-
: never,
|
|
100
|
-
[Eff] extends [never] ? never
|
|
101
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
102
|
-
: never
|
|
103
|
-
>,
|
|
104
|
-
...args: NoInfer<Args>
|
|
105
|
-
) => A
|
|
106
|
-
): CommandOutHelper<Args, A>
|
|
107
|
-
<
|
|
108
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
109
|
-
AEff,
|
|
110
|
-
Args extends Array<any>,
|
|
111
|
-
A,
|
|
112
|
-
B extends Effect.Effect<any, any, RT | CommandContext>
|
|
113
|
-
>(
|
|
114
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
115
|
-
a: (
|
|
116
|
-
_: Effect.Effect<
|
|
117
|
-
AEff,
|
|
118
|
-
[Eff] extends [never] ? never
|
|
119
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
120
|
-
: never,
|
|
121
|
-
[Eff] extends [never] ? never
|
|
122
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
123
|
-
: never
|
|
124
|
-
>,
|
|
125
|
-
...args: NoInfer<Args>
|
|
126
|
-
) => A,
|
|
127
|
-
b: (_: A, ...args: NoInfer<Args>) => B
|
|
128
|
-
): CommandOutHelper<Args, B>
|
|
129
|
-
<
|
|
130
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
131
|
-
AEff,
|
|
132
|
-
Args extends Array<any>,
|
|
133
|
-
A,
|
|
134
|
-
B,
|
|
135
|
-
C extends Effect.Effect<any, any, RT | CommandContext>
|
|
136
|
-
>(
|
|
137
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
138
|
-
a: (
|
|
139
|
-
_: Effect.Effect<
|
|
140
|
-
AEff,
|
|
141
|
-
[Eff] extends [never] ? never
|
|
142
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
143
|
-
: never,
|
|
144
|
-
[Eff] extends [never] ? never
|
|
145
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
146
|
-
: never
|
|
147
|
-
>,
|
|
148
|
-
...args: NoInfer<Args>
|
|
149
|
-
) => A,
|
|
150
|
-
b: (_: A, ...args: NoInfer<Args>) => B,
|
|
151
|
-
c: (_: B, ...args: NoInfer<Args>) => C
|
|
152
|
-
): CommandOutHelper<Args, C>
|
|
153
|
-
<
|
|
154
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
155
|
-
AEff,
|
|
156
|
-
Args extends Array<any>,
|
|
157
|
-
A,
|
|
158
|
-
B,
|
|
159
|
-
C,
|
|
160
|
-
D extends Effect.Effect<any, any, RT | CommandContext>
|
|
161
|
-
>(
|
|
162
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
163
|
-
a: (
|
|
164
|
-
_: Effect.Effect<
|
|
165
|
-
AEff,
|
|
166
|
-
[Eff] extends [never] ? never
|
|
167
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
168
|
-
: never,
|
|
169
|
-
[Eff] extends [never] ? never
|
|
170
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
171
|
-
: never
|
|
172
|
-
>,
|
|
173
|
-
...args: NoInfer<Args>
|
|
174
|
-
) => A,
|
|
175
|
-
b: (_: A, ...args: NoInfer<Args>) => B,
|
|
176
|
-
c: (_: B, ...args: NoInfer<Args>) => C,
|
|
177
|
-
d: (_: C, ...args: NoInfer<Args>) => D
|
|
178
|
-
): CommandOutHelper<Args, D>
|
|
179
|
-
<
|
|
180
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
181
|
-
AEff,
|
|
182
|
-
Args extends Array<any>,
|
|
183
|
-
A,
|
|
184
|
-
B,
|
|
185
|
-
C,
|
|
186
|
-
D,
|
|
187
|
-
E extends Effect.Effect<any, any, RT | CommandContext>
|
|
188
|
-
>(
|
|
189
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
190
|
-
a: (
|
|
191
|
-
_: Effect.Effect<
|
|
192
|
-
AEff,
|
|
193
|
-
[Eff] extends [never] ? never
|
|
194
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
195
|
-
: never,
|
|
196
|
-
[Eff] extends [never] ? never
|
|
197
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
198
|
-
: never
|
|
199
|
-
>,
|
|
200
|
-
...args: NoInfer<Args>
|
|
201
|
-
) => A,
|
|
202
|
-
b: (_: A, ...args: NoInfer<Args>) => B,
|
|
203
|
-
c: (_: B, ...args: NoInfer<Args>) => C,
|
|
204
|
-
d: (_: C, ...args: NoInfer<Args>) => D,
|
|
205
|
-
e: (_: D, ...args: NoInfer<Args>) => E
|
|
206
|
-
): CommandOutHelper<Args, E>
|
|
207
|
-
<
|
|
208
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
209
|
-
AEff,
|
|
210
|
-
Args extends Array<any>,
|
|
211
|
-
A,
|
|
212
|
-
B,
|
|
213
|
-
C,
|
|
214
|
-
D,
|
|
215
|
-
E,
|
|
216
|
-
F extends Effect.Effect<any, any, RT | CommandContext>
|
|
217
|
-
>(
|
|
218
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
219
|
-
a: (
|
|
220
|
-
_: Effect.Effect<
|
|
221
|
-
AEff,
|
|
222
|
-
[Eff] extends [never] ? never
|
|
223
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
224
|
-
: never,
|
|
225
|
-
[Eff] extends [never] ? never
|
|
226
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
227
|
-
: never
|
|
228
|
-
>,
|
|
229
|
-
...args: NoInfer<Args>
|
|
230
|
-
) => A,
|
|
231
|
-
b: (_: A, ...args: NoInfer<Args>) => B,
|
|
232
|
-
c: (_: B, ...args: NoInfer<Args>) => C,
|
|
233
|
-
d: (_: C, ...args: NoInfer<Args>) => D,
|
|
234
|
-
e: (_: D, ...args: NoInfer<Args>) => E,
|
|
235
|
-
f: (_: E, ...args: NoInfer<Args>) => F
|
|
236
|
-
): CommandOutHelper<Args, F>
|
|
237
|
-
<
|
|
238
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
239
|
-
AEff,
|
|
240
|
-
Args extends Array<any>,
|
|
241
|
-
A,
|
|
242
|
-
B,
|
|
243
|
-
C,
|
|
244
|
-
D,
|
|
245
|
-
E,
|
|
246
|
-
F,
|
|
247
|
-
G extends Effect.Effect<any, any, RT | CommandContext>
|
|
248
|
-
>(
|
|
249
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
250
|
-
a: (
|
|
251
|
-
_: Effect.Effect<
|
|
252
|
-
AEff,
|
|
253
|
-
[Eff] extends [never] ? never
|
|
254
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
255
|
-
: never,
|
|
256
|
-
[Eff] extends [never] ? never
|
|
257
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
258
|
-
: never
|
|
259
|
-
>,
|
|
260
|
-
...args: NoInfer<Args>
|
|
261
|
-
) => A,
|
|
262
|
-
b: (_: A, ...args: NoInfer<Args>) => B,
|
|
263
|
-
c: (_: B, ...args: NoInfer<Args>) => C,
|
|
264
|
-
d: (_: C, ...args: NoInfer<Args>) => D,
|
|
265
|
-
e: (_: D, ...args: NoInfer<Args>) => E,
|
|
266
|
-
f: (_: E, ...args: NoInfer<Args>) => F,
|
|
267
|
-
g: (_: F, ...args: NoInfer<Args>) => G
|
|
268
|
-
): CommandOutHelper<Args, G>
|
|
269
|
-
<
|
|
270
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
271
|
-
AEff,
|
|
272
|
-
Args extends Array<any>,
|
|
273
|
-
A,
|
|
274
|
-
B,
|
|
275
|
-
C,
|
|
276
|
-
D,
|
|
277
|
-
E,
|
|
278
|
-
F,
|
|
279
|
-
G,
|
|
280
|
-
H extends Effect.Effect<any, any, RT | CommandContext>
|
|
281
|
-
>(
|
|
282
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
283
|
-
a: (
|
|
284
|
-
_: Effect.Effect<
|
|
285
|
-
AEff,
|
|
286
|
-
[Eff] extends [never] ? never
|
|
287
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
288
|
-
: never,
|
|
289
|
-
[Eff] extends [never] ? never
|
|
290
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
291
|
-
: never
|
|
292
|
-
>,
|
|
293
|
-
...args: NoInfer<Args>
|
|
294
|
-
) => A,
|
|
295
|
-
b: (_: A, ...args: NoInfer<Args>) => B,
|
|
296
|
-
c: (_: B, ...args: NoInfer<Args>) => C,
|
|
297
|
-
d: (_: C, ...args: NoInfer<Args>) => D,
|
|
298
|
-
e: (_: D, ...args: NoInfer<Args>) => E,
|
|
299
|
-
f: (_: E, ...args: NoInfer<Args>) => F,
|
|
300
|
-
g: (_: F, ...args: NoInfer<Args>) => G,
|
|
301
|
-
h: (_: G, ...args: NoInfer<Args>) => H
|
|
302
|
-
): CommandOutHelper<Args, H>
|
|
303
|
-
<
|
|
304
|
-
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
305
|
-
AEff,
|
|
306
|
-
Args extends Array<any>,
|
|
307
|
-
A,
|
|
308
|
-
B,
|
|
309
|
-
C,
|
|
310
|
-
D,
|
|
311
|
-
E,
|
|
312
|
-
F,
|
|
313
|
-
G,
|
|
314
|
-
H,
|
|
315
|
-
I extends Effect.Effect<any, any, RT | CommandContext>
|
|
316
|
-
>(
|
|
317
|
-
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
318
|
-
a: (
|
|
319
|
-
_: Effect.Effect<
|
|
320
|
-
AEff,
|
|
321
|
-
[Eff] extends [never] ? never
|
|
322
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
|
|
323
|
-
: never,
|
|
324
|
-
[Eff] extends [never] ? never
|
|
325
|
-
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
|
|
326
|
-
: never
|
|
327
|
-
>,
|
|
328
|
-
...args: NoInfer<Args>
|
|
329
|
-
) => A,
|
|
330
|
-
b: (_: A, ...args: NoInfer<Args>) => B,
|
|
331
|
-
c: (_: B, ...args: NoInfer<Args>) => C,
|
|
332
|
-
d: (_: C, ...args: NoInfer<Args>) => D,
|
|
333
|
-
e: (_: D, ...args: NoInfer<Args>) => E,
|
|
334
|
-
f: (_: E, ...args: NoInfer<Args>) => F,
|
|
335
|
-
g: (_: F, ...args: NoInfer<Args>) => G,
|
|
336
|
-
h: (_: G, ...args: NoInfer<Args>) => H,
|
|
337
|
-
i: (_: H, ...args: NoInfer<Args>) => I
|
|
338
|
-
): CommandOutHelper<Args, I>
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const makeCommand =
|
|
342
|
-
(actionName: string, errorDef?: Error) =>
|
|
343
|
-
<Args extends ReadonlyArray<any>, A, E, R extends RT | CommandContext>(
|
|
344
|
-
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
345
|
-
) => {
|
|
346
|
-
const limit = Error.stackTraceLimit
|
|
347
|
-
Error.stackTraceLimit = 2
|
|
348
|
-
const localErrorDef = new Error()
|
|
349
|
-
Error.stackTraceLimit = limit
|
|
350
|
-
if (!errorDef) {
|
|
351
|
-
errorDef = localErrorDef
|
|
352
|
-
}
|
|
353
|
-
const action = intl.value.formatMessage({
|
|
354
|
-
id: `action.${actionName}`,
|
|
355
|
-
defaultMessage: actionName
|
|
356
|
-
})
|
|
357
|
-
const context = { action }
|
|
358
|
-
|
|
359
|
-
const errorReporter = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
360
|
-
self.pipe(
|
|
361
|
-
Effect.tapErrorCause(
|
|
362
|
-
Effect.fnUntraced(function*(cause) {
|
|
363
|
-
if (Cause.isInterruptedOnly(cause)) {
|
|
364
|
-
console.info(`Interrupted while trying to ${actionName}`)
|
|
365
|
-
return
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const fail = Cause.failureOption(cause)
|
|
369
|
-
if (Option.isSome(fail)) {
|
|
370
|
-
// if (fail.value._tag === "SuppressErrors") {
|
|
371
|
-
// console.info(
|
|
372
|
-
// `Suppressed error trying to ${action}`,
|
|
373
|
-
// fail.value,
|
|
374
|
-
// )
|
|
375
|
-
// return
|
|
376
|
-
// }
|
|
377
|
-
const message = `Failure trying to ${actionName}`
|
|
378
|
-
yield* reportMessage(message, {
|
|
379
|
-
action: actionName,
|
|
380
|
-
error: fail.value
|
|
381
|
-
})
|
|
382
|
-
return
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const extra = {
|
|
386
|
-
action,
|
|
387
|
-
message: `Unexpected Error trying to ${actionName}`
|
|
388
|
-
}
|
|
389
|
-
yield* reportRuntimeError(cause, extra)
|
|
390
|
-
})
|
|
391
|
-
)
|
|
392
|
-
)
|
|
393
|
-
|
|
394
|
-
const theHandler = flow(
|
|
395
|
-
handler,
|
|
396
|
-
// all must be within the Effect.fn to fit within the Span
|
|
397
|
-
Effect.provideService(CommandContext, context),
|
|
398
|
-
(_) => Effect.annotateCurrentSpan({ action }).pipe(Effect.zipRight(_)),
|
|
399
|
-
errorReporter
|
|
400
|
-
)
|
|
401
|
-
|
|
402
|
-
const [result, mut] = asResult(theHandler)
|
|
403
|
-
|
|
404
|
-
return computed(() =>
|
|
405
|
-
Object.assign(
|
|
406
|
-
(...args: Args) => {
|
|
407
|
-
const limit = Error.stackTraceLimit
|
|
408
|
-
Error.stackTraceLimit = 2
|
|
409
|
-
const errorCall = new Error()
|
|
410
|
-
Error.stackTraceLimit = limit
|
|
411
|
-
|
|
412
|
-
let cache: false | string = false
|
|
413
|
-
const captureStackTrace = () => {
|
|
414
|
-
if (cache !== false) {
|
|
415
|
-
return cache
|
|
416
|
-
}
|
|
417
|
-
if (errorCall.stack) {
|
|
418
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
419
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
420
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
421
|
-
if (!endStackDef.includes(`(`)) {
|
|
422
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
423
|
-
}
|
|
424
|
-
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
425
|
-
if (!endStackCall.includes(`(`)) {
|
|
426
|
-
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
427
|
-
}
|
|
428
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
429
|
-
return cache
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
return runFork(Effect.withSpan(mut(...args), actionName, { captureStackTrace }))
|
|
433
|
-
}, /* make sure always create a new one, or the state won't properly propagate */
|
|
434
|
-
{
|
|
435
|
-
action,
|
|
436
|
-
result: result.value,
|
|
437
|
-
waiting: result.value.waiting
|
|
438
|
-
} as CommandProps<A, E>
|
|
439
|
-
)
|
|
440
|
-
)
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
return {
|
|
444
|
-
/** Version of confirmOrInterrupt that automatically includes the action name in the default messages */
|
|
445
|
-
confirmOrInterrupt: Effect.fnUntraced(function*(
|
|
446
|
-
message: string | undefined = undefined
|
|
447
|
-
) {
|
|
448
|
-
const context = yield* CommandContext
|
|
449
|
-
yield* confirmOrInterrupt(
|
|
450
|
-
message
|
|
451
|
-
?? intl.value.formatMessage(
|
|
452
|
-
{ id: "handle.confirmation" },
|
|
453
|
-
{ action: context.action }
|
|
454
|
-
)
|
|
455
|
-
)
|
|
456
|
-
}),
|
|
457
|
-
/** Version of withDefaultToast that automatically includes the action name in the default messages and uses intl */
|
|
458
|
-
withDefaultToast: <A, E>(errorRenderer?: (e: E) => string | undefined) =>
|
|
459
|
-
(
|
|
460
|
-
self: Effect.Effect<A, E, CommandContext>
|
|
461
|
-
) =>
|
|
462
|
-
Effect.gen(function*() {
|
|
463
|
-
const { action } = yield* CommandContext
|
|
464
|
-
|
|
465
|
-
const defaultWarnMessage = intl.value.formatMessage(
|
|
466
|
-
{ id: "handle.with_warnings" },
|
|
467
|
-
{ action }
|
|
468
|
-
)
|
|
469
|
-
const defaultErrorMessage = intl.value.formatMessage(
|
|
470
|
-
{ id: "handle.with_errors" },
|
|
471
|
-
{ action }
|
|
472
|
-
)
|
|
473
|
-
function renderError(e: E): string {
|
|
474
|
-
if (errorRenderer) {
|
|
475
|
-
const m = errorRenderer(e)
|
|
476
|
-
if (m) {
|
|
477
|
-
return m
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
if (!S.is(SupportedErrors)(e) && !S.ParseResult.isParseError(e)) {
|
|
481
|
-
if (typeof e === "object" && e !== null) {
|
|
482
|
-
if ("message" in e) {
|
|
483
|
-
return `${e.message}`
|
|
484
|
-
}
|
|
485
|
-
if ("_tag" in e) {
|
|
486
|
-
return `${e._tag}`
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
return ""
|
|
490
|
-
}
|
|
491
|
-
const e2: SupportedErrors | S.ParseResult.ParseError = e
|
|
492
|
-
return Match.value(e2).pipe(
|
|
493
|
-
Match.tags({
|
|
494
|
-
ParseError: (e) => {
|
|
495
|
-
console.warn(e.toString())
|
|
496
|
-
return intl.value.formatMessage({ id: "validation.failed" })
|
|
497
|
-
}
|
|
498
|
-
}),
|
|
499
|
-
Match.orElse((e) => `${e.message ?? e._tag ?? e}`)
|
|
500
|
-
)
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return yield* self.pipe(
|
|
504
|
-
withToast({
|
|
505
|
-
onWaiting: intl.value.formatMessage(
|
|
506
|
-
{ id: "handle.waiting" },
|
|
507
|
-
{ action }
|
|
508
|
-
),
|
|
509
|
-
onSuccess: (a) =>
|
|
510
|
-
intl.value.formatMessage({ id: "handle.success" }, { action })
|
|
511
|
-
+ (S.is(OperationSuccess)(a) && a.message ? "\n" + a.message : ""),
|
|
512
|
-
onFailure: Option.match({
|
|
513
|
-
onNone: () =>
|
|
514
|
-
intl.value.formatMessage(
|
|
515
|
-
{ id: "handle.unexpected_error2" },
|
|
516
|
-
{
|
|
517
|
-
action,
|
|
518
|
-
error: "" // TODO consider again Cause.pretty(cause), // will be reported to Sentry/Otel anyway.. and we shouldn't bother users with error dumps?
|
|
519
|
-
}
|
|
520
|
-
),
|
|
521
|
-
onSome: (e) =>
|
|
522
|
-
S.is(OperationFailure)(e)
|
|
523
|
-
? {
|
|
524
|
-
level: "warn",
|
|
525
|
-
message: defaultWarnMessage + e.message ? "\n" + e.message : ""
|
|
526
|
-
}
|
|
527
|
-
: `${defaultErrorMessage}:\n` + renderError(e)
|
|
528
|
-
})
|
|
529
|
-
})
|
|
530
|
-
)
|
|
531
|
-
}),
|
|
532
|
-
/**
|
|
533
|
-
* Define a Command
|
|
534
|
-
* @param actionName The internal name of the action. will be used as Span. will be used to lookup user facing name via intl. `action.${actionName}`
|
|
535
|
-
* @returns A function that can be called to execute the mutation, like directly in a `@click` handler. Error reporting is built-in.
|
|
536
|
-
* the Effects **only** have access to the `CommandContext` service, which contains the user-facing action name.
|
|
537
|
-
* The function also has the following properties:
|
|
538
|
-
* - action: The user-facing name of the action, as defined in the intl messages. Can be used e.g as Button label.
|
|
539
|
-
* - result: The Result of the mutation
|
|
540
|
-
* - waiting: Whether the mutation is currently in progress. (shorthand for .result.waiting). Can be used e.g as Button loading/disabled state.
|
|
541
|
-
* Reporting status to the user is recommended to use the `withDefaultToast` helper, or render the .result inline
|
|
542
|
-
*/
|
|
543
|
-
fn: (actionName: string): Gen =>
|
|
544
|
-
// TODO constrain/type combinators
|
|
545
|
-
(
|
|
546
|
-
fn: any,
|
|
547
|
-
// TODO: combinators can freely take A, E, R and change it to whatever they want, as long as the end result Requires not more than CommandContext | R
|
|
548
|
-
...combinators: any[]
|
|
549
|
-
): any => {
|
|
550
|
-
const limit = Error.stackTraceLimit
|
|
551
|
-
Error.stackTraceLimit = 2
|
|
552
|
-
const errorDef = new Error()
|
|
553
|
-
Error.stackTraceLimit = limit
|
|
554
|
-
|
|
555
|
-
return makeCommand(actionName, errorDef)(Effect.fnUntraced(fn, ...combinators as [any]) as any)
|
|
556
|
-
},
|
|
557
|
-
|
|
558
|
-
alt: makeCommand as (
|
|
559
|
-
actionName: string
|
|
560
|
-
) => <Args extends ReadonlyArray<any>, A, E, R extends RT | CommandContext>(
|
|
561
|
-
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
562
|
-
) => ComputedRef<((...a: Args) => RuntimeFiber<Exit.Exit<A, E>, never>) & CommandProps<A, E>>
|
|
563
|
-
}
|
|
564
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect-app"
|
|
2
|
-
import { type MakeIntlReturn } from "../makeIntl.js"
|
|
3
|
-
|
|
4
|
-
export const makeUseConfirm = <Locale extends string>(_useIntl: MakeIntlReturn<Locale>["useIntl"]) => () => {
|
|
5
|
-
const { intl } = _useIntl()
|
|
6
|
-
const getDefaultMessage = () =>
|
|
7
|
-
intl.value.formatMessage({ id: "confirm.default", defaultMessage: "Sind sie Sicher?" })
|
|
8
|
-
|
|
9
|
-
const confirm = (message = getDefaultMessage()) => Effect.sync(() => window.confirm(message))
|
|
10
|
-
|
|
11
|
-
const confirmOrInterrupt = (message = getDefaultMessage()) =>
|
|
12
|
-
confirm(message).pipe(
|
|
13
|
-
Effect.flatMap((result) => (result ? Effect.void : Effect.interrupt))
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
return { confirm, confirmOrInterrupt }
|
|
17
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Cause, Effect, type Option } from "effect-app"
|
|
2
|
-
|
|
3
|
-
export interface ToastOptions<A, E, Args extends ReadonlyArray<unknown>> {
|
|
4
|
-
onWaiting: string | ((...args: Args) => string)
|
|
5
|
-
onSuccess: string | ((a: A, ...args: Args) => string)
|
|
6
|
-
onFailure:
|
|
7
|
-
| string
|
|
8
|
-
| ((
|
|
9
|
-
error: Option.Option<E>,
|
|
10
|
-
...args: Args
|
|
11
|
-
) => string | { level: "warn" | "error"; message: string })
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type ToastId = string | number
|
|
15
|
-
export type ToastOpts = { id?: ToastId; timeout?: number }
|
|
16
|
-
|
|
17
|
-
export type UseToast = () => {
|
|
18
|
-
error: (message: string, options?: ToastOpts) => ToastId
|
|
19
|
-
warning: (message: string, options?: ToastOpts) => ToastId
|
|
20
|
-
success: (message: string, options?: ToastOpts) => ToastId
|
|
21
|
-
info: (message: string, options?: ToastOpts) => ToastId
|
|
22
|
-
dismiss: (id: ToastId) => void
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const makeUseWithToast = (useToast: UseToast) => () => {
|
|
26
|
-
const toast = useToast()
|
|
27
|
-
return <A, E, Args extends ReadonlyArray<unknown>, R>(
|
|
28
|
-
options: ToastOptions<A, E, Args>
|
|
29
|
-
) =>
|
|
30
|
-
Effect.fnUntraced(function*(self: Effect.Effect<A, E, R>, ...args: Args) {
|
|
31
|
-
const toastId = toast.info(
|
|
32
|
-
// .loading
|
|
33
|
-
typeof options.onWaiting === "string"
|
|
34
|
-
? options.onWaiting
|
|
35
|
-
: options.onWaiting(...args)
|
|
36
|
-
)
|
|
37
|
-
return yield* self.pipe(
|
|
38
|
-
Effect.tap((a) => {
|
|
39
|
-
toast.success(
|
|
40
|
-
typeof options.onSuccess === "string"
|
|
41
|
-
? options.onSuccess
|
|
42
|
-
: options.onSuccess(a, ...args),
|
|
43
|
-
{ id: toastId, timeout: 3_000 }
|
|
44
|
-
)
|
|
45
|
-
}),
|
|
46
|
-
Effect.tapErrorCause((cause) =>
|
|
47
|
-
Effect.sync(() => {
|
|
48
|
-
if (Cause.isInterruptedOnly(cause)) {
|
|
49
|
-
toast.dismiss(toastId)
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
const t = typeof options.onFailure === "string"
|
|
53
|
-
? options.onFailure
|
|
54
|
-
: options.onFailure(Cause.failureOption(cause), ...args)
|
|
55
|
-
if (typeof t === "object") {
|
|
56
|
-
return t.level === "warn"
|
|
57
|
-
? toast.warning(t.message, { id: toastId, timeout: 5_000 })
|
|
58
|
-
: toast.error(t.message, { id: toastId, timeout: 5_000 })
|
|
59
|
-
}
|
|
60
|
-
toast.error(t, { id: toastId, timeout: 5_000 })
|
|
61
|
-
})
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
|
-
})
|
|
65
|
-
}
|