@effect-app/vue 2.51.18 → 2.52.0

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.
@@ -0,0 +1,296 @@
1
+ import { it } from "@effect/vitest"
2
+ import { Cause, Effect, Exit, Fiber, Option } from "effect-app"
3
+ import { CommandContext, DefaultIntl } from "../src/experimental/useCommand.js"
4
+ import { Result } from "../src/lib.js"
5
+ import { useExperimental } from "./stubs.js"
6
+
7
+ it.live("works", () =>
8
+ Effect
9
+ .gen(function*() {
10
+ const toasts: any[] = []
11
+ const { useCommand } = useExperimental({ toasts })
12
+ const Command = useCommand()
13
+
14
+ let executed = false
15
+
16
+ const command = Command.fn("Test Action")(
17
+ function*() {
18
+ expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
19
+ expect(command.value.waiting).toBe(true)
20
+
21
+ expect(yield* CommandContext).toEqual({ action: "Test Action" })
22
+
23
+ expect(toasts.length).toBe(0)
24
+
25
+ return "test-value"
26
+ },
27
+ Effect.tap(Effect.fnUntraced(function*() {
28
+ expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
29
+ })),
30
+ Effect.tap(() =>
31
+ Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => expect(_).toBe("Test Action")))
32
+ ),
33
+ Effect.tap(() => executed = true)
34
+ )
35
+ expect(command.value.action).toBe("Test Action")
36
+
37
+ const r = yield* Fiber.join(command.value()).pipe(Effect.flatten) // we receive an Exit as errors/results are processed, so we flatten it.
38
+ expect(command.value.waiting).toBe(false)
39
+
40
+ expect(r).toBe("test-value") // to confirm that the initial function has ran.
41
+ expect(executed).toBe(true) // to confirm that the combinators have ran.
42
+
43
+ expect(command.value.result.pipe(Result.value)).toEqual(Option.some("test-value"))
44
+
45
+ expect(toasts.length).toBe(0)
46
+ }))
47
+
48
+ it.live("has custom action name", () =>
49
+ Effect
50
+ .gen(function*() {
51
+ const toasts: any[] = []
52
+ const { useCommand } = useExperimental({ toasts, messages: { "action.Test Action": "Test Action Translated" } })
53
+ const Command = useCommand()
54
+
55
+ let executed = false
56
+
57
+ const command = Command.fn("Test Action")(
58
+ function*() {
59
+ expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
60
+
61
+ expect(yield* CommandContext).toEqual({ action: "Test Action Translated" })
62
+ return "test-value"
63
+ },
64
+ Effect.tap(() => executed = true)
65
+ )
66
+ expect(command.value.action).toBe("Test Action Translated")
67
+ const r = yield* Fiber.join(command.value()).pipe(Effect.flatten) // we receive an Exit as errors/results are processed, so we flatten it.
68
+
69
+ expect(r).toBe("test-value") // to confirm that the initial function has ran.
70
+ expect(executed).toBe(true) // to confirm that the combinators have ran.
71
+ }))
72
+
73
+ it.live("can map the result", () =>
74
+ Effect
75
+ .gen(function*() {
76
+ const toasts: any[] = []
77
+ const { useCommand } = useExperimental({ toasts })
78
+ const Command = useCommand()
79
+
80
+ let executed = false
81
+
82
+ const command = Command.fn("Test Action")(
83
+ function*() {
84
+ expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
85
+
86
+ return "test-value"
87
+ },
88
+ Effect.map((_) => _ + _),
89
+ Effect.tap(() => executed = true)
90
+ )
91
+ const r = yield* Fiber.join(command.value()).pipe(Effect.flatten) // we receive an Exit as errors/results are processed, so we flatten it.
92
+
93
+ expect(r).toBe("test-valuetest-value") // to confirm that the initial function and map has ran.
94
+ expect(executed).toBe(true) // to confirm that the combinators have ran.
95
+ }))
96
+
97
+ it.live("can receive and use input", () =>
98
+ Effect
99
+ .gen(function*() {
100
+ const toasts: any[] = []
101
+ const { useCommand } = useExperimental({ toasts })
102
+ const Command = useCommand()
103
+
104
+ let executed = false
105
+
106
+ const command = Command.fn("Test Action")(
107
+ function*(input1: number, input2: string) {
108
+ expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
109
+
110
+ return { input1, input2 }
111
+ },
112
+ Effect.tap(() => executed = true)
113
+ )
114
+ const r = yield* Fiber.join(command.value(1, "2")).pipe(Effect.flatten) // we receive an Exit as errors/results are processed, so we flatten it.
115
+
116
+ expect(r).toEqual({ input1: 1, input2: "2" }) // to confirm that the initial function has ran and received input.
117
+ expect(executed).toBe(true) // to confirm that the combinators have ran.
118
+ }))
119
+
120
+ it.live("can replace the result", () =>
121
+ Effect
122
+ .gen(function*() {
123
+ const toasts: any[] = []
124
+ const { useCommand } = useExperimental({ toasts, messages: { "action.Test Action": "Test Action Translated" } })
125
+ const Command = useCommand()
126
+
127
+ let executed = false
128
+
129
+ const command = Command.fn("Test Action")(
130
+ function*() {
131
+ expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
132
+
133
+ return "test-value"
134
+ },
135
+ Effect.zipRight(Effect.succeed(42)),
136
+ Effect.tap(() => executed = true)
137
+ )
138
+ const r = yield* Fiber.join(command.value()).pipe(Effect.flatten) // we receive an Exit as errors/results are processed, so we flatten it.
139
+
140
+ expect(r).toBe(42) // to confirm that the initial function and zipRight has ran.
141
+ expect(executed).toBe(true) // to confirm that the combinators have ran.
142
+ }))
143
+
144
+ it.live("with toasts", () =>
145
+ Effect
146
+ .gen(function*() {
147
+ const toasts: any[] = []
148
+ const { useCommand } = useExperimental({
149
+ toasts,
150
+ messages: DefaultIntl.en
151
+ })
152
+ const Command = useCommand()
153
+
154
+ let executed = false
155
+
156
+ const command = Command.fn("Test Action")(
157
+ function*() {
158
+ expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
159
+
160
+ expect(toasts.length).toBe(1)
161
+ expect(toasts[0].message).toBe("Test Action executing...")
162
+
163
+ return "test-value"
164
+ },
165
+ Effect.tap(Effect.fnUntraced(function*() {
166
+ expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
167
+ })),
168
+ Effect.tap(() =>
169
+ Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => expect(_).toBe("Test Action")))
170
+ ),
171
+ Command.withDefaultToast,
172
+ Effect.tap(() => executed = true)
173
+ )
174
+
175
+ const r = yield* Fiber.join(command.value()).pipe(Effect.flatten) // we receive an Exit as errors/results are processed, so we flatten it.
176
+
177
+ expect(r).toBe("test-value") // to confirm that the initial function has ran.
178
+ expect(executed).toBe(true) // to confirm that the combinators have ran.
179
+
180
+ expect(toasts.length).toBe(1)
181
+ expect(toasts[0].message).toBe("Test Action Success")
182
+ }))
183
+
184
+ it.live("interrupted", () =>
185
+ Effect
186
+ .gen(function*() {
187
+ let executed = false
188
+ const toasts: any[] = []
189
+ const { useCommand } = useExperimental({ toasts, messages: DefaultIntl.en })
190
+ const Command = useCommand()
191
+
192
+ const command = Command.fn("Test Action")(
193
+ function*() {
194
+ expect(toasts.length).toBe(1)
195
+ yield* Effect.interrupt
196
+ return "test-value"
197
+ },
198
+ Command.withDefaultToast,
199
+ Effect.tap(() => executed = true)
200
+ )
201
+
202
+ const r = yield* Fiber.join(command.value()) // we receive an Exit as errors/results are processed
203
+
204
+ expect(executed).toBe(false) // we were interrupted after all :)
205
+ expect(Exit.isInterrupted(r)).toBe(true) // to confirm that the initial function has interrupted
206
+
207
+ expect(command.value.waiting).toBe(false)
208
+ expect(Exit.isInterrupted(Result.toExit(command.value.result))).toBe(true)
209
+ expect(toasts.length).toBe(0) // toast is removed on interruption. TODO: maybe a nicer user experience can be had?
210
+ }))
211
+
212
+ it.live("fail", () =>
213
+ Effect
214
+ .gen(function*() {
215
+ let executed = false
216
+ const toasts: any[] = []
217
+ const { useCommand } = useExperimental({ toasts, messages: DefaultIntl.en })
218
+ const Command = useCommand()
219
+
220
+ const command = Command.fn("Test Action")(
221
+ function*() {
222
+ expect(toasts.length).toBe(1)
223
+ return yield* Effect.fail({ message: "Boom!" })
224
+ },
225
+ Command.withDefaultToast,
226
+ Effect.tap(() => executed = true)
227
+ )
228
+
229
+ const r = yield* Fiber.join(command.value()) // we receive an Exit as errors/results are processed
230
+
231
+ expect(executed).toBe(false) // we failed after all :)
232
+ expect(Exit.isFailure(r) && Cause.isFailure(r.cause)).toBe(true) // to confirm that the initial function has failed
233
+
234
+ expect(command.value.waiting).toBe(false)
235
+ expect(Exit.isFailure(Result.toExit(command.value.result))).toBe(true)
236
+ expect(toasts.length).toBe(1) // toast should show error
237
+ expect(toasts[0].message).toBe("Test Action Failed:\nBoom!")
238
+ }))
239
+
240
+ it.live("fail and recover", () =>
241
+ Effect
242
+ .gen(function*() {
243
+ let executed = false
244
+ const toasts: any[] = []
245
+ const { useCommand } = useExperimental({ toasts, messages: DefaultIntl.en })
246
+ const Command = useCommand()
247
+
248
+ const command = Command.fn("Test Action")(
249
+ function*() {
250
+ expect(toasts.length).toBe(1)
251
+ return yield* Effect.fail({ message: "Boom!" })
252
+ },
253
+ Effect.catchAll(() => Effect.succeed("recovered")), // we recover from the error here, so the final result is success
254
+ Command.withDefaultToast,
255
+ Effect.tap(() => executed = true)
256
+ )
257
+
258
+ const r = yield* Fiber.join(command.value()).pipe(Effect.flatten) // we receive an Exit as errors/results are processed
259
+
260
+ expect(executed).toBe(true) // we recovered after all :)
261
+ expect(r).toBe("recovered") // to confirm that the initial function has failed but we recovered
262
+
263
+ expect(command.value.waiting).toBe(false)
264
+ expect(Result.toExit(command.value.result)).toEqual(Exit.succeed("recovered"))
265
+ expect(toasts.length).toBe(1) // toast should show error
266
+ expect(toasts[0].message).toBe("Test Action Success")
267
+ }))
268
+
269
+ it.live("defect", () =>
270
+ Effect
271
+ .gen(function*() {
272
+ let executed = false
273
+ const toasts: any[] = []
274
+ const { useCommand } = useExperimental({ toasts, messages: DefaultIntl.en })
275
+ const Command = useCommand()
276
+
277
+ const command = Command.fn("Test Action")(
278
+ function*() {
279
+ expect(toasts.length).toBe(1)
280
+ return yield* Effect.die({ message: "Boom!" })
281
+ },
282
+ Command.withDefaultToast,
283
+ Effect.tap(() => executed = true)
284
+ )
285
+
286
+ const r = yield* Fiber.join(command.value()) // we receive an Exit as errors/results are processed
287
+ // TODO: confirm we reported error
288
+
289
+ expect(executed).toBe(false) // we died after all :)
290
+ expect(Exit.isFailure(r) && Cause.isDie(r.cause)).toBe(true) // to confirm that the initial function has died
291
+
292
+ expect(command.value.waiting).toBe(false)
293
+ expect(Exit.isFailure(Result.toExit(command.value.result))).toBe(true)
294
+ expect(toasts.length).toBe(1) // toast should show error
295
+ expect(toasts[0].message).toBe("Test Action unexpected error, please try again shortly.")
296
+ }))
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mutation.test.d.ts","sourceRoot":"","sources":["../Mutation.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,68 @@
1
+ import { type MessageFormatElement } from "@formatjs/icu-messageformat-parser";
2
+ export declare const useExperimental: (options?: {
3
+ messages?: Record<string, string> | Record<string, MessageFormatElement[]>;
4
+ toasts: any[];
5
+ }) => {
6
+ useConfirm: () => {
7
+ confirm: (message?: string) => import("effect/Effect").Effect<boolean, never, never>;
8
+ confirmOrInterrupt: (message?: string) => import("effect/Effect").Effect<void, never, never>;
9
+ };
10
+ useCommand: () => {
11
+ confirmOrInterrupt: (message?: string | undefined) => import("effect/Effect").Effect<void, never, import("../src/experimental/useCommand.js").CommandContext>;
12
+ withDefaultToast: <A, E>(self: import("effect/Effect").Effect<A, E, import("../src/experimental/useCommand.js").CommandContext>, errorRenderer?: ((e: E) => string | undefined) | undefined) => import("effect/Effect").Effect<A, E, import("../src/experimental/useCommand.js").CommandContext>;
13
+ fn: (actionName: string) => {
14
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>, AEff, Args extends Array<any>>(body: (...args: Args) => Generator<Eff, AEff, never>): import("vue").ComputedRef<((...a: Args) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<AEff, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_1, infer _R>>] ? E_1 : never>, never>) & {
15
+ action: string;
16
+ result: import("@effect-atom/atom/Result").Result<AEff, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_1, infer _R>>] ? E_1 : never>;
17
+ waiting: boolean;
18
+ }>;
19
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_1, Args_1 extends Array<any>, A extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_1) => Generator<Eff, AEff_1, never>, a: (_: import("effect/Effect").Effect<AEff_1, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_1, infer _R>>] ? E_1 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A): import("vue").ComputedRef<((...a: Args_1) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<A>, import("effect/Effect").Effect.Error<A>>, never>) & {
20
+ action: string;
21
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<A>, import("effect/Effect").Effect.Error<A>>;
22
+ waiting: boolean;
23
+ }>;
24
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_2, Args_2 extends Array<any>, A_1, B extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_2) => Generator<Eff, AEff_2, never>, a: (_: import("effect/Effect").Effect<AEff_2, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_1, infer _R>>] ? E_1 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A_1, b: (_: A_1) => B): import("vue").ComputedRef<((...a: Args_2) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<B>, import("effect/Effect").Effect.Error<B>>, never>) & {
25
+ action: string;
26
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<B>, import("effect/Effect").Effect.Error<B>>;
27
+ waiting: boolean;
28
+ }>;
29
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_3, Args_3 extends Array<any>, A_2, B_1, C extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_3) => Generator<Eff, AEff_3, never>, a: (_: import("effect/Effect").Effect<AEff_3, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_1, infer _R>>] ? E_1 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A_2, b: (_: A_2) => B_1, c: (_: B_1) => C): import("vue").ComputedRef<((...a: Args_3) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<C>, import("effect/Effect").Effect.Error<C>>, never>) & {
30
+ action: string;
31
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<C>, import("effect/Effect").Effect.Error<C>>;
32
+ waiting: boolean;
33
+ }>;
34
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_4, Args_4 extends Array<any>, A_3, B_2, C_1, D extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_4) => Generator<Eff, AEff_4, never>, a: (_: import("effect/Effect").Effect<AEff_4, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_1, infer _R>>] ? E_1 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A_3, b: (_: A_3) => B_2, c: (_: B_2) => C_1, d: (_: C_1) => D): import("vue").ComputedRef<((...a: Args_4) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<D>, import("effect/Effect").Effect.Error<D>>, never>) & {
35
+ action: string;
36
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<D>, import("effect/Effect").Effect.Error<D>>;
37
+ waiting: boolean;
38
+ }>;
39
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_5, Args_5 extends Array<any>, A_4, B_3, C_2, D_1, E_1 extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_5) => Generator<Eff, AEff_5, never>, a: (_: import("effect/Effect").Effect<AEff_5, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_2, infer _R>>] ? E_2 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A_4, b: (_: A_4) => B_3, c: (_: B_3) => C_2, d: (_: C_2) => D_1, e: (_: D_1) => E_1): import("vue").ComputedRef<((...a: Args_5) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<E_1>, import("effect/Effect").Effect.Error<E_1>>, never>) & {
40
+ action: string;
41
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<E_1>, import("effect/Effect").Effect.Error<E_1>>;
42
+ waiting: boolean;
43
+ }>;
44
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_6, Args_6 extends Array<any>, A_5, B_4, C_3, D_2, E_2, F extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_6) => Generator<Eff, AEff_6, never>, a: (_: import("effect/Effect").Effect<AEff_6, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_3, infer _R>>] ? E_3 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A_5, b: (_: A_5) => B_4, c: (_: B_4) => C_3, d: (_: C_3) => D_2, e: (_: D_2) => E_2, f: (_: E_2) => F): import("vue").ComputedRef<((...a: Args_6) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<F>, import("effect/Effect").Effect.Error<F>>, never>) & {
45
+ action: string;
46
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<F>, import("effect/Effect").Effect.Error<F>>;
47
+ waiting: boolean;
48
+ }>;
49
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_7, Args_7 extends Array<any>, A_6, B_5, C_4, D_3, E_3, F_1, G extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_7) => Generator<Eff, AEff_7, never>, a: (_: import("effect/Effect").Effect<AEff_7, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_4, infer _R>>] ? E_4 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A_6, b: (_: A_6) => B_5, c: (_: B_5) => C_4, d: (_: C_4) => D_3, e: (_: D_3) => E_3, f: (_: E_3) => F_1, g: (_: F_1) => G): import("vue").ComputedRef<((...a: Args_7) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<G>, import("effect/Effect").Effect.Error<G>>, never>) & {
50
+ action: string;
51
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<G>, import("effect/Effect").Effect.Error<G>>;
52
+ waiting: boolean;
53
+ }>;
54
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_8, Args_8 extends Array<any>, A_7, B_6, C_5, D_4, E_4, F_2, G_1, H extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_8) => Generator<Eff, AEff_8, never>, a: (_: import("effect/Effect").Effect<AEff_8, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_5, infer _R>>] ? E_5 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A_7, b: (_: A_7) => B_6, c: (_: B_6) => C_5, d: (_: C_5) => D_4, e: (_: D_4) => E_4, f: (_: E_4) => F_2, g: (_: F_2) => G_1, h: (_: G_1) => H): import("vue").ComputedRef<((...a: Args_8) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<H>, import("effect/Effect").Effect.Error<H>>, never>) & {
55
+ action: string;
56
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<H>, import("effect/Effect").Effect.Error<H>>;
57
+ waiting: boolean;
58
+ }>;
59
+ <Eff extends import("effect/Utils").YieldWrap<import("effect/Effect").Effect<any, any, any>>, AEff_9, Args_9 extends Array<any>, A_8, B_7, C_6, D_5, E_5, F_3, G_2, H_1, I extends import("effect/Effect").Effect<any, any, import("../src/experimental/useCommand.js").CommandContext>>(body: (...args: Args_9) => Generator<Eff, AEff_9, never>, a: (_: import("effect/Effect").Effect<AEff_9, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A, infer E_6, infer _R>>] ? E_6 : never, [Eff] extends [never] ? never : [Eff] extends [import("effect/Utils").YieldWrap<import("effect/Effect").Effect<infer _A_1, infer _E, infer R_1>>] ? R_1 : never>) => A_8, b: (_: A_8) => B_7, c: (_: B_7) => C_6, d: (_: C_6) => D_5, e: (_: D_5) => E_5, f: (_: E_5) => F_3, g: (_: F_3) => G_2, h: (_: G_2) => H_1, i: (_: H_1) => I): import("vue").ComputedRef<((...a: Args_9) => import("effect/Fiber").RuntimeFiber<import("effect/Exit").Exit<import("effect/Effect").Effect.Success<I>, import("effect/Effect").Effect.Error<I>>, never>) & {
60
+ action: string;
61
+ result: import("@effect-atom/atom/Result").Result<import("effect/Effect").Effect.Success<I>, import("effect/Effect").Effect.Error<I>>;
62
+ waiting: boolean;
63
+ }>;
64
+ };
65
+ };
66
+ useWithToast: () => <A_9, E_6, Args_10 extends ReadonlyArray<unknown>, R_1>(options: import("../src/experimental/useWithToast.js").ToastOptions<A_9, E_6, Args_10>) => (self: import("effect/Effect").Effect<A_9, E_6, R_1>, ...args: Args_10) => import("effect/Effect").Effect<A_9, E_6, R_1>;
67
+ };
68
+ //# sourceMappingURL=stubs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stubs.d.ts","sourceRoot":"","sources":["../stubs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AA0B9E,eAAO,MAAM,eAAe,GAC1B,UAAU;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,GAAG,EAAE,CAAA;CAAE;;yBAnBlG,CAAC;oCAEuC,CAAC;;;oCAGd,CAAC;sJAM7B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iOAwDixU,GAAI;CAD3xU,CAAA"}
@@ -0,0 +1,60 @@
1
+ import * as Intl from "@formatjs/intl";
2
+ import { Runtime } from "effect-app";
3
+ import { computed, ref } from "vue";
4
+ import { makeExperimental } from "../src/experimental/makeExperimental.js";
5
+ // const mockIntl = {
6
+ // locale: ref("en" as const),
7
+ // trans: (id: string) => id,
8
+ // intl: ref({ formatMessage: (msg: { id: string }) => msg.id })
9
+ // } as unknown as ReturnType<ReturnType<typeof makeIntl<string>>["useIntl"]>
10
+ const makeUseIntl = (messages) => () => {
11
+ const locale = ref("en");
12
+ const intlCache = Intl.createIntlCache();
13
+ const intl = Intl.createIntl({
14
+ locale: locale.value,
15
+ messages
16
+ }, intlCache);
17
+ return { locale, intl: computed(() => intl), trans: (id, values) => intl.formatMessage({ id }, values) };
18
+ };
19
+ export const useExperimental = (options) => {
20
+ const toasts = options?.toasts ?? [];
21
+ const useIntl = makeUseIntl({ ...options?.messages });
22
+ const dismiss = (id) => {
23
+ const idx = toasts.findIndex((_) => _.id === id);
24
+ if (idx > -1) {
25
+ const toast = toasts[idx];
26
+ clearTimeout(toast.timeoutId);
27
+ toasts.splice(idx, 1);
28
+ }
29
+ };
30
+ const fakeToast = (message, options) => {
31
+ const id = options?.id ?? Math.random().toString(36).substring(2, 15);
32
+ console.log(`Toast [${id}]: ${message}`, options);
33
+ options = { ...options, id };
34
+ const idx = toasts.findIndex((_) => _.id === id);
35
+ if (idx > -1) {
36
+ const toast = toasts[idx];
37
+ clearTimeout(toast.timeoutId);
38
+ Object.assign(toast, { message, options });
39
+ toast.timeoutId = setTimeout(() => {
40
+ toasts.splice(idx, 1);
41
+ }, options?.timeout ?? 3000);
42
+ }
43
+ else {
44
+ const toast = { id, message, options };
45
+ toast.timeoutId = setTimeout(() => {
46
+ toasts.splice(idx, 1);
47
+ }, options?.timeout ?? 3000);
48
+ toasts.push(toast);
49
+ }
50
+ return id;
51
+ };
52
+ return makeExperimental(useIntl, () => ({
53
+ error: fakeToast,
54
+ warning: fakeToast,
55
+ success: fakeToast,
56
+ info: fakeToast,
57
+ dismiss
58
+ }), Runtime.defaultRuntime);
59
+ };
60
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJza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PLEVBQUUsQ0FBQTtJQUNYLENBQUMsQ0FBQTtJQUVELE9BQU8sZ0JBQWdCLENBQ3JCLE9BQU8sRUFDUCxHQUFHLEVBQUUsQ0FBQyxDQUFDO1FBQ0wsS0FBSyxFQUFFLFNBQVM7UUFDaEIsT0FBTyxFQUFFLFNBQVM7UUFDbEIsT0FBTyxFQUFFLFNBQVM7UUFDbEIsSUFBSSxFQUFFLFNBQVM7UUFDZixPQUFPO0tBQ1IsQ0FBQyxFQUNGLE9BQU8sQ0FBQyxjQUFjLENBQ3ZCLENBQUE7QUFDSCxDQUFDLENBQUEifQ==
package/test/stubs.ts ADDED
@@ -0,0 +1,75 @@
1
+ import { type MessageFormatElement } from "@formatjs/icu-messageformat-parser"
2
+ import * as Intl from "@formatjs/intl"
3
+ import { Runtime } from "effect-app"
4
+ import { computed, ref } from "vue"
5
+ import { makeExperimental } from "../src/experimental/makeExperimental.js"
6
+ import { type ToastId } from "../src/experimental/useWithToast.js"
7
+
8
+ // const mockIntl = {
9
+ // locale: ref("en" as const),
10
+ // trans: (id: string) => id,
11
+ // intl: ref({ formatMessage: (msg: { id: string }) => msg.id })
12
+ // } as unknown as ReturnType<ReturnType<typeof makeIntl<string>>["useIntl"]>
13
+
14
+ const makeUseIntl = (messages: Record<string, string> | Record<string, MessageFormatElement[]>) => () => {
15
+ const locale = ref("en" as const)
16
+ const intlCache = Intl.createIntlCache()
17
+ const intl = Intl.createIntl<typeof locale.value>(
18
+ {
19
+ locale: locale.value,
20
+ messages
21
+ },
22
+ intlCache
23
+ )
24
+ return { locale, intl: computed(() => intl), trans: (id: any, values: any) => intl.formatMessage({ id }, values) }
25
+ }
26
+
27
+ export const useExperimental = (
28
+ options?: { messages?: Record<string, string> | Record<string, MessageFormatElement[]>; toasts: any[] }
29
+ ) => {
30
+ const toasts: any[] = options?.toasts ?? []
31
+ const useIntl = makeUseIntl({ ...options?.messages })
32
+
33
+ const dismiss = (id: ToastId) => {
34
+ const idx = toasts.findIndex((_) => _.id === id)
35
+ if (idx > -1) {
36
+ const toast = toasts[idx]
37
+ clearTimeout(toast.timeoutId)
38
+ toasts.splice(idx, 1)
39
+ }
40
+ }
41
+ const fakeToast = (message: string, options?: { timeout?: number; id?: ToastId }) => {
42
+ const id = options?.id ?? Math.random().toString(36).substring(2, 15)
43
+ console.log(`Toast [${id}]: ${message}`, options)
44
+
45
+ options = { ...options, id }
46
+ const idx = toasts.findIndex((_) => _.id === id)
47
+ if (idx > -1) {
48
+ const toast = toasts[idx]
49
+ clearTimeout(toast.timeoutId)
50
+ Object.assign(toast, { message, options })
51
+ toast.timeoutId = setTimeout(() => {
52
+ toasts.splice(idx, 1)
53
+ }, options?.timeout ?? 3000)
54
+ } else {
55
+ const toast: any = { id, message, options }
56
+ toast.timeoutId = setTimeout(() => {
57
+ toasts.splice(idx, 1)
58
+ }, options?.timeout ?? 3000)
59
+ toasts.push(toast)
60
+ }
61
+ return id
62
+ }
63
+
64
+ return makeExperimental(
65
+ useIntl,
66
+ () => ({
67
+ error: fakeToast,
68
+ warning: fakeToast,
69
+ success: fakeToast,
70
+ info: fakeToast,
71
+ dismiss
72
+ }),
73
+ Runtime.defaultRuntime
74
+ )
75
+ }
package/tsconfig.src.json CHANGED
@@ -2,7 +2,8 @@
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "lib": [
5
- "esnext"
5
+ "esnext",
6
+ "DOM"
6
7
  ],
7
8
  "tsBuildInfoFile": "./dist/.tsbuildinfo",
8
9
  "esModuleInterop": true,
package/vitest.config.ts CHANGED
@@ -1,5 +1,18 @@
1
1
  /// <reference types="vitest" />
2
- import { defineConfig } from "vite"
2
+ import { defineConfig } from "vitest/config"
3
+ import vue from '@vitejs/plugin-vue'
3
4
  import makeConfig from "../../vite.config.base"
4
5
 
5
- export default defineConfig(makeConfig(__dirname))
6
+ export default defineConfig({
7
+ ...makeConfig(__dirname),
8
+ plugins: [vue()],
9
+ test: {
10
+ environment: 'jsdom',
11
+ include: ['src/**/*.test.{ts,tsx}', '**/test/**/*.test.{ts,tsx}', '**/__tests__/**/*.test.{ts,tsx}'],
12
+ exclude: ['node_modules/**', 'dist/**'],
13
+ globals: true
14
+ },
15
+ optimizeDeps: {
16
+ exclude: ['**/__tests__/**', '**/test/**', '**/*.test.*']
17
+ }
18
+ })