diff --git a/.changeset/huge-bobcats-greet.md b/.changeset/huge-bobcats-greet.md new file mode 100644 index 0000000000..1d06304ea3 --- /dev/null +++ b/.changeset/huge-bobcats-greet.md @@ -0,0 +1,5 @@ +--- +"@effect-app/vue": minor +--- + +Change Commander to be unary and pass Context as second arg. \ No newline at end of file diff --git a/package.json b/package.json index 48a94db980..8233016f46 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "@effect/language-service": "0.41.1", "@effect/platform": "^0.92.0", "@effect/platform-node": "^0.98.0", + "@effect/vitest": "^0.26.0", "@tsconfig/strictest": "^2.0.6", "@types/lodash": "^4.17.20", "@types/node": "~24.6.0", diff --git a/packages/vue/package.json b/packages/vue/package.json index f02e1beab3..2684f85f20 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -54,6 +54,10 @@ "types": "./dist/experimental/commander.d.ts", "default": "./dist/experimental/commander.js" }, + "./experimental/commander2": { + "types": "./dist/experimental/commander2.d.ts", + "default": "./dist/experimental/commander2.js" + }, "./experimental/confirm": { "types": "./dist/experimental/confirm.d.ts", "default": "./dist/experimental/confirm.js" diff --git a/packages/vue/src/experimental/commander.ts b/packages/vue/src/experimental/commander.ts index 10718fa818..382967f33b 100644 --- a/packages/vue/src/experimental/commander.ts +++ b/packages/vue/src/experimental/commander.ts @@ -93,9 +93,9 @@ export const wrapEmit = ( export declare namespace Commander { export type CommanderBase = - & Commander.Gen - & Commander.NonGen - & Commander.CommandContextLocal + & Gen + & NonGen + & CommandContextLocal & { state: Context.Tag<`Commander.Command.${Id}.state`, State> } @@ -108,7 +108,7 @@ export declare namespace Commander { Id extends string, I18nCustomKey extends string, State extends IntlRecord | undefined, - I extends any[], + I, A, E, R @@ -147,7 +147,7 @@ export declare namespace Commander { } export interface CommandOut< - Args extends Array, + Arg, A, E, R, @@ -158,35 +158,41 @@ export declare namespace Commander { new(): {} /** click handlers */ - handle: ((...args: Args) => RuntimeFiber, never>) & { + handle: ((arg: Arg) => RuntimeFiber, never>) & { /** @deprecated don't exist */ - effect: (...args: Args) => Effect.Effect + effect: (arg: Arg) => Effect.Effect } // // TODO: if we keep them, it would probably be nicer as an option api, deciding the return value like in Atom? // /** @experimental */ - // compose: (...args: Args) => Effect.Effect, R> + // compose: (arg: Arg) => Effect.Effect, R> // /** @experimental */ - // compose2: (...args: Args) => Effect.Effect + // compose2: (arg: Arg) => Effect.Effect // /** // * @experimental // * captures the current span and returns an Effect that when run will execute the command // */ - // handleEffect: (...args: Args) => Effect.Effect, never>> + // handleEffect: (arg: Arg) => Effect.Effect, never>> // /** // * @experimental // */ - // exec: (...args: Args) => Effect.Effect, never, Exclude> + // exec: (arg: Arg) => Effect.Effect, never, Exclude> + } + + export interface CommandContextLocal2 + extends CommandContextLocal + { + state: State } type CommandOutHelper< - Args extends Array, + Arg, Eff extends Effect.Effect, Id extends string, I18nKey extends string, State extends IntlRecord | undefined > = CommandOut< - Args, + Arg, Effect.Effect.Success, Effect.Effect.Error, Effect.Effect.Context, @@ -199,11 +205,11 @@ export declare namespace Commander { < Eff extends YieldWrap>, AEff, - Args extends Array + Arg = void >( - body: (...args: Args) => Generator + body: (arg: Arg) => Generator ): CommandOut< - Args, + Arg, AEff, [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? E @@ -218,10 +224,10 @@ export declare namespace Commander { < Eff extends YieldWrap>, AEff, - Args extends Array, - A extends Effect.Effect + A extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -232,17 +238,18 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A - ): CommandOutHelper + ): CommandOutHelper < Eff extends YieldWrap>, AEff, - Args extends Array, A, - B extends Effect.Effect + B extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -253,19 +260,20 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B + ): CommandOutHelper < Eff extends YieldWrap>, AEff, - Args extends Array, A, B, - C extends Effect.Effect + C extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -276,21 +284,22 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C + ): CommandOutHelper < Eff extends YieldWrap>, AEff, - Args extends Array, A, B, C, - D extends Effect.Effect + D extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -301,23 +310,24 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D + ): CommandOutHelper < Eff extends YieldWrap>, AEff, - Args extends Array, A, B, C, D, - E extends Effect.Effect + E extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -328,25 +338,26 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E + ): CommandOutHelper < Eff extends YieldWrap>, AEff, - Args extends Array, A, B, C, D, E, - F extends Effect.Effect + F extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -357,27 +368,28 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E, - f: (_: E, ...args: NoInfer) => F - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + f: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F + ): CommandOutHelper < Eff extends YieldWrap>, AEff, - Args extends Array, A, B, C, D, E, F, - G extends Effect.Effect + G extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -388,19 +400,19 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E, - f: (_: E, ...args: NoInfer) => F, - g: (_: F, ...args: NoInfer) => G - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + f: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + g: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G + ): CommandOutHelper < Eff extends YieldWrap>, AEff, - Args extends Array, A, B, C, @@ -408,9 +420,10 @@ export declare namespace Commander { E, F, G, - H extends Effect.Effect + H extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -421,20 +434,20 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E, - f: (_: E, ...args: NoInfer) => F, - g: (_: F, ...args: NoInfer) => G, - h: (_: G, ...args: NoInfer) => H - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + f: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + g: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + h: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => H + ): CommandOutHelper < Eff extends YieldWrap>, AEff, - Args extends Array, A, B, C, @@ -443,9 +456,10 @@ export declare namespace Commander { F, G, H, - I extends Effect.Effect + I extends Effect.Effect, + Arg = void >( - body: (...args: Args) => Generator, + body: (arg: Arg, ctx: CommandContextLocal2) => Generator, a: ( _: Effect.Effect< AEff, @@ -456,70 +470,71 @@ export declare namespace Commander { : [Eff] extends [YieldWrap>] ? R : never >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E, - f: (_: E, ...args: NoInfer) => F, - g: (_: F, ...args: NoInfer) => G, - h: (_: G, ...args: NoInfer) => H, - i: (_: H, ...args: NoInfer) => I - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + f: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + g: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + h: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => H, + i: (_: H, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => I + ): CommandOutHelper } export type NonGen = { < Eff extends Effect.Effect, - Args extends Array + Arg = void >( - body: (...args: Args) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, B, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => B, - b: (_: B, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, B, C, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, B, C, D, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, @@ -527,15 +542,15 @@ export declare namespace Commander { C, D, E, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, @@ -544,16 +559,16 @@ export declare namespace Commander { D, E, F, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => F, - f: (_: F, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + f: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, @@ -563,17 +578,17 @@ export declare namespace Commander { E, F, G, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => F, - f: (_: F, ...args: NoInfer) => G, - g: (_: G, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + f: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + g: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, @@ -584,18 +599,18 @@ export declare namespace Commander { F, G, H, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => F, - f: (_: F, ...args: NoInfer) => G, - g: (_: G, ...args: NoInfer) => H, - h: (_: H, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + f: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + g: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => H, + h: (_: H, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, A, @@ -607,33 +622,33 @@ export declare namespace Commander { G, H, I, - Args extends Array + Arg = void >( - body: (...args: Args) => A, - a: (_: A, ...args: NoInfer) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => F, - f: (_: F, ...args: NoInfer) => G, - g: (_: G, ...args: NoInfer) => H, - h: (_: H, ...args: NoInfer) => I, - i: (_: H, ...args: NoInfer) => Eff - ): CommandOutHelper + body: (arg: Arg, ctx: CommandContextLocal2) => A, + a: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + f: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + g: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => H, + h: (_: H, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => I, + i: (_: H, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper } export type GenWrap< RT, Id extends string, I18nKey extends string, - Args extends Array, + Arg, AEff, EEff, REff, State extends IntlRecord | undefined > = { (): Exclude extends never ? CommandOut< - Args, + Arg, AEff, EEff, REff, @@ -651,9 +666,10 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A - ): CommandOutHelper + ): CommandOutHelper < A, B extends Effect.Effect @@ -664,10 +680,11 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B + ): CommandOutHelper < A, B, @@ -679,11 +696,12 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C + ): CommandOutHelper < A, B, @@ -696,12 +714,13 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D + ): CommandOutHelper < A, B, @@ -715,13 +734,14 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E + ): CommandOutHelper < A, B, @@ -736,14 +756,15 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E, - f: (_: E, ...args: NoInfer) => F - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + f: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F + ): CommandOutHelper < A, B, @@ -759,15 +780,16 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E, - f: (_: E, ...args: NoInfer) => F, - g: (_: F, ...args: NoInfer) => G - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + f: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + g: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G + ): CommandOutHelper >( a: ( _: Effect.Effect< @@ -775,16 +797,17 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E, - f: (_: E, ...args: NoInfer) => F, - g: (_: F, ...args: NoInfer) => G, - h: (_: G, ...args: NoInfer) => H - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + f: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + g: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + h: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => H + ): CommandOutHelper >( a: ( _: Effect.Effect< @@ -792,34 +815,35 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => A, - b: (_: A, ...args: NoInfer) => B, - c: (_: B, ...args: NoInfer) => C, - d: (_: C, ...args: NoInfer) => D, - e: (_: D, ...args: NoInfer) => E, - f: (_: E, ...args: NoInfer) => F, - g: (_: F, ...args: NoInfer) => G, - h: (_: G, ...args: NoInfer) => H, - i: (_: H, ...args: NoInfer) => I - ): CommandOutHelper + b: (_: A, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => B, + c: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + d: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + e: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + f: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + g: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + h: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => H, + i: (_: H, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => I + ): CommandOutHelper } export type NonGenWrap< RT, Id extends string, I18nKey extends string, - Args extends Array, + Arg, AEff, EEff, REff, State extends IntlRecord | undefined > = { - (): Exclude extends never ? CommandOutHelper, Id, I18nKey, State> + (): Exclude extends never ? CommandOutHelper, Id, I18nKey, State> : MissingDependencies & {} < Eff extends Effect.Effect, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -827,13 +851,14 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => Eff - ): CommandOutHelper + ): CommandOutHelper < Eff extends Effect.Effect, B, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -841,15 +866,16 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => B, - b: (_: B, ...args: NoInfer) => Eff - ): CommandOutHelper + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, B, C, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -857,17 +883,18 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => Eff - ): CommandOutHelper + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, B, C, D, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -875,19 +902,20 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => Eff - ): CommandOutHelper + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, B, C, D, E, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -895,13 +923,14 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => Eff - ): CommandOutHelper + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, B, @@ -909,7 +938,7 @@ export declare namespace Commander { D, E, F, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -917,14 +946,15 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => F, - f: (_: F, ...args: NoInfer) => Eff - ): CommandOutHelper + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + f: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, B, @@ -933,7 +963,7 @@ export declare namespace Commander { E, F, G, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -941,15 +971,16 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => F, - f: (_: F, ...args: NoInfer) => G, - g: (_: G, ...args: NoInfer) => Eff - ): CommandOutHelper + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + f: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + g: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, B, @@ -959,7 +990,7 @@ export declare namespace Commander { F, G, H, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -967,16 +998,17 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => F, - f: (_: F, ...args: NoInfer) => G, - g: (_: G, ...args: NoInfer) => H, - h: (_: H, ...args: NoInfer) => Eff - ): CommandOutHelper + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + f: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + g: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => H, + h: (_: H, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper < Eff extends Effect.Effect, B, @@ -987,7 +1019,7 @@ export declare namespace Commander { G, H, I, - Args extends Array + Arg >( a: ( _: Effect.Effect< @@ -995,17 +1027,18 @@ export declare namespace Commander { EEff, REff >, - ...args: NoInfer + arg: NoInfer, + ctx: CommandContextLocal2, NoInfer, NoInfer> ) => B, - b: (_: B, ...args: NoInfer) => C, - c: (_: C, ...args: NoInfer) => D, - d: (_: D, ...args: NoInfer) => E, - e: (_: E, ...args: NoInfer) => F, - f: (_: F, ...args: NoInfer) => G, - g: (_: G, ...args: NoInfer) => H, - h: (_: H, ...args: NoInfer) => I, - i: (_: H, ...args: NoInfer) => Eff - ): CommandOutHelper + b: (_: B, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => C, + c: (_: C, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => D, + d: (_: D, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => E, + e: (_: E, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => F, + f: (_: F, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => G, + g: (_: G, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => H, + h: (_: H, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => I, + i: (_: H, arg: NoInfer, ctx: CommandContextLocal2, NoInfer, NoInfer>) => Eff + ): CommandOutHelper } } @@ -1308,8 +1341,8 @@ export class CommanderImpl { const state = getStateValues(options) return Object.assign( - , A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>( - handler: (...args: Args) => Effect.Effect + ( + handler: (arg: Arg, ctx: Commander.CommandContextLocal2) => Effect.Effect ) => { // we capture the definition stack here, so we can append it to later stack traces const limit = Error.stackTraceLimit @@ -1387,7 +1420,7 @@ export class CommanderImpl { const exec = options?.disableSharedWaiting ? exec_ : Effect - .fnUntraced(function*(...args: Args) { + .fnUntraced(function*(...args: [any, any]) { registerWait(id) return yield* exec_(...args) }, Effect.onExit(() => Effect.sync(() => unregisterWait(id)))) @@ -1396,7 +1429,7 @@ export class CommanderImpl { ? computed(() => result.value.waiting) : computed(() => result.value.waiting || (waitState.value[id] ?? 0) > 0) - const handle = Object.assign((...args: Args) => { + const handle = Object.assign((arg: Arg) => { // we capture the call site stack here const limit = Error.stackTraceLimit Error.stackTraceLimit = 2 @@ -1429,12 +1462,12 @@ export class CommanderImpl { const command = currentState.pipe(Effect.flatMap((state) => Effect.withSpan( - exec(...args), + exec(arg, { ...context.value, state } as any), id, { captureStackTrace, attributes: { - input: args, + input: arg, state, action: initialContext.action, label: initialContext.label, @@ -1595,10 +1628,10 @@ export class CommanderImpl { } ) - /** @experimental */ + /** @experimental @deprecated */ alt2: < const Id extends string, - MutArgs extends Array, + MutArg, MutA, MutE, MutR, @@ -1607,19 +1640,19 @@ export class CommanderImpl { >( id: | Id - | { id: Id; mutate: (...args: MutArgs) => Effect.Effect } - | ((...args: MutArgs) => Effect.Effect) & { id: Id }, + | { id: Id; mutate: (arg: MutArg) => Effect.Effect } + | ((arg: MutArg) => Effect.Effect) & { id: Id }, options?: FnOptions ) => & Commander.CommandContextLocal - & (, A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>( + & (( handler: ( ctx: Effect.fn.Gen & Effect.fn.NonGen & Commander.CommandContextLocal & { // todo: only if we passed in one - mutate: (...args: MutArgs) => Effect.Effect + mutate: (arg: Arg) => Effect.Effect } - ) => (...args: Args) => Effect.Effect - ) => Commander.CommandOut) = ( + ) => (arg: Arg, ctx: Commander.CommandContextLocal2) => Effect.Effect + ) => Commander.CommandOut) = ( _id, options? ) => { @@ -1657,9 +1690,9 @@ export class CommanderImpl { customI18nKey?: I18nKey ) => & Commander.CommandContextLocal - & (, A, E, R extends RT | CommandContext | `Commander.Command.${Id}.state`>( - handler: (...args: Args) => Effect.Effect - ) => Commander.CommandOut) + & (( + handler: (arg: Arg, ctx: Commander.CommandContextLocal2) => Effect.Effect + ) => Commander.CommandOut) /** * Define a Command for handling user actions with built-in error reporting and state management. @@ -1690,7 +1723,7 @@ export class CommanderImpl { */ wrap = < const Id extends string, - Args extends Array, + Arg, A, E, R, @@ -1698,10 +1731,10 @@ export class CommanderImpl { I18nKey extends string = Id >( mutation: - | { mutate: (...args: Args) => Effect.Effect; id: Id } - | ((...args: Args) => Effect.Effect) & { id: Id }, + | { mutate: (arg: Arg) => Effect.Effect; id: Id } + | ((arg: Arg) => Effect.Effect) & { id: Id }, options?: FnOptions - ): Commander.CommanderWrap => + ): Commander.CommanderWrap => Object.assign( ( ...combinators: any[] @@ -1717,8 +1750,8 @@ export class CommanderImpl { return this.makeCommand(mutation.id, options, errorDef)( Effect.fnUntraced( // fnUntraced only supports generators as first arg, so we convert to generator if needed - isGeneratorFunction(mutate) ? mutate : function*(...args: Args) { - return yield* mutate(...args) + isGeneratorFunction(mutate) ? mutate : function*(arg: Arg) { + return yield* mutate(arg) }, ...combinators as [any] ) as any diff --git a/packages/vue/test/Mutation.test.ts b/packages/vue/test/Mutation.test.ts index 153ddcd937..bf352e35ec 100644 --- a/packages/vue/test/Mutation.test.ts +++ b/packages/vue/test/Mutation.test.ts @@ -24,10 +24,10 @@ describe("alt2", () => { const someMutation = { id: "Test Action", - mutate: (() => {}) as unknown as (a: number, b: string) => Effect.Effect + mutate: (() => {}) as unknown as (a: number) => Effect.Effect } as const const someMutation2 = Object.assign( - (() => {}) as unknown as (a: number, b: string) => Effect.Effect, + (() => {}) as unknown as (a: number) => Effect.Effect, { id: "Test Action" } as const @@ -252,16 +252,19 @@ it.live("can receive and use input", () => let executed = false const command = Command.fn("Test Action")( - function*(input1: number, input2: string) { + function*(input1: number, input2) { expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action") return { input1, input2 } }, Effect.tap(() => executed = true) ) - const r = yield* unwrap(command.handle(1, "2")) + const r = yield* unwrap(command.handle(1)) - expect(r).toEqual({ input1: 1, input2: "2" }) // to confirm that the initial function has ran and received input. + expect(r.input1).toBe(1) // to confirm that the initial function has ran and received input. + const { handle, result, waiting, ...rest } = command + const ctx = { ...rest, state: undefined } + expect(JSON.stringify(r.input2)).equal(JSON.stringify(ctx)) expect(executed).toBe(true) // to confirm that the combinators have ran. })) @@ -547,19 +550,25 @@ it.live("can receive and use input with alt", () => let executed = false - const command = Command.alt("Test Action")( - Effect.fnUntraced( - function*(input1: number, input2: string) { - expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action") + const command = Command.alt("Test Action")((input1: number, input2) => + Effect + .gen( + function*() { + expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action") - return { input1, input2 } - }, - Effect.tap(() => executed = true) - ) + return { input1, input2 } + } + ) + .pipe( + Effect.tap(() => executed = true) + ) ) - const r = yield* unwrap(command.handle(1, "2")) + const r = yield* unwrap(command.handle(1)) - expect(r).toEqual({ input1: 1, input2: "2" }) // to confirm that the initial function has ran and received input. + const { handle, result, waiting, ...rest } = command + const ctx = { ...rest, state: undefined } + expect(r.input1).toBe(1) + expect(JSON.stringify(r.input2)).equal(JSON.stringify(ctx)) // to confirm that the initial function has ran and received input. expect(executed).toBe(true) // to confirm that the combinators have ran. })) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c0a9d9ac49..c82f17bf9e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -67,6 +67,9 @@ importers: '@effect/platform-node': specifier: ^0.98.0 version: 0.98.0(@effect/cluster@0.46.4(75de7a998cf2258bdcd42684c0598ed2))(@effect/platform@0.92.0(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a)))(@effect/rpc@0.71.0(@effect/platform@0.92.0(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a)))(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a)))(@effect/sql@0.46.0(@effect/experimental@0.56.0(@effect/platform@0.92.0(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a)))(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a)))(@effect/platform@0.92.0(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a)))(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a)))(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a)) + '@effect/vitest': + specifier: ^0.26.0 + version: 0.26.0(effect@3.18.0(patch_hash=43c3b64130695b34e77e33c4bce41699657064974a32b770f14bbeefe69bf30a))(vitest@3.2.4(@types/node@24.6.0)(jsdom@27.0.0(postcss@8.5.6))(sass@1.93.2)(terser@5.44.0)(tsx@4.20.6)(yaml@2.8.1)) '@tsconfig/strictest': specifier: ^2.0.6 version: 2.0.6 diff --git a/vite.config.base.ts b/vite.config.base.ts index 223b137861..7586a0d532 100644 --- a/vite.config.base.ts +++ b/vite.config.base.ts @@ -12,6 +12,7 @@ import fs from "fs" // ] // }) + export default function makeConfig(dirName?: string) { const prefix = path.resolve(__dirname, "packages") const packages = fs.readdirSync(prefix).map(f => prefix + "/" + f).filter(f => fs.lstatSync(f).isDirectory() ) @@ -21,7 +22,8 @@ export default function makeConfig(dirName?: string) { test: { include: ["./test/**/*.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], reporters: "verbose", - globals: true + globals: true, + setupFiles: [path.join(__dirname, "vitest.setup.ts")], }, resolve: { alias: packages.map(pkg => ({ pkg, json: pkg + "/package.json"})).filter(_ => fs.existsSync(_.json)).reduce((acc, { pkg, json}) => { diff --git a/vitest.setup.ts b/vitest.setup.ts new file mode 100644 index 0000000000..7c3c6dccbc --- /dev/null +++ b/vitest.setup.ts @@ -0,0 +1,3 @@ +import { addEqualityTesters } from "@effect/vitest" + +addEqualityTesters() \ No newline at end of file