@effect-app/vue 4.0.0-beta.186 → 4.0.0-beta.187

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @effect-app/vue
2
2
 
3
+ ## 4.0.0-beta.187
4
+
5
+ ### Patch Changes
6
+
7
+ - 0d4e0b8: Fix `isGeneratorFunction` using `isObject` instead of `isFunction`: generator functions have `typeof === "function"`, not `"object"`, so the check always returned `false`. This caused `Command.streamFn` generator-form handlers to silently pass a raw `Generator` object rather than an `Effect<Stream>`, meaning the mutation was never executed.
8
+ - Updated dependencies [0d4e0b8]
9
+ - effect-app@4.0.0-beta.187
10
+
3
11
  ## 4.0.0-beta.186
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue",
3
- "version": "4.0.0-beta.186",
3
+ "version": "4.0.0-beta.187",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/effect-ts-app/libs/tree/main/packages/vue",
@@ -11,7 +11,7 @@
11
11
  "@vueuse/core": "^14.2.1",
12
12
  "change-case": "^5.4.4",
13
13
  "query-string": "^9.3.1",
14
- "effect-app": "4.0.0-beta.186"
14
+ "effect-app": "4.0.0-beta.187"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@effect/atom-vue": "^4.0.0-beta.59",
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamFn.test.d.ts","sourceRoot":"","sources":["../streamFn.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,218 @@
1
+ import { expect, it } from "@effect/vitest"
2
+ import { Effect, Fiber } from "effect-app"
3
+ import * as Stream from "effect/Stream"
4
+ import { AsyncResult } from "../src/lib.js"
5
+ import { useExperimental } from "./stubs.js"
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // Helpers
9
+ // ---------------------------------------------------------------------------
10
+
11
+ /** Wait for the fiber spawned by `cmd.handle()` to finish. */
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ const join = (fiber: Fiber.Fiber<any, any>) => Fiber.join(fiber)
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Non-generator form — (arg) => Stream
17
+ // ---------------------------------------------------------------------------
18
+
19
+ it.live("streamFn: non-generator returning Stream runs stream and updates result", () =>
20
+ Effect.gen(function*() {
21
+ const Command = useExperimental({ toasts: [] })
22
+
23
+ const cmd = Command.streamFn("test-stream-plain")(
24
+ (_arg: number) => Stream.make(10, 20, 30)
25
+ )
26
+
27
+ expect(cmd.waiting).toBe(false)
28
+ yield* join(cmd.handle(1))
29
+
30
+ expect(cmd.result._tag).toBe("Success")
31
+ if (cmd.result._tag === "Success") {
32
+ expect(cmd.result.value).toBe(30)
33
+ expect(cmd.result.waiting).toBe(false)
34
+ }
35
+ }))
36
+
37
+ // ---------------------------------------------------------------------------
38
+ // Generator form — function*(arg) { yield* effect; return Stream }
39
+ // ---------------------------------------------------------------------------
40
+
41
+ it.live("streamFn: generator form executes yielded effects and subscribes to returned stream", () =>
42
+ Effect.gen(function*() {
43
+ const Command = useExperimental({ toasts: [] })
44
+
45
+ let generatorBodyExecuted = false
46
+
47
+ const cmd = Command.streamFn("test-stream-gen")(
48
+ function*(arg: number) {
49
+ generatorBodyExecuted = true
50
+ const doubled = yield* Effect.succeed(arg * 2)
51
+ return Stream.make(doubled, doubled + 1, doubled + 2)
52
+ }
53
+ )
54
+
55
+ yield* join(cmd.handle(5))
56
+
57
+ // Generator body MUST have run
58
+ expect(generatorBodyExecuted).toBe(true)
59
+
60
+ // Stream emitted three values: 10, 11, 12; last one should be in result
61
+ expect(cmd.result._tag).toBe("Success")
62
+ if (cmd.result._tag === "Success") {
63
+ expect(cmd.result.value).toBe(12)
64
+ expect(cmd.result.waiting).toBe(false)
65
+ }
66
+ }))
67
+
68
+ // ---------------------------------------------------------------------------
69
+ // Generator form with async effect (Effect.promise)
70
+ // ---------------------------------------------------------------------------
71
+
72
+ it.live("streamFn: generator form with async Effect.promise works", () =>
73
+ Effect.gen(function*() {
74
+ const Command = useExperimental({ toasts: [] })
75
+
76
+ let asyncValueReceived: string | undefined
77
+
78
+ const cmd = Command.streamFn("test-stream-gen-async")(
79
+ function*(arg: string) {
80
+ // Simulate the pattern from the bug report: yield* Effect.promise(...)
81
+ const result = yield* Effect.promise(() => Promise.resolve(`processed:${arg}`))
82
+ asyncValueReceived = result
83
+ return Stream.make(result, result + "!")
84
+ }
85
+ )
86
+
87
+ yield* join(cmd.handle("hello"))
88
+
89
+ expect(asyncValueReceived).toBe("processed:hello")
90
+ expect(cmd.result._tag).toBe("Success")
91
+ if (cmd.result._tag === "Success") {
92
+ expect(cmd.result.value).toBe("processed:hello!")
93
+ }
94
+ }))
95
+
96
+ // ---------------------------------------------------------------------------
97
+ // Non-generator returning Effect<Stream>
98
+ // ---------------------------------------------------------------------------
99
+
100
+ it.live("streamFn: non-generator returning Effect<Stream> runs stream", () =>
101
+ Effect.gen(function*() {
102
+ const Command = useExperimental({ toasts: [] })
103
+
104
+ const cmd = Command.streamFn("test-stream-effect-stream")(
105
+ (arg: number) => Effect.succeed(Stream.make(arg * 3, arg * 3 + 1))
106
+ )
107
+
108
+ yield* join(cmd.handle(4))
109
+
110
+ expect(cmd.result._tag).toBe("Success")
111
+ if (cmd.result._tag === "Success") {
112
+ expect(cmd.result.value).toBe(13) // 4*3+1 = 13
113
+ }
114
+ }))
115
+
116
+ // ---------------------------------------------------------------------------
117
+ // Generator form — waiting state flips correctly
118
+ // ---------------------------------------------------------------------------
119
+
120
+ it.live("streamFn: generator form sets waiting=true during execution then false after", () =>
121
+ Effect.gen(function*() {
122
+ const Command = useExperimental({ toasts: [] })
123
+
124
+ const cmd = Command.streamFn("test-stream-gen-waiting")(
125
+ function*(_arg: void) {
126
+ return Stream.make(1, 2, 3)
127
+ }
128
+ )
129
+
130
+ expect(cmd.waiting).toBe(false)
131
+ const fiber = cmd.handle()
132
+
133
+ // result transitions to initial(true) = waiting synchronously inside runStream
134
+ // after the fiber runs, waiting should settle to false
135
+ yield* join(fiber)
136
+ expect(cmd.waiting).toBe(false)
137
+
138
+ expect(AsyncResult.isSuccess(cmd.result)).toBe(true)
139
+ }))
140
+
141
+ // ---------------------------------------------------------------------------
142
+ // Generator form with a stream-transformer combinator
143
+ // ---------------------------------------------------------------------------
144
+
145
+ it.live("streamFn: generator form with combinator — combinator transforms the stream", () =>
146
+ Effect.gen(function*() {
147
+ const Command = useExperimental({ toasts: [] })
148
+
149
+ const emittedByCombinator: number[] = []
150
+
151
+ // A combinator that records each element it sees.
152
+ // The first argument may be a Stream or an Effect<Stream> (for generator-form handlers),
153
+ // matching how withDefaultToastStream handles it.
154
+ const spyCombinator = (
155
+ input: Stream.Stream<number, never, never> | Effect.Effect<Stream.Stream<number, never, never>>
156
+ ) => {
157
+ const stream: Stream.Stream<number, never, never> = Stream.isStream(input)
158
+ ? input
159
+ : Stream.unwrap(input as Effect.Effect<Stream.Stream<number, never, never>>)
160
+ return stream.pipe(
161
+ Stream.tap((v) =>
162
+ Effect.sync(() => {
163
+ emittedByCombinator.push(v)
164
+ })
165
+ )
166
+ )
167
+ }
168
+
169
+ const cmd = Command.streamFn("test-stream-gen-combinator")(
170
+ function*(arg: number) {
171
+ const base = yield* Effect.succeed(arg * 10)
172
+ return Stream.make(base, base + 1, base + 2)
173
+ },
174
+ // combinator receives (input, arg, ctx) — input is Stream or Effect<Stream> depending on handler form
175
+ (input: Stream.Stream<number, never, never> | Effect.Effect<Stream.Stream<number, never, never>>) =>
176
+ spyCombinator(input)
177
+ )
178
+
179
+ yield* join(cmd.handle(3))
180
+
181
+ // combinator must have seen all elements: 30, 31, 32
182
+ expect(emittedByCombinator).toEqual([30, 31, 32])
183
+
184
+ expect(cmd.result._tag).toBe("Success")
185
+ if (cmd.result._tag === "Success") {
186
+ expect(cmd.result.value).toBe(32)
187
+ }
188
+ }))
189
+
190
+ // ---------------------------------------------------------------------------
191
+ // Generator form — Stream.ensuring runs after stream completes
192
+ // ---------------------------------------------------------------------------
193
+
194
+ it.live("streamFn: generator form Stream.ensuring cleanup runs after stream ends", () =>
195
+ Effect.gen(function*() {
196
+ const Command = useExperimental({ toasts: [] })
197
+
198
+ let cleanupRan = false
199
+
200
+ const cmd = Command.streamFn("test-stream-gen-ensuring")(
201
+ function*(arg: number) {
202
+ const value = yield* Effect.succeed(arg + 100)
203
+ return Stream.make(value).pipe(
204
+ Stream.ensuring(Effect.sync(() => {
205
+ cleanupRan = true
206
+ }))
207
+ )
208
+ }
209
+ )
210
+
211
+ yield* join(cmd.handle(7))
212
+
213
+ expect(cleanupRan).toBe(true)
214
+ expect(cmd.result._tag).toBe("Success")
215
+ if (cmd.result._tag === "Success") {
216
+ expect(cmd.result.value).toBe(107)
217
+ }
218
+ }))