@effect-app/vue 2.75.1 → 2.75.3
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 +55 -52
- package/dist/experimental/commander.d.ts.map +1 -1
- package/dist/experimental/commander.js +9 -5
- package/dist/experimental/makeUseCommand.d.ts +22 -24
- package/dist/experimental/makeUseCommand.d.ts.map +1 -1
- package/dist/makeClient.d.ts +50 -64
- package/dist/makeClient.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/experimental/commander.ts +429 -261
- package/test/dist/stubs.d.ts +22 -24
- 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,9 +16,10 @@ 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
|
-
|
|
21
|
+
/** passed to the i18n formatMessage calls so you can use it in translation messages */
|
|
22
|
+
i18nValues?: ComputedRef<State> | (() => State)
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
type FnOptionsInternal<I18nCustomKey extends string> = {
|
|
@@ -131,7 +132,11 @@ export declare namespace Commander {
|
|
|
131
132
|
>
|
|
132
133
|
|
|
133
134
|
export type Gen<RT, Id extends string, I18nKey extends string> = {
|
|
134
|
-
<
|
|
135
|
+
<
|
|
136
|
+
Eff extends YieldWrap<Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>,
|
|
137
|
+
AEff,
|
|
138
|
+
Args extends Array<unknown>
|
|
139
|
+
>(
|
|
135
140
|
body: (...args: Args) => Generator<Eff, AEff, never>
|
|
136
141
|
): CommandOut<
|
|
137
142
|
Args,
|
|
@@ -149,7 +154,7 @@ export declare namespace Commander {
|
|
|
149
154
|
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
|
|
150
155
|
AEff,
|
|
151
156
|
Args extends Array<unknown>,
|
|
152
|
-
A extends Effect.Effect<any, any, RT | CommandContext
|
|
157
|
+
A extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
153
158
|
>(
|
|
154
159
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
155
160
|
a: (
|
|
@@ -170,7 +175,7 @@ export declare namespace Commander {
|
|
|
170
175
|
AEff,
|
|
171
176
|
Args extends Array<unknown>,
|
|
172
177
|
A,
|
|
173
|
-
B extends Effect.Effect<any, any, RT | CommandContext
|
|
178
|
+
B extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
174
179
|
>(
|
|
175
180
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
176
181
|
a: (
|
|
@@ -193,7 +198,7 @@ export declare namespace Commander {
|
|
|
193
198
|
Args extends Array<unknown>,
|
|
194
199
|
A,
|
|
195
200
|
B,
|
|
196
|
-
C extends Effect.Effect<any, any, RT | CommandContext
|
|
201
|
+
C extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
197
202
|
>(
|
|
198
203
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
199
204
|
a: (
|
|
@@ -218,7 +223,7 @@ export declare namespace Commander {
|
|
|
218
223
|
A,
|
|
219
224
|
B,
|
|
220
225
|
C,
|
|
221
|
-
D extends Effect.Effect<any, any, RT | CommandContext
|
|
226
|
+
D extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
222
227
|
>(
|
|
223
228
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
224
229
|
a: (
|
|
@@ -245,7 +250,7 @@ export declare namespace Commander {
|
|
|
245
250
|
B,
|
|
246
251
|
C,
|
|
247
252
|
D,
|
|
248
|
-
E extends Effect.Effect<any, any, RT | CommandContext
|
|
253
|
+
E extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
249
254
|
>(
|
|
250
255
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
251
256
|
a: (
|
|
@@ -274,7 +279,7 @@ export declare namespace Commander {
|
|
|
274
279
|
C,
|
|
275
280
|
D,
|
|
276
281
|
E,
|
|
277
|
-
F extends Effect.Effect<any, any, RT | CommandContext
|
|
282
|
+
F extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
278
283
|
>(
|
|
279
284
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
280
285
|
a: (
|
|
@@ -305,7 +310,7 @@ export declare namespace Commander {
|
|
|
305
310
|
D,
|
|
306
311
|
E,
|
|
307
312
|
F,
|
|
308
|
-
G extends Effect.Effect<any, any, RT | CommandContext
|
|
313
|
+
G extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
309
314
|
>(
|
|
310
315
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
311
316
|
a: (
|
|
@@ -338,7 +343,7 @@ export declare namespace Commander {
|
|
|
338
343
|
E,
|
|
339
344
|
F,
|
|
340
345
|
G,
|
|
341
|
-
H extends Effect.Effect<any, any, RT | CommandContext
|
|
346
|
+
H extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
342
347
|
>(
|
|
343
348
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
344
349
|
a: (
|
|
@@ -373,7 +378,7 @@ export declare namespace Commander {
|
|
|
373
378
|
F,
|
|
374
379
|
G,
|
|
375
380
|
H,
|
|
376
|
-
I extends Effect.Effect<any, any, RT | CommandContext
|
|
381
|
+
I extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
377
382
|
>(
|
|
378
383
|
body: (...args: Args) => Generator<Eff, AEff, never>,
|
|
379
384
|
a: (
|
|
@@ -400,32 +405,65 @@ export declare namespace Commander {
|
|
|
400
405
|
}
|
|
401
406
|
|
|
402
407
|
export type NonGen<RT, Id extends string, I18nKey extends string> = {
|
|
403
|
-
<
|
|
408
|
+
<
|
|
409
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
410
|
+
Args extends Array<unknown>
|
|
411
|
+
>(
|
|
404
412
|
body: (...args: Args) => Eff
|
|
405
413
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
406
|
-
<
|
|
414
|
+
<
|
|
415
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
416
|
+
A,
|
|
417
|
+
Args extends Array<unknown>
|
|
418
|
+
>(
|
|
407
419
|
body: (...args: Args) => A,
|
|
408
420
|
a: (_: A, ...args: NoInfer<Args>) => Eff
|
|
409
421
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
410
|
-
<
|
|
422
|
+
<
|
|
423
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
424
|
+
A,
|
|
425
|
+
B,
|
|
426
|
+
Args extends Array<unknown>
|
|
427
|
+
>(
|
|
411
428
|
body: (...args: Args) => A,
|
|
412
429
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
413
430
|
b: (_: B, ...args: NoInfer<Args>) => Eff
|
|
414
431
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
415
|
-
<
|
|
432
|
+
<
|
|
433
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
434
|
+
A,
|
|
435
|
+
B,
|
|
436
|
+
C,
|
|
437
|
+
Args extends Array<unknown>
|
|
438
|
+
>(
|
|
416
439
|
body: (...args: Args) => A,
|
|
417
440
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
418
441
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
419
442
|
c: (_: C, ...args: NoInfer<Args>) => Eff
|
|
420
443
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
421
|
-
<
|
|
444
|
+
<
|
|
445
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
446
|
+
A,
|
|
447
|
+
B,
|
|
448
|
+
C,
|
|
449
|
+
D,
|
|
450
|
+
Args extends Array<unknown>
|
|
451
|
+
>(
|
|
422
452
|
body: (...args: Args) => A,
|
|
423
453
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
424
454
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
425
455
|
c: (_: C, ...args: NoInfer<Args>) => D,
|
|
426
456
|
d: (_: D, ...args: NoInfer<Args>) => Eff
|
|
427
457
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
428
|
-
<
|
|
458
|
+
<
|
|
459
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
460
|
+
A,
|
|
461
|
+
B,
|
|
462
|
+
C,
|
|
463
|
+
D,
|
|
464
|
+
E,
|
|
465
|
+
Args extends Array<unknown>
|
|
466
|
+
>(
|
|
429
467
|
body: (...args: Args) => A,
|
|
430
468
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
431
469
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -433,7 +471,16 @@ export declare namespace Commander {
|
|
|
433
471
|
d: (_: D, ...args: NoInfer<Args>) => E,
|
|
434
472
|
e: (_: E, ...args: NoInfer<Args>) => Eff
|
|
435
473
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
436
|
-
<
|
|
474
|
+
<
|
|
475
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
476
|
+
A,
|
|
477
|
+
B,
|
|
478
|
+
C,
|
|
479
|
+
D,
|
|
480
|
+
E,
|
|
481
|
+
F,
|
|
482
|
+
Args extends Array<unknown>
|
|
483
|
+
>(
|
|
437
484
|
body: (...args: Args) => A,
|
|
438
485
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
439
486
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -442,7 +489,17 @@ export declare namespace Commander {
|
|
|
442
489
|
e: (_: E, ...args: NoInfer<Args>) => F,
|
|
443
490
|
f: (_: F, ...args: NoInfer<Args>) => Eff
|
|
444
491
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
445
|
-
<
|
|
492
|
+
<
|
|
493
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
494
|
+
A,
|
|
495
|
+
B,
|
|
496
|
+
C,
|
|
497
|
+
D,
|
|
498
|
+
E,
|
|
499
|
+
F,
|
|
500
|
+
G,
|
|
501
|
+
Args extends Array<unknown>
|
|
502
|
+
>(
|
|
446
503
|
body: (...args: Args) => A,
|
|
447
504
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
448
505
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -452,7 +509,18 @@ export declare namespace Commander {
|
|
|
452
509
|
f: (_: F, ...args: NoInfer<Args>) => G,
|
|
453
510
|
g: (_: G, ...args: NoInfer<Args>) => Eff
|
|
454
511
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
455
|
-
<
|
|
512
|
+
<
|
|
513
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
514
|
+
A,
|
|
515
|
+
B,
|
|
516
|
+
C,
|
|
517
|
+
D,
|
|
518
|
+
E,
|
|
519
|
+
F,
|
|
520
|
+
G,
|
|
521
|
+
H,
|
|
522
|
+
Args extends Array<unknown>
|
|
523
|
+
>(
|
|
456
524
|
body: (...args: Args) => A,
|
|
457
525
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
458
526
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -463,7 +531,19 @@ export declare namespace Commander {
|
|
|
463
531
|
g: (_: G, ...args: NoInfer<Args>) => H,
|
|
464
532
|
h: (_: H, ...args: NoInfer<Args>) => Eff
|
|
465
533
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
466
|
-
<
|
|
534
|
+
<
|
|
535
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
536
|
+
A,
|
|
537
|
+
B,
|
|
538
|
+
C,
|
|
539
|
+
D,
|
|
540
|
+
E,
|
|
541
|
+
F,
|
|
542
|
+
G,
|
|
543
|
+
H,
|
|
544
|
+
I,
|
|
545
|
+
Args extends Array<unknown>
|
|
546
|
+
>(
|
|
467
547
|
body: (...args: Args) => A,
|
|
468
548
|
a: (_: A, ...args: NoInfer<Args>) => B,
|
|
469
549
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
@@ -482,12 +562,12 @@ export declare namespace Commander {
|
|
|
482
562
|
Args,
|
|
483
563
|
AEff,
|
|
484
564
|
EEff,
|
|
485
|
-
REff, // TODO: only allowed to be RT | CommandContext
|
|
565
|
+
REff, // TODO: only allowed to be RT | CommandContext | `Commander.Command.${Id}.state`
|
|
486
566
|
Id,
|
|
487
567
|
I18nKey
|
|
488
568
|
>
|
|
489
569
|
<
|
|
490
|
-
A extends Effect.Effect<any, any, RT | CommandContext
|
|
570
|
+
A extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
491
571
|
>(
|
|
492
572
|
a: (
|
|
493
573
|
_: Effect.Effect<
|
|
@@ -500,7 +580,7 @@ export declare namespace Commander {
|
|
|
500
580
|
): CommandOutHelper<Args, A, Id, I18nKey>
|
|
501
581
|
<
|
|
502
582
|
A,
|
|
503
|
-
B extends Effect.Effect<any, any, RT | CommandContext
|
|
583
|
+
B extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
504
584
|
>(
|
|
505
585
|
a: (
|
|
506
586
|
_: Effect.Effect<
|
|
@@ -515,7 +595,7 @@ export declare namespace Commander {
|
|
|
515
595
|
<
|
|
516
596
|
A,
|
|
517
597
|
B,
|
|
518
|
-
C extends Effect.Effect<any, any, RT | CommandContext
|
|
598
|
+
C extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
519
599
|
>(
|
|
520
600
|
a: (
|
|
521
601
|
_: Effect.Effect<
|
|
@@ -532,7 +612,7 @@ export declare namespace Commander {
|
|
|
532
612
|
A,
|
|
533
613
|
B,
|
|
534
614
|
C,
|
|
535
|
-
D extends Effect.Effect<any, any, RT | CommandContext
|
|
615
|
+
D extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
536
616
|
>(
|
|
537
617
|
a: (
|
|
538
618
|
_: Effect.Effect<
|
|
@@ -551,7 +631,7 @@ export declare namespace Commander {
|
|
|
551
631
|
B,
|
|
552
632
|
C,
|
|
553
633
|
D,
|
|
554
|
-
E extends Effect.Effect<any, any, RT | CommandContext
|
|
634
|
+
E extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
555
635
|
>(
|
|
556
636
|
a: (
|
|
557
637
|
_: Effect.Effect<
|
|
@@ -572,7 +652,7 @@ export declare namespace Commander {
|
|
|
572
652
|
C,
|
|
573
653
|
D,
|
|
574
654
|
E,
|
|
575
|
-
F extends Effect.Effect<any, any, RT | CommandContext
|
|
655
|
+
F extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
576
656
|
>(
|
|
577
657
|
a: (
|
|
578
658
|
_: Effect.Effect<
|
|
@@ -595,7 +675,7 @@ export declare namespace Commander {
|
|
|
595
675
|
D,
|
|
596
676
|
E,
|
|
597
677
|
F,
|
|
598
|
-
G extends Effect.Effect<any, any, RT | CommandContext
|
|
678
|
+
G extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>
|
|
599
679
|
>(
|
|
600
680
|
a: (
|
|
601
681
|
_: Effect.Effect<
|
|
@@ -612,7 +692,7 @@ export declare namespace Commander {
|
|
|
612
692
|
f: (_: E, ...args: NoInfer<Args>) => F,
|
|
613
693
|
g: (_: F, ...args: NoInfer<Args>) => G
|
|
614
694
|
): CommandOutHelper<Args, G, Id, I18nKey>
|
|
615
|
-
<A, B, C, D, E, F, G, H extends Effect.Effect<any, any, RT | CommandContext
|
|
695
|
+
<A, B, C, D, E, F, G, H extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(
|
|
616
696
|
a: (
|
|
617
697
|
_: Effect.Effect<
|
|
618
698
|
AEff,
|
|
@@ -629,7 +709,7 @@ export declare namespace Commander {
|
|
|
629
709
|
g: (_: F, ...args: NoInfer<Args>) => G,
|
|
630
710
|
h: (_: G, ...args: NoInfer<Args>) => H
|
|
631
711
|
): CommandOutHelper<Args, H, Id, I18nKey>
|
|
632
|
-
<A, B, C, D, E, F, G, H, I extends Effect.Effect<any, any, RT | CommandContext
|
|
712
|
+
<A, B, C, D, E, F, G, H, I extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(
|
|
633
713
|
a: (
|
|
634
714
|
_: Effect.Effect<
|
|
635
715
|
AEff,
|
|
@@ -652,7 +732,10 @@ export declare namespace Commander {
|
|
|
652
732
|
export type NonGenWrap<RT, Id extends string, I18nKey extends string, Args extends Array<unknown>, AEff, EEff, REff> =
|
|
653
733
|
{
|
|
654
734
|
(): CommandOutHelper<Args, Effect.Effect<AEff, EEff, REff>, Id, I18nKey>
|
|
655
|
-
<
|
|
735
|
+
<
|
|
736
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
737
|
+
Args extends Array<unknown>
|
|
738
|
+
>(
|
|
656
739
|
a: (
|
|
657
740
|
_: Effect.Effect<
|
|
658
741
|
AEff,
|
|
@@ -662,7 +745,11 @@ export declare namespace Commander {
|
|
|
662
745
|
...args: NoInfer<Args>
|
|
663
746
|
) => Eff
|
|
664
747
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
665
|
-
<
|
|
748
|
+
<
|
|
749
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
750
|
+
B,
|
|
751
|
+
Args extends Array<unknown>
|
|
752
|
+
>(
|
|
666
753
|
a: (
|
|
667
754
|
_: Effect.Effect<
|
|
668
755
|
AEff,
|
|
@@ -673,7 +760,12 @@ export declare namespace Commander {
|
|
|
673
760
|
) => B,
|
|
674
761
|
b: (_: B, ...args: NoInfer<Args>) => Eff
|
|
675
762
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
676
|
-
<
|
|
763
|
+
<
|
|
764
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
765
|
+
B,
|
|
766
|
+
C,
|
|
767
|
+
Args extends Array<unknown>
|
|
768
|
+
>(
|
|
677
769
|
a: (
|
|
678
770
|
_: Effect.Effect<
|
|
679
771
|
AEff,
|
|
@@ -685,7 +777,13 @@ export declare namespace Commander {
|
|
|
685
777
|
b: (_: B, ...args: NoInfer<Args>) => C,
|
|
686
778
|
c: (_: C, ...args: NoInfer<Args>) => Eff
|
|
687
779
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
688
|
-
<
|
|
780
|
+
<
|
|
781
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
782
|
+
B,
|
|
783
|
+
C,
|
|
784
|
+
D,
|
|
785
|
+
Args extends Array<unknown>
|
|
786
|
+
>(
|
|
689
787
|
a: (
|
|
690
788
|
_: Effect.Effect<
|
|
691
789
|
AEff,
|
|
@@ -698,7 +796,14 @@ export declare namespace Commander {
|
|
|
698
796
|
c: (_: C, ...args: NoInfer<Args>) => D,
|
|
699
797
|
d: (_: D, ...args: NoInfer<Args>) => Eff
|
|
700
798
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
701
|
-
<
|
|
799
|
+
<
|
|
800
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
801
|
+
B,
|
|
802
|
+
C,
|
|
803
|
+
D,
|
|
804
|
+
E,
|
|
805
|
+
Args extends Array<unknown>
|
|
806
|
+
>(
|
|
702
807
|
a: (
|
|
703
808
|
_: Effect.Effect<
|
|
704
809
|
AEff,
|
|
@@ -712,7 +817,15 @@ export declare namespace Commander {
|
|
|
712
817
|
d: (_: D, ...args: NoInfer<Args>) => E,
|
|
713
818
|
e: (_: E, ...args: NoInfer<Args>) => Eff
|
|
714
819
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
715
|
-
<
|
|
820
|
+
<
|
|
821
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
822
|
+
B,
|
|
823
|
+
C,
|
|
824
|
+
D,
|
|
825
|
+
E,
|
|
826
|
+
F,
|
|
827
|
+
Args extends Array<unknown>
|
|
828
|
+
>(
|
|
716
829
|
a: (
|
|
717
830
|
_: Effect.Effect<
|
|
718
831
|
AEff,
|
|
@@ -727,7 +840,16 @@ export declare namespace Commander {
|
|
|
727
840
|
e: (_: E, ...args: NoInfer<Args>) => F,
|
|
728
841
|
f: (_: F, ...args: NoInfer<Args>) => Eff
|
|
729
842
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
730
|
-
<
|
|
843
|
+
<
|
|
844
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
845
|
+
B,
|
|
846
|
+
C,
|
|
847
|
+
D,
|
|
848
|
+
E,
|
|
849
|
+
F,
|
|
850
|
+
G,
|
|
851
|
+
Args extends Array<unknown>
|
|
852
|
+
>(
|
|
731
853
|
a: (
|
|
732
854
|
_: Effect.Effect<
|
|
733
855
|
AEff,
|
|
@@ -743,7 +865,17 @@ export declare namespace Commander {
|
|
|
743
865
|
f: (_: F, ...args: NoInfer<Args>) => G,
|
|
744
866
|
g: (_: G, ...args: NoInfer<Args>) => Eff
|
|
745
867
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
746
|
-
<
|
|
868
|
+
<
|
|
869
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
870
|
+
B,
|
|
871
|
+
C,
|
|
872
|
+
D,
|
|
873
|
+
E,
|
|
874
|
+
F,
|
|
875
|
+
G,
|
|
876
|
+
H,
|
|
877
|
+
Args extends Array<unknown>
|
|
878
|
+
>(
|
|
747
879
|
a: (
|
|
748
880
|
_: Effect.Effect<
|
|
749
881
|
AEff,
|
|
@@ -760,7 +892,18 @@ export declare namespace Commander {
|
|
|
760
892
|
g: (_: G, ...args: NoInfer<Args>) => H,
|
|
761
893
|
h: (_: H, ...args: NoInfer<Args>) => Eff
|
|
762
894
|
): CommandOutHelper<Args, Eff, Id, I18nKey>
|
|
763
|
-
<
|
|
895
|
+
<
|
|
896
|
+
Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
|
|
897
|
+
B,
|
|
898
|
+
C,
|
|
899
|
+
D,
|
|
900
|
+
E,
|
|
901
|
+
F,
|
|
902
|
+
G,
|
|
903
|
+
H,
|
|
904
|
+
I,
|
|
905
|
+
Args extends Array<unknown>
|
|
906
|
+
>(
|
|
764
907
|
a: (
|
|
765
908
|
_: Effect.Effect<
|
|
766
909
|
AEff,
|
|
@@ -963,7 +1106,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
963
1106
|
return context
|
|
964
1107
|
}
|
|
965
1108
|
|
|
966
|
-
const getI18nValues = <const I18nKey extends string>(options?: FnOptions<I18nKey>) => {
|
|
1109
|
+
const getI18nValues = <const I18nKey extends string>(options?: FnOptions<I18nKey, any>) => {
|
|
967
1110
|
const i18nValues = !options?.i18nValues ? undefined : typeof options.i18nValues === "function"
|
|
968
1111
|
? computed(options.i18nValues)
|
|
969
1112
|
: options.i18nValues
|
|
@@ -972,260 +1115,270 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
972
1115
|
|
|
973
1116
|
const makeCommand = <RT>(runtime: Runtime.Runtime<RT>) => {
|
|
974
1117
|
const runFork = Runtime.runFork(runtime)
|
|
975
|
-
return <const Id extends string, const I18nKey extends string = Id>(
|
|
1118
|
+
return <const Id extends string, State extends IntlRecord, const I18nKey extends string = Id>(
|
|
976
1119
|
id_: Id | { id: Id },
|
|
977
|
-
options?: FnOptions<I18nKey>,
|
|
1120
|
+
options?: FnOptions<I18nKey, State>,
|
|
978
1121
|
errorDef?: Error
|
|
979
1122
|
) => {
|
|
980
1123
|
const id = typeof id_ === "string" ? id_ : id_.id
|
|
981
1124
|
const i18nValues = getI18nValues(options)
|
|
982
1125
|
|
|
983
|
-
return Object.assign(
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
errorDef
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
const makeContext_ = () => makeContext(id, { ...options, i18nValues: i18nValues?.value })
|
|
996
|
-
const initialContext = makeContext_()
|
|
997
|
-
const action = computed(() => makeContext_().action)
|
|
998
|
-
|
|
999
|
-
const errorReporter = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
1000
|
-
self.pipe(
|
|
1001
|
-
Effect.tapErrorCause(
|
|
1002
|
-
Effect.fnUntraced(function*(cause) {
|
|
1003
|
-
if (Cause.isInterruptedOnly(cause)) {
|
|
1004
|
-
console.info(`Interrupted while trying to ${id}`)
|
|
1005
|
-
return
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
const fail = Cause.failureOption(cause)
|
|
1009
|
-
if (Option.isSome(fail)) {
|
|
1010
|
-
// if (fail.value._tag === "SuppressErrors") {
|
|
1011
|
-
// console.info(
|
|
1012
|
-
// `Suppressed error trying to ${action}`,
|
|
1013
|
-
// fail.value,
|
|
1014
|
-
// )
|
|
1015
|
-
// return
|
|
1016
|
-
// }
|
|
1017
|
-
const message = `Failure trying to ${id}`
|
|
1018
|
-
yield* reportMessage(message, {
|
|
1019
|
-
action: id,
|
|
1020
|
-
error: fail.value
|
|
1021
|
-
})
|
|
1022
|
-
return
|
|
1023
|
-
}
|
|
1126
|
+
return Object.assign(
|
|
1127
|
+
<Args extends ReadonlyArray<unknown>, A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>(
|
|
1128
|
+
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
1129
|
+
) => {
|
|
1130
|
+
// we capture the definition stack here, so we can append it to later stack traces
|
|
1131
|
+
const limit = Error.stackTraceLimit
|
|
1132
|
+
Error.stackTraceLimit = 2
|
|
1133
|
+
const localErrorDef = new Error()
|
|
1134
|
+
Error.stackTraceLimit = limit
|
|
1135
|
+
if (!errorDef) {
|
|
1136
|
+
errorDef = localErrorDef
|
|
1137
|
+
}
|
|
1024
1138
|
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1139
|
+
const key = `Commander.Command.${id}.state` as const
|
|
1140
|
+
const state = Context.GenericTag<typeof key, State>(key)
|
|
1141
|
+
|
|
1142
|
+
const makeContext_ = () => makeContext(id, { ...options, i18nValues: i18nValues?.value })
|
|
1143
|
+
const initialContext = makeContext_()
|
|
1144
|
+
const action = computed(() => makeContext_().action)
|
|
1145
|
+
|
|
1146
|
+
const errorReporter = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
1147
|
+
self.pipe(
|
|
1148
|
+
Effect.tapErrorCause(
|
|
1149
|
+
Effect.fnUntraced(function*(cause) {
|
|
1150
|
+
if (Cause.isInterruptedOnly(cause)) {
|
|
1151
|
+
console.info(`Interrupted while trying to ${id}`)
|
|
1152
|
+
return
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
const fail = Cause.failureOption(cause)
|
|
1156
|
+
if (Option.isSome(fail)) {
|
|
1157
|
+
// if (fail.value._tag === "SuppressErrors") {
|
|
1158
|
+
// console.info(
|
|
1159
|
+
// `Suppressed error trying to ${action}`,
|
|
1160
|
+
// fail.value,
|
|
1161
|
+
// )
|
|
1162
|
+
// return
|
|
1163
|
+
// }
|
|
1164
|
+
const message = `Failure trying to ${id}`
|
|
1165
|
+
yield* reportMessage(message, {
|
|
1166
|
+
action: id,
|
|
1167
|
+
error: fail.value
|
|
1168
|
+
})
|
|
1169
|
+
return
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
const context = yield* CommandContext
|
|
1173
|
+
const extra = {
|
|
1174
|
+
action: context.action,
|
|
1175
|
+
message: `Unexpected Error trying to ${id}`
|
|
1176
|
+
}
|
|
1177
|
+
yield* reportRuntimeError(cause, extra)
|
|
1178
|
+
}, Effect.uninterruptible)
|
|
1179
|
+
)
|
|
1032
1180
|
)
|
|
1033
|
-
)
|
|
1034
1181
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1182
|
+
const theHandler = flow(
|
|
1183
|
+
handler,
|
|
1184
|
+
errorReporter,
|
|
1185
|
+
// all must be within the Effect.fn to fit within the Span
|
|
1186
|
+
Effect.provideServiceEffect(
|
|
1187
|
+
CommandContext,
|
|
1188
|
+
Effect.sync(() => makeContext_())
|
|
1189
|
+
),
|
|
1190
|
+
Effect.provideServiceEffect(
|
|
1191
|
+
state,
|
|
1192
|
+
Effect.sync(() => i18nValues?.value)
|
|
1193
|
+
), // todo; service make errors?
|
|
1194
|
+
(_) => Effect.annotateCurrentSpan({ action }).pipe(Effect.zipRight(_))
|
|
1195
|
+
)
|
|
1045
1196
|
|
|
1046
|
-
|
|
1197
|
+
const [result, exec] = asResult(theHandler)
|
|
1047
1198
|
|
|
1048
|
-
|
|
1199
|
+
const waiting = computed(() => result.value.waiting)
|
|
1049
1200
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1201
|
+
const handle = Object.assign((...args: Args) => {
|
|
1202
|
+
// we capture the call site stack here
|
|
1203
|
+
const limit = Error.stackTraceLimit
|
|
1204
|
+
Error.stackTraceLimit = 2
|
|
1205
|
+
const errorCall = new Error()
|
|
1206
|
+
Error.stackTraceLimit = limit
|
|
1056
1207
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1208
|
+
let cache: false | string = false
|
|
1209
|
+
const captureStackTrace = () => {
|
|
1210
|
+
// in case of an error, we want to append the definition stack to the call site stack,
|
|
1211
|
+
// so we can see where the handler was defined too
|
|
1061
1212
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
}
|
|
1065
|
-
if (errorCall.stack) {
|
|
1066
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1067
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
1068
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1069
|
-
if (!endStackDef.includes(`(`)) {
|
|
1070
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1213
|
+
if (cache !== false) {
|
|
1214
|
+
return cache
|
|
1071
1215
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1216
|
+
if (errorCall.stack) {
|
|
1217
|
+
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1218
|
+
const stackCall = errorCall.stack.trim().split("\n")
|
|
1219
|
+
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1220
|
+
if (!endStackDef.includes(`(`)) {
|
|
1221
|
+
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1222
|
+
}
|
|
1223
|
+
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
1224
|
+
if (!endStackCall.includes(`(`)) {
|
|
1225
|
+
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
1226
|
+
}
|
|
1227
|
+
cache = `${endStackDef}\n${endStackCall}`
|
|
1228
|
+
return cache
|
|
1075
1229
|
}
|
|
1076
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
1077
|
-
return cache
|
|
1078
1230
|
}
|
|
1079
|
-
}
|
|
1080
1231
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1232
|
+
const command = Effect.withSpan(
|
|
1233
|
+
exec(...args),
|
|
1234
|
+
id,
|
|
1235
|
+
{ captureStackTrace }
|
|
1236
|
+
)
|
|
1086
1237
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1238
|
+
return runFork(command)
|
|
1239
|
+
}, { action })
|
|
1089
1240
|
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1241
|
+
const handleEffect = Object.assign((...args: Args) => {
|
|
1242
|
+
// we capture the call site stack here
|
|
1243
|
+
const limit = Error.stackTraceLimit
|
|
1244
|
+
Error.stackTraceLimit = 2
|
|
1245
|
+
const errorCall = new Error()
|
|
1246
|
+
Error.stackTraceLimit = limit
|
|
1096
1247
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1248
|
+
let cache: false | string = false
|
|
1249
|
+
const captureStackTrace = () => {
|
|
1250
|
+
// in case of an error, we want to append the definition stack to the call site stack,
|
|
1251
|
+
// so we can see where the handler was defined too
|
|
1101
1252
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
}
|
|
1105
|
-
if (errorCall.stack) {
|
|
1106
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1107
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
1108
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1109
|
-
if (!endStackDef.includes(`(`)) {
|
|
1110
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1253
|
+
if (cache !== false) {
|
|
1254
|
+
return cache
|
|
1111
1255
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1256
|
+
if (errorCall.stack) {
|
|
1257
|
+
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1258
|
+
const stackCall = errorCall.stack.trim().split("\n")
|
|
1259
|
+
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1260
|
+
if (!endStackDef.includes(`(`)) {
|
|
1261
|
+
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1262
|
+
}
|
|
1263
|
+
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
1264
|
+
if (!endStackCall.includes(`(`)) {
|
|
1265
|
+
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
1266
|
+
}
|
|
1267
|
+
cache = `${endStackDef}\n${endStackCall}`
|
|
1268
|
+
return cache
|
|
1115
1269
|
}
|
|
1116
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
1117
|
-
return cache
|
|
1118
1270
|
}
|
|
1119
|
-
}
|
|
1120
1271
|
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1272
|
+
const command = Effect.withSpan(
|
|
1273
|
+
exec(...args),
|
|
1274
|
+
id,
|
|
1275
|
+
{ captureStackTrace }
|
|
1276
|
+
)
|
|
1126
1277
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1278
|
+
return Effect.currentSpan.pipe(
|
|
1279
|
+
Effect.option,
|
|
1280
|
+
Effect.map((span) =>
|
|
1281
|
+
runFork(Option.isSome(span) ? command.pipe(Effect.withParentSpan(span.value)) : command)
|
|
1282
|
+
)
|
|
1131
1283
|
)
|
|
1132
|
-
)
|
|
1133
|
-
}, { action })
|
|
1284
|
+
}, { action, state })
|
|
1134
1285
|
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1286
|
+
const compose = Object.assign((...args: Args) => {
|
|
1287
|
+
// we capture the call site stack here
|
|
1288
|
+
const limit = Error.stackTraceLimit
|
|
1289
|
+
Error.stackTraceLimit = 2
|
|
1290
|
+
const errorCall = new Error()
|
|
1291
|
+
Error.stackTraceLimit = limit
|
|
1141
1292
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1293
|
+
let cache: false | string = false
|
|
1294
|
+
const captureStackTrace = () => {
|
|
1295
|
+
// in case of an error, we want to append the definition stack to the call site stack,
|
|
1296
|
+
// so we can see where the handler was defined too
|
|
1146
1297
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
}
|
|
1150
|
-
if (errorCall.stack) {
|
|
1151
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1152
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
1153
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1154
|
-
if (!endStackDef.includes(`(`)) {
|
|
1155
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1298
|
+
if (cache !== false) {
|
|
1299
|
+
return cache
|
|
1156
1300
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1301
|
+
if (errorCall.stack) {
|
|
1302
|
+
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1303
|
+
const stackCall = errorCall.stack.trim().split("\n")
|
|
1304
|
+
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1305
|
+
if (!endStackDef.includes(`(`)) {
|
|
1306
|
+
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1307
|
+
}
|
|
1308
|
+
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
1309
|
+
if (!endStackCall.includes(`(`)) {
|
|
1310
|
+
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
1311
|
+
}
|
|
1312
|
+
cache = `${endStackDef}\n${endStackCall}`
|
|
1313
|
+
return cache
|
|
1160
1314
|
}
|
|
1161
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
1162
|
-
return cache
|
|
1163
1315
|
}
|
|
1164
|
-
}
|
|
1165
1316
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1317
|
+
const command = Effect.withSpan(
|
|
1318
|
+
exec(...args),
|
|
1319
|
+
id,
|
|
1320
|
+
{ captureStackTrace }
|
|
1321
|
+
)
|
|
1171
1322
|
|
|
1172
|
-
|
|
1173
|
-
|
|
1323
|
+
return command
|
|
1324
|
+
}, { action })
|
|
1174
1325
|
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1326
|
+
const compose2 = Object.assign((...args: Args) => {
|
|
1327
|
+
// we capture the call site stack here
|
|
1328
|
+
const limit = Error.stackTraceLimit
|
|
1329
|
+
Error.stackTraceLimit = 2
|
|
1330
|
+
const errorCall = new Error()
|
|
1331
|
+
Error.stackTraceLimit = limit
|
|
1181
1332
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1333
|
+
let cache: false | string = false
|
|
1334
|
+
const captureStackTrace = () => {
|
|
1335
|
+
// in case of an error, we want to append the definition stack to the call site stack,
|
|
1336
|
+
// so we can see where the handler was defined too
|
|
1186
1337
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
if (errorCall.stack) {
|
|
1191
|
-
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1192
|
-
const stackCall = errorCall.stack.trim().split("\n")
|
|
1193
|
-
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1194
|
-
if (!endStackDef.includes(`(`)) {
|
|
1195
|
-
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1338
|
+
if (cache !== false) {
|
|
1339
|
+
return cache
|
|
1196
1340
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1341
|
+
if (errorCall.stack) {
|
|
1342
|
+
const stackDef = errorDef!.stack!.trim().split("\n")
|
|
1343
|
+
const stackCall = errorCall.stack.trim().split("\n")
|
|
1344
|
+
let endStackDef = stackDef.slice(2).join("\n").trim()
|
|
1345
|
+
if (!endStackDef.includes(`(`)) {
|
|
1346
|
+
endStackDef = endStackDef.replace(/at (.*)/, "at ($1)")
|
|
1347
|
+
}
|
|
1348
|
+
let endStackCall = stackCall.slice(2).join("\n").trim()
|
|
1349
|
+
if (!endStackCall.includes(`(`)) {
|
|
1350
|
+
endStackCall = endStackCall.replace(/at (.*)/, "at ($1)")
|
|
1351
|
+
}
|
|
1352
|
+
cache = `${endStackDef}\n${endStackCall}`
|
|
1353
|
+
return cache
|
|
1200
1354
|
}
|
|
1201
|
-
cache = `${endStackDef}\n${endStackCall}`
|
|
1202
|
-
return cache
|
|
1203
1355
|
}
|
|
1204
|
-
}
|
|
1205
1356
|
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1357
|
+
const command = Effect.withSpan(
|
|
1358
|
+
exec(...args).pipe(Effect.flatten),
|
|
1359
|
+
id,
|
|
1360
|
+
{ captureStackTrace }
|
|
1361
|
+
)
|
|
1211
1362
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1363
|
+
return command
|
|
1364
|
+
}, { action })
|
|
1214
1365
|
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1366
|
+
return reactive({
|
|
1367
|
+
id,
|
|
1368
|
+
namespaced: initialContext.namespaced,
|
|
1369
|
+
namespace: initialContext.namespace,
|
|
1370
|
+
result,
|
|
1371
|
+
waiting,
|
|
1372
|
+
action,
|
|
1373
|
+
handle,
|
|
1374
|
+
handleEffect,
|
|
1375
|
+
compose,
|
|
1376
|
+
compose2,
|
|
1377
|
+
exec
|
|
1378
|
+
})
|
|
1379
|
+
},
|
|
1380
|
+
{ id }
|
|
1381
|
+
)
|
|
1229
1382
|
}
|
|
1230
1383
|
}
|
|
1231
1384
|
|
|
@@ -1302,10 +1455,12 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1302
1455
|
*/
|
|
1303
1456
|
fn: <RT>(runtime: Runtime.Runtime<RT>) => {
|
|
1304
1457
|
const make = makeCommand(runtime)
|
|
1305
|
-
return <const Id extends string, const I18nKey extends string = Id>(
|
|
1458
|
+
return <const Id extends string, State extends IntlRecord, const I18nKey extends string = Id>(
|
|
1306
1459
|
id: Id | { id: Id },
|
|
1307
|
-
options?: FnOptions<I18nKey>
|
|
1308
|
-
): Commander.Gen<RT, Id, I18nKey> & Commander.NonGen<RT, Id, I18nKey>
|
|
1460
|
+
options?: FnOptions<I18nKey, State>
|
|
1461
|
+
): Commander.Gen<RT, Id, I18nKey> & Commander.NonGen<RT, Id, I18nKey> & {
|
|
1462
|
+
state: Context.Tag<`Commander.Command.${Id}.state`, State>
|
|
1463
|
+
} =>
|
|
1309
1464
|
Object.assign(
|
|
1310
1465
|
(
|
|
1311
1466
|
fn: any,
|
|
@@ -1327,13 +1482,18 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1327
1482
|
) as any
|
|
1328
1483
|
)
|
|
1329
1484
|
},
|
|
1330
|
-
makeContext(typeof id === "string" ? id : id.id, { ...options, i18nValues: getI18nValues(options)?.value })
|
|
1485
|
+
makeContext(typeof id === "string" ? id : id.id, { ...options, i18nValues: getI18nValues(options)?.value }),
|
|
1486
|
+
{
|
|
1487
|
+
state: Context.GenericTag<`Commander.Command.${Id}.state`, State>(
|
|
1488
|
+
`Commander.Command.${typeof id === "string" ? id : id.id}.state`
|
|
1489
|
+
)
|
|
1490
|
+
}
|
|
1331
1491
|
)
|
|
1332
1492
|
},
|
|
1333
1493
|
|
|
1334
1494
|
alt2: ((rt: any) => {
|
|
1335
1495
|
const cmd = makeCommand(rt)
|
|
1336
|
-
return (_id: any, options?: FnOptions<string>) => {
|
|
1496
|
+
return (_id: any, options?: FnOptions<string, IntlRecord>) => {
|
|
1337
1497
|
const isObject = typeof _id === "object" || typeof _id === "function"
|
|
1338
1498
|
const id = isObject ? _id.id : _id
|
|
1339
1499
|
const context = makeContext(id, { ...options, i18nValues: getI18nValues(options)?.value })
|
|
@@ -1374,7 +1534,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1374
1534
|
customI18nKey?: I18nKey
|
|
1375
1535
|
) =>
|
|
1376
1536
|
& Commander.CommandContextLocal<Id, I18nKey>
|
|
1377
|
-
& (<Args extends Array<unknown>, A, E, R extends RT | CommandContext
|
|
1537
|
+
& (<Args extends Array<unknown>, A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>(
|
|
1378
1538
|
handler: (
|
|
1379
1539
|
ctx: Effect.fn.Gen & Effect.fn.NonGen & Commander.CommandContextLocal<Id, I18nKey> & {
|
|
1380
1540
|
// todo: only if we passed in one
|
|
@@ -1391,18 +1551,26 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
|
|
|
1391
1551
|
customI18nKey?: I18nKey
|
|
1392
1552
|
) =>
|
|
1393
1553
|
& Commander.CommandContextLocal<Id, I18nKey>
|
|
1394
|
-
& (<Args extends Array<unknown>, A, E, R extends RT | CommandContext
|
|
1554
|
+
& (<Args extends Array<unknown>, A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>(
|
|
1395
1555
|
handler: (...args: Args) => Effect.Effect<A, E, R>
|
|
1396
1556
|
) => Commander.CommandOut<Args, A, E, R, Id, I18nKey>),
|
|
1397
1557
|
|
|
1398
1558
|
/** @experimental */
|
|
1399
1559
|
wrap: <RT>(runtime: Runtime.Runtime<RT>) => {
|
|
1400
1560
|
const make = makeCommand(runtime)
|
|
1401
|
-
return <
|
|
1561
|
+
return <
|
|
1562
|
+
const Id extends string,
|
|
1563
|
+
Args extends Array<unknown>,
|
|
1564
|
+
A,
|
|
1565
|
+
E,
|
|
1566
|
+
R,
|
|
1567
|
+
State extends IntlRecord,
|
|
1568
|
+
I18nKey extends string = Id
|
|
1569
|
+
>(
|
|
1402
1570
|
mutation:
|
|
1403
1571
|
| { mutate: (...args: Args) => Effect.Effect<A, E, R>; id: Id }
|
|
1404
1572
|
| ((...args: Args) => Effect.Effect<A, E, R>) & { id: Id },
|
|
1405
|
-
options?: FnOptions<I18nKey>
|
|
1573
|
+
options?: FnOptions<I18nKey, State>
|
|
1406
1574
|
):
|
|
1407
1575
|
& Commander.CommandContextLocal<Id, I18nKey>
|
|
1408
1576
|
& Commander.GenWrap<RT, Id, I18nKey, Args, A, E, R>
|