@effect-app/vue 2.75.2 → 2.75.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/experimental/commander.d.ts +57 -50
- package/dist/experimental/commander.d.ts.map +1 -1
- package/dist/experimental/commander.js +19 -15
- package/dist/experimental/makeUseCommand.d.ts +17 -15
- package/dist/experimental/makeUseCommand.d.ts.map +1 -1
- package/dist/makeClient.d.ts +68 -48
- package/dist/makeClient.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/experimental/commander.ts +443 -271
- package/src/makeClient.ts +4 -4
- package/test/dist/stubs.d.ts +17 -15
- package/test/dist/stubs.d.ts.map +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { asResult, reportRuntimeError } from "@effect-app/vue"
|
|
3
3
|
import { reportMessage } from "@effect-app/vue/errorReporter"
|
|
4
4
|
import { type Result } from "@effect-atom/atom/Result"
|
|
5
|
-
import { Cause, Effect, type Exit, flow, Match, Option, Runtime, S } from "effect-app"
|
|
5
|
+
import { Cause, Context, Effect, type Exit, flow, Match, Option, Runtime, S } from "effect-app"
|
|
6
6
|
import { SupportedErrors } from "effect-app/client"
|
|
7
7
|
import { OperationFailure, OperationSuccess } from "effect-app/Operations"
|
|
8
8
|
import { wrapEffect } from "effect-app/utils"
|
|
@@ -16,15 +16,20 @@ import { I18n } from "./intl.js"
|
|
|
16
16
|
import { WithToast } from "./withToast.js"
|
|
17
17
|
|
|
18
18
|
type IntlRecord = Record<string, PrimitiveType | FormatXMLElementFn<string, string>>
|
|
19
|
-
type FnOptions<I18nCustomKey extends string> = {
|
|
19
|
+
type FnOptions<I18nCustomKey extends string, State extends IntlRecord> = {
|
|
20
20
|
i18nCustomKey?: I18nCustomKey
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* passed to the i18n formatMessage calls so you can use it in translation messagee
|
|
23
|
+
* including the Command `action` string.
|
|
24
|
+
* Automatically wrapped with Computed if just a thunk.
|
|
25
|
+
* provided as Command.state tag, so you can access it in the function.
|
|
26
|
+
*/
|
|
27
|
+
state?: ComputedRef<State> | (() => State)
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
type FnOptionsInternal<I18nCustomKey extends string> = {
|
|
26
31
|
i18nCustomKey?: I18nCustomKey | undefined
|
|
27
|
-
|
|
32
|
+
state?: IntlRecord | undefined
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
export const DefaultIntl = {
|
|
@@ -132,7 +137,11 @@ export declare namespace Commander {
|
|
|
132
137
|
>
|
|
133
138
|
|
|
134
139
|
export type Gen<RT, Id extends string, I18nKey extends string> = {
|
|
135
|
-
<
|
|
140
|
+
<
|
|
141
|
+
Eff extends YieldWrap<Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>,
|
|
142
|
+
AEff,
|
|
143
|
+
Args extends Array<unknown>
|
|
144
|
+
>(
|
|
136
145
|
body: (...args: Args) => Generator<Eff, AEff, never>
|
|
137
146
|
): CommandOut<
|
|
138
147
|
Args,
|
|
@@ -150,7 +159,7 @@ export declare namespace Commander {
|
|
|
150
159
|
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
151
160
|
AEff,
|
|
152
161
|
Args extends Array<unknown>,
|
|
153
|
-
A extends Effect.Effect<any, any, RT | CommandContext
|
|
162
|
+
A extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
154
163
|
>(
|
|
155
164
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
156
165
|
a: (
|
|
@@ -171,7 +180,7 @@ export declare namespace Commander {
|
|
|
171
180
|
AEff,
|
|
172
181
|
Args extends Array<unknown>,
|
|
173
182
|
A,
|
|
174
|
-
B extends Effect.Effect<any, any, RT | CommandContext
|
|
183
|
+
B extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
175
184
|
>(
|
|
176
185
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
177
186
|
a: (
|
|
@@ -194,7 +203,7 @@ export declare namespace Commander {
|
|
|
194
203
|
Args extends Array<unknown>,
|
|
195
204
|
A,
|
|
196
205
|
B,
|
|
197
|
-
C extends Effect.Effect<any, any, RT | CommandContext
|
|
206
|
+
C extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
198
207
|
>(
|
|
199
208
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
200
209
|
a: (
|
|
@@ -219,7 +228,7 @@ export declare namespace Commander {
|
|
|
219
228
|
A,
|
|
220
229
|
B,
|
|
221
230
|
C,
|
|
222
|
-
D extends Effect.Effect<any, any, RT | CommandContext
|
|
231
|
+
D extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
223
232
|
>(
|
|
224
233
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
225
234
|
a: (
|
|
@@ -246,7 +255,7 @@ export declare namespace Commander {
|
|
|
246
255
|
B,
|
|
247
256
|
C,
|
|
248
257
|
D,
|
|
249
|
-
E extends Effect.Effect<any, any, RT | CommandContext
|
|
258
|
+
E extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
250
259
|
>(
|
|
251
260
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
252
261
|
a: (
|
|
@@ -275,7 +284,7 @@ export declare namespace Commander {
|
|
|
275
284
|
C,
|
|
276
285
|
D,
|
|
277
286
|
E,
|
|
278
|
-
F extends Effect.Effect<any, any, RT | CommandContext
|
|
287
|
+
F extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
279
288
|
>(
|
|
280
289
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
281
290
|
a: (
|
|
@@ -306,7 +315,7 @@ export declare namespace Commander {
|
|
|
306
315
|
D,
|
|
307
316
|
E,
|
|
308
317
|
F,
|
|
309
|
-
G extends Effect.Effect<any, any, RT | CommandContext
|
|
318
|
+
G extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
310
319
|
>(
|
|
311
320
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
312
321
|
a: (
|
|
@@ -339,7 +348,7 @@ export declare namespace Commander {
|
|
|
339
348
|
E,
|
|
340
349
|
F,
|
|
341
350
|
G,
|
|
342
|
-
H extends Effect.Effect<any, any, RT | CommandContext
|
|
351
|
+
H extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
343
352
|
>(
|
|
344
353
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
345
354
|
a: (
|
|
@@ -374,7 +383,7 @@ export declare namespace Commander {
|
|
|
374
383
|
F,
|
|
375
384
|
G,
|
|
376
385
|
H,
|
|
377
|
-
I extends Effect.Effect<any, any, RT | CommandContext
|
|
386
|
+
I extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
378
387
|
>(
|
|
379
388
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
380
389
|
a: (
|
|
@@ -401,32 +410,65 @@ export declare namespace Commander {
|
|
|
401
410
|
}
|
|
402
411
|
|
|
403
412
|
export type NonGen<RT, Id extends string, I18nKey extends string> = {
|
|
404
|
-
<
|
|
413
|
+
<
|
|
414
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
415
|
+
Args extends Array<unknown>
|
|
416
|
+
>(
|
|
405
417
|
body: (...args: Args) => Eff
|
|
406
418
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
407
|
-
<
|
|
419
|
+
<
|
|
420
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
421
|
+
A,
|
|
422
|
+
Args extends Array<unknown>
|
|
423
|
+
>(
|
|
408
424
|
body: (...args: Args) => A,
|
|
409
425
|
a: (_: A, ...args: NoInfer<Args>) => Eff
|
|
410
426
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
411
|
-
<
|
|
427
|
+
<
|
|
428
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
429
|
+
A,
|
|
430
|
+
B,
|
|
431
|
+
Args extends Array<unknown>
|
|
432
|
+
>(
|
|
412
433
|
body: (...args: Args) => A,
|
|
413
434
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
414
435
|
b: (_: B, ...args: NoInfer<Args>) => Eff
|
|
415
436
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
416
|
-
<
|
|
437
|
+
<
|
|
438
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
439
|
+
A,
|
|
440
|
+
B,
|
|
441
|
+
C,
|
|
442
|
+
Args extends Array<unknown>
|
|
443
|
+
>(
|
|
417
444
|
body: (...args: Args) => A,
|
|
418
445
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
419
446
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
420
447
|
c: (_: C, ...args: NoInfer<Args>) => Eff
|
|
421
448
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
422
|
-
<
|
|
449
|
+
<
|
|
450
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
451
|
+
A,
|
|
452
|
+
B,
|
|
453
|
+
C,
|
|
454
|
+
D,
|
|
455
|
+
Args extends Array<unknown>
|
|
456
|
+
>(
|
|
423
457
|
body: (...args: Args) => A,
|
|
424
458
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
425
459
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
426
460
|
c: (_: C, ...args: NoInfer<Args>) => D,
|
|
427
461
|
d: (_: D, ...args: NoInfer<Args>) => Eff
|
|
428
462
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
429
|
-
<
|
|
463
|
+
<
|
|
464
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
465
|
+
A,
|
|
466
|
+
B,
|
|
467
|
+
C,
|
|
468
|
+
D,
|
|
469
|
+
E,
|
|
470
|
+
Args extends Array<unknown>
|
|
471
|
+
>(
|
|
430
472
|
body: (...args: Args) => A,
|
|
431
473
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
432
474
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -434,7 +476,16 @@ export declare namespace Commander {
|
|
|
434
476
|
d: (_: D, ...args: NoInfer<Args>) => E,
|
|
435
477
|
e: (_: E, ...args: NoInfer<Args>) => Eff
|
|
436
478
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
437
|
-
<
|
|
479
|
+
<
|
|
480
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
481
|
+
A,
|
|
482
|
+
B,
|
|
483
|
+
C,
|
|
484
|
+
D,
|
|
485
|
+
E,
|
|
486
|
+
F,
|
|
487
|
+
Args extends Array<unknown>
|
|
488
|
+
>(
|
|
438
489
|
body: (...args: Args) => A,
|
|
439
490
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
440
491
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -443,7 +494,17 @@ export declare namespace Commander {
|
|
|
443
494
|
e: (_: E, ...args: NoInfer<Args>) => F,
|
|
444
495
|
f: (_: F, ...args: NoInfer<Args>) => Eff
|
|
445
496
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
446
|
-
<
|
|
497
|
+
<
|
|
498
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
499
|
+
A,
|
|
500
|
+
B,
|
|
501
|
+
C,
|
|
502
|
+
D,
|
|
503
|
+
E,
|
|
504
|
+
F,
|
|
505
|
+
G,
|
|
506
|
+
Args extends Array<unknown>
|
|
507
|
+
>(
|
|
447
508
|
body: (...args: Args) => A,
|
|
448
509
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
449
510
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -453,7 +514,18 @@ export declare namespace Commander {
|
|
|
453
514
|
f: (_: F, ...args: NoInfer<Args>) => G,
|
|
454
515
|
g: (_: G, ...args: NoInfer<Args>) => Eff
|
|
455
516
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
456
|
-
<
|
|
517
|
+
<
|
|
518
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
519
|
+
A,
|
|
520
|
+
B,
|
|
521
|
+
C,
|
|
522
|
+
D,
|
|
523
|
+
E,
|
|
524
|
+
F,
|
|
525
|
+
G,
|
|
526
|
+
H,
|
|
527
|
+
Args extends Array<unknown>
|
|
528
|
+
>(
|
|
457
529
|
body: (...args: Args) => A,
|
|
458
530
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
459
531
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -464,7 +536,19 @@ export declare namespace Commander {
|
|
|
464
536
|
g: (_: G, ...args: NoInfer<Args>) => H,
|
|
465
537
|
h: (_: H, ...args: NoInfer<Args>) => Eff
|
|
466
538
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
467
|
-
<
|
|
539
|
+
<
|
|
540
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
541
|
+
A,
|
|
542
|
+
B,
|
|
543
|
+
C,
|
|
544
|
+
D,
|
|
545
|
+
E,
|
|
546
|
+
F,
|
|
547
|
+
G,
|
|
548
|
+
H,
|
|
549
|
+
I,
|
|
550
|
+
Args extends Array<unknown>
|
|
551
|
+
>(
|
|
468
552
|
body: (...args: Args) => A,
|
|
469
553
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
470
554
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -483,12 +567,12 @@ export declare namespace Commander {
|
|
|
483
567
|
Args,
|
|
484
568
|
AEff,
|
|
485
569
|
EEff,
|
|
486
|
-
REff, // TODO: only allowed to be RT | CommandContext
|
|
570
|
+
REff, // TODO: only allowed to be RT | CommandContext | `Commander.Command.${Id}.state`
|
|
487
571
|
Id,
|
|
488
572
|
I18nKey
|
|
489
573
|
>
|
|
490
574
|
<
|
|
491
|
-
A extends Effect.Effect<any, any, RT | CommandContext
|
|
575
|
+
A extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
492
576
|
>(
|
|
493
577
|
a: (
|
|
494
578
|
_: Effect.Effect<
|
|
@@ -501,7 +585,7 @@ export declare namespace Commander {
|
|
|
501
585
|
): CommandOutHelper<Args, A, Id, I18nKey>
|
|
502
586
|
<
|
|
503
587
|
A,
|
|
504
|
-
B extends Effect.Effect<any, any, RT | CommandContext
|
|
588
|
+
B extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
505
589
|
>(
|
|
506
590
|
a: (
|
|
507
591
|
_: Effect.Effect<
|
|
@@ -516,7 +600,7 @@ export declare namespace Commander {
|
|
|
516
600
|
<
|
|
517
601
|
A,
|
|
518
602
|
B,
|
|
519
|
-
C extends Effect.Effect<any, any, RT | CommandContext
|
|
603
|
+
C extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
520
604
|
>(
|
|
521
605
|
a: (
|
|
522
606
|
_: Effect.Effect<
|
|
@@ -533,7 +617,7 @@ export declare namespace Commander {
|
|
|
533
617
|
A,
|
|
534
618
|
B,
|
|
535
619
|
C,
|
|
536
|
-
D extends Effect.Effect<any, any, RT | CommandContext
|
|
620
|
+
D extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
537
621
|
>(
|
|
538
622
|
a: (
|
|
539
623
|
_: Effect.Effect<
|
|
@@ -552,7 +636,7 @@ export declare namespace Commander {
|
|
|
552
636
|
B,
|
|
553
637
|
C,
|
|
554
638
|
D,
|
|
555
|
-
E extends Effect.Effect<any, any, RT | CommandContext
|
|
639
|
+
E extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
556
640
|
>(
|
|
557
641
|
a: (
|
|
558
642
|
_: Effect.Effect<
|
|
@@ -573,7 +657,7 @@ export declare namespace Commander {
|
|
|
573
657
|
C,
|
|
574
658
|
D,
|
|
575
659
|
E,
|
|
576
|
-
F extends Effect.Effect<any, any, RT | CommandContext
|
|
660
|
+
F extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
577
661
|
>(
|
|
578
662
|
a: (
|
|
579
663
|
_: Effect.Effect<
|
|
@@ -596,7 +680,7 @@ export declare namespace Commander {
|
|
|
596
680
|
D,
|
|
597
681
|
E,
|
|
598
682
|
F,
|
|
599
|
-
G extends Effect.Effect<any, any, RT | CommandContext
|
|
683
|
+
G extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
600
684
|
>(
|
|
601
685
|
a: (
|
|
602
686
|
_: Effect.Effect<
|
|
@@ -613,7 +697,7 @@ export declare namespace Commander {
|
|
|
613
697
|
f: (_: E, ...args: NoInfer<Args>) => F,
|
|
614
698
|
g: (_: F, ...args: NoInfer<Args>) => G
|
|
615
699
|
): CommandOutHelper<Args, G, Id, I18nKey>
|
|
616
|
-
<A, B, C, D, E, F, G, H extends Effect.Effect<any, any, RT | CommandContext
|
|
700
|
+
<A, B, C, D, E, F, G, H extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(
|
|
617
701
|
a: (
|
|
618
702
|
_: Effect.Effect<
|
|
619
703
|
AEff,
|
|
@@ -630,7 +714,7 @@ export declare namespace Commander {
|
|
|
630
714
|
g: (_: F, ...args: NoInfer<Args>) => G,
|
|
631
715
|
h: (_: G, ...args: NoInfer<Args>) => H
|
|
632
716
|
): CommandOutHelper<Args, H, Id, I18nKey>
|
|
633
|
-
<A, B, C, D, E, F, G, H, I extends Effect.Effect<any, any, RT | CommandContext
|
|
717
|
+
<A, B, C, D, E, F, G, H, I extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(
|
|
634
718
|
a: (
|
|
635
719
|
_: Effect.Effect<
|
|
636
720
|
AEff,
|
|
@@ -653,7 +737,10 @@ export declare namespace Commander {
|
|
|
653
737
|
export type NonGenWrap<RT, Id extends string, I18nKey extends string, Args extends Array<unknown>, AEff, EEff, REff> =
|
|
654
738
|
{
|
|
655
739
|
(): CommandOutHelper<Args, Effect.Effect<AEff, EEff, REff>, Id, I18nKey>
|
|
656
|
-
<
|
|
740
|
+
<
|
|
741
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
742
|
+
Args extends Array<unknown>
|
|
743
|
+
>(
|
|
657
744
|
a: (
|
|
658
745
|
_: Effect.Effect<
|
|
659
746
|
AEff,
|
|
@@ -663,7 +750,11 @@ export declare namespace Commander {
|
|
|
663
750
|
...args: NoInfer<Args>
|
|
664
751
|
) => Eff
|
|
665
752
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
666
|
-
<
|
|
753
|
+
<
|
|
754
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
755
|
+
B,
|
|
756
|
+
Args extends Array<unknown>
|
|
757
|
+
>(
|
|
667
758
|
a: (
|
|
668
759
|
_: Effect.Effect<
|
|
669
760
|
AEff,
|
|
@@ -674,7 +765,12 @@ export declare namespace Commander {
|
|
|
674
765
|
) => B,
|
|
675
766
|
b: (_: B, ...args: NoInfer<Args>) => Eff
|
|
676
767
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
677
|
-
<
|
|
768
|
+
<
|
|
769
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
770
|
+
B,
|
|
771
|
+
C,
|
|
772
|
+
Args extends Array<unknown>
|
|
773
|
+
>(
|
|
678
774
|
a: (
|
|
679
775
|
_: Effect.Effect<
|
|
680
776
|
AEff,
|
|
@@ -686,7 +782,13 @@ export declare namespace Commander {
|
|
|
686
782
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
687
783
|
c: (_: C, ...args: NoInfer<Args>) => Eff
|
|
688
784
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
689
|
-
<
|
|
785
|
+
<
|
|
786
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
787
|
+
B,
|
|
788
|
+
C,
|
|
789
|
+
D,
|
|
790
|
+
Args extends Array<unknown>
|
|
791
|
+
>(
|
|
690
792
|
a: (
|
|
691
793
|
_: Effect.Effect<
|
|
692
794
|
AEff,
|
|
@@ -699,7 +801,14 @@ export declare namespace Commander {
|
|
|
699
801
|
c: (_: C, ...args: NoInfer<Args>) => D,
|
|
700
802
|
d: (_: D, ...args: NoInfer<Args>) => Eff
|
|
701
803
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
702
|
-
<
|
|
804
|
+
<
|
|
805
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
806
|
+
B,
|
|
807
|
+
C,
|
|
808
|
+
D,
|
|
809
|
+
E,
|
|
810
|
+
Args extends Array<unknown>
|
|
811
|
+
>(
|
|
703
812
|
a: (
|
|
704
813
|
_: Effect.Effect<
|
|
705
814
|
AEff,
|
|
@@ -713,7 +822,15 @@ export declare namespace Commander {
|
|
|
713
822
|
d: (_: D, ...args: NoInfer<Args>) => E,
|
|
714
823
|
e: (_: E, ...args: NoInfer<Args>) => Eff
|
|
715
824
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
716
|
-
<
|
|
825
|
+
<
|
|
826
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
827
|
+
B,
|
|
828
|
+
C,
|
|
829
|
+
D,
|
|
830
|
+
E,
|
|
831
|
+
F,
|
|
832
|
+
Args extends Array<unknown>
|
|
833
|
+
>(
|
|
717
834
|
a: (
|
|
718
835
|
_: Effect.Effect<
|
|
719
836
|
AEff,
|
|
@@ -728,7 +845,16 @@ export declare namespace Commander {
|
|
|
728
845
|
e: (_: E, ...args: NoInfer<Args>) => F,
|
|
729
846
|
f: (_: F, ...args: NoInfer<Args>) => Eff
|
|
730
847
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
731
|
-
<
|
|
848
|
+
<
|
|
849
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
850
|
+
B,
|
|
851
|
+
C,
|
|
852
|
+
D,
|
|
853
|
+
E,
|
|
854
|
+
F,
|
|
855
|
+
G,
|
|
856
|
+
Args extends Array<unknown>
|
|
857
|
+
>(
|
|
732
858
|
a: (
|
|
733
859
|
_: Effect.Effect<
|
|
734
860
|
AEff,
|
|
@@ -744,7 +870,17 @@ export declare namespace Commander {
|
|
|
744
870
|
f: (_: F, ...args: NoInfer<Args>) => G,
|
|
745
871
|
g: (_: G, ...args: NoInfer<Args>) => Eff
|
|
746
872
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
747
|
-
<
|
|
873
|
+
<
|
|
874
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
875
|
+
B,
|
|
876
|
+
C,
|
|
877
|
+
D,
|
|
878
|
+
E,
|
|
879
|
+
F,
|
|
880
|
+
G,
|
|
881
|
+
H,
|
|
882
|
+
Args extends Array<unknown>
|
|
883
|
+
>(
|
|
748
884
|
a: (
|
|
749
885
|
_: Effect.Effect<
|
|
750
886
|
AEff,
|
|
@@ -761,7 +897,18 @@ export declare namespace Commander {
|
|
|
761
897
|
g: (_: G, ...args: NoInfer<Args>) => H,
|
|
762
898
|
h: (_: H, ...args: NoInfer<Args>) => Eff
|
|
763
899
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
764
|
-
<
|
|
900
|
+
<
|
|
901
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
902
|
+
B,
|
|
903
|
+
C,
|
|
904
|
+
D,
|
|
905
|
+
E,
|
|
906
|
+
F,
|
|
907
|
+
G,
|
|
908
|
+
H,
|
|
909
|
+
I,
|
|
910
|
+
Args extends Array<unknown>
|
|
911
|
+
>(
|
|
765
912
|
a: (
|
|
766
913
|
_: Effect.Effect<
|
|
767
914
|
AEff,
|
|
@@ -952,7 +1099,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
952
1099
|
const action = intl.formatMessage({
|
|
953
1100
|
id: namespace,
|
|
954
1101
|
defaultMessage: id
|
|
955
|
-
}, options?.
|
|
1102
|
+
}, options?.state)
|
|
956
1103
|
const context = {
|
|
957
1104
|
action,
|
|
958
1105
|
id,
|
|
@@ -964,269 +1111,279 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
964
1111
|
return context
|
|
965
1112
|
}
|
|
966
1113
|
|
|
967
|
-
const
|
|
968
|
-
const
|
|
969
|
-
? computed(options.
|
|
970
|
-
: options.
|
|
971
|
-
return
|
|
1114
|
+
const getStateValues = <const I18nKey extends string>(options?: FnOptions<I18nKey, any>) => {
|
|
1115
|
+
const state = !options?.state ? undefined : typeof options.state === "function"
|
|
1116
|
+
? computed(options.state)
|
|
1117
|
+
: options.state
|
|
1118
|
+
return state
|
|
972
1119
|
}
|
|
973
1120
|
|
|
974
1121
|
const makeCommand = <RT>(runtime: Runtime.Runtime<RT>) => {
|
|
975
1122
|
const runFork = Runtime.runFork(runtime)
|
|
976
|
-
return <const Id extends string, const I18nKey extends string = Id>(
|
|
1123
|
+
return <const Id extends string, State extends IntlRecord, const I18nKey extends string = Id>(
|
|
977
1124
|
id_: Id | { id: Id },
|
|
978
|
-
options?: FnOptions<I18nKey>,
|
|
1125
|
+
options?: FnOptions<I18nKey, State>,
|
|
979
1126
|
errorDef?: Error
|
|
980
1127
|
) => {
|
|
981
1128
|
const id = typeof id_ === "string" ? id_ : id_.id
|
|
982
|
-
const
|
|
983
|
-
|
|
984
|
-
return Object.assign(<Args extends ReadonlyArray<unknown>, A, E, R extends RT | CommandContext>(
|
|
985
|
-
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
986
|
-
) => {
|
|
987
|
-
// we capture the definition stack here, so we can append it to later stack traces
|
|
988
|
-
const limit = Error.stackTraceLimit
|
|
989
|
-
Error.stackTraceLimit = 2
|
|
990
|
-
const localErrorDef = new Error()
|
|
991
|
-
Error.stackTraceLimit = limit
|
|
992
|
-
if (!errorDef) {
|
|
993
|
-
errorDef = localErrorDef
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
const makeContext_ = () => makeContext(id, { ...options, i18nValues: i18nValues?.value })
|
|
997
|
-
const initialContext = makeContext_()
|
|
998
|
-
const action = computed(() => makeContext_().action)
|
|
999
|
-
|
|
1000
|
-
const errorReporter = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
1001
|
-
self.pipe(
|
|
1002
|
-
Effect.tapErrorCause(
|
|
1003
|
-
Effect.fnUntraced(function*(cause) {
|
|
1004
|
-
if (Cause.isInterruptedOnly(cause)) {
|
|
1005
|
-
console.info(`Interrupted while trying to ${id}`)
|
|
1006
|
-
return
|
|
1007
|
-
}
|
|
1129
|
+
const state = getStateValues(options)
|
|
1008
1130
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
error: fail.value
|
|
1022
|
-
})
|
|
1023
|
-
return
|
|
1024
|
-
}
|
|
1131
|
+
return Object.assign(
|
|
1132
|
+
<Args extends ReadonlyArray<unknown>, A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>(
|
|
1133
|
+
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
1134
|
+
) => {
|
|
1135
|
+
// we capture the definition stack here, so we can append it to later stack traces
|
|
1136
|
+
const limit = Error.stackTraceLimit
|
|
1137
|
+
Error.stackTraceLimit = 2
|
|
1138
|
+
const localErrorDef = new Error()
|
|
1139
|
+
Error.stackTraceLimit = limit
|
|
1140
|
+
if (!errorDef) {
|
|
1141
|
+
errorDef = localErrorDef
|
|
1142
|
+
}
|
|
1025
1143
|
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1144
|
+
const key = `Commander.Command.${id}.state` as const
|
|
1145
|
+
const stateTag = Context.GenericTag<typeof key, State>(key)
|
|
1146
|
+
|
|
1147
|
+
const makeContext_ = () => makeContext(id, { ...options, state: state?.value })
|
|
1148
|
+
const initialContext = makeContext_()
|
|
1149
|
+
const action = computed(() => makeContext_().action)
|
|
1150
|
+
|
|
1151
|
+
const errorReporter = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
1152
|
+
self.pipe(
|
|
1153
|
+
Effect.tapErrorCause(
|
|
1154
|
+
Effect.fnUntraced(function*(cause) {
|
|
1155
|
+
if (Cause.isInterruptedOnly(cause)) {
|
|
1156
|
+
console.info(`Interrupted while trying to ${id}`)
|
|
1157
|
+
return
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
const fail = Cause.failureOption(cause)
|
|
1161
|
+
if (Option.isSome(fail)) {
|
|
1162
|
+
// if (fail.value._tag === "SuppressErrors") {
|
|
1163
|
+
// console.info(
|
|
1164
|
+
// `Suppressed error trying to ${action}`,
|
|
1165
|
+
// fail.value,
|
|
1166
|
+
// )
|
|
1167
|
+
// return
|
|
1168
|
+
// }
|
|
1169
|
+
const message = `Failure trying to ${id}`
|
|
1170
|
+
yield* reportMessage(message, {
|
|
1171
|
+
action: id,
|
|
1172
|
+
error: fail.value
|
|
1173
|
+
})
|
|
1174
|
+
return
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
const context = yield* CommandContext
|
|
1178
|
+
const extra = {
|
|
1179
|
+
action: context.action,
|
|
1180
|
+
message: `Unexpected Error trying to ${id}`
|
|
1181
|
+
}
|
|
1182
|
+
yield* reportRuntimeError(cause, extra)
|
|
1183
|
+
}, Effect.uninterruptible)
|
|
1184
|
+
)
|
|
1033
1185
|
)
|
|
1034
|
-
)
|
|
1035
1186
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1187
|
+
const theHandler = flow(
|
|
1188
|
+
handler,
|
|
1189
|
+
errorReporter,
|
|
1190
|
+
// all must be within the Effect.fn to fit within the Span
|
|
1191
|
+
Effect.provideServiceEffect(
|
|
1192
|
+
CommandContext,
|
|
1193
|
+
Effect.sync(() => makeContext_())
|
|
1194
|
+
),
|
|
1195
|
+
Effect.provideServiceEffect(
|
|
1196
|
+
stateTag,
|
|
1197
|
+
Effect.sync(() => state?.value)
|
|
1198
|
+
), // todo; service make errors?
|
|
1199
|
+
(_) => Effect.annotateCurrentSpan({ action }).pipe(Effect.zipRight(_))
|
|
1200
|
+
)
|
|
1046
1201
|
|
|
1047
|
-
|
|
1202
|
+
const [result, exec] = asResult(theHandler)
|
|
1048
1203
|
|
|
1049
|
-
|
|
1204
|
+
const waiting = computed(() => result.value.waiting)
|
|
1050
1205
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1206
|
+
const handle = Object.assign((...args: Args) => {
|
|
1207
|
+
// we capture the call site stack here
|
|
1208
|
+
const limit = Error.stackTraceLimit
|
|
1209
|
+
Error.stackTraceLimit = 2
|
|
1210
|
+
const errorCall = new Error()
|
|
1211
|
+
Error.stackTraceLimit = limit
|
|
1057
1212
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1213
|
+
let cache: false | string = false
|
|
1214
|
+
const captureStackTrace = () => {
|
|
1215
|
+
// in case of an error, we want to append the definition stack to the call site stack,
|
|
1216
|
+
// so we can see where the handler was defined too
|
|
1062
1217
|
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
}
|
|
1066
|
-
if (errorCall.stack) {
|
|
1067
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1068
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
1069
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1070
|
-
if (!endStackDef.includes(`(`)) {
|
|
1071
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1218
|
+
if (cache !== false) {
|
|
1219
|
+
return cache
|
|
1072
1220
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1221
|
+
if (errorCall.stack) {
|
|
1222
|
+
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1223
|
+
const stackCall = errorCall.stack.trim().split("\n")
|
|
1224
|
+
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1225
|
+
if (!endStackDef.includes(`(`)) {
|
|
1226
|
+
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1227
|
+
}
|
|
1228
|
+
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
1229
|
+
if (!endStackCall.includes(`(`)) {
|
|
1230
|
+
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
1231
|
+
}
|
|
1232
|
+
cache = `${endStackDef}\n${endStackCall}`
|
|
1233
|
+
return cache
|
|
1076
1234
|
}
|
|
1077
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
1078
|
-
return cache
|
|
1079
1235
|
}
|
|
1080
|
-
}
|
|
1081
1236
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1237
|
+
const command = Effect.withSpan(
|
|
1238
|
+
exec(...args),
|
|
1239
|
+
id,
|
|
1240
|
+
{ captureStackTrace }
|
|
1241
|
+
)
|
|
1087
1242
|
|
|
1088
|
-
|
|
1089
|
-
|
|
1243
|
+
return runFork(command)
|
|
1244
|
+
}, { action })
|
|
1090
1245
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1246
|
+
const handleEffect = Object.assign((...args: Args) => {
|
|
1247
|
+
// we capture the call site stack here
|
|
1248
|
+
const limit = Error.stackTraceLimit
|
|
1249
|
+
Error.stackTraceLimit = 2
|
|
1250
|
+
const errorCall = new Error()
|
|
1251
|
+
Error.stackTraceLimit = limit
|
|
1097
1252
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1253
|
+
let cache: false | string = false
|
|
1254
|
+
const captureStackTrace = () => {
|
|
1255
|
+
// in case of an error, we want to append the definition stack to the call site stack,
|
|
1256
|
+
// so we can see where the handler was defined too
|
|
1102
1257
|
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1106
|
-
if (errorCall.stack) {
|
|
1107
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1108
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
1109
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1110
|
-
if (!endStackDef.includes(`(`)) {
|
|
1111
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1258
|
+
if (cache !== false) {
|
|
1259
|
+
return cache
|
|
1112
1260
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1261
|
+
if (errorCall.stack) {
|
|
1262
|
+
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1263
|
+
const stackCall = errorCall.stack.trim().split("\n")
|
|
1264
|
+
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1265
|
+
if (!endStackDef.includes(`(`)) {
|
|
1266
|
+
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1267
|
+
}
|
|
1268
|
+
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
1269
|
+
if (!endStackCall.includes(`(`)) {
|
|
1270
|
+
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
1271
|
+
}
|
|
1272
|
+
cache = `${endStackDef}\n${endStackCall}`
|
|
1273
|
+
return cache
|
|
1116
1274
|
}
|
|
1117
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
1118
|
-
return cache
|
|
1119
1275
|
}
|
|
1120
|
-
}
|
|
1121
1276
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1277
|
+
const command = Effect.withSpan(
|
|
1278
|
+
exec(...args),
|
|
1279
|
+
id,
|
|
1280
|
+
{ captureStackTrace }
|
|
1281
|
+
)
|
|
1127
1282
|
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1283
|
+
return Effect.currentSpan.pipe(
|
|
1284
|
+
Effect.option,
|
|
1285
|
+
Effect.map((span) =>
|
|
1286
|
+
runFork(Option.isSome(span) ? command.pipe(Effect.withParentSpan(span.value)) : command)
|
|
1287
|
+
)
|
|
1132
1288
|
)
|
|
1133
|
-
)
|
|
1134
|
-
}, { action })
|
|
1289
|
+
}, { action, state })
|
|
1135
1290
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1291
|
+
const compose = Object.assign((...args: Args) => {
|
|
1292
|
+
// we capture the call site stack here
|
|
1293
|
+
const limit = Error.stackTraceLimit
|
|
1294
|
+
Error.stackTraceLimit = 2
|
|
1295
|
+
const errorCall = new Error()
|
|
1296
|
+
Error.stackTraceLimit = limit
|
|
1142
1297
|
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1298
|
+
let cache: false | string = false
|
|
1299
|
+
const captureStackTrace = () => {
|
|
1300
|
+
// in case of an error, we want to append the definition stack to the call site stack,
|
|
1301
|
+
// so we can see where the handler was defined too
|
|
1147
1302
|
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
}
|
|
1151
|
-
if (errorCall.stack) {
|
|
1152
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1153
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
1154
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1155
|
-
if (!endStackDef.includes(`(`)) {
|
|
1156
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1303
|
+
if (cache !== false) {
|
|
1304
|
+
return cache
|
|
1157
1305
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1306
|
+
if (errorCall.stack) {
|
|
1307
|
+
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1308
|
+
const stackCall = errorCall.stack.trim().split("\n")
|
|
1309
|
+
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1310
|
+
if (!endStackDef.includes(`(`)) {
|
|
1311
|
+
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1312
|
+
}
|
|
1313
|
+
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
1314
|
+
if (!endStackCall.includes(`(`)) {
|
|
1315
|
+
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
1316
|
+
}
|
|
1317
|
+
cache = `${endStackDef}\n${endStackCall}`
|
|
1318
|
+
return cache
|
|
1161
1319
|
}
|
|
1162
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
1163
|
-
return cache
|
|
1164
1320
|
}
|
|
1165
|
-
}
|
|
1166
1321
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1322
|
+
const command = Effect.withSpan(
|
|
1323
|
+
exec(...args),
|
|
1324
|
+
id,
|
|
1325
|
+
{ captureStackTrace }
|
|
1326
|
+
)
|
|
1172
1327
|
|
|
1173
|
-
|
|
1174
|
-
|
|
1328
|
+
return command
|
|
1329
|
+
}, { action })
|
|
1175
1330
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1331
|
+
const compose2 = Object.assign((...args: Args) => {
|
|
1332
|
+
// we capture the call site stack here
|
|
1333
|
+
const limit = Error.stackTraceLimit
|
|
1334
|
+
Error.stackTraceLimit = 2
|
|
1335
|
+
const errorCall = new Error()
|
|
1336
|
+
Error.stackTraceLimit = limit
|
|
1182
1337
|
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1338
|
+
let cache: false | string = false
|
|
1339
|
+
const captureStackTrace = () => {
|
|
1340
|
+
// in case of an error, we want to append the definition stack to the call site stack,
|
|
1341
|
+
// so we can see where the handler was defined too
|
|
1187
1342
|
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
}
|
|
1191
|
-
if (errorCall.stack) {
|
|
1192
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1193
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
1194
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1195
|
-
if (!endStackDef.includes(`(`)) {
|
|
1196
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1343
|
+
if (cache !== false) {
|
|
1344
|
+
return cache
|
|
1197
1345
|
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1346
|
+
if (errorCall.stack) {
|
|
1347
|
+
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1348
|
+
const stackCall = errorCall.stack.trim().split("\n")
|
|
1349
|
+
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1350
|
+
if (!endStackDef.includes(`(`)) {
|
|
1351
|
+
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1352
|
+
}
|
|
1353
|
+
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
1354
|
+
if (!endStackCall.includes(`(`)) {
|
|
1355
|
+
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
1356
|
+
}
|
|
1357
|
+
cache = `${endStackDef}\n${endStackCall}`
|
|
1358
|
+
return cache
|
|
1201
1359
|
}
|
|
1202
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
1203
|
-
return cache
|
|
1204
1360
|
}
|
|
1205
|
-
}
|
|
1206
1361
|
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1362
|
+
const command = Effect.withSpan(
|
|
1363
|
+
exec(...args).pipe(Effect.flatten),
|
|
1364
|
+
id,
|
|
1365
|
+
{ captureStackTrace }
|
|
1366
|
+
)
|
|
1212
1367
|
|
|
1213
|
-
|
|
1214
|
-
|
|
1368
|
+
return command
|
|
1369
|
+
}, { action })
|
|
1215
1370
|
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1371
|
+
return reactive({
|
|
1372
|
+
id,
|
|
1373
|
+
namespaced: initialContext.namespaced,
|
|
1374
|
+
namespace: initialContext.namespace,
|
|
1375
|
+
result,
|
|
1376
|
+
waiting,
|
|
1377
|
+
action,
|
|
1378
|
+
handle,
|
|
1379
|
+
handleEffect,
|
|
1380
|
+
compose,
|
|
1381
|
+
compose2,
|
|
1382
|
+
exec
|
|
1383
|
+
})
|
|
1384
|
+
},
|
|
1385
|
+
{ id }
|
|
1386
|
+
)
|
|
1230
1387
|
}
|
|
1231
1388
|
}
|
|
1232
1389
|
|
|
@@ -1303,10 +1460,12 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1303
1460
|
*/
|
|
1304
1461
|
fn: <RT>(runtime: Runtime.Runtime<RT>) => {
|
|
1305
1462
|
const make = makeCommand(runtime)
|
|
1306
|
-
return <const Id extends string, const I18nKey extends string = Id>(
|
|
1463
|
+
return <const Id extends string, State extends IntlRecord = IntlRecord, const I18nKey extends string = Id>(
|
|
1307
1464
|
id: Id | { id: Id },
|
|
1308
|
-
options?: FnOptions<I18nKey>
|
|
1309
|
-
): Commander.Gen<RT, Id, I18nKey> & Commander.NonGen<RT, Id, I18nKey>
|
|
1465
|
+
options?: FnOptions<I18nKey, State>
|
|
1466
|
+
): Commander.Gen<RT, Id, I18nKey> & Commander.NonGen<RT, Id, I18nKey> & {
|
|
1467
|
+
state: Context.Tag<`Commander.Command.${Id}.state`, State>
|
|
1468
|
+
} =>
|
|
1310
1469
|
Object.assign(
|
|
1311
1470
|
(
|
|
1312
1471
|
fn: any,
|
|
@@ -1328,16 +1487,21 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1328
1487
|
) as any
|
|
1329
1488
|
)
|
|
1330
1489
|
},
|
|
1331
|
-
makeContext(typeof id === "string" ? id : id.id, { ...options,
|
|
1490
|
+
makeContext(typeof id === "string" ? id : id.id, { ...options, state: getStateValues(options)?.value }),
|
|
1491
|
+
{
|
|
1492
|
+
state: Context.GenericTag<`Commander.Command.${Id}.state`, State>(
|
|
1493
|
+
`Commander.Command.${typeof id === "string" ? id : id.id}.state`
|
|
1494
|
+
)
|
|
1495
|
+
}
|
|
1332
1496
|
)
|
|
1333
1497
|
},
|
|
1334
1498
|
|
|
1335
1499
|
alt2: ((rt: any) => {
|
|
1336
1500
|
const cmd = makeCommand(rt)
|
|
1337
|
-
return (_id: any, options?: FnOptions<string>) => {
|
|
1501
|
+
return (_id: any, options?: FnOptions<string, IntlRecord>) => {
|
|
1338
1502
|
const isObject = typeof _id === "object" || typeof _id === "function"
|
|
1339
1503
|
const id = isObject ? _id.id : _id
|
|
1340
|
-
const context = makeContext(id, { ...options,
|
|
1504
|
+
const context = makeContext(id, { ...options, state: getStateValues(options)?.value })
|
|
1341
1505
|
const idCmd = cmd(id, options)
|
|
1342
1506
|
// TODO: implement proper tracing stack
|
|
1343
1507
|
return Object.assign((cb: any) =>
|
|
@@ -1375,7 +1539,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1375
1539
|
customI18nKey?: I18nKey
|
|
1376
1540
|
) =>
|
|
1377
1541
|
& Commander.CommandContextLocal<Id, I18nKey>
|
|
1378
|
-
& (<Args extends Array<unknown>, A, E, R extends RT | CommandContext
|
|
1542
|
+
& (<Args extends Array<unknown>, A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>(
|
|
1379
1543
|
handler: (
|
|
1380
1544
|
ctx: Effect.fn.Gen & Effect.fn.NonGen & Commander.CommandContextLocal<Id, I18nKey> & {
|
|
1381
1545
|
// todo: only if we passed in one
|
|
@@ -1392,18 +1556,26 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1392
1556
|
customI18nKey?: I18nKey
|
|
1393
1557
|
) =>
|
|
1394
1558
|
& Commander.CommandContextLocal<Id, I18nKey>
|
|
1395
|
-
& (<Args extends Array<unknown>, A, E, R extends RT | CommandContext
|
|
1559
|
+
& (<Args extends Array<unknown>, A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>(
|
|
1396
1560
|
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
1397
1561
|
) => Commander.CommandOut<Args, A, E, R, Id, I18nKey>),
|
|
1398
1562
|
|
|
1399
1563
|
/** @experimental */
|
|
1400
1564
|
wrap: <RT>(runtime: Runtime.Runtime<RT>) => {
|
|
1401
1565
|
const make = makeCommand(runtime)
|
|
1402
|
-
return <
|
|
1566
|
+
return <
|
|
1567
|
+
const Id extends string,
|
|
1568
|
+
Args extends Array<unknown>,
|
|
1569
|
+
A,
|
|
1570
|
+
E,
|
|
1571
|
+
R,
|
|
1572
|
+
State extends IntlRecord = IntlRecord,
|
|
1573
|
+
I18nKey extends string = Id
|
|
1574
|
+
>(
|
|
1403
1575
|
mutation:
|
|
1404
1576
|
| { mutate: (...args: Args) => Effect.Effect<A, E, R>; id: Id }
|
|
1405
1577
|
| ((...args: Args) => Effect.Effect<A, E, R>) & { id: Id },
|
|
1406
|
-
options?: FnOptions<I18nKey>
|
|
1578
|
+
options?: FnOptions<I18nKey, State>
|
|
1407
1579
|
):
|
|
1408
1580
|
& Commander.CommandContextLocal<Id, I18nKey>
|
|
1409
1581
|
& Commander.GenWrap<RT, Id, I18nKey, Args, A, E, R>
|
|
@@ -1428,7 +1600,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1428
1600
|
...combinators as [any]
|
|
1429
1601
|
) as any
|
|
1430
1602
|
)
|
|
1431
|
-
}, makeContext(mutation.id, { ...options,
|
|
1603
|
+
}, makeContext(mutation.id, { ...options, state: getStateValues(options)?.value }))
|
|
1432
1604
|
}
|
|
1433
1605
|
}
|
|
1434
1606
|
})
|