@effect-app/vue 4.0.0-beta.19 → 4.0.0-beta.190

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +1383 -0
  2. package/dist/commander.d.ts +620 -0
  3. package/dist/commander.d.ts.map +1 -0
  4. package/dist/commander.js +1056 -0
  5. package/dist/confirm.d.ts +19 -0
  6. package/dist/confirm.d.ts.map +1 -0
  7. package/dist/confirm.js +24 -0
  8. package/dist/errorReporter.d.ts +4 -4
  9. package/dist/errorReporter.d.ts.map +1 -1
  10. package/dist/errorReporter.js +12 -18
  11. package/dist/form.d.ts +13 -4
  12. package/dist/form.d.ts.map +1 -1
  13. package/dist/form.js +41 -12
  14. package/dist/index.d.ts +1 -1
  15. package/dist/intl.d.ts +15 -0
  16. package/dist/intl.d.ts.map +1 -0
  17. package/dist/intl.js +9 -0
  18. package/dist/lib.d.ts +6 -8
  19. package/dist/lib.d.ts.map +1 -1
  20. package/dist/lib.js +34 -7
  21. package/dist/makeClient.d.ts +191 -292
  22. package/dist/makeClient.d.ts.map +1 -1
  23. package/dist/makeClient.js +217 -369
  24. package/dist/makeContext.d.ts +1 -1
  25. package/dist/makeContext.d.ts.map +1 -1
  26. package/dist/makeIntl.d.ts +1 -1
  27. package/dist/makeIntl.d.ts.map +1 -1
  28. package/dist/makeUseCommand.d.ts +8 -0
  29. package/dist/makeUseCommand.d.ts.map +1 -0
  30. package/dist/makeUseCommand.js +13 -0
  31. package/dist/mutate.d.ts +56 -25
  32. package/dist/mutate.d.ts.map +1 -1
  33. package/dist/mutate.js +132 -33
  34. package/dist/query.d.ts +24 -16
  35. package/dist/query.d.ts.map +1 -1
  36. package/dist/query.js +119 -37
  37. package/dist/routeParams.d.ts +1 -1
  38. package/dist/runtime.d.ts +5 -2
  39. package/dist/runtime.d.ts.map +1 -1
  40. package/dist/runtime.js +27 -17
  41. package/dist/toast.d.ts +46 -0
  42. package/dist/toast.d.ts.map +1 -0
  43. package/dist/toast.js +32 -0
  44. package/dist/withToast.d.ts +26 -0
  45. package/dist/withToast.d.ts.map +1 -0
  46. package/dist/withToast.js +54 -0
  47. package/eslint.config.mjs +2 -2
  48. package/examples/streamMutation.ts +70 -0
  49. package/package.json +48 -48
  50. package/src/commander.ts +3378 -0
  51. package/src/{experimental/confirm.ts → confirm.ts} +10 -14
  52. package/src/errorReporter.ts +62 -74
  53. package/src/form.ts +55 -16
  54. package/src/intl.ts +12 -0
  55. package/src/lib.ts +46 -13
  56. package/src/makeClient.ts +623 -1043
  57. package/src/{experimental/makeUseCommand.ts → makeUseCommand.ts} +6 -4
  58. package/src/mutate.ts +273 -72
  59. package/src/query.ts +181 -68
  60. package/src/runtime.ts +39 -18
  61. package/src/{experimental/toast.ts → toast.ts} +11 -25
  62. package/src/{experimental/withToast.ts → withToast.ts} +28 -10
  63. package/test/Mutation.test.ts +105 -11
  64. package/test/dist/form.test.d.ts.map +1 -1
  65. package/test/dist/lib.test.d.ts.map +1 -0
  66. package/test/dist/streamFinal.test.d.ts.map +1 -0
  67. package/test/dist/streamFn.test.d.ts.map +1 -0
  68. package/test/dist/stubs.d.ts +3289 -114
  69. package/test/dist/stubs.d.ts.map +1 -1
  70. package/test/dist/stubs.js +152 -25
  71. package/test/form-validation-errors.test.ts +23 -19
  72. package/test/form.test.ts +20 -2
  73. package/test/lib.test.ts +240 -0
  74. package/test/makeClient.test.ts +286 -38
  75. package/test/streamFinal.test.ts +63 -0
  76. package/test/streamFn.test.ts +436 -0
  77. package/test/stubs.ts +192 -42
  78. package/tsconfig.examples.json +20 -0
  79. package/tsconfig.json +0 -1
  80. package/tsconfig.json.bak +5 -2
  81. package/tsconfig.src.json +34 -34
  82. package/tsconfig.test.json +2 -2
  83. package/vitest.config.ts +5 -5
  84. package/dist/experimental/commander.d.ts +0 -359
  85. package/dist/experimental/commander.d.ts.map +0 -1
  86. package/dist/experimental/commander.js +0 -557
  87. package/dist/experimental/confirm.d.ts +0 -19
  88. package/dist/experimental/confirm.d.ts.map +0 -1
  89. package/dist/experimental/confirm.js +0 -28
  90. package/dist/experimental/intl.d.ts +0 -16
  91. package/dist/experimental/intl.d.ts.map +0 -1
  92. package/dist/experimental/intl.js +0 -5
  93. package/dist/experimental/makeUseCommand.d.ts +0 -8
  94. package/dist/experimental/makeUseCommand.d.ts.map +0 -1
  95. package/dist/experimental/makeUseCommand.js +0 -13
  96. package/dist/experimental/toast.d.ts +0 -47
  97. package/dist/experimental/toast.d.ts.map +0 -1
  98. package/dist/experimental/toast.js +0 -41
  99. package/dist/experimental/withToast.d.ts +0 -25
  100. package/dist/experimental/withToast.d.ts.map +0 -1
  101. package/dist/experimental/withToast.js +0 -45
  102. package/src/experimental/commander.ts +0 -1835
  103. package/src/experimental/intl.ts +0 -9
@@ -0,0 +1,436 @@
1
+ import { expect, it } from "@effect/vitest"
2
+ import { Deferred, Effect, Fiber } from "effect-app"
3
+ import * as Stream from "effect/Stream"
4
+ import { CommanderStatic } from "../src/commander.js"
5
+ import { AsyncResult } from "../src/lib.js"
6
+ import { useExperimental } from "./stubs.js"
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // Helpers
10
+ // ---------------------------------------------------------------------------
11
+
12
+ /** Wait for the fiber spawned by `cmd.handle()` to finish. */
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ const join = (fiber: Fiber.Fiber<any, any>) => Fiber.join(fiber)
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Non-generator form — (arg) => Stream
18
+ // ---------------------------------------------------------------------------
19
+
20
+ it.live("streamFn: non-generator returning Stream runs stream and updates result", () =>
21
+ Effect.gen(function*() {
22
+ const Command = useExperimental({ toasts: [] })
23
+
24
+ const cmd = Command.streamFn("test-stream-plain")(
25
+ (_arg: number) => Stream.make(10, 20, 30)
26
+ )
27
+
28
+ expect(cmd.waiting).toBe(false)
29
+ yield* join(cmd.handle(1))
30
+
31
+ expect(cmd.result._tag).toBe("Success")
32
+ if (cmd.result._tag === "Success") {
33
+ expect(cmd.result.value).toBe(30)
34
+ expect(cmd.result.waiting).toBe(false)
35
+ }
36
+ }))
37
+
38
+ // ---------------------------------------------------------------------------
39
+ // Generator form — function*(arg) { yield* effect; return Stream }
40
+ // ---------------------------------------------------------------------------
41
+
42
+ it.live("streamFn: generator form executes yielded effects and subscribes to returned stream", () =>
43
+ Effect.gen(function*() {
44
+ const Command = useExperimental({ toasts: [] })
45
+
46
+ let generatorBodyExecuted = false
47
+
48
+ const cmd = Command.streamFn("test-stream-gen")(
49
+ function*(arg: number) {
50
+ generatorBodyExecuted = true
51
+ const doubled = yield* Effect.succeed(arg * 2)
52
+ return Stream.make(doubled, doubled + 1, doubled + 2)
53
+ }
54
+ )
55
+
56
+ yield* join(cmd.handle(5))
57
+
58
+ // Generator body MUST have run
59
+ expect(generatorBodyExecuted).toBe(true)
60
+
61
+ // Stream emitted three values: 10, 11, 12; last one should be in result
62
+ expect(cmd.result._tag).toBe("Success")
63
+ if (cmd.result._tag === "Success") {
64
+ expect(cmd.result.value).toBe(12)
65
+ expect(cmd.result.waiting).toBe(false)
66
+ }
67
+ }))
68
+
69
+ // ---------------------------------------------------------------------------
70
+ // Generator form with async effect (Effect.promise)
71
+ // ---------------------------------------------------------------------------
72
+
73
+ it.live("streamFn: generator form with async Effect.promise works", () =>
74
+ Effect.gen(function*() {
75
+ const Command = useExperimental({ toasts: [] })
76
+
77
+ let asyncValueReceived: string | undefined
78
+
79
+ const cmd = Command.streamFn("test-stream-gen-async")(
80
+ function*(arg: string) {
81
+ // Simulate the pattern from the bug report: yield* Effect.promise(...)
82
+ const result = yield* Effect.promise(() => Promise.resolve(`processed:${arg}`))
83
+ asyncValueReceived = result
84
+ return Stream.make(result, result + "!")
85
+ }
86
+ )
87
+
88
+ yield* join(cmd.handle("hello"))
89
+
90
+ expect(asyncValueReceived).toBe("processed:hello")
91
+ expect(cmd.result._tag).toBe("Success")
92
+ if (cmd.result._tag === "Success") {
93
+ expect(cmd.result.value).toBe("processed:hello!")
94
+ }
95
+ }))
96
+
97
+ // ---------------------------------------------------------------------------
98
+ // Non-generator returning Effect<Stream>
99
+ // ---------------------------------------------------------------------------
100
+
101
+ it.live("streamFn: non-generator returning Effect<Stream> runs stream", () =>
102
+ Effect.gen(function*() {
103
+ const Command = useExperimental({ toasts: [] })
104
+
105
+ const cmd = Command.streamFn("test-stream-effect-stream")(
106
+ (arg: number) => Effect.succeed(Stream.make(arg * 3, arg * 3 + 1))
107
+ )
108
+
109
+ yield* join(cmd.handle(4))
110
+
111
+ expect(cmd.result._tag).toBe("Success")
112
+ if (cmd.result._tag === "Success") {
113
+ expect(cmd.result.value).toBe(13) // 4*3+1 = 13
114
+ }
115
+ }))
116
+
117
+ // ---------------------------------------------------------------------------
118
+ // Generator form — waiting state flips correctly
119
+ // ---------------------------------------------------------------------------
120
+
121
+ it.live("streamFn: generator form sets waiting=true during execution then false after", () =>
122
+ Effect.gen(function*() {
123
+ const Command = useExperimental({ toasts: [] })
124
+
125
+ const cmd = Command.streamFn("test-stream-gen-waiting")(
126
+ function*(_arg: void) {
127
+ return Stream.make(1, 2, 3)
128
+ }
129
+ )
130
+
131
+ expect(cmd.waiting).toBe(false)
132
+ const fiber = cmd.handle()
133
+
134
+ // result transitions to initial(true) = waiting synchronously inside runStream
135
+ // after the fiber runs, waiting should settle to false
136
+ yield* join(fiber)
137
+ expect(cmd.waiting).toBe(false)
138
+
139
+ expect(AsyncResult.isSuccess(cmd.result)).toBe(true)
140
+ }))
141
+
142
+ // ---------------------------------------------------------------------------
143
+ // Generator form with a stream-transformer combinator
144
+ // ---------------------------------------------------------------------------
145
+
146
+ it.live("streamFn: generator form with combinator — combinator transforms the stream", () =>
147
+ Effect.gen(function*() {
148
+ const Command = useExperimental({ toasts: [] })
149
+
150
+ const emittedByCombinator: number[] = []
151
+
152
+ // A combinator that records each element it sees.
153
+ // The first argument may be a Stream or an Effect<Stream> (for generator-form handlers),
154
+ // matching how withDefaultToastStream handles it.
155
+ const spyCombinator = (
156
+ input: Stream.Stream<number, never, never> | Effect.Effect<Stream.Stream<number, never, never>>
157
+ ) => {
158
+ const stream: Stream.Stream<number, never, never> = Stream.isStream(input)
159
+ ? input
160
+ : Stream.unwrap(input as Effect.Effect<Stream.Stream<number, never, never>>)
161
+ return stream.pipe(
162
+ Stream.tap((v) =>
163
+ Effect.sync(() => {
164
+ emittedByCombinator.push(v)
165
+ })
166
+ )
167
+ )
168
+ }
169
+
170
+ const cmd = Command.streamFn("test-stream-gen-combinator")(
171
+ function*(arg: number) {
172
+ const base = yield* Effect.succeed(arg * 10)
173
+ return Stream.make(base, base + 1, base + 2)
174
+ },
175
+ // combinator receives (input, arg, ctx) — input is Stream or Effect<Stream> depending on handler form
176
+ (input: Stream.Stream<number, never, never> | Effect.Effect<Stream.Stream<number, never, never>>) =>
177
+ spyCombinator(input)
178
+ )
179
+
180
+ yield* join(cmd.handle(3))
181
+
182
+ // combinator must have seen all elements: 30, 31, 32
183
+ expect(emittedByCombinator).toEqual([30, 31, 32])
184
+
185
+ expect(cmd.result._tag).toBe("Success")
186
+ if (cmd.result._tag === "Success") {
187
+ expect(cmd.result.value).toBe(32)
188
+ }
189
+ }))
190
+
191
+ // ---------------------------------------------------------------------------
192
+ // Generator form — Stream.ensuring runs after stream completes
193
+ // ---------------------------------------------------------------------------
194
+
195
+ it.live("streamFn: generator form Stream.ensuring cleanup runs after stream ends", () =>
196
+ Effect.gen(function*() {
197
+ const Command = useExperimental({ toasts: [] })
198
+
199
+ let cleanupRan = false
200
+
201
+ const cmd = Command.streamFn("test-stream-gen-ensuring")(
202
+ function*(arg: number) {
203
+ const value = yield* Effect.succeed(arg + 100)
204
+ return Stream.make(value).pipe(
205
+ Stream.ensuring(Effect.sync(() => {
206
+ cleanupRan = true
207
+ }))
208
+ )
209
+ }
210
+ )
211
+
212
+ yield* join(cmd.handle(7))
213
+
214
+ expect(cleanupRan).toBe(true)
215
+ expect(cmd.result._tag).toBe("Success")
216
+ if (cmd.result._tag === "Success") {
217
+ expect(cmd.result.value).toBe(107)
218
+ }
219
+ }))
220
+
221
+ // ---------------------------------------------------------------------------
222
+ // Command.mapProgress — updates progress ref for each element
223
+ // ---------------------------------------------------------------------------
224
+
225
+ it.live("streamFn: Command.mapProgress updates progress ref for each stream element", () =>
226
+ Effect.gen(function*() {
227
+ const Command = useExperimental({ toasts: [] })
228
+
229
+ const cmd = Command.streamFn("test-map-progress")(
230
+ function*(_arg: void) {
231
+ return Stream.make(1, 2, 3).pipe(
232
+ CommanderStatic.mapProgress((r) =>
233
+ AsyncResult.isSuccess(r)
234
+ ? { text: `item-${r.value}`, percentage: r.value * 10 }
235
+ : undefined
236
+ )
237
+ )
238
+ }
239
+ )
240
+
241
+ // progress starts undefined (reactive unwraps the ref)
242
+ expect(cmd.progress).toBeUndefined()
243
+
244
+ yield* join(cmd.handle())
245
+
246
+ // after stream drains, last mapped progress value should be set
247
+ expect(cmd.progress).toEqual({ text: "item-3", percentage: 30 })
248
+ }))
249
+
250
+ // ---------------------------------------------------------------------------
251
+ // Command.updateProgress — imperative progress update from stream
252
+ // ---------------------------------------------------------------------------
253
+
254
+ it.live("streamFn: Command.updateProgress imperatively drives the progress ref", () =>
255
+ Effect.gen(function*() {
256
+ const Command = useExperimental({ toasts: [] })
257
+
258
+ const cmd = Command.streamFn("test-update-progress")(
259
+ function*(_arg: void) {
260
+ return Stream.make("a", "b").pipe(
261
+ Stream.tap((v) => CommanderStatic.updateProgress(`processing ${v}`))
262
+ )
263
+ }
264
+ )
265
+
266
+ expect(cmd.progress).toBeUndefined()
267
+ yield* join(cmd.handle())
268
+
269
+ expect(cmd.progress).toBe("processing b")
270
+ }))
271
+
272
+ // ---------------------------------------------------------------------------
273
+ // Command.withDefaultToastStream — in-progress (waiting) initial toast
274
+ // ---------------------------------------------------------------------------
275
+
276
+ it.live("withDefaultToastStream: shows info toast while stream is running", () =>
277
+ Effect.gen(function*() {
278
+ const toasts: any[] = []
279
+ const Command = useExperimental({ toasts, messages: { "handle.waiting": "{action} waiting…" } })
280
+
281
+ // Gate that lets us inspect toast state while the stream is paused mid-flight.
282
+ const streamPaused = yield* Deferred.make<void>()
283
+ const resume = yield* Deferred.make<void>()
284
+
285
+ const cmd = Command.streamFn("doWork")(
286
+ function*(_arg: void) {
287
+ return Stream.make(1).pipe(
288
+ Stream.tap(() =>
289
+ Effect.gen(function*() {
290
+ yield* Deferred.succeed(streamPaused, undefined)
291
+ yield* Deferred.await(resume)
292
+ })
293
+ )
294
+ )
295
+ },
296
+ Command.withDefaultToastStream()
297
+ )
298
+
299
+ const fiber = cmd.handle()
300
+
301
+ // Wait until the stream has emitted its first element (and paused).
302
+ yield* Deferred.await(streamPaused)
303
+
304
+ // The waiting info toast should exist before the stream finishes.
305
+ expect(toasts.some((t) => t.type === "info")).toBe(true)
306
+ const infoToast = toasts.find((t) => t.type === "info")
307
+ expect(infoToast.message).toContain("doWork")
308
+
309
+ // Let the stream finish.
310
+ yield* Deferred.succeed(resume, undefined)
311
+ yield* join(fiber)
312
+
313
+ // After completion the same toast slot is replaced with a success toast.
314
+ expect(toasts.some((t) => t.type === "success")).toBe(true)
315
+ }))
316
+
317
+ // ---------------------------------------------------------------------------
318
+ // Command.withDefaultToastStream — progress text/percent updates the toast
319
+ // ---------------------------------------------------------------------------
320
+
321
+ it.live("withDefaultToastStream: progress option updates waiting toast message", () =>
322
+ Effect.gen(function*() {
323
+ const toasts: any[] = []
324
+ const Command = useExperimental({
325
+ toasts,
326
+ messages: { "handle.waiting": "Working…", "handle.success": "{action} done" }
327
+ })
328
+
329
+ const progressSnapshots: string[] = []
330
+
331
+ const cmd = Command.streamFn("doWorkProgress")(
332
+ function*(_arg: void) {
333
+ return Stream.make(10, 50, 100).pipe(
334
+ Stream.tap((pct) =>
335
+ Effect.sync(() => {
336
+ progressSnapshots.push(`${pct}%`)
337
+ })
338
+ )
339
+ )
340
+ },
341
+ Command.withDefaultToastStream({
342
+ progress: (r) =>
343
+ AsyncResult.isSuccess(r)
344
+ ? { text: `${r.value}%`, percentage: r.value }
345
+ : undefined
346
+ })
347
+ )
348
+
349
+ yield* join(cmd.handle())
350
+
351
+ // All three stream elements were visited by the tap above
352
+ expect(progressSnapshots).toEqual(["10%", "50%", "100%"])
353
+
354
+ // cmd.progress reflects the last mapped value (reactive unwraps the ref)
355
+ expect(cmd.progress).toEqual({ text: "100%", percentage: 100 })
356
+
357
+ // A success toast should appear after the stream completes
358
+ expect(toasts.some((t) => t.type === "success")).toBe(true)
359
+ }))
360
+
361
+ // ---------------------------------------------------------------------------
362
+ // Command.withDefaultToastStream — failure shows warning/error toast
363
+ // ---------------------------------------------------------------------------
364
+
365
+ it.live("withDefaultToastStream: failure shows failure toast, not success toast", () =>
366
+ Effect.gen(function*() {
367
+ const toasts: any[] = []
368
+ const Command = useExperimental({ toasts })
369
+
370
+ class BoomError {
371
+ readonly _tag = "BoomError"
372
+ readonly message = "boom"
373
+ }
374
+
375
+ const cmd = Command.streamFn("doWorkFail")(
376
+ function*(_arg: void) {
377
+ return Stream.fail(new BoomError())
378
+ },
379
+ Command.withDefaultToastStream()
380
+ )
381
+
382
+ yield* join(cmd.handle())
383
+
384
+ // Typed errors → withDefaultToastStream calls toast.warning (level: "warn")
385
+ expect(toasts.some((t) => t.type === "warning" || t.type === "error")).toBe(true)
386
+ expect(toasts.some((t) => t.type === "success")).toBe(false)
387
+ }))
388
+
389
+ // ---------------------------------------------------------------------------
390
+ // Command.withDefaultToastStream — die (defect) shows error toast
391
+ // ---------------------------------------------------------------------------
392
+
393
+ it.live("withDefaultToastStream: die/defect shows error toast, not warning or success", () =>
394
+ Effect.gen(function*() {
395
+ const toasts: any[] = []
396
+ const Command = useExperimental({ toasts })
397
+
398
+ const cmd = Command.streamFn("doWorkDie")(
399
+ function*(_arg: void) {
400
+ // Stream.die produces a defect — Cause.findErrorOption returns Option.none()
401
+ // so defaultFailureMessageHandler returns a plain string → toast.error
402
+ return Stream.die(new Error("unexpected defect"))
403
+ },
404
+ Command.withDefaultToastStream()
405
+ )
406
+
407
+ yield* join(cmd.handle())
408
+
409
+ expect(toasts.some((t) => t.type === "error")).toBe(true)
410
+ expect(toasts.some((t) => t.type === "warning")).toBe(false)
411
+ expect(toasts.some((t) => t.type === "success")).toBe(false)
412
+ }))
413
+
414
+ // ---------------------------------------------------------------------------
415
+ // Command.withDefaultToastStream — success shows success toast
416
+ // ---------------------------------------------------------------------------
417
+
418
+ it.live("withDefaultToastStream: success shows success toast after stream drains", () =>
419
+ Effect.gen(function*() {
420
+ const toasts: any[] = []
421
+ const Command = useExperimental({ toasts, messages: { "handle.success": "{action} complete" } })
422
+
423
+ const cmd = Command.streamFn("doWorkSuccess")(
424
+ function*(_arg: void) {
425
+ return Stream.make(42)
426
+ },
427
+ Command.withDefaultToastStream()
428
+ )
429
+
430
+ yield* join(cmd.handle())
431
+
432
+ const successToast = toasts.find((t) => t.type === "success")
433
+ expect(successToast).toBeDefined()
434
+ expect(successToast.message).toContain("doWorkSuccess")
435
+ expect(toasts.some((t) => t.type === "error")).toBe(false)
436
+ }))