@effect-app/vue 4.0.0-beta.2 → 4.0.0-beta.200

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 +1611 -0
  2. package/dist/commander.d.ts +628 -0
  3. package/dist/commander.d.ts.map +1 -0
  4. package/dist/commander.js +1055 -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 +14 -5
  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 -9
  19. package/dist/lib.d.ts.map +1 -1
  20. package/dist/lib.js +35 -10
  21. package/dist/makeClient.d.ts +153 -340
  22. package/dist/makeClient.d.ts.map +1 -1
  23. package/dist/makeClient.js +222 -377
  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 +53 -35
  32. package/dist/mutate.d.ts.map +1 -1
  33. package/dist/mutate.js +138 -47
  34. package/dist/query.d.ts +20 -40
  35. package/dist/query.d.ts.map +1 -1
  36. package/dist/query.js +138 -71
  37. package/dist/routeParams.d.ts +1 -1
  38. package/dist/runtime.d.ts +7 -4
  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/examples/streamMutation.ts +70 -0
  48. package/package.json +48 -50
  49. package/src/commander.ts +3384 -0
  50. package/src/{experimental/confirm.ts → confirm.ts} +10 -14
  51. package/src/errorReporter.ts +62 -74
  52. package/src/form.ts +56 -17
  53. package/src/intl.ts +12 -0
  54. package/src/lib.ts +47 -20
  55. package/src/makeClient.ts +569 -1135
  56. package/src/{experimental/makeUseCommand.ts → makeUseCommand.ts} +6 -4
  57. package/src/mutate.ts +266 -128
  58. package/src/query.ts +207 -181
  59. package/src/runtime.ts +41 -20
  60. package/src/{experimental/toast.ts → toast.ts} +11 -25
  61. package/src/{experimental/withToast.ts → withToast.ts} +28 -10
  62. package/test/Mutation.test.ts +176 -23
  63. package/test/dist/form.test.d.ts.map +1 -1
  64. package/test/dist/lib.test.d.ts.map +1 -0
  65. package/test/dist/streamFinal.test.d.ts.map +1 -0
  66. package/test/dist/streamFn.test.d.ts.map +1 -0
  67. package/test/dist/stubs.d.ts +3274 -122
  68. package/test/dist/stubs.d.ts.map +1 -1
  69. package/test/dist/stubs.js +178 -31
  70. package/test/form-validation-errors.test.ts +23 -19
  71. package/test/form.test.ts +20 -2
  72. package/test/lib.test.ts +240 -0
  73. package/test/makeClient.test.ts +292 -38
  74. package/test/streamFinal.test.ts +63 -0
  75. package/test/streamFn.test.ts +455 -0
  76. package/test/stubs.ts +214 -42
  77. package/tsconfig.examples.json +20 -0
  78. package/tsconfig.json +0 -1
  79. package/tsconfig.json.bak +5 -2
  80. package/tsconfig.src.json +34 -34
  81. package/tsconfig.test.json +2 -2
  82. package/vitest.config.ts +5 -5
  83. package/dist/experimental/commander.d.ts +0 -359
  84. package/dist/experimental/commander.d.ts.map +0 -1
  85. package/dist/experimental/commander.js +0 -558
  86. package/dist/experimental/confirm.d.ts +0 -19
  87. package/dist/experimental/confirm.d.ts.map +0 -1
  88. package/dist/experimental/confirm.js +0 -28
  89. package/dist/experimental/intl.d.ts +0 -16
  90. package/dist/experimental/intl.d.ts.map +0 -1
  91. package/dist/experimental/intl.js +0 -5
  92. package/dist/experimental/makeUseCommand.d.ts +0 -8
  93. package/dist/experimental/makeUseCommand.d.ts.map +0 -1
  94. package/dist/experimental/makeUseCommand.js +0 -13
  95. package/dist/experimental/toast.d.ts +0 -47
  96. package/dist/experimental/toast.d.ts.map +0 -1
  97. package/dist/experimental/toast.js +0 -41
  98. package/dist/experimental/withToast.d.ts +0 -25
  99. package/dist/experimental/withToast.d.ts.map +0 -1
  100. package/dist/experimental/withToast.js +0 -45
  101. package/eslint.config.mjs +0 -24
  102. package/src/experimental/commander.ts +0 -1836
  103. package/src/experimental/intl.ts +0 -9
@@ -1,1836 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { asResult, type MissingDependencies, reportRuntimeError } from "@effect-app/vue"
3
- import { reportMessage } from "@effect-app/vue/errorReporter"
4
- import { type AsyncResult } from "effect/unstable/reactivity/AsyncResult"
5
- import { Cause, Effect, type Exit, type Fiber, flow, Layer, Match, MutableHashMap, Option, S, ServiceMap } from "effect-app"
6
- import { SupportedErrors } from "effect-app/client"
7
- import { OperationFailure, OperationSuccess } from "effect-app/Operations"
8
- import { wrapEffect } from "effect-app/utils"
9
- import { isGeneratorFunction } from "effect/Utils"
10
- import { type FormatXMLElementFn, type PrimitiveType } from "intl-messageformat"
11
- import { computed, type ComputedRef, reactive, ref } from "vue"
12
- import { Confirm } from "./confirm.js"
13
- import { I18n } from "./intl.js"
14
- import { WithToast } from "./withToast.js"
15
-
16
- type IntlRecord = Record<string, PrimitiveType | FormatXMLElementFn<string, string>>
17
- type FnOptions<Id extends string, I18nCustomKey extends string, State extends IntlRecord | undefined> = {
18
- i18nCustomKey?: I18nCustomKey
19
- /**
20
- * passed to the i18n formatMessage calls so you can use it in translation messagee
21
- * including the Command `action` string.
22
- * Automatically wrapped with Computed if just a thunk.
23
- * provided as Command.state tag, so you can access it in the function.
24
- */
25
- state?: ComputedRef<State> | (() => State)
26
- // TODO: namespaced keys like reactivity keys: ["modify_thing", item], so that one can block also on "modify_thing" *
27
- blockKey?: (id: Id) => string | undefined
28
- waitKey?: (id: Id) => string | undefined
29
- allowed?: (id: Id, state: ComputedRef<State>) => boolean
30
- }
31
-
32
- type FnOptionsInternal<I18nCustomKey extends string> = {
33
- i18nCustomKey?: I18nCustomKey | undefined
34
- state?: IntlRecord | undefined
35
- }
36
-
37
- export const DefaultIntl = {
38
- de: {
39
- "handle.confirmation": "{action} bestätigen?",
40
- "handle.waiting": "{action} wird ausgeführt...",
41
- "handle.success": "{action} erfolgreich",
42
- "handle.with_errors": "{action} fehlgeschlagen",
43
- "handle.with_warnings": "{action} erfolgreich, mit Warnungen",
44
- "handle.error_response":
45
- "Die Anfrage war nicht erfolgreich:\n{error}\nWir wurden benachrichtigt und werden das Problem in Kürze beheben.",
46
- "handle.response_error": "Die Antwort konnte nicht verarbeitet werden:\n{error}",
47
- "handle.request_error": "Die Anfrage konnte nicht gesendet werden:\n{error}",
48
- "handle.unexpected_error2": "{action} unerwarteter Fehler, probieren sie es in kurze nochmals.",
49
-
50
- "handle.unexpected_error": "Unerwarteter Fehler:\n{error}",
51
- "handle.not_found": "Das gesuchte war nicht gefunden"
52
- },
53
- en: {
54
- "handle.confirmation": "Confirm {action}?",
55
- "handle.waiting": "{action} executing...",
56
- "handle.success": "{action} Success",
57
- "handle.with_errors": "{action} Failed",
58
- "handle.with_warnings": "{action}, with warnings",
59
- "handle.error_response":
60
- "There was an error in processing the response:\n{error}\nWe have been notified and will fix the problem shortly.",
61
- "handle.request_error": "There was an error in the request:\n{error}",
62
- "handle.response_error": "The request was not successful:\n{error}",
63
- "handle.unexpected_error2": "{action} unexpected error, please try again shortly.",
64
-
65
- "handle.unexpected_error": "Unexpected Error:\n{error}",
66
- "handle.not_found": "The requested item was not found."
67
- }
68
- }
69
-
70
- export class CommandContext extends ServiceMap.Service<CommandContext, {
71
- id: string
72
- i18nKey: string
73
- action: string
74
- label: string
75
- namespace: string
76
- namespaced: (key: string) => string
77
- state?: IntlRecord | undefined
78
- }>()(
79
- "CommandContext"
80
- ) {}
81
-
82
- export type EmitWithCallback<A, Event extends string> = (event: Event, value: A, onDone: () => void) => void
83
-
84
- /**
85
- * Use to wrap emit calls with a callback to signal completion.
86
- * Useful when the publisher wants to wait for the subscriber to finish processing.
87
- */
88
- export const wrapEmit = <A, Event extends string>(
89
- emit: EmitWithCallback<A, NoInfer<Event>>,
90
- event: Event
91
- ) =>
92
- (value: A) => new Promise<void>((resolve) => emit(event, value, resolve))
93
-
94
- export declare namespace Commander {
95
- export type CommanderBase<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> =
96
- & Gen<RT, Id, I18nKey, State>
97
- & NonGen<RT, Id, I18nKey, State>
98
- & CommandContextLocal<Id, I18nKey>
99
- & {
100
- state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>
101
- }
102
-
103
- export type CommanderFn<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> =
104
- CommanderBase<RT, Id, I18nKey, State>
105
-
106
- export type CommanderWrap<
107
- RT,
108
- Id extends string,
109
- I18nCustomKey extends string,
110
- State extends IntlRecord | undefined,
111
- I,
112
- A,
113
- E,
114
- R
115
- > =
116
- & CommandContextLocal<Id, I18nCustomKey>
117
- & GenWrap<RT, Id, I18nCustomKey, I, A, E, R, State>
118
- & NonGenWrap<RT, Id, I18nCustomKey, I, A, E, R, State>
119
- & {
120
- state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>
121
- }
122
-
123
- export interface CommandContextLocal<Id extends string, I18nKey extends string> {
124
- id: Id
125
- i18nKey: I18nKey
126
- namespace: `action.${I18nKey}`
127
- namespaced: <K extends string>(k: K) => `action.${I18nKey}.${K}`
128
- }
129
-
130
- export interface CommandProps<
131
- A,
132
- E,
133
- Id extends string,
134
- I18nKey extends string,
135
- State extends IntlRecord | undefined
136
- > extends CommandContextLocal<Id, I18nKey> {
137
- /** reactive */
138
- action: string
139
- /** reactive */
140
- label: string
141
- /** reactive */
142
- result: AsyncResult<A, E>
143
- /** reactive */
144
- waiting: boolean
145
- /** reactive */
146
- blocked: boolean
147
- /** reactive */
148
- allowed: boolean
149
- /** reactive */
150
- state: State
151
- }
152
-
153
- export interface CommandOut<
154
- Arg,
155
- A,
156
- E,
157
- R,
158
- Id extends string,
159
- I18nKey extends string,
160
- State extends IntlRecord | undefined
161
- > extends CommandProps<A, E, Id, I18nKey, State> {
162
- new(): {}
163
-
164
- /** click handlers */
165
- handle: ((arg: Arg) => Fiber.Fiber<Exit.Exit<A, E>, never>) & {
166
- /** @deprecated don't exist */
167
- effect: (arg: Arg) => Effect.Effect<A, E, R>
168
- }
169
-
170
- // // TODO: if we keep them, it would probably be nicer as an option api, deciding the return value like in Atom?
171
- // /** @experimental */
172
- // compose: (arg: Arg) => Effect.Effect<Exit.Exit<A, E>, R>
173
- // /** @experimental */
174
- // compose2: (arg: Arg) => Effect.Effect<A, E, R>
175
- // /**
176
- // * @experimental
177
- // * captures the current span and returns an Effect that when run will execute the command
178
- // */
179
- // handleEffect: (arg: Arg) => Effect.Effect<Fiber.Fiber<Exit.Exit<A, E>, never>>
180
- // /**
181
- // * @experimental
182
- // */
183
- // exec: (arg: Arg) => Effect.Effect<Exit.Exit<A, E>, never, Exclude<R, CommandContext>>
184
- }
185
-
186
- export interface CommandContextLocal2<Id extends string, I18nKey extends string, State extends IntlRecord | undefined>
187
- extends CommandContextLocal<Id, I18nKey>
188
- {
189
- state: State
190
- }
191
-
192
- type CommandOutHelper<
193
- Arg,
194
- Eff extends Effect.Effect<any, any, any>,
195
- Id extends string,
196
- I18nKey extends string,
197
- State extends IntlRecord | undefined
198
- > = CommandOut<
199
- Arg,
200
- Effect.Success<Eff>,
201
- Effect.Error<Eff>,
202
- Effect.Services<Eff>,
203
- Id,
204
- I18nKey,
205
- State
206
- >
207
-
208
- export type Gen<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = {
209
- <
210
- Eff extends Effect.Yieldable<any, any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
211
- AEff,
212
- Arg = void
213
- >(
214
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>
215
- ): CommandOut<
216
- Arg,
217
- AEff,
218
- [Eff] extends [never] ? never
219
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
220
- : never,
221
- [Eff] extends [never] ? never
222
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
223
- : never,
224
- Id,
225
- I18nKey,
226
- State
227
- >
228
- <
229
- Eff extends Effect.Yieldable<any, any, any, any>,
230
- AEff,
231
- A extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
232
- Arg = void
233
- >(
234
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
235
- a: (
236
- _: Effect.Effect<
237
- AEff,
238
- [Eff] extends [never] ? never
239
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
240
- : never,
241
- [Eff] extends [never] ? never
242
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
243
- : never
244
- >,
245
- arg: NoInfer<Arg>,
246
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
247
- ) => A
248
- ): CommandOutHelper<Arg, A, Id, I18nKey, State>
249
- <
250
- Eff extends Effect.Yieldable<any, any, any, any>,
251
- AEff,
252
- A,
253
- B extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
254
- Arg = void
255
- >(
256
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
257
- a: (
258
- _: Effect.Effect<
259
- AEff,
260
- [Eff] extends [never] ? never
261
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
262
- : never,
263
- [Eff] extends [never] ? never
264
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
265
- : never
266
- >,
267
- arg: NoInfer<Arg>,
268
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
269
- ) => A,
270
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B
271
- ): CommandOutHelper<Arg, B, Id, I18nKey, State>
272
- <
273
- Eff extends Effect.Yieldable<any, any, any, any>,
274
- AEff,
275
- A,
276
- B,
277
- C extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
278
- Arg = void
279
- >(
280
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
281
- a: (
282
- _: Effect.Effect<
283
- AEff,
284
- [Eff] extends [never] ? never
285
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
286
- : never,
287
- [Eff] extends [never] ? never
288
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
289
- : never
290
- >,
291
- arg: NoInfer<Arg>,
292
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
293
- ) => A,
294
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
295
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C
296
- ): CommandOutHelper<Arg, C, Id, I18nKey, State>
297
- <
298
- Eff extends Effect.Yieldable<any, any, any, any>,
299
- AEff,
300
- A,
301
- B,
302
- C,
303
- D extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
304
- Arg = void
305
- >(
306
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
307
- a: (
308
- _: Effect.Effect<
309
- AEff,
310
- [Eff] extends [never] ? never
311
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
312
- : never,
313
- [Eff] extends [never] ? never
314
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
315
- : never
316
- >,
317
- arg: NoInfer<Arg>,
318
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
319
- ) => A,
320
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
321
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
322
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D
323
- ): CommandOutHelper<Arg, D, Id, I18nKey, State>
324
- <
325
- Eff extends Effect.Yieldable<any, any, any, any>,
326
- AEff,
327
- A,
328
- B,
329
- C,
330
- D,
331
- E extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
332
- Arg = void
333
- >(
334
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
335
- a: (
336
- _: Effect.Effect<
337
- AEff,
338
- [Eff] extends [never] ? never
339
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
340
- : never,
341
- [Eff] extends [never] ? never
342
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
343
- : never
344
- >,
345
- arg: NoInfer<Arg>,
346
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
347
- ) => A,
348
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
349
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
350
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
351
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E
352
- ): CommandOutHelper<Arg, E, Id, I18nKey, State>
353
- <
354
- Eff extends Effect.Yieldable<any, any, any, any>,
355
- AEff,
356
- A,
357
- B,
358
- C,
359
- D,
360
- E,
361
- F extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
362
- Arg = void
363
- >(
364
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
365
- a: (
366
- _: Effect.Effect<
367
- AEff,
368
- [Eff] extends [never] ? never
369
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
370
- : never,
371
- [Eff] extends [never] ? never
372
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
373
- : never
374
- >,
375
- arg: NoInfer<Arg>,
376
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
377
- ) => A,
378
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
379
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
380
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
381
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
382
- f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F
383
- ): CommandOutHelper<Arg, F, Id, I18nKey, State>
384
- <
385
- Eff extends Effect.Yieldable<any, any, any, any>,
386
- AEff,
387
- A,
388
- B,
389
- C,
390
- D,
391
- E,
392
- F,
393
- G extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
394
- Arg = void
395
- >(
396
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
397
- a: (
398
- _: Effect.Effect<
399
- AEff,
400
- [Eff] extends [never] ? never
401
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
402
- : never,
403
- [Eff] extends [never] ? never
404
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
405
- : never
406
- >,
407
- arg: NoInfer<Arg>,
408
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
409
- ) => A,
410
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
411
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
412
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
413
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
414
- f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
415
- g: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G
416
- ): CommandOutHelper<Arg, G, Id, I18nKey, State>
417
- <
418
- Eff extends Effect.Yieldable<any, any, any, any>,
419
- AEff,
420
- A,
421
- B,
422
- C,
423
- D,
424
- E,
425
- F,
426
- G,
427
- H extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
428
- Arg = void
429
- >(
430
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
431
- a: (
432
- _: Effect.Effect<
433
- AEff,
434
- [Eff] extends [never] ? never
435
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
436
- : never,
437
- [Eff] extends [never] ? never
438
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
439
- : never
440
- >,
441
- arg: NoInfer<Arg>,
442
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
443
- ) => A,
444
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
445
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
446
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
447
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
448
- f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
449
- g: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
450
- h: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H
451
- ): CommandOutHelper<Arg, H, Id, I18nKey, State>
452
- <
453
- Eff extends Effect.Yieldable<any, any, any, any>,
454
- AEff,
455
- A,
456
- B,
457
- C,
458
- D,
459
- E,
460
- F,
461
- G,
462
- H,
463
- I extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
464
- Arg = void
465
- >(
466
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>,
467
- a: (
468
- _: Effect.Effect<
469
- AEff,
470
- [Eff] extends [never] ? never
471
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
472
- : never,
473
- [Eff] extends [never] ? never
474
- : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
475
- : never
476
- >,
477
- arg: NoInfer<Arg>,
478
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
479
- ) => A,
480
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
481
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
482
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
483
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
484
- f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
485
- g: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
486
- h: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H,
487
- i: (_: H, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => I
488
- ): CommandOutHelper<Arg, I, Id, I18nKey, State>
489
- }
490
-
491
- export type NonGen<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = {
492
- <
493
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
494
- Arg = void
495
- >(
496
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Eff
497
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
498
- <
499
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
500
- A,
501
- Arg = void
502
- >(
503
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
504
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
505
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
506
- <
507
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
508
- A,
509
- B,
510
- Arg = void
511
- >(
512
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
513
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
514
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
515
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
516
- <
517
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
518
- A,
519
- B,
520
- C,
521
- Arg = void
522
- >(
523
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
524
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
525
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
526
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
527
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
528
- <
529
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
530
- A,
531
- B,
532
- C,
533
- D,
534
- Arg = void
535
- >(
536
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
537
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
538
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
539
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
540
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
541
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
542
- <
543
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
544
- A,
545
- B,
546
- C,
547
- D,
548
- E,
549
- Arg = void
550
- >(
551
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
552
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
553
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
554
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
555
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
556
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
557
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
558
- <
559
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
560
- A,
561
- B,
562
- C,
563
- D,
564
- E,
565
- F,
566
- Arg = void
567
- >(
568
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
569
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
570
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
571
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
572
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
573
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
574
- f: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
575
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
576
- <
577
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
578
- A,
579
- B,
580
- C,
581
- D,
582
- E,
583
- F,
584
- G,
585
- Arg = void
586
- >(
587
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
588
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
589
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
590
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
591
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
592
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
593
- f: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
594
- g: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
595
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
596
- <
597
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
598
- A,
599
- B,
600
- C,
601
- D,
602
- E,
603
- F,
604
- G,
605
- H,
606
- Arg = void
607
- >(
608
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
609
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
610
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
611
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
612
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
613
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
614
- f: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
615
- g: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H,
616
- h: (_: H, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
617
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
618
- <
619
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
620
- A,
621
- B,
622
- C,
623
- D,
624
- E,
625
- F,
626
- G,
627
- H,
628
- I,
629
- Arg = void
630
- >(
631
- body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => A,
632
- a: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
633
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
634
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
635
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
636
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
637
- f: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
638
- g: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H,
639
- h: (_: H, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => I,
640
- i: (_: H, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
641
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
642
- }
643
-
644
- export type GenWrap<
645
- RT,
646
- Id extends string,
647
- I18nKey extends string,
648
- Arg,
649
- AEff,
650
- EEff,
651
- REff,
652
- State extends IntlRecord | undefined
653
- > = {
654
- (): Exclude<REff, RT> extends never ? CommandOut<
655
- Arg,
656
- AEff,
657
- EEff,
658
- REff,
659
- Id,
660
- I18nKey,
661
- State
662
- >
663
- : MissingDependencies<RT, REff> & {}
664
- <
665
- A extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
666
- >(
667
- a: (
668
- _: Effect.Effect<
669
- AEff,
670
- EEff,
671
- REff
672
- >,
673
- arg: NoInfer<Arg>,
674
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
675
- ) => A
676
- ): CommandOutHelper<Arg, A, Id, I18nKey, State>
677
- <
678
- A,
679
- B extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
680
- >(
681
- a: (
682
- _: Effect.Effect<
683
- AEff,
684
- EEff,
685
- REff
686
- >,
687
- arg: NoInfer<Arg>,
688
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
689
- ) => A,
690
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B
691
- ): CommandOutHelper<Arg, B, Id, I18nKey, State>
692
- <
693
- A,
694
- B,
695
- C extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
696
- >(
697
- a: (
698
- _: Effect.Effect<
699
- AEff,
700
- EEff,
701
- REff
702
- >,
703
- arg: NoInfer<Arg>,
704
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
705
- ) => A,
706
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
707
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C
708
- ): CommandOutHelper<Arg, C, Id, I18nKey, State>
709
- <
710
- A,
711
- B,
712
- C,
713
- D extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
714
- >(
715
- a: (
716
- _: Effect.Effect<
717
- AEff,
718
- EEff,
719
- REff
720
- >,
721
- arg: NoInfer<Arg>,
722
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
723
- ) => A,
724
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
725
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
726
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D
727
- ): CommandOutHelper<Arg, D, Id, I18nKey, State>
728
- <
729
- A,
730
- B,
731
- C,
732
- D,
733
- E extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
734
- >(
735
- a: (
736
- _: Effect.Effect<
737
- AEff,
738
- EEff,
739
- REff
740
- >,
741
- arg: NoInfer<Arg>,
742
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
743
- ) => A,
744
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
745
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
746
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
747
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E
748
- ): CommandOutHelper<Arg, E, Id, I18nKey, State>
749
- <
750
- A,
751
- B,
752
- C,
753
- D,
754
- E,
755
- F extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
756
- >(
757
- a: (
758
- _: Effect.Effect<
759
- AEff,
760
- EEff,
761
- REff
762
- >,
763
- arg: NoInfer<Arg>,
764
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
765
- ) => A,
766
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
767
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
768
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
769
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
770
- f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F
771
- ): CommandOutHelper<Arg, F, Id, I18nKey, State>
772
- <
773
- A,
774
- B,
775
- C,
776
- D,
777
- E,
778
- F,
779
- G extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
780
- >(
781
- a: (
782
- _: Effect.Effect<
783
- AEff,
784
- EEff,
785
- REff
786
- >,
787
- arg: NoInfer<Arg>,
788
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
789
- ) => A,
790
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
791
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
792
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
793
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
794
- f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
795
- g: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G
796
- ): CommandOutHelper<Arg, G, Id, I18nKey, State>
797
- <A, B, C, D, E, F, G, H extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(
798
- a: (
799
- _: Effect.Effect<
800
- AEff,
801
- EEff,
802
- REff
803
- >,
804
- arg: NoInfer<Arg>,
805
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
806
- ) => A,
807
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
808
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
809
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
810
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
811
- f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
812
- g: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
813
- h: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H
814
- ): CommandOutHelper<Arg, H, Id, I18nKey, State>
815
- <A, B, C, D, E, F, G, H, I extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(
816
- a: (
817
- _: Effect.Effect<
818
- AEff,
819
- EEff,
820
- REff
821
- >,
822
- arg: NoInfer<Arg>,
823
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
824
- ) => A,
825
- b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B,
826
- c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
827
- d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
828
- e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
829
- f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
830
- g: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
831
- h: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H,
832
- i: (_: H, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => I
833
- ): CommandOutHelper<Arg, I, Id, I18nKey, State>
834
- }
835
-
836
- export type NonGenWrap<
837
- RT,
838
- Id extends string,
839
- I18nKey extends string,
840
- Arg,
841
- AEff,
842
- EEff,
843
- REff,
844
- State extends IntlRecord | undefined
845
- > = {
846
- (): Exclude<REff, RT> extends never ? CommandOutHelper<Arg, Effect.Effect<AEff, EEff, REff>, Id, I18nKey, State>
847
- : MissingDependencies<RT, REff> & {}
848
- <
849
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
850
- Arg
851
- >(
852
- a: (
853
- _: Effect.Effect<
854
- AEff,
855
- EEff,
856
- REff
857
- >,
858
- arg: NoInfer<Arg>,
859
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
860
- ) => Eff
861
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
862
- <
863
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
864
- B,
865
- Arg
866
- >(
867
- a: (
868
- _: Effect.Effect<
869
- AEff,
870
- EEff,
871
- REff
872
- >,
873
- arg: NoInfer<Arg>,
874
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
875
- ) => B,
876
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
877
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
878
- <
879
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
880
- B,
881
- C,
882
- Arg
883
- >(
884
- a: (
885
- _: Effect.Effect<
886
- AEff,
887
- EEff,
888
- REff
889
- >,
890
- arg: NoInfer<Arg>,
891
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
892
- ) => B,
893
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
894
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
895
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
896
- <
897
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
898
- B,
899
- C,
900
- D,
901
- Arg
902
- >(
903
- a: (
904
- _: Effect.Effect<
905
- AEff,
906
- EEff,
907
- REff
908
- >,
909
- arg: NoInfer<Arg>,
910
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
911
- ) => B,
912
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
913
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
914
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
915
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
916
- <
917
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
918
- B,
919
- C,
920
- D,
921
- E,
922
- Arg
923
- >(
924
- a: (
925
- _: Effect.Effect<
926
- AEff,
927
- EEff,
928
- REff
929
- >,
930
- arg: NoInfer<Arg>,
931
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
932
- ) => B,
933
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
934
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
935
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
936
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
937
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
938
- <
939
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
940
- B,
941
- C,
942
- D,
943
- E,
944
- F,
945
- Arg
946
- >(
947
- a: (
948
- _: Effect.Effect<
949
- AEff,
950
- EEff,
951
- REff
952
- >,
953
- arg: NoInfer<Arg>,
954
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
955
- ) => B,
956
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
957
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
958
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
959
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
960
- f: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
961
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
962
- <
963
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
964
- B,
965
- C,
966
- D,
967
- E,
968
- F,
969
- G,
970
- Arg
971
- >(
972
- a: (
973
- _: Effect.Effect<
974
- AEff,
975
- EEff,
976
- REff
977
- >,
978
- arg: NoInfer<Arg>,
979
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
980
- ) => B,
981
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
982
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
983
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
984
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
985
- f: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
986
- g: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
987
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
988
- <
989
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
990
- B,
991
- C,
992
- D,
993
- E,
994
- F,
995
- G,
996
- H,
997
- Arg
998
- >(
999
- a: (
1000
- _: Effect.Effect<
1001
- AEff,
1002
- EEff,
1003
- REff
1004
- >,
1005
- arg: NoInfer<Arg>,
1006
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
1007
- ) => B,
1008
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
1009
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
1010
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
1011
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
1012
- f: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
1013
- g: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H,
1014
- h: (_: H, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
1015
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
1016
- <
1017
- Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
1018
- B,
1019
- C,
1020
- D,
1021
- E,
1022
- F,
1023
- G,
1024
- H,
1025
- I,
1026
- Arg
1027
- >(
1028
- a: (
1029
- _: Effect.Effect<
1030
- AEff,
1031
- EEff,
1032
- REff
1033
- >,
1034
- arg: NoInfer<Arg>,
1035
- ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>
1036
- ) => B,
1037
- b: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C,
1038
- c: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D,
1039
- d: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E,
1040
- e: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F,
1041
- f: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G,
1042
- g: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H,
1043
- h: (_: H, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => I,
1044
- i: (_: H, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff
1045
- ): CommandOutHelper<Arg, Eff, Id, I18nKey, State>
1046
- }
1047
- }
1048
-
1049
- type ErrorRenderer<E, Args extends readonly any[]> = (e: E, action: string, ...args: Args) => string | undefined
1050
-
1051
- const renderErrorMaker = I18n.useSync(
1052
- ({ intl }) =>
1053
- <E, Args extends readonly any[]>(action: string, errorRenderer?: ErrorRenderer<E, Args>) =>
1054
- (e: E, ...args: Args): string => {
1055
- if (errorRenderer) {
1056
- const m = errorRenderer(e, action, ...args)
1057
- if (m !== undefined) {
1058
- return m
1059
- }
1060
- }
1061
- if (!S.is(SupportedErrors)(e) && !S.isSchemaError(e)) {
1062
- if (typeof e === "object" && e !== null) {
1063
- if ("message" in e) {
1064
- return `${e.message}`
1065
- }
1066
- if ("_tag" in e) {
1067
- return `${e._tag}`
1068
- }
1069
- }
1070
- return ""
1071
- }
1072
- const e2: SupportedErrors | S.SchemaError = e
1073
- return Match.value(e2).pipe(
1074
- Match.tags({
1075
- NotFoundError: (e) => {
1076
- return intl.formatMessage({ id: "handle.not_found" }, { type: e.type, id: e.id })
1077
- },
1078
- SchemaError: (e) => {
1079
- console.warn(e.toString())
1080
- return intl.formatMessage({ id: "validation.failed" })
1081
- }
1082
- }),
1083
- Match.orElse((e) => `${e.message ?? e._tag ?? e}`)
1084
- )
1085
- }
1086
- )
1087
-
1088
- const defaultFailureMessageHandler = <E, Args extends Array<unknown>, AME, AMR>(
1089
- actionMaker:
1090
- | string
1091
- | ((o: Option.Option<E>, ...args: Args) => string)
1092
- | ((o: Option.Option<E>, ...args: Args) => Effect.Effect<string, AME, AMR>),
1093
- errorRenderer?: ErrorRenderer<E, Args>
1094
- ) =>
1095
- Effect.fnUntraced(function*(o: Option.Option<E>, ...args: Args) {
1096
- const action = yield* wrapEffect(actionMaker)(o, ...args)
1097
- const { intl } = yield* I18n
1098
- const renderError = yield* renderErrorMaker
1099
-
1100
- return Option.match(o, {
1101
- onNone: () =>
1102
- intl.formatMessage(
1103
- { id: "handle.unexpected_error2" },
1104
- {
1105
- action,
1106
- error: "" // TODO consider again Cause.pretty(cause), // will be reported to Sentry/Otel anyway.. and we shouldn't bother users with error dumps?
1107
- }
1108
- ),
1109
- onSome: (e) =>
1110
- S.is(OperationFailure)(e)
1111
- ? {
1112
- level: "warn" as const,
1113
- message: intl.formatMessage(
1114
- { id: "handle.with_warnings" },
1115
- { action }
1116
- ) + e.message
1117
- ? "\n" + e.message
1118
- : ""
1119
- }
1120
- : `${
1121
- intl.formatMessage(
1122
- { id: "handle.with_errors" },
1123
- { action }
1124
- )
1125
- }:\n` + renderError(action, errorRenderer)(e, ...args)
1126
- })
1127
- })
1128
-
1129
- export const CommanderStatic = {
1130
- accessArgs: <In, Out, Arg2, Arg = void>(
1131
- cb: (a: NoInfer<Arg>, b: NoInfer<Arg2>) => (self: NoInfer<In>) => Out
1132
- ) =>
1133
- (self: In, arg: Arg, arg2: Arg2) => cb(arg, arg2)(self),
1134
-
1135
- /** Version of @see confirmOrInterrupt that automatically includes the action name in the default messages */
1136
- confirmOrInterrupt: Effect.fnUntraced(function*(
1137
- message: string | undefined = undefined
1138
- ) {
1139
- const context = yield* CommandContext
1140
- const { intl } = yield* I18n
1141
-
1142
- yield* Confirm.confirmOrInterrupt(
1143
- message
1144
- ?? intl.formatMessage(
1145
- { id: "handle.confirmation" },
1146
- { action: context.action }
1147
- )
1148
- )
1149
- }),
1150
- /** Version of @see confirm that automatically includes the action name in the default messages */
1151
- confirm: Effect.fnUntraced(function*(
1152
- message: string | undefined = undefined
1153
- ) {
1154
- const context = yield* CommandContext
1155
- const { intl } = yield* I18n
1156
- return yield* Confirm.confirm(
1157
- message
1158
- ?? intl.formatMessage(
1159
- { id: "handle.confirmation" },
1160
- { action: context.action }
1161
- )
1162
- )
1163
- }),
1164
- updateAction:
1165
- <Args extends Array<unknown>>(update: (currentActionId: string, ...args: Args) => string) =>
1166
- <A, E, R>(_: Effect.Effect<A, E, R>, ...input: Args) =>
1167
- Effect.updateService(
1168
- _,
1169
- CommandContext,
1170
- (c) => ({ ...c, action: update(c.action, ...input) })
1171
- ),
1172
- defaultFailureMessageHandler,
1173
- renderError: renderErrorMaker,
1174
- /**
1175
- * Version of withDefaultToast that automatically includes the action name in the default messages and uses intl.
1176
- * uses the Command id as i18n namespace. `action.{id}` is the main action name,
1177
- * and `action.{id}.waiting`, `action.{id}.success`, `action.{id}.failure` can be used to override the default messages for the respective states.
1178
- *
1179
- * the computed `state` provided to the Command can be used for interpolation in the i18n messages. (the state is captured at the start of each command execution and remains stable throughout)
1180
- *
1181
- * Note: if you provide `onWaiting` or `onSuccess` as `null`, no toast will be shown for that state.
1182
- * If you provide a string or function, it will be used instead of the i18n message.
1183
- * If you provide an `errorRenderer`, it will be used to render errors in the failure message.
1184
- */
1185
- withDefaultToast: <A, E, R, Args extends Array<unknown>>(
1186
- options?: {
1187
- /**
1188
- * if true, previous toasts with this key will be replaced
1189
- */
1190
- stableToastId?: undefined | true | string | ((id: string, ...args: Args) => true | string | undefined)
1191
- errorRenderer?: ErrorRenderer<E, Args>
1192
- onWaiting?: null | undefined | string | ((id: string, ...args: Args) => string | null | undefined)
1193
- onSuccess?: null | undefined | string | ((a: A, action: string, ...args: Args) => string | null | undefined)
1194
- }
1195
- ) =>
1196
- (
1197
- self: Effect.Effect<A, E, R>,
1198
- ...args: Args
1199
- ) =>
1200
- Effect.gen(function*() {
1201
- const cc = yield* CommandContext
1202
- const { intl } = yield* I18n
1203
- const withToast = yield* WithToast
1204
- const customWaiting = cc.namespaced("waiting")
1205
- const hasCustomWaiting = !!intl.messages[customWaiting]
1206
- const customSuccess = cc.namespaced("success")
1207
- const hasCustomSuccess = !!intl.messages[customSuccess]
1208
- const customFailure = cc.namespaced("failure")
1209
- const hasCustomFailure = !!intl.messages[customFailure]
1210
- const stableToastId = options?.stableToastId
1211
- ? typeof options.stableToastId === "string"
1212
- ? options.stableToastId
1213
- : typeof options.stableToastId === "boolean"
1214
- ? cc.id
1215
- : typeof options.stableToastId === "function"
1216
- ? (...args: Args) => {
1217
- const r = (options.stableToastId as any)(cc.id, ...args)
1218
- if (typeof r === "string") return r
1219
- if (r === true) return cc.id
1220
- return undefined
1221
- }
1222
- : undefined
1223
- : undefined
1224
- return yield* self.pipe(
1225
- (_) =>
1226
- withToast<A, E, Args, R, never, never, I18n>({
1227
- onWaiting: options?.onWaiting === null ? null : hasCustomWaiting
1228
- ? intl.formatMessage({
1229
- id: customWaiting
1230
- }, cc.state)
1231
- : intl.formatMessage(
1232
- { id: "handle.waiting" },
1233
- { action: cc.action }
1234
- ),
1235
- onSuccess: options?.onSuccess === null
1236
- ? null
1237
- : (a, ..._args) =>
1238
- hasCustomSuccess
1239
- ? intl.formatMessage(
1240
- { id: customSuccess },
1241
- cc.state
1242
- )
1243
- : (intl.formatMessage({ id: "handle.success" }, { action: cc.action })
1244
- + (S.is(OperationSuccess)(a) && a.message ? "\n" + a.message : "")),
1245
- onFailure: defaultFailureMessageHandler(
1246
- hasCustomFailure ? intl.formatMessage({ id: customFailure }, cc.state) : cc.action,
1247
- options?.errorRenderer
1248
- ),
1249
- stableToastId
1250
- })(_, ...args)
1251
- )
1252
- }),
1253
-
1254
- /** borrowing the idea from Families in Effect Atom */
1255
- family: <T extends object, Arg, ArgIn = Arg>(
1256
- maker: (arg: Arg) => T,
1257
- keyMaker?: (arg: ArgIn) => Arg
1258
- ): (arg: ArgIn) => T => {
1259
- const commands = MutableHashMap.empty<Arg, WeakRef<T>>()
1260
- const registry = new FinalizationRegistry<Arg>((arg) => {
1261
- MutableHashMap.remove(commands, arg)
1262
- })
1263
-
1264
- return (_k: ArgIn) => {
1265
- const k = keyMaker ? keyMaker(_k) : _k as unknown as Arg
1266
- // we want to compare structurally, unless custom equal/hash has been implemented
1267
- const item = MutableHashMap.get(commands, k).pipe(Option.flatMap((r) => Option.fromNullishOr(r.deref())))
1268
- if (item.value) {
1269
- return item.value
1270
- }
1271
- const v = maker(k)
1272
- MutableHashMap.set(commands, k, new WeakRef(v))
1273
-
1274
- registry.register(v, k)
1275
- return v
1276
- }
1277
- }
1278
- }
1279
-
1280
- const makeBaseInfo = <const Id extends string, const I18nKey extends string = Id>(
1281
- id: Id,
1282
- options?: Pick<FnOptionsInternal<I18nKey>, "i18nCustomKey">
1283
- ) => {
1284
- if (!id) throw new Error("must specify an id")
1285
- const i18nKey: I18nKey = options?.i18nCustomKey ?? id as unknown as I18nKey
1286
-
1287
- const namespace = `action.${i18nKey}` as const
1288
-
1289
- const context = {
1290
- id,
1291
- i18nKey,
1292
- namespace,
1293
- namespaced: <const K extends string>(k: K) => `${namespace}.${k}` as const
1294
- }
1295
-
1296
- return context
1297
- }
1298
-
1299
- const waitState = ref<Record<string, number>>({})
1300
- const registerWait = (id: string) => {
1301
- // console.debug("register wait", id)
1302
- waitState.value[id] = waitState.value[id] ? waitState.value[id] + 1 : 1
1303
- }
1304
- const unregisterWait = (id: string) => {
1305
- // console.debug("unregister wait", id)
1306
- if (waitState.value[id]) {
1307
- waitState.value[id] = waitState.value[id] - 1
1308
- if (waitState.value[id] <= 0) {
1309
- delete waitState.value[id]
1310
- }
1311
- }
1312
- }
1313
-
1314
- const getStateValues = <const Id extends string, const I18nKey extends string, State extends IntlRecord | undefined>(
1315
- options?: FnOptions<Id, I18nKey, State>
1316
- ): ComputedRef<State> => {
1317
- const state_ = options?.state
1318
- const state = !state_ ? computed(() => undefined as State) : typeof state_ === "function"
1319
- ? computed(state_)
1320
- : state_
1321
- return state
1322
- }
1323
-
1324
- // class preserves JSDoc throughout..
1325
- export class CommanderImpl<RT, RTHooks> {
1326
- constructor(
1327
- private readonly rt: ServiceMap.ServiceMap<RT>,
1328
- private readonly intl: I18n,
1329
- private readonly hooks: Layer.Layer<RTHooks, never, RT>
1330
- ) {
1331
- }
1332
-
1333
- readonly makeContext = <const Id extends string, const I18nKey extends string = Id>(
1334
- id: Id,
1335
- options?: FnOptionsInternal<I18nKey>
1336
- ) => {
1337
- if (!id) throw new Error("must specify an id")
1338
- const i18nKey: I18nKey = options?.i18nCustomKey ?? id as unknown as I18nKey
1339
-
1340
- const namespace = `action.${i18nKey}` as const
1341
-
1342
- // must remain stable through out single call
1343
- const action = this.intl.formatMessage({
1344
- id: namespace,
1345
- defaultMessage: id
1346
- }, { ...options?.state, _isLabel: false })
1347
-
1348
- const label = this.intl.formatMessage({
1349
- id: namespace,
1350
- defaultMessage: id
1351
- }, { ...options?.state, _isLabel: true })
1352
-
1353
- const context = CommandContext.of({
1354
- ...makeBaseInfo(id, options),
1355
- action,
1356
- label,
1357
- state: options?.state
1358
- })
1359
-
1360
- return context
1361
- }
1362
-
1363
- readonly makeCommand = <
1364
- const Id extends string,
1365
- const State extends IntlRecord | undefined,
1366
- const I18nKey extends string = Id
1367
- >(
1368
- id_: Id | { id: Id },
1369
- options?: FnOptions<Id, I18nKey, State>,
1370
- errorDef?: Error
1371
- ) => {
1372
- const id = typeof id_ === "string" ? id_ : id_.id
1373
- const state = getStateValues(options)
1374
-
1375
- return Object.assign(
1376
- <Arg, A, E, R extends RT | RTHooks | CommandContext | `Commander.Command.${Id}.state`>(
1377
- handler: (arg: Arg, ctx: Commander.CommandContextLocal2<Id, I18nKey, State>) => Effect.Effect<A, E, R>
1378
- ) => {
1379
- // we capture the definition stack here, so we can append it to later stack traces
1380
- const limit = Error.stackTraceLimit
1381
- Error.stackTraceLimit = 2
1382
- const localErrorDef = new Error()
1383
- Error.stackTraceLimit = limit
1384
- if (!errorDef) {
1385
- errorDef = localErrorDef
1386
- }
1387
-
1388
- const key = `Commander.Command.${id}.state` as const
1389
- const stateTag = ServiceMap.Service<typeof key, State>(key)
1390
-
1391
- const makeContext_ = () => this.makeContext(id, { ...options, state: state?.value })
1392
- const initialContext = makeContext_()
1393
- const context = computed(() => makeContext_())
1394
- const action = computed(() => context.value.action)
1395
- const label = computed(() => context.value.label)
1396
-
1397
- const errorReporter = <A, E, R>(self: Effect.Effect<A, E, R>) =>
1398
- self.pipe(
1399
- Effect.tapCause(
1400
- Effect.fnUntraced(function*(cause) {
1401
- if (Cause.hasInterruptsOnly(cause)) {
1402
- console.info(`Interrupted while trying to ${id}`)
1403
- return
1404
- }
1405
-
1406
- const fail = Cause.findErrorOption(cause)
1407
- if (Option.isSome(fail)) {
1408
- // if (fail.value._tag === "SuppressErrors") {
1409
- // console.info(
1410
- // `Suppressed error trying to ${action}`,
1411
- // fail.value,
1412
- // )
1413
- // return
1414
- // }
1415
- const message = `Failure trying to ${id}`
1416
- yield* reportMessage(message, {
1417
- action: id,
1418
- error: fail.value
1419
- })
1420
- return
1421
- }
1422
-
1423
- const context = yield* CommandContext
1424
- const extra = {
1425
- action: context.action,
1426
- message: `Unexpected Error trying to ${id}`
1427
- }
1428
- yield* reportRuntimeError(cause, extra)
1429
- }, Effect.uninterruptible)
1430
- )
1431
- )
1432
-
1433
- const currentState = Effect.sync(() => state.value)
1434
-
1435
- const theHandler = flow(
1436
- handler,
1437
- errorReporter,
1438
- // all must be within the Effect.fn to fit within the Span
1439
- Effect.provideServiceEffect(
1440
- stateTag,
1441
- currentState
1442
- ),
1443
- Effect.provideServiceEffect(
1444
- CommandContext,
1445
- Effect.sync(() => makeContext_())
1446
- )
1447
- )
1448
- const waitId = options?.waitKey ? options.waitKey(id) : undefined
1449
- const blockId = options?.blockKey ? options.blockKey(id) : undefined
1450
-
1451
- const [result, exec_] = asResult(theHandler)
1452
-
1453
- const exec = Effect
1454
- .fnUntraced(
1455
- function*(...args: [any, any]) {
1456
- if (waitId !== undefined) registerWait(waitId)
1457
- if (blockId !== undefined && blockId !== waitId) {
1458
- registerWait(blockId)
1459
- }
1460
- return yield* exec_(...args)
1461
- },
1462
- Effect.onExit(() =>
1463
- Effect.sync(() => {
1464
- if (waitId !== undefined) unregisterWait(waitId)
1465
- if (blockId !== undefined && blockId !== waitId) {
1466
- unregisterWait(blockId)
1467
- }
1468
- })
1469
- )
1470
- )
1471
-
1472
- const waiting = waitId !== undefined
1473
- ? computed(() => result.value.waiting || (waitState.value[waitId] ?? 0) > 0)
1474
- : computed(() => result.value.waiting)
1475
-
1476
- const blocked = blockId !== undefined
1477
- ? computed(() => waiting.value || (waitState.value[blockId] ?? 0) > 0)
1478
- : computed(() => waiting.value)
1479
-
1480
- const computeAllowed = options?.allowed
1481
- const allowed = computeAllowed ? computed(() => computeAllowed(id, state)) : true
1482
-
1483
- const rt = Effect.services<RT | RTHooks>().pipe(Effect.provide(this.hooks)).pipe(Effect.runSyncWith(this.rt))
1484
- const runFork = Effect.runForkWith(rt)
1485
-
1486
- const handle = Object.assign((arg: Arg) => {
1487
- // we capture the call site stack here
1488
- const limit = Error.stackTraceLimit
1489
- Error.stackTraceLimit = 2
1490
- const errorCall = new Error()
1491
- Error.stackTraceLimit = limit
1492
-
1493
- let cache: false | string = false
1494
- const captureStackTrace = () => {
1495
- // in case of an error, we want to append the definition stack to the call site stack,
1496
- // so we can see where the handler was defined too
1497
-
1498
- if (cache !== false) {
1499
- return cache
1500
- }
1501
- if (errorCall.stack) {
1502
- const stackDef = errorDef!.stack!.trim().split("\n")
1503
- const stackCall = errorCall.stack.trim().split("\n")
1504
- let endStackDef = stackDef.slice(2).join("\n").trim()
1505
- if (!endStackDef.includes(`(`)) {
1506
- endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
1507
- }
1508
- let endStackCall = stackCall.slice(2).join("\n").trim()
1509
- if (!endStackCall.includes(`(`)) {
1510
- endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
1511
- }
1512
- cache = `${endStackDef}\n${endStackCall}`
1513
- return cache
1514
- }
1515
- }
1516
-
1517
- const command = currentState.pipe(Effect.flatMap((state) =>
1518
- Effect.withSpan(
1519
- exec(arg, { ...context.value, state } as any),
1520
- id,
1521
- {
1522
- captureStackTrace,
1523
- attributes: {
1524
- input: arg,
1525
- state,
1526
- action: initialContext.action,
1527
- label: initialContext.label,
1528
- id: initialContext.id,
1529
- i18nKey: initialContext.i18nKey
1530
- }
1531
- }
1532
- )
1533
- ))
1534
-
1535
- return runFork(command)
1536
- }, { action, label })
1537
-
1538
- return reactive({
1539
- /** static */
1540
- id,
1541
-
1542
- /** the base i18n key, based on id by default. static */
1543
- i18nKey: initialContext.i18nKey,
1544
- /** the `action.` namespace based on i18nKey.. static */
1545
- namespace: initialContext.namespace,
1546
-
1547
- /** easy generate namespaced 18n keys, based on namespace. static */
1548
- namespaced: initialContext.namespaced,
1549
-
1550
- /** reactive */
1551
- result,
1552
- /** reactive */
1553
- waiting,
1554
- /** reactive */
1555
- blocked,
1556
- /** reactive */
1557
- allowed,
1558
- /** reactive */
1559
- action,
1560
- /** reactive */
1561
- label,
1562
- /** reactive */
1563
- state,
1564
-
1565
- handle
1566
- })
1567
- },
1568
- { id }
1569
- )
1570
- }
1571
-
1572
- // /** @experimental */
1573
- // takeOver:
1574
- // <Args extends any[], A, E, R, const Id extends string>(command: Commander.CommandOut<Args, A, E, R, Id,I18nKey>) =>
1575
- // (...args: Args) => {
1576
- // // we capture the call site stack here
1577
- // const limit = Error.stackTraceLimit
1578
- // Error.stackTraceLimit = 2
1579
- // const errorCall = new Error()
1580
- // const localErrorDef = new Error()
1581
- // Error.stackTraceLimit = limit
1582
-
1583
- // // TODO
1584
- // const errorDef = localErrorDef
1585
-
1586
- // let cache: false | string = false
1587
- // const captureStackTrace = () => {
1588
- // // in case of an error, we want to append the definition stack to the call site stack,
1589
- // // so we can see where the handler was defined too
1590
-
1591
- // if (cache !== false) {
1592
- // return cache
1593
- // }
1594
- // if (errorCall.stack) {
1595
- // const stackDef = errorDef.stack!.trim().split("\n")
1596
- // const stackCall = errorCall.stack.trim().split("\n")
1597
- // let endStackDef = stackDef.slice(2).join("\n").trim()
1598
- // if (!endStackDef.includes(`(`)) {
1599
- // endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
1600
- // }
1601
- // let endStackCall = stackCall.slice(2).join("\n").trim()
1602
- // if (!endStackCall.includes(`(`)) {
1603
- // endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
1604
- // }
1605
- // cache = `${endStackDef}\n${endStackCall}`
1606
- // return cache
1607
- // }
1608
- // }
1609
-
1610
- // return Effect.gen(function*() {
1611
- // const ctx = yield* CommandContext
1612
- // ctx.action = command.action
1613
- // return yield* command.exec(...args).pipe(
1614
- // Effect.flatten,
1615
- // Effect.withSpan(
1616
- // command.action,
1617
- // { captureStackTrace }
1618
- // )
1619
- // )
1620
- // })
1621
- // },
1622
-
1623
- /**
1624
- * Define a Command for handling user actions with built-in error reporting and state management.
1625
- *
1626
- * @param id The internal identifier for the action. Used as a tracing span and to lookup
1627
- * the user-facing name via internationalization (`action.${id}`).
1628
- * @param options Optional configuration for internationalization and state.
1629
- * @param options.i18nCustomKey Custom i18n key to use instead of `id` (e.g., for grouping similar actions)
1630
- * @param options.state Optional reactive state object (or function returning one) that is
1631
- * made available to the command effects and can be used for i18n interpolation.
1632
- * The state is captured at the start of each command execution and remains stable throughout.
1633
- * @returns A function that executes the command when called (e.g., directly in `@click` handlers).
1634
- * Built-in error reporting handles failures automatically.
1635
- *
1636
- * **Effect Context**: Effects have access to the `CommandContext` service, which provides
1637
- * the user-facing action name.
1638
- *
1639
- * **Returned Properties**:
1640
- * - `action`: User-facing action name from intl messages (useful for button labels)
1641
- * - `result`: The command result state
1642
- * - `waiting`: Boolean indicating if the command is in progress (shorthand for `result.waiting`)
1643
- * - `handle`: Function to execute the command
1644
- * - `exec`: The raw Effect that will be executed when calling `handle` (for advanced use cases)
1645
- * - `i18nKey`, `namespace`, `namespaced`: Helpers for internationalization keys
1646
- *
1647
- * **User Feedback**: Use the `withDefaultToast` helper for status notifications, or render
1648
- * the `result` inline for custom UI feedback.
1649
- */
1650
- fn = <
1651
- const Id extends string,
1652
- const State extends IntlRecord = IntlRecord,
1653
- const I18nKey extends string = Id
1654
- >(
1655
- id: Id | { id: Id },
1656
- options?: FnOptions<Id, I18nKey, State>
1657
- ): Commander.Gen<RT | RTHooks, Id, I18nKey, State> & Commander.NonGen<RT | RTHooks, Id, I18nKey, State> & {
1658
- state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>
1659
- } =>
1660
- Object.assign(
1661
- (
1662
- fn: any,
1663
- ...combinators: any[]
1664
- ): any => {
1665
- // we capture the definition stack here, so we can append it to later stack traces
1666
- const limit = Error.stackTraceLimit
1667
- Error.stackTraceLimit = 2
1668
- const errorDef = new Error()
1669
- Error.stackTraceLimit = limit
1670
-
1671
- return this.makeCommand(id, options, errorDef)(
1672
- Effect.fnUntraced(
1673
- // fnUntraced only supports generators as first arg, so we convert to generator if needed
1674
- isGeneratorFunction(fn) ? fn : function*(...args) {
1675
- return yield* fn(...args)
1676
- },
1677
- ...combinators as [any]
1678
- ) as any
1679
- )
1680
- },
1681
- makeBaseInfo(typeof id === "string" ? id : id.id, options),
1682
- {
1683
- state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>(
1684
- `Commander.Command.${typeof id === "string" ? id : id.id}.state`
1685
- )
1686
- }
1687
- )
1688
-
1689
- /** @experimental @deprecated */
1690
- alt2: <
1691
- const Id extends string,
1692
- MutArg,
1693
- MutA,
1694
- MutE,
1695
- MutR,
1696
- const I18nKey extends string = Id,
1697
- State extends IntlRecord | undefined = undefined
1698
- >(
1699
- id:
1700
- | Id
1701
- | { id: Id; mutate: (arg: MutArg) => Effect.Effect<MutA, MutE, MutR> }
1702
- | ((arg: MutArg) => Effect.Effect<MutA, MutE, MutR>) & { id: Id },
1703
- options?: FnOptions<Id, I18nKey, State>
1704
- ) =>
1705
- & Commander.CommandContextLocal<Id, I18nKey>
1706
- & (<A, E, R extends RT | RTHooks | CommandContext | `Commander.Command.${Id}.state`, Arg = void>(
1707
- handler: (
1708
- ctx: Effect.fn.Traced & Effect.fn.Untraced & Commander.CommandContextLocal<Id, I18nKey> & {
1709
- // todo: only if we passed in one
1710
- mutate: (arg: Arg) => Effect.Effect<MutA, MutE, MutR>
1711
- }
1712
- ) => (arg: Arg, ctx: Commander.CommandContextLocal2<Id, I18nKey, State>) => Effect.Effect<A, E, R>
1713
- ) => Commander.CommandOut<Arg, A, E, R, Id, I18nKey, State>) = (
1714
- _id,
1715
- options?
1716
- ) => {
1717
- const isObject = typeof _id === "object" || typeof _id === "function"
1718
- const id = isObject ? _id.id : _id
1719
- const baseInfo = makeBaseInfo(id, options)
1720
- const idCmd = this.makeCommand(id, options)
1721
- // TODO: implement proper tracing stack
1722
- return Object.assign((cb: any) =>
1723
- idCmd(cb(
1724
- Object.assign(
1725
- (fn: any, ...combinators: any[]) =>
1726
- Effect.fnUntraced(
1727
- // fnUntraced only supports generators as first arg, so we convert to generator if needed
1728
- isGeneratorFunction(fn) ? fn : function*(...args) {
1729
- return yield* fn(...args)
1730
- },
1731
- ...combinators as [any]
1732
- ),
1733
- baseInfo,
1734
- isObject
1735
- ? { mutate: "mutate" in _id ? _id.mutate : typeof _id === "function" ? _id : undefined }
1736
- : {}
1737
- )
1738
- )), baseInfo) as any
1739
- }
1740
-
1741
- /** @experimental */
1742
- alt = this.makeCommand as unknown as <
1743
- const Id extends string,
1744
- const I18nKey extends string = Id,
1745
- State extends IntlRecord | undefined = undefined
1746
- >(
1747
- id: Id,
1748
- customI18nKey?: I18nKey
1749
- ) =>
1750
- & Commander.CommandContextLocal<Id, I18nKey>
1751
- & (<A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`, Arg = void>(
1752
- handler: (arg: Arg, ctx: Commander.CommandContextLocal2<Id, I18nKey, State>) => Effect.Effect<A, E, R>
1753
- ) => Commander.CommandOut<Arg, A, E, R, Id, I18nKey, State>)
1754
-
1755
- /**
1756
- * Define a Command for handling user actions with built-in error reporting and state management.
1757
- *
1758
- * @param mutation The mutation function to take the identifier and initial handler from. Used as a tracing span and to lookup
1759
- * the user-facing name via internationalization (`action.${id}`).
1760
- * @param options Optional configuration for internationalization and state.
1761
- * @param options.i18nCustomKey Custom i18n key to use instead of `id` (e.g., for grouping similar actions)
1762
- * @param options.state Optional reactive state object (or function returning one) that is
1763
- * made available to the command effects and can be used for i18n interpolation.
1764
- * The state is captured at the start of each command execution and remains stable throughout.
1765
- * @returns A function that executes the command when called (e.g., directly in `@click` handlers).
1766
- * Built-in error reporting handles failures automatically.
1767
- *
1768
- * **Effect Context**: Effects have access to the `CommandContext` service, which provides
1769
- * the user-facing action name.
1770
- *
1771
- * **Returned Properties**:
1772
- * - `action`: User-facing action name from intl messages (useful for button labels)
1773
- * - `result`: The command result state
1774
- * - `waiting`: Boolean indicating if the command is in progress (shorthand for `result.waiting`)
1775
- * - `handle`: Function to execute the command
1776
- * - `exec`: The raw Effect that will be executed when calling `handle` (for advanced use cases)
1777
- * - `i18nKey`, `namespace`, `namespaced`: Helpers for internationalization keys
1778
- *
1779
- * **User Feedback**: Use the `withDefaultToast` helper for status notifications, or render
1780
- * the `result` inline for custom UI feedback.
1781
- */
1782
- wrap = <
1783
- const Id extends string,
1784
- Arg,
1785
- A,
1786
- E,
1787
- R,
1788
- const State extends IntlRecord = IntlRecord,
1789
- I18nKey extends string = Id
1790
- >(
1791
- mutation:
1792
- | { mutate: (arg: Arg) => Effect.Effect<A, E, R>; id: Id }
1793
- | ((arg: Arg) => Effect.Effect<A, E, R>) & { id: Id },
1794
- options?: FnOptions<Id, I18nKey, State>
1795
- ): Commander.CommanderWrap<RT | RTHooks, Id, I18nKey, State, Arg, A, E, R> =>
1796
- Object.assign(
1797
- (
1798
- ...combinators: any[]
1799
- ): any => {
1800
- // we capture the definition stack here, so we can append it to later stack traces
1801
- const limit = Error.stackTraceLimit
1802
- Error.stackTraceLimit = 2
1803
- const errorDef = new Error()
1804
- Error.stackTraceLimit = limit
1805
- const mutate = "mutate" in mutation ? mutation.mutate : mutation
1806
-
1807
- return this.makeCommand(mutation.id, options, errorDef)(
1808
- Effect.fnUntraced(
1809
- // fnUntraced only supports generators as first arg, so we convert to generator if needed
1810
- isGeneratorFunction(mutate) ? mutate : function*(arg: Arg) {
1811
- return yield* mutate(arg)
1812
- },
1813
- ...combinators as [any]
1814
- ) as any
1815
- )
1816
- },
1817
- makeBaseInfo(mutation.id, options),
1818
- {
1819
- state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>(
1820
- `Commander.Command.${mutation.id}.state`
1821
- )
1822
- }
1823
- )
1824
- }
1825
-
1826
- // @effect-diagnostics-next-line missingEffectServiceDependency:off
1827
- export class Commander extends ServiceMap.Service<Commander>()("Commander", {
1828
- make: Effect.gen(function*() {
1829
- const i18n = yield* I18n
1830
- return <RT, RTHooks>(rt: ServiceMap.ServiceMap<RT>, rtHooks: Layer.Layer<RTHooks, never, RT>) =>
1831
- new CommanderImpl(rt, i18n, rtHooks)
1832
- })
1833
- }) {
1834
- static readonly DefaultWithoutDependencies = Layer.effect(this, this.make)
1835
- static readonly Default = this.DefaultWithoutDependencies
1836
- }