@effect-app/vue 2.77.7 → 2.77.9

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.
@@ -90,12 +90,31 @@ export const wrapEmit = <A, Event extends string>(
90
90
  (value: A) => new Promise<void>((resolve) => emit(event, value, resolve))
91
91
 
92
92
  export declare namespace Commander {
93
+ export type CommanderBase<RT, Id extends string, I18nKey extends string, State> =
94
+ & Commander.Gen<RT, Id, I18nKey>
95
+ & Commander.NonGen<RT, Id, I18nKey>
96
+ & Commander.CommandContextLocal<Id, I18nKey>
97
+ & {
98
+ state: Context.Tag<`Commander.Command.${Id}.state`, State>
99
+ }
100
+
101
+ export type CommanderFn<RT, Id extends string, I18nKey extends string, State> = CommanderBase<RT, Id, I18nKey, State>
102
+
103
+ export type CommanderWrap<RT, Id extends string, I18nCustomKey extends string, State, I extends any[], A, E, R> =
104
+ & CommandContextLocal<Id, I18nCustomKey>
105
+ & GenWrap<RT, Id, I18nCustomKey, I, A, E, R>
106
+ & NonGenWrap<RT, Id, I18nCustomKey, I, A, E, R>
107
+ & {
108
+ state: Context.Tag<`Commander.Command.${Id}.state`, State>
109
+ }
110
+
93
111
  export interface CommandContextLocal<Id extends string, I18nKey extends string> {
94
112
  id: Id
95
113
  i18nKey: I18nKey
96
114
  namespace: `action.${I18nKey}`
97
115
  namespaced: <K extends string>(k: K) => `action.${I18nKey}.${K}`
98
116
  }
117
+
99
118
  export interface CommandProps<A, E, Id extends string, I18nKey extends string>
100
119
  extends CommandContextLocal<Id, I18nKey>
101
120
  {
@@ -1538,6 +1557,11 @@ export class CommanderImpl<RT> {
1538
1557
  *
1539
1558
  * @param id The internal identifier for the action. Used as a tracing span and to lookup
1540
1559
  * the user-facing name via internationalization (`action.${id}`).
1560
+ * @param options Optional configuration for internationalization and state.
1561
+ * @param options.i18nCustomKey Custom i18n key to use instead of `id` (e.g., for grouping similar actions)
1562
+ * @param options.state Optional reactive state object (or function returning one) that is
1563
+ * made available to the command effects and can be used for i18n interpolation.
1564
+ * The state is captured at the start of each command execution and remains stable throughout.
1541
1565
  * @returns A function that executes the command when called (e.g., directly in `@click` handlers).
1542
1566
  * Built-in error reporting handles failures automatically.
1543
1567
  *
@@ -1549,6 +1573,8 @@ export class CommanderImpl<RT> {
1549
1573
  * - `result`: The command result state
1550
1574
  * - `waiting`: Boolean indicating if the command is in progress (shorthand for `result.waiting`)
1551
1575
  * - `handle`: Function to execute the command
1576
+ * - `exec`: The raw Effect that will be executed when calling `handle` (for advanced use cases)
1577
+ * - `i18nKey`, `namespace`, `namespaced`: Helpers for internationalization keys
1552
1578
  *
1553
1579
  * **User Feedback**: Use the `withDefaultToast` helper for status notifications, or render
1554
1580
  * the `result` inline for custom UI feedback.
@@ -1653,7 +1679,33 @@ export class CommanderImpl<RT> {
1653
1679
  handler: (...args: Args) => Effect.Effect<A, E, R>
1654
1680
  ) => Commander.CommandOut<Args, A, E, R, Id, I18nKey>)
1655
1681
 
1656
- /** @experimental */
1682
+ /**
1683
+ * Define a Command for handling user actions with built-in error reporting and state management.
1684
+ *
1685
+ * @param mutation The mutation function to take the identifier and initial handler from. Used as a tracing span and to lookup
1686
+ * the user-facing name via internationalization (`action.${id}`).
1687
+ * @param options Optional configuration for internationalization and state.
1688
+ * @param options.i18nCustomKey Custom i18n key to use instead of `id` (e.g., for grouping similar actions)
1689
+ * @param options.state Optional reactive state object (or function returning one) that is
1690
+ * made available to the command effects and can be used for i18n interpolation.
1691
+ * The state is captured at the start of each command execution and remains stable throughout.
1692
+ * @returns A function that executes the command when called (e.g., directly in `@click` handlers).
1693
+ * Built-in error reporting handles failures automatically.
1694
+ *
1695
+ * **Effect Context**: Effects have access to the `CommandContext` service, which provides
1696
+ * the user-facing action name.
1697
+ *
1698
+ * **Returned Properties**:
1699
+ * - `action`: User-facing action name from intl messages (useful for button labels)
1700
+ * - `result`: The command result state
1701
+ * - `waiting`: Boolean indicating if the command is in progress (shorthand for `result.waiting`)
1702
+ * - `handle`: Function to execute the command
1703
+ * - `exec`: The raw Effect that will be executed when calling `handle` (for advanced use cases)
1704
+ * - `i18nKey`, `namespace`, `namespaced`: Helpers for internationalization keys
1705
+ *
1706
+ * **User Feedback**: Use the `withDefaultToast` helper for status notifications, or render
1707
+ * the `result` inline for custom UI feedback.
1708
+ */
1657
1709
  wrap = <
1658
1710
  const Id extends string,
1659
1711
  Args extends Array<unknown>,
@@ -1667,31 +1719,36 @@ export class CommanderImpl<RT> {
1667
1719
  | { mutate: (...args: Args) => Effect.Effect<A, E, R>; id: Id }
1668
1720
  | ((...args: Args) => Effect.Effect<A, E, R>) & { id: Id },
1669
1721
  options?: FnOptions<I18nKey, State>
1670
- ):
1671
- & Commander.CommandContextLocal<Id, I18nKey>
1672
- & Commander.GenWrap<RT, Id, I18nKey, Args, A, E, R>
1673
- & Commander.NonGenWrap<RT, Id, I18nKey, Args, A, E, R> =>
1674
- Object.assign((
1675
- ...combinators: any[]
1676
- ): any => {
1677
- // we capture the definition stack here, so we can append it to later stack traces
1678
- const limit = Error.stackTraceLimit
1679
- Error.stackTraceLimit = 2
1680
- const errorDef = new Error()
1681
- Error.stackTraceLimit = limit
1682
-
1683
- const mutate = "mutate" in mutation ? mutation.mutate : mutation
1684
-
1685
- return this.makeCommand(mutation.id, options, errorDef)(
1686
- Effect.fnUntraced(
1687
- // fnUntraced only supports generators as first arg, so we convert to generator if needed
1688
- isGeneratorFunction(mutate) ? mutate : function*(...args: Args) {
1689
- return yield* mutate(...args)
1690
- },
1691
- ...combinators as [any]
1692
- ) as any
1693
- )
1694
- }, makeBaseInfo(mutation.id, options))
1722
+ ): Commander.CommanderWrap<RT, Id, I18nKey, State, Args, A, E, R> =>
1723
+ Object.assign(
1724
+ (
1725
+ ...combinators: any[]
1726
+ ): any => {
1727
+ // we capture the definition stack here, so we can append it to later stack traces
1728
+ const limit = Error.stackTraceLimit
1729
+ Error.stackTraceLimit = 2
1730
+ const errorDef = new Error()
1731
+ Error.stackTraceLimit = limit
1732
+
1733
+ const mutate = "mutate" in mutation ? mutation.mutate : mutation
1734
+
1735
+ return this.makeCommand(mutation.id, options, errorDef)(
1736
+ Effect.fnUntraced(
1737
+ // fnUntraced only supports generators as first arg, so we convert to generator if needed
1738
+ isGeneratorFunction(mutate) ? mutate : function*(...args: Args) {
1739
+ return yield* mutate(...args)
1740
+ },
1741
+ ...combinators as [any]
1742
+ ) as any
1743
+ )
1744
+ },
1745
+ makeBaseInfo(mutation.id, options),
1746
+ {
1747
+ state: Context.GenericTag<`Commander.Command.${Id}.state`, State>(
1748
+ `Commander.Command.${mutation.id}.state`
1749
+ )
1750
+ }
1751
+ )
1695
1752
  }
1696
1753
 
1697
1754
  // @effect-diagnostics-next-line missingEffectServiceDependency:off
package/src/makeClient.ts CHANGED
@@ -27,6 +27,55 @@ const mapHandler = <A, E, R, I = void, A2 = A, E2 = E, R2 = R>(
27
27
  map: (self: Effect.Effect<A, E, R>, i: I) => Effect.Effect<A2, E2, R2>
28
28
  ) => Effect.isEffect(handler) ? map(handler, undefined as any) : (i: I) => map(handler(i), i)
29
29
 
30
+ export interface MutationExtensions<RT, Id extends string, I extends any[], A, E, R> {
31
+ /** @see Command.wrap */
32
+ wrap: Commander.CommanderWrap<RT, Id, Id, undefined, I, A, E, R>
33
+ /** @see Command.fn */
34
+ fn: Commander.CommanderFn<RT, Id, Id, undefined>
35
+ }
36
+
37
+ /** my other doc */
38
+ export interface MutationExtWithInput<
39
+ RT,
40
+ Id extends string,
41
+ I extends any[],
42
+ A,
43
+ E,
44
+ R
45
+ > extends Commander.CommandContextLocal<Id, Id>, MutationExtensions<RT, Id, I, A, E, R> {
46
+ /**
47
+ * Call the endpoint with input
48
+ */
49
+ (i: I): Effect.Effect<A, E, R>
50
+ }
51
+
52
+ /** my other doc */
53
+ export interface MutationExt<
54
+ RT,
55
+ Id extends string,
56
+ A,
57
+ E,
58
+ R
59
+ > extends
60
+ Commander.CommandContextLocal<Id, Id>,
61
+ Commander.CommanderWrap<RT, Id, Id, undefined, [], A, E, R>,
62
+ MutationExtensions<RT, Id, [], A, E, R>,
63
+ Effect.Effect<A, E, R>
64
+ {
65
+ }
66
+
67
+ export type MutationWithExtensions<RT, Req> =
68
+ & (Req extends RequestHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id>
69
+ ? Commander.CommandContextLocal<Id, Id>
70
+ : Req extends RequestHandler<infer _A, infer _E, infer _R, infer _Request, infer Id>
71
+ ? Commander.CommandContextLocal<Id, Id>
72
+ : never)
73
+ & (Req extends RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer _Request, infer Id>
74
+ ? MutationExtWithInput<RT, Id, [I], A, E, R>
75
+ : Req extends RequestHandler<infer A, infer E, infer R, infer _Request, infer Id>
76
+ ? MutationExtWithInput<RT, Id, [], A, E, R>
77
+ : never)
78
+
30
79
  /**
31
80
  * Use this after handling an error yourself, still continueing on the Error track, but the error will not be reported.
32
81
  */
@@ -1155,14 +1204,12 @@ export const makeClient = <RT>(
1155
1204
  client: ClientFrom<M>
1156
1205
  ) => {
1157
1206
  const Command = useCommand()
1158
- const wrap_ = Command.wrap
1159
- const fn_ = Command.fn
1160
1207
  const mutation = useMutation()
1161
1208
  const mutations = Struct.keys(client).reduce(
1162
1209
  (acc, key) => {
1163
1210
  const mut = mutation(client[key] as any)
1164
- const fn = fn_(client[key].id)
1165
- const wrap = wrap_(mut)
1211
+ const fn = Command.fn(client[key].id)
1212
+ const wrap = Command.wrap(mut)
1166
1213
  ;(acc as any)[camelCase(key) + "Mutation"] = Object.assign(
1167
1214
  mut,
1168
1215
  { wrap, fn },
@@ -1171,51 +1218,10 @@ export const makeClient = <RT>(
1171
1218
  return acc
1172
1219
  },
1173
1220
  {} as {
1174
- [Key in keyof typeof client as `${ToCamel<string & Key>}Mutation`]:
1175
- & (typeof client[Key] extends
1176
- RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id> ?
1177
- & ReturnType<typeof mutation<I, E, A, R, Request, Id>>
1178
- & (typeof client[Key] extends
1179
- RequestHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id>
1180
- ? Commander.CommandContextLocal<Id, Id>
1181
- : typeof client[Key] extends RequestHandler<infer _A, infer _E, infer _R, infer _Request, infer Id>
1182
- ? Commander.CommandContextLocal<Id, Id>
1183
- : never)
1184
- : typeof client[Key] extends RequestHandler<infer A, infer E, infer R, infer Request, infer Id> ?
1185
- & ReturnType<typeof mutation<E, A, R, Request, Id>>
1186
- & (typeof client[Key] extends
1187
- RequestHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id>
1188
- ? Commander.CommandContextLocal<Id, Id>
1189
- : typeof client[Key] extends RequestHandler<infer _A, infer _E, infer _R, infer _Request, infer Id>
1190
- ? Commander.CommandContextLocal<Id, Id>
1191
- : never)
1192
- : never)
1193
- & (typeof client[Key] extends
1194
- RequestHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id>
1195
- ? Commander.CommandContextLocal<Id, Id>
1196
- : typeof client[Key] extends RequestHandler<infer _A, infer _E, infer _R, infer _Request, infer Id>
1197
- ? Commander.CommandContextLocal<Id, Id>
1198
- : never)
1199
- & (typeof client[Key] extends
1200
- RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id>
1201
- ? ReturnType<typeof mutation<I, E, A, R, Request, Id>>
1202
- : typeof client[Key] extends RequestHandler<infer A, infer E, infer R, infer Request, infer Id>
1203
- ? ReturnType<typeof mutation<E, A, R, Request, Id>>
1204
- : never)
1205
- & {
1206
- wrap: typeof client[Key] extends
1207
- RequestHandlerWithInput<infer I, infer A, infer E, infer _R, infer _Request, infer Id>
1208
- ? ReturnType<typeof wrap_<Id, [I], A, E, never>> & Commander.CommandContextLocal<Id, Id>
1209
- : typeof client[Key] extends RequestHandler<infer A, infer E, infer _R, infer _Request, infer Id>
1210
- ? ReturnType<typeof wrap_<Id, [], A, E, never>> & Commander.CommandContextLocal<Id, Id>
1211
- : never
1212
- fn: typeof client[Key] extends
1213
- RequestHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id>
1214
- ? ReturnType<typeof fn_<Id>> & Commander.CommandContextLocal<Id, Id>
1215
- : typeof client[Key] extends RequestHandler<infer _A, infer _E, infer _R, infer _Request, infer Id>
1216
- ? ReturnType<typeof fn_<Id>> & Commander.CommandContextLocal<Id, Id>
1217
- : never
1218
- }
1221
+ [Key in keyof typeof client as `${ToCamel<string & Key>}Mutation`]: MutationWithExtensions<
1222
+ RT,
1223
+ typeof client[Key]
1224
+ >
1219
1225
  }
1220
1226
  )
1221
1227
  return mutations
@@ -1231,12 +1237,10 @@ export const makeClient = <RT>(
1231
1237
  ) => {
1232
1238
  const Command = useCommand()
1233
1239
  const mutation = useMutation()
1234
- const wrap = Command.wrap
1235
- const fn_ = Command.fn
1236
1240
  const invalidation = queryInvalidation?.(client)
1237
1241
  const extended = Struct.keys(client).reduce(
1238
1242
  (acc, key) => {
1239
- const fn = fn_(client[key].id)
1243
+ const fn = Command.fn(client[key].id)
1240
1244
  const awesome = {
1241
1245
  ...client[key],
1242
1246
  ...fn,
@@ -1247,44 +1251,12 @@ export const makeClient = <RT>(
1247
1251
  client[key] as any,
1248
1252
  invalidation?.[key] ? { queryInvalidation: invalidation[key] } : undefined
1249
1253
  )
1250
- ;(acc as any)[key] = Object.assign(mutate, { wrap: wrap({ mutate, id: awesome.id }), fn }, awesome, fn)
1254
+ ;(acc as any)[key] = Object.assign(mutate, { wrap: Command.wrap({ mutate, id: awesome.id }), fn }, awesome, fn)
1251
1255
  return acc
1252
1256
  },
1253
1257
  {} as {
1254
1258
  [Key in keyof typeof client]:
1255
- & (typeof client[Key] extends
1256
- RequestHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id>
1257
- ? Commander.CommandContextLocal<Id, Id>
1258
- : typeof client[Key] extends RequestHandler<infer _A, infer _E, infer _R, infer _Request, infer Id>
1259
- ? Commander.CommandContextLocal<Id, Id>
1260
- : never)
1261
- & (typeof client[Key] extends
1262
- RequestHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id>
1263
- ? Commander.CommandContextLocal<Id, Id>
1264
- : typeof client[Key] extends RequestHandler<infer _A, infer _E, infer _R, infer _Request, infer Id>
1265
- ? Commander.CommandContextLocal<Id, Id>
1266
- : never)
1267
- & (typeof client[Key] extends
1268
- RequestHandlerWithInput<infer I, infer A, infer E, infer R, infer Request, infer Id>
1269
- ? ReturnType<typeof mutation<I, E, A, R, Request, Id>>
1270
- : typeof client[Key] extends RequestHandler<infer A, infer E, infer R, infer Request, infer Id>
1271
- ? ReturnType<typeof mutation<E, A, R, Request, Id>>
1272
- : never)
1273
- & {
1274
- wrap: typeof client[Key] extends
1275
- RequestHandlerWithInput<infer I, infer A, infer E, infer _R, infer _Request, infer Id>
1276
- ? ReturnType<typeof wrap<Id, [I], A, E, never>> & Commander.CommandContextLocal<Id, Id>
1277
- : typeof client[Key] extends RequestHandler<infer A, infer E, infer _R, infer _Request, infer Id>
1278
- ? ReturnType<typeof wrap<Id, [], A, E, never>> & Commander.CommandContextLocal<Id, Id>
1279
- : never
1280
- fn: typeof client[Key] extends
1281
- RequestHandlerWithInput<infer _I, infer _A, infer _E, infer _R, infer _Request, infer Id>
1282
- ? ReturnType<typeof fn_<Id>> & Commander.CommandContextLocal<Id, Id>
1283
- : typeof client[Key] extends RequestHandler<infer _A, infer _E, infer _R, infer _Request, infer Id>
1284
- ? ReturnType<typeof fn_<Id>> & Commander.CommandContextLocal<Id, Id>
1285
- : never
1286
- }
1287
- & typeof client[Key]
1259
+ & MutationWithExtensions<RT, typeof client[Key]>
1288
1260
  & {
1289
1261
  query: typeof client[Key] extends
1290
1262
  RequestHandlerWithInput<infer I, infer A, infer E, infer _R, infer Request, infer Id>