@effect-app/vue 2.65.0 → 2.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ import { type Result } from "@effect-atom/atom/Result"
5
5
  import { Cause, 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
+ import { wrapEffect } from "effect-app/utils"
8
9
  import { type RuntimeFiber } from "effect/Fiber"
9
10
  import { type NoInfer } from "effect/Types"
10
11
  import { isGeneratorFunction, type YieldWrap } from "effect/Utils"
@@ -69,7 +70,7 @@ export declare namespace Commander {
69
70
  waiting: boolean
70
71
  }
71
72
 
72
- export interface CommandOut<Args extends Array<any>, A, E, R, Id extends string> extends CommandProps<A, E, Id> {
73
+ export interface CommandOut<Args extends Array<unknown>, A, E, R, Id extends string> extends CommandProps<A, E, Id> {
73
74
  new(): {}
74
75
 
75
76
  /** click handlers */
@@ -91,7 +92,7 @@ export declare namespace Commander {
91
92
  exec: (...args: Args) => Effect.Effect<Exit.Exit<A, E>, never, Exclude<R, CommandContext>>
92
93
  }
93
94
 
94
- type CommandOutHelper<Args extends Array<any>, Eff extends Effect.Effect<any, any, any>, Id extends string> =
95
+ type CommandOutHelper<Args extends Array<unknown>, Eff extends Effect.Effect<any, any, any>, Id extends string> =
95
96
  CommandOut<
96
97
  Args,
97
98
  Effect.Effect.Success<Eff>,
@@ -101,7 +102,7 @@ export declare namespace Commander {
101
102
  >
102
103
 
103
104
  export type Gen<RT, Id extends string> = {
104
- <Eff extends YieldWrap<Effect.Effect<any, any, RT | CommandContext>>, AEff, Args extends Array<any>>(
105
+ <Eff extends YieldWrap<Effect.Effect<any, any, RT | CommandContext>>, AEff, Args extends Array<unknown>>(
105
106
  body: (...args: Args) => Generator<Eff, AEff, never>
106
107
  ): CommandOut<
107
108
  Args,
@@ -117,7 +118,7 @@ export declare namespace Commander {
117
118
  <
118
119
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
119
120
  AEff,
120
- Args extends Array<any>,
121
+ Args extends Array<unknown>,
121
122
  A extends Effect.Effect<any, any, RT | CommandContext>
122
123
  >(
123
124
  body: (...args: Args) => Generator<Eff, AEff, never>,
@@ -137,7 +138,7 @@ export declare namespace Commander {
137
138
  <
138
139
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
139
140
  AEff,
140
- Args extends Array<any>,
141
+ Args extends Array<unknown>,
141
142
  A,
142
143
  B extends Effect.Effect<any, any, RT | CommandContext>
143
144
  >(
@@ -159,7 +160,7 @@ export declare namespace Commander {
159
160
  <
160
161
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
161
162
  AEff,
162
- Args extends Array<any>,
163
+ Args extends Array<unknown>,
163
164
  A,
164
165
  B,
165
166
  C extends Effect.Effect<any, any, RT | CommandContext>
@@ -183,7 +184,7 @@ export declare namespace Commander {
183
184
  <
184
185
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
185
186
  AEff,
186
- Args extends Array<any>,
187
+ Args extends Array<unknown>,
187
188
  A,
188
189
  B,
189
190
  C,
@@ -209,7 +210,7 @@ export declare namespace Commander {
209
210
  <
210
211
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
211
212
  AEff,
212
- Args extends Array<any>,
213
+ Args extends Array<unknown>,
213
214
  A,
214
215
  B,
215
216
  C,
@@ -237,7 +238,7 @@ export declare namespace Commander {
237
238
  <
238
239
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
239
240
  AEff,
240
- Args extends Array<any>,
241
+ Args extends Array<unknown>,
241
242
  A,
242
243
  B,
243
244
  C,
@@ -267,7 +268,7 @@ export declare namespace Commander {
267
268
  <
268
269
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
269
270
  AEff,
270
- Args extends Array<any>,
271
+ Args extends Array<unknown>,
271
272
  A,
272
273
  B,
273
274
  C,
@@ -299,7 +300,7 @@ export declare namespace Commander {
299
300
  <
300
301
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
301
302
  AEff,
302
- Args extends Array<any>,
303
+ Args extends Array<unknown>,
303
304
  A,
304
305
  B,
305
306
  C,
@@ -333,7 +334,7 @@ export declare namespace Commander {
333
334
  <
334
335
  Eff extends YieldWrap<Effect.Effect<any, any, any>>,
335
336
  AEff,
336
- Args extends Array<any>,
337
+ Args extends Array<unknown>,
337
338
  A,
338
339
  B,
339
340
  C,
@@ -369,32 +370,32 @@ export declare namespace Commander {
369
370
  }
370
371
 
371
372
  export type NonGen<RT, Id extends string> = {
372
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, Args extends Array<any>>(
373
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, Args extends Array<unknown>>(
373
374
  body: (...args: Args) => Eff
374
375
  ): CommandOutHelper<Args, Eff, Id>
375
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, Args extends Array<any>>(
376
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, Args extends Array<unknown>>(
376
377
  body: (...args: Args) => A,
377
378
  a: (_: A, ...args: NoInfer<Args>) => Eff
378
379
  ): CommandOutHelper<Args, Eff, Id>
379
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, Args extends Array<any>>(
380
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, Args extends Array<unknown>>(
380
381
  body: (...args: Args) => A,
381
382
  a: (_: A, ...args: NoInfer<Args>) => B,
382
383
  b: (_: B, ...args: NoInfer<Args>) => Eff
383
384
  ): CommandOutHelper<Args, Eff, Id>
384
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, Args extends Array<any>>(
385
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, Args extends Array<unknown>>(
385
386
  body: (...args: Args) => A,
386
387
  a: (_: A, ...args: NoInfer<Args>) => B,
387
388
  b: (_: B, ...args: NoInfer<Args>) => C,
388
389
  c: (_: C, ...args: NoInfer<Args>) => Eff
389
390
  ): CommandOutHelper<Args, Eff, Id>
390
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, Args extends Array<any>>(
391
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, Args extends Array<unknown>>(
391
392
  body: (...args: Args) => A,
392
393
  a: (_: A, ...args: NoInfer<Args>) => B,
393
394
  b: (_: B, ...args: NoInfer<Args>) => C,
394
395
  c: (_: C, ...args: NoInfer<Args>) => D,
395
396
  d: (_: D, ...args: NoInfer<Args>) => Eff
396
397
  ): CommandOutHelper<Args, Eff, Id>
397
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, Args extends Array<any>>(
398
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, Args extends Array<unknown>>(
398
399
  body: (...args: Args) => A,
399
400
  a: (_: A, ...args: NoInfer<Args>) => B,
400
401
  b: (_: B, ...args: NoInfer<Args>) => C,
@@ -402,7 +403,7 @@ export declare namespace Commander {
402
403
  d: (_: D, ...args: NoInfer<Args>) => E,
403
404
  e: (_: E, ...args: NoInfer<Args>) => Eff
404
405
  ): CommandOutHelper<Args, Eff, Id>
405
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, F, Args extends Array<any>>(
406
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, F, Args extends Array<unknown>>(
406
407
  body: (...args: Args) => A,
407
408
  a: (_: A, ...args: NoInfer<Args>) => B,
408
409
  b: (_: B, ...args: NoInfer<Args>) => C,
@@ -411,7 +412,7 @@ export declare namespace Commander {
411
412
  e: (_: E, ...args: NoInfer<Args>) => F,
412
413
  f: (_: F, ...args: NoInfer<Args>) => Eff
413
414
  ): CommandOutHelper<Args, Eff, Id>
414
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, F, G, Args extends Array<any>>(
415
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, F, G, Args extends Array<unknown>>(
415
416
  body: (...args: Args) => A,
416
417
  a: (_: A, ...args: NoInfer<Args>) => B,
417
418
  b: (_: B, ...args: NoInfer<Args>) => C,
@@ -421,7 +422,7 @@ export declare namespace Commander {
421
422
  f: (_: F, ...args: NoInfer<Args>) => G,
422
423
  g: (_: G, ...args: NoInfer<Args>) => Eff
423
424
  ): CommandOutHelper<Args, Eff, Id>
424
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, F, G, H, Args extends Array<any>>(
425
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, F, G, H, Args extends Array<unknown>>(
425
426
  body: (...args: Args) => A,
426
427
  a: (_: A, ...args: NoInfer<Args>) => B,
427
428
  b: (_: B, ...args: NoInfer<Args>) => C,
@@ -432,7 +433,7 @@ export declare namespace Commander {
432
433
  g: (_: G, ...args: NoInfer<Args>) => H,
433
434
  h: (_: H, ...args: NoInfer<Args>) => Eff
434
435
  ): CommandOutHelper<Args, Eff, Id>
435
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, F, G, H, I, Args extends Array<any>>(
436
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, A, B, C, D, E, F, G, H, I, Args extends Array<unknown>>(
436
437
  body: (...args: Args) => A,
437
438
  a: (_: A, ...args: NoInfer<Args>) => B,
438
439
  b: (_: B, ...args: NoInfer<Args>) => C,
@@ -446,7 +447,7 @@ export declare namespace Commander {
446
447
  ): CommandOutHelper<Args, Eff, Id>
447
448
  }
448
449
 
449
- export type GenWrap<RT, Id extends string, Args extends Array<any>, AEff, EEff, REff> = {
450
+ export type GenWrap<RT, Id extends string, Args extends Array<unknown>, AEff, EEff, REff> = {
450
451
  (): CommandOut<
451
452
  Args,
452
453
  AEff,
@@ -617,9 +618,9 @@ export declare namespace Commander {
617
618
  ): CommandOutHelper<Args, I, Id>
618
619
  }
619
620
 
620
- export type NonGenWrap<RT, Id extends string, Args extends Array<any>, AEff, EEff, REff> = {
621
+ export type NonGenWrap<RT, Id extends string, Args extends Array<unknown>, AEff, EEff, REff> = {
621
622
  (): CommandOutHelper<Args, Effect.Effect<AEff, EEff, REff>, Id>
622
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, Args extends Array<any>>(
623
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, Args extends Array<unknown>>(
623
624
  a: (
624
625
  _: Effect.Effect<
625
626
  AEff,
@@ -629,7 +630,7 @@ export declare namespace Commander {
629
630
  ...args: NoInfer<Args>
630
631
  ) => Eff
631
632
  ): CommandOutHelper<Args, Eff, Id>
632
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, Args extends Array<any>>(
633
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, Args extends Array<unknown>>(
633
634
  a: (
634
635
  _: Effect.Effect<
635
636
  AEff,
@@ -640,7 +641,7 @@ export declare namespace Commander {
640
641
  ) => B,
641
642
  b: (_: B, ...args: NoInfer<Args>) => Eff
642
643
  ): CommandOutHelper<Args, Eff, Id>
643
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, Args extends Array<any>>(
644
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, Args extends Array<unknown>>(
644
645
  a: (
645
646
  _: Effect.Effect<
646
647
  AEff,
@@ -652,7 +653,7 @@ export declare namespace Commander {
652
653
  b: (_: B, ...args: NoInfer<Args>) => C,
653
654
  c: (_: C, ...args: NoInfer<Args>) => Eff
654
655
  ): CommandOutHelper<Args, Eff, Id>
655
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, Args extends Array<any>>(
656
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, Args extends Array<unknown>>(
656
657
  a: (
657
658
  _: Effect.Effect<
658
659
  AEff,
@@ -665,7 +666,7 @@ export declare namespace Commander {
665
666
  c: (_: C, ...args: NoInfer<Args>) => D,
666
667
  d: (_: D, ...args: NoInfer<Args>) => Eff
667
668
  ): CommandOutHelper<Args, Eff, Id>
668
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, Args extends Array<any>>(
669
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, Args extends Array<unknown>>(
669
670
  a: (
670
671
  _: Effect.Effect<
671
672
  AEff,
@@ -679,7 +680,7 @@ export declare namespace Commander {
679
680
  d: (_: D, ...args: NoInfer<Args>) => E,
680
681
  e: (_: E, ...args: NoInfer<Args>) => Eff
681
682
  ): CommandOutHelper<Args, Eff, Id>
682
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, F, Args extends Array<any>>(
683
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, F, Args extends Array<unknown>>(
683
684
  a: (
684
685
  _: Effect.Effect<
685
686
  AEff,
@@ -694,7 +695,7 @@ export declare namespace Commander {
694
695
  e: (_: E, ...args: NoInfer<Args>) => F,
695
696
  f: (_: F, ...args: NoInfer<Args>) => Eff
696
697
  ): CommandOutHelper<Args, Eff, Id>
697
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, F, G, Args extends Array<any>>(
698
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, F, G, Args extends Array<unknown>>(
698
699
  a: (
699
700
  _: Effect.Effect<
700
701
  AEff,
@@ -710,7 +711,7 @@ export declare namespace Commander {
710
711
  f: (_: F, ...args: NoInfer<Args>) => G,
711
712
  g: (_: G, ...args: NoInfer<Args>) => Eff
712
713
  ): CommandOutHelper<Args, Eff, Id>
713
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, F, G, H, Args extends Array<any>>(
714
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, F, G, H, Args extends Array<unknown>>(
714
715
  a: (
715
716
  _: Effect.Effect<
716
717
  AEff,
@@ -727,7 +728,7 @@ export declare namespace Commander {
727
728
  g: (_: G, ...args: NoInfer<Args>) => H,
728
729
  h: (_: H, ...args: NoInfer<Args>) => Eff
729
730
  ): CommandOutHelper<Args, Eff, Id>
730
- <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, F, G, H, I, Args extends Array<any>>(
731
+ <Eff extends Effect.Effect<any, any, RT | CommandContext>, B, C, D, E, F, G, H, I, Args extends Array<unknown>>(
731
732
  a: (
732
733
  _: Effect.Effect<
733
734
  AEff,
@@ -759,6 +760,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
759
760
  const { confirm, confirmOrInterrupt } = yield* Confirm
760
761
 
761
762
  const makeContext = <Id extends string>(id: Id) => {
763
+ if (!id) throw new Error("must specify an id")
762
764
  const namespace = `action.${id}` as const
763
765
 
764
766
  const action = intl.formatMessage({
@@ -778,7 +780,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
778
780
  const makeCommand = <RT>(runtime: Runtime.Runtime<RT>) => {
779
781
  const runFork = Runtime.runFork(runtime)
780
782
  return <const Id extends string>(id: Id, errorDef?: Error) =>
781
- <Args extends ReadonlyArray<any>, A, E, R extends RT | CommandContext>(
783
+ <Args extends ReadonlyArray<unknown>, A, E, R extends RT | CommandContext>(
782
784
  handler: (...args: Args) => Effect.Effect<A, E, R>
783
785
  ) => {
784
786
  // we capture the definition stack here, so we can append it to later stack traces
@@ -1053,10 +1055,17 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
1053
1055
  )
1054
1056
  }
1055
1057
 
1056
- const defaultFailureMessageHandler =
1057
- <E, Args extends readonly any[]>(action: string, errorRenderer?: ErrorRenderer<E, Args>) =>
1058
- (o: Option.Option<E>, ...args: Args) =>
1059
- Option.match(o, {
1058
+ const defaultFailureMessageHandler = <E, Args extends Array<unknown>, AME, AMR>(
1059
+ actionMaker:
1060
+ | string
1061
+ | ((o: Option.Option<E>, ...args: Args) => string)
1062
+ | ((o: Option.Option<E>, ...args: Args) => Effect.Effect<string, AME, AMR>),
1063
+ errorRenderer?: ErrorRenderer<E, Args>
1064
+ ) =>
1065
+ Effect.fnUntraced(function*(o: Option.Option<E>, ...args: Args) {
1066
+ const action = yield* wrapEffect(actionMaker)(o, ...args)
1067
+
1068
+ return Option.match(o, {
1060
1069
  onNone: () =>
1061
1070
  intl.formatMessage(
1062
1071
  { id: "handle.unexpected_error2" },
@@ -1083,6 +1092,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
1083
1092
  )
1084
1093
  }:\n` + renderError(action, errorRenderer)(e, ...args)
1085
1094
  })
1095
+ })
1086
1096
 
1087
1097
  return {
1088
1098
  /** @experimental */
@@ -1163,7 +1173,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
1163
1173
  )
1164
1174
  }),
1165
1175
  updateAction:
1166
- <Args extends Array<any>>(update: (currentActionId: string, ...args: Args) => string) =>
1176
+ <Args extends Array<unknown>>(update: (currentActionId: string, ...args: Args) => string) =>
1167
1177
  <A, E, R>(_: Effect.Effect<A, E, R>, ...input: Args) =>
1168
1178
  Effect.updateService(
1169
1179
  _,
@@ -1173,7 +1183,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
1173
1183
  defaultFailureMessageHandler,
1174
1184
  renderError,
1175
1185
  /** Version of withDefaultToast that automatically includes the action name in the default messages and uses intl */
1176
- withDefaultToast: <A, E, R, Args extends ReadonlyArray<unknown>>(
1186
+ withDefaultToast: <A, E, R, Args extends Array<unknown>>(
1177
1187
  options?: {
1178
1188
  errorRenderer?: ErrorRenderer<E, Args>
1179
1189
  onWaiting?: null | undefined | string | ((action: string, ...args: Args) => string | null | undefined)
@@ -1252,7 +1262,7 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
1252
1262
  const cmd = makeCommand(rt)
1253
1263
  return (_id: any) => {
1254
1264
  const isObject = typeof _id === "object" || typeof _id === "function"
1255
- const id = isObject ? _id.name : _id
1265
+ const id = isObject ? _id.id : _id
1256
1266
  const context = makeContext(id)
1257
1267
  const idCmd = cmd(id)
1258
1268
  // TODO: implement proper tracing stack
@@ -1269,16 +1279,19 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
1269
1279
  ),
1270
1280
  context,
1271
1281
  isObject
1272
- ? { mutate: _id.mutate }
1282
+ ? { mutate: "mutate" in _id ? _id.mutate : typeof _id === "function" ? _id : undefined }
1273
1283
  : {}
1274
1284
  )
1275
1285
  ))
1276
1286
  }
1277
1287
  }) as unknown as <RT>(
1278
1288
  runtime: Runtime.Runtime<RT>
1279
- ) => <const Id extends string, MutArgs extends Array<any>, MutA, MutE, MutR>(
1280
- id: Id | { name: Id; mutate: (...args: MutArgs) => Effect.Effect<MutA, MutE, MutR> }
1281
- ) => <Args extends Array<any>, A, E, R extends RT | CommandContext>(
1289
+ ) => <const Id extends string, MutArgs extends Array<unknown>, MutA, MutE, MutR>(
1290
+ id:
1291
+ | Id
1292
+ | { id: Id; mutate: (...args: MutArgs) => Effect.Effect<MutA, MutE, MutR> }
1293
+ | ((...args: MutArgs) => Effect.Effect<MutA, MutE, MutR>) & { id: Id }
1294
+ ) => <Args extends Array<unknown>, A, E, R extends RT | CommandContext>(
1282
1295
  handler: (
1283
1296
  ctx: Effect.fn.Gen & Effect.fn.NonGen & Commander.CommandContextLocal<Id> & {
1284
1297
  // todo: only if we passed in one
@@ -1290,15 +1303,17 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
1290
1303
  /** @experimental */
1291
1304
  alt: makeCommand as unknown as <RT>(runtime: Runtime.Runtime<RT>) => <const Id extends string>(
1292
1305
  id: Id
1293
- ) => <Args extends Array<any>, A, E, R extends RT | CommandContext>(
1306
+ ) => <Args extends Array<unknown>, A, E, R extends RT | CommandContext>(
1294
1307
  handler: (...args: Args) => Effect.Effect<A, E, R>
1295
1308
  ) => Commander.CommandOut<Args, A, E, R, Id>,
1296
1309
 
1297
1310
  /** @experimental */
1298
1311
  wrap: <RT>(runtime: Runtime.Runtime<RT>) => {
1299
1312
  const make = makeCommand(runtime)
1300
- return <const Id extends string, Args extends Array<any>, A, E, R>(
1301
- mutation: { mutate: (...args: Args) => Effect.Effect<A, E, R>; name: Id }
1313
+ return <const Id extends string, Args extends Array<unknown>, A, E, R>(
1314
+ mutation:
1315
+ | { mutate: (...args: Args) => Effect.Effect<A, E, R>; id: Id }
1316
+ | ((...args: Args) => Effect.Effect<A, E, R>) & { id: Id }
1302
1317
  ): Commander.GenWrap<RT, Id, Args, A, E, R> & Commander.NonGenWrap<RT, Id, Args, A, E, R> =>
1303
1318
  (
1304
1319
  ...combinators: any[]
@@ -1309,11 +1324,13 @@ export class Commander extends Effect.Service<Commander>()("Commander", {
1309
1324
  const errorDef = new Error()
1310
1325
  Error.stackTraceLimit = limit
1311
1326
 
1312
- return make(mutation.name, errorDef)(
1327
+ const mutate = "mutate" in mutation ? mutation.mutate : mutation
1328
+
1329
+ return make(mutation.id, errorDef)(
1313
1330
  Effect.fnUntraced(
1314
1331
  // fnUntraced only supports generators as first arg, so we convert to generator if needed
1315
- isGeneratorFunction(mutation.mutate) ? mutation.mutate : function*(...args: Args) {
1316
- return yield* mutation.mutate(...args)
1332
+ isGeneratorFunction(mutate) ? mutate : function*(...args: Args) {
1333
+ return yield* mutate(...args)
1317
1334
  },
1318
1335
  ...combinators as [any]
1319
1336
  ) as any
@@ -1,4 +1,5 @@
1
1
  import { Cause, Effect, type Option } from "effect-app"
2
+ import { wrapEffect } from "effect-app/utils"
2
3
  import { CurrentToastId, Toast } from "./toast.js"
3
4
 
4
5
  export interface ToastOptions<A, E, Args extends ReadonlyArray<unknown>, WaiR, SucR, ErrR> {
@@ -30,25 +31,11 @@ export interface ToastOptions<A, E, Args extends ReadonlyArray<unknown>, WaiR, S
30
31
  ) => Effect.Effect<string | { level: "warn" | "error"; message: string }, never, ErrR>)
31
32
  }
32
33
 
33
- // unifies any input to be an effect.
34
- const wrapEffect = <I, A, E, R, Args extends Array<any>>(
35
- m: I | ((...args: Args) => A) | ((...args: Args) => Effect.Effect<A, E, R>)
36
- ) => {
37
- if (typeof m === "function") {
38
- return (...args: Args): Effect.Effect<A | I, E, R> => {
39
- const r = (m as any)(...args)
40
- if (Effect.isEffect(r)) return r as Effect.Effect<A, E, R>
41
- return Effect.succeed(r)
42
- }
43
- }
44
- return (): Effect.Effect<A | I, E, R> => Effect.succeed(m)
45
- }
46
-
47
34
  // @effect-diagnostics-next-line missingEffectServiceDependency:off
48
35
  export class WithToast extends Effect.Service<WithToast>()("WithToast", {
49
36
  effect: Effect.gen(function*() {
50
37
  const toast = yield* Toast
51
- return <A, E, Args extends ReadonlyArray<unknown>, R, WaiR = never, SucR = never, ErrR = never>(
38
+ return <A, E, Args extends Array<unknown>, R, WaiR = never, SucR = never, ErrR = never>(
52
39
  options: ToastOptions<A, E, Args, WaiR, SucR, ErrR>
53
40
  ) =>
54
41
  Effect.fnUntraced(function*(self: Effect.Effect<A, E, R>, ...args: Args) {
@@ -96,7 +83,7 @@ export class WithToast extends Effect.Service<WithToast>()("WithToast", {
96
83
  })
97
84
  })
98
85
  }) {
99
- static readonly handle = <A, E, Args extends ReadonlyArray<unknown>, R, WaiR = never, SucR = never, ErrR = never>(
86
+ static readonly handle = <A, E, Args extends Array<unknown>, R, WaiR = never, SucR = never, ErrR = never>(
100
87
  options: ToastOptions<A, E, Args, WaiR, SucR, ErrR>
101
88
  ): (self: Effect.Effect<A, E, R>, ...args: Args) => Effect.Effect<A, E, R | WaiR | SucR | ErrR | WithToast> =>
102
89
  (self, ...args) => this.use((_) => _<A, E, Args, R, WaiR, SucR, ErrR>(options)(self, ...args))
package/src/lib.ts CHANGED
@@ -30,9 +30,9 @@ export const reportRuntimeError = (cause: Cause.Cause<unknown>, extras?: Record<
30
30
 
31
31
  // $Project/$Configuration.Index
32
32
  // -> "$Project", "$Configuration", "Index"
33
- export const makeQueryKey = ({ name, options }: { name: string; options?: ClientForOptions }) =>
33
+ export const makeQueryKey = ({ id, options }: { id: string; options?: ClientForOptions }) =>
34
34
  pipe(
35
- name.split("/"),
35
+ id.split("/"),
36
36
  (split) => split.filter((_) => !options || !options?.skipQueryKey?.includes(_)).map((_) => "$" + _)
37
37
  )
38
38
  .join(".")
package/src/makeClient.ts CHANGED
@@ -126,7 +126,7 @@ function handleRequest<
126
126
  RDefect = never
127
127
  >(
128
128
  f: Effect.Effect<Exit.Exit<A, E>, never, R> | ((i: I) => Effect.Effect<Exit.Exit<A, E>, never, R>),
129
- name: string,
129
+ id: string,
130
130
  action: string,
131
131
  options: {
132
132
  onSuccess: (a: A, i: I) => Effect.Effect<void, ESuccess, RSuccess>
@@ -168,7 +168,7 @@ function handleRequest<
168
168
  })
169
169
  })
170
170
  ),
171
- Effect.withSpan(`mutation ${name}`, { captureStackTrace: false })
171
+ Effect.withSpan(`mutation ${id}`, { captureStackTrace: false })
172
172
  )
173
173
  return Object.assign(
174
174
  Effect.isEffect(f)
@@ -190,7 +190,7 @@ const _useMutation = makeMutation()
190
190
  /**
191
191
  * Pass an Effect or a function that returns an Effect, e.g from a client action
192
192
  * Executes query cache invalidation based on default rules or provided option.
193
- * adds a span with the mutation name
193
+ * adds a span with the mutation id
194
194
  */
195
195
  export const useMutation: typeof _useMutation = <
196
196
  I,
@@ -205,7 +205,7 @@ export const useMutation: typeof _useMutation = <
205
205
  ) =>
206
206
  mapHandler(
207
207
  _useMutation(self as any, options),
208
- Effect.withSpan(`mutation ${self.name}`, { captureStackTrace: false })
208
+ Effect.withSpan(`mutation ${self.id}`, { captureStackTrace: false })
209
209
  ) as any
210
210
 
211
211
  // @effect-diagnostics-next-line missingEffectServiceDependency:off
@@ -248,7 +248,7 @@ export class LegacyMutation extends Effect.Service<LegacyMutation>()("LegacyMuta
248
248
  a,
249
249
  mapHandler(
250
250
  b,
251
- Effect.withSpan(`mutation ${self.name}`, { captureStackTrace: false })
251
+ Effect.withSpan(`mutation ${self.id}`, { captureStackTrace: false })
252
252
  )
253
253
  ] as const as any
254
254
  }
@@ -276,7 +276,7 @@ export class LegacyMutation extends Effect.Service<LegacyMutation>()("LegacyMuta
276
276
  RDefect = never
277
277
  >(
278
278
  f: Effect.Effect<Exit.Exit<A2, E2>, never, R2> | ((i: I) => Effect.Effect<Exit.Exit<A2, E2>, never, R2>),
279
- name: string,
279
+ id: string,
280
280
  action: string,
281
281
  options: Opts<A, E, R, I, A2, E2, R2, ESuccess, RSuccess, EError, RError, EDefect, RDefect> = {}
282
282
  ) {
@@ -294,7 +294,7 @@ export class LegacyMutation extends Effect.Service<LegacyMutation>()("LegacyMuta
294
294
  { action: actionMessage }
295
295
  )
296
296
 
297
- return handleRequest<E2, A2, R2, any, ESuccess, RSuccess, EError, RError, EDefect, RDefect>(f, name, action, {
297
+ return handleRequest<E2, A2, R2, any, ESuccess, RSuccess, EError, RError, EDefect, RDefect>(f, id, action, {
298
298
  onSuccess: Effect.fnUntraced(function*(a, i) {
299
299
  const message = options.successMessage ? yield* options.successMessage(a, i) : defaultSuccessMessage
300
300
  + (S.is(OperationSuccess)(a) && a.message
@@ -460,7 +460,7 @@ export class LegacyMutation extends Effect.Service<LegacyMutation>()("LegacyMuta
460
460
 
461
461
  return tuple(
462
462
  a,
463
- handleRequestWithToast(b as any, self.name, action, options)
463
+ handleRequestWithToast(b as any, self.id, action, options)
464
464
  )
465
465
  }
466
466
  //
@@ -697,7 +697,7 @@ export class LegacyMutation extends Effect.Service<LegacyMutation>()("LegacyMuta
697
697
 
698
698
  return tuple(
699
699
  computed(() => mutationResultToVue(a.value)),
700
- handleRequest(b as any, self.name, action, {
700
+ handleRequest(b as any, self.id, action, {
701
701
  onSuccess: suppressToast,
702
702
  onDefect: suppressToast,
703
703
  onFail: suppressToast,
package/src/mutate.ts CHANGED
@@ -7,13 +7,13 @@ import { tuple } from "effect-app/Function"
7
7
  import { computed, type ComputedRef, shallowRef } from "vue"
8
8
  import { makeQueryKey } from "./lib.js"
9
9
 
10
- export const getQueryKey = (h: { name: string }) => {
10
+ export const getQueryKey = (h: { id: string }) => {
11
11
  const key = makeQueryKey(h)
12
12
  const ns = key.filter((_) => _.startsWith("$"))
13
13
  // we invalidate the parent namespace e.g $project/$configuration.get, we invalidate $project
14
14
  // for $project/$configuration/$something.get, we invalidate $project/$configuration
15
15
  const k = ns.length ? ns.length > 1 ? ns.slice(0, ns.length - 1) : ns : undefined
16
- if (!k) throw new Error("empty query key for: " + h.name)
16
+ if (!k) throw new Error("empty query key for: " + h.id)
17
17
  return k
18
18
  }
19
19
 
@@ -180,7 +180,7 @@ export const makeMutation = () => {
180
180
  const queryKey = getQueryKey(self)
181
181
 
182
182
  if (options?.queryInvalidation) {
183
- const opts = options.queryInvalidation(queryKey, self.name)
183
+ const opts = options.queryInvalidation(queryKey, self.id)
184
184
  if (!opts.length) {
185
185
  return Effect.void
186
186
  }
package/src/query.ts CHANGED
@@ -75,7 +75,7 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
75
75
  handler
76
76
  .pipe(
77
77
  Effect.tapDefect(reportRuntimeError),
78
- Effect.withSpan(`query ${q.name}`, { captureStackTrace: false }),
78
+ Effect.withSpan(`query ${q.id}`, { captureStackTrace: false }),
79
79
  meta?.["span"] ? Effect.withParentSpan(meta["span"] as Span) : (_) => _
80
80
  ),
81
81
  { signal }
@@ -100,7 +100,7 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
100
100
  handler(req.value)
101
101
  .pipe(
102
102
  Effect.tapDefect(reportRuntimeError),
103
- Effect.withSpan(`query ${q.name}`, { captureStackTrace: false }),
103
+ Effect.withSpan(`query ${q.id}`, { captureStackTrace: false }),
104
104
  meta?.["span"] ? Effect.withParentSpan(meta["span"] as Span) : (_) => _
105
105
  ),
106
106
  { signal }
@@ -23,9 +23,31 @@ describe("alt2", () => {
23
23
  let executed = false
24
24
 
25
25
  const someMutation = {
26
- name: "Test Action",
27
- mutate: (() => {}) as unknown as (a: number, b: string) => Effect.Effect<string, number, boolean>
28
- }
26
+ id: "Test Action",
27
+ mutate: (() => {}) as unknown as (a: number, b: string) => Effect.Effect<string, number, CommandContext>
28
+ } as const
29
+ const someMutation2 = Object.assign(
30
+ (() => {}) as unknown as (a: number, b: string) => Effect.Effect<string, number, CommandContext>,
31
+ {
32
+ id: "Test Action"
33
+ } as const
34
+ )
35
+ const command1 = Command.alt2(someMutation2)((fn) =>
36
+ fn(
37
+ function*() {
38
+ expect(typeof fn.mutate).toBe("function")
39
+ expect(fn.id).toBe("Test Action")
40
+ expect(fn.namespace).toBe("action.Test Action")
41
+ expect(fn.namespaced("a")).toBe("action.Test Action.a")
42
+ }
43
+ )
44
+ )
45
+ yield* unwrap(command1.handle())
46
+ expect(command1.action).toBe("Test Action")
47
+ expect(command1.id).toBe("Test Action")
48
+ expect(command1.namespace).toBe("action.Test Action")
49
+ expect(command1.namespaced("a")).toBe("action.Test Action.a")
50
+
29
51
  const command = Command.alt2(someMutation)((fn) =>
30
52
  fn(
31
53
  function*() {
@@ -55,7 +77,7 @@ describe("alt2", () => {
55
77
  Effect.tap(() => executed = true)
56
78
  )
57
79
  )
58
- console.log(command)
80
+
59
81
  expect(command.action).toBe("Test Action")
60
82
  expect(command.id).toBe("Test Action")
61
83
  expect(command.namespace).toBe("action.Test Action")