@effect-app/vue 4.0.0-beta.98 → 4.0.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.
- package/CHANGELOG.md +2707 -0
- package/dist/atomQuery.d.ts +120 -0
- package/dist/atomQuery.d.ts.map +1 -0
- package/dist/atomQuery.js +434 -0
- package/dist/commander.d.ts +318 -43
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +593 -81
- package/dist/confirm.d.ts +5 -3
- package/dist/confirm.d.ts.map +1 -1
- package/dist/confirm.js +12 -14
- package/dist/dependencyMetadata.d.ts +18 -0
- package/dist/dependencyMetadata.d.ts.map +1 -0
- package/dist/dependencyMetadata.js +67 -0
- package/dist/errorReporter.d.ts +6 -4
- package/dist/errorReporter.d.ts.map +1 -1
- package/dist/errorReporter.js +14 -19
- package/dist/form.d.ts +5 -5
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +16 -10
- package/dist/internal/tanstackQuery.d.ts +9 -0
- package/dist/internal/tanstackQuery.d.ts.map +1 -0
- package/dist/internal/tanstackQuery.js +204 -0
- package/dist/intl.d.ts +4 -4
- package/dist/intl.d.ts.map +1 -1
- package/dist/intl.js +2 -2
- package/dist/lib.d.ts +8 -10
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +37 -12
- package/dist/liveQueryInvalidation.d.ts +16 -0
- package/dist/liveQueryInvalidation.d.ts.map +1 -0
- package/dist/liveQueryInvalidation.js +115 -0
- package/dist/makeClient.d.ts +232 -109
- package/dist/makeClient.d.ts.map +1 -1
- package/dist/makeClient.js +416 -84
- package/dist/makeContext.d.ts.map +1 -1
- package/dist/makeIntl.d.ts.map +1 -1
- package/dist/makeUseCommand.d.ts +3 -2
- package/dist/makeUseCommand.d.ts.map +1 -1
- package/dist/makeUseCommand.js +2 -2
- package/dist/mutate.d.ts +110 -41
- package/dist/mutate.d.ts.map +1 -1
- package/dist/mutate.js +236 -59
- package/dist/query.d.ts +161 -44
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +382 -113
- package/dist/queryLifetime.d.ts +25 -0
- package/dist/queryLifetime.d.ts.map +1 -0
- package/dist/queryLifetime.js +54 -0
- package/dist/routeParams.d.ts +4 -4
- package/dist/routeParams.d.ts.map +1 -1
- package/dist/routeParams.js +4 -3
- package/dist/runtime.d.ts +1 -17
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +2 -38
- package/dist/suspense.d.ts +19 -0
- package/dist/suspense.d.ts.map +1 -0
- package/dist/suspense.js +38 -0
- package/dist/toast.d.ts +1 -45
- package/dist/toast.d.ts.map +1 -1
- package/dist/toast.js +2 -32
- package/dist/withToast.d.ts +1 -24
- package/dist/withToast.d.ts.map +1 -1
- package/dist/withToast.js +2 -45
- package/docs/atom-query-api-redesign.md +207 -0
- package/docs/mutation-command-atoms.md +40 -0
- package/docs/query-key-invalidation.md +107 -0
- package/examples/streamMutation.ts +72 -0
- package/package.json +35 -94
- package/src/atomQuery.ts +600 -0
- package/src/commander.ts +1064 -116
- package/src/confirm.ts +12 -14
- package/src/dependencyMetadata.ts +84 -0
- package/src/errorReporter.ts +65 -75
- package/src/form.ts +22 -15
- package/src/index.ts +7 -7
- package/src/internal/tanstackQuery.ts +308 -0
- package/src/intl.ts +2 -2
- package/src/lib.ts +51 -23
- package/src/liveQueryInvalidation.ts +138 -0
- package/src/makeClient.ts +972 -263
- package/src/makeIntl.ts +2 -2
- package/src/makeUseCommand.ts +8 -5
- package/src/mutate.ts +407 -154
- package/src/query.ts +758 -242
- package/src/queryLifetime.ts +74 -0
- package/src/routeParams.ts +7 -7
- package/src/runtime.ts +1 -54
- package/src/suspense.ts +43 -0
- package/src/toast.ts +1 -52
- package/src/withToast.ts +1 -99
- package/test/Mutation.test.ts +104 -17
- package/test/dependencyInvalidation.test.ts +444 -0
- package/test/dist/dependencyInvalidation.test.d.ts.map +1 -0
- package/test/dist/form.test.d.ts.map +1 -1
- package/test/dist/inactiveInvalidation.test.d.ts.map +1 -0
- package/test/dist/interrupt-refetch-repro.test.d.ts.map +1 -0
- package/test/dist/lib.test.d.ts.map +1 -0
- package/test/dist/liveQueryInvalidation.test.d.ts.map +1 -0
- package/test/dist/query-span.test.d.ts.map +1 -0
- package/test/dist/queryOptions.test.d.ts.map +1 -0
- package/test/dist/streamFinal.test.d.ts.map +1 -0
- package/test/dist/streamFn.test.d.ts.map +1 -0
- package/test/dist/stubs.d.ts +3681 -256
- package/test/dist/stubs.d.ts.map +1 -1
- package/test/dist/stubs.js +166 -25
- package/test/dist/suspense-regression.test.d.ts.map +1 -0
- package/test/dist/suspense.test.d.ts.map +1 -0
- package/test/form-validation-errors.test.ts +2 -1
- package/test/form.test.ts +2 -1
- package/test/inactiveInvalidation.test.ts +172 -0
- package/test/interrupt-refetch-repro.test.ts +625 -0
- package/test/lib.test.ts +240 -0
- package/test/liveQueryInvalidation.test.ts +108 -0
- package/test/makeClient.test.ts +414 -32
- package/test/query-span.test.ts +92 -0
- package/test/queryOptions.test.ts +88 -0
- package/test/streamFinal.test.ts +64 -0
- package/test/streamFn.test.ts +457 -0
- package/test/stubs.ts +194 -36
- package/test/suspense-regression.test.ts +168 -0
- package/test/suspense.test.ts +160 -0
- package/tsconfig.examples.json +20 -0
- package/tsconfig.json +9 -1
- package/tsconfig.src.json +34 -34
- package/tsconfig.test.json +2 -2
- package/vitest.config.ts +5 -5
- package/eslint.config.mjs +0 -24
- package/tsconfig.json.bak +0 -12
package/dist/commander.d.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
import { type MissingDependencies } from "@effect-app/vue";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { type MissingDependencies } from "@effect-app/vue/makeClient";
|
|
2
|
+
import * as Context from "effect-app/Context";
|
|
3
|
+
import * as Effect from "effect-app/Effect";
|
|
4
|
+
import * as Layer from "effect-app/Layer";
|
|
5
|
+
import * as Option from "effect-app/Option";
|
|
6
|
+
import type * as Exit from "effect/Exit";
|
|
7
|
+
import type * as Fiber from "effect/Fiber";
|
|
8
|
+
import * as Predicate from "effect/Predicate";
|
|
9
|
+
import { type Refinement } from "effect/Predicate";
|
|
10
|
+
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
11
|
+
import * as Stream from "effect/Stream";
|
|
4
12
|
import { type FormatXMLElementFn, type PrimitiveType } from "intl-messageformat";
|
|
5
13
|
import { type ComputedRef } from "vue";
|
|
6
14
|
import { Confirm } from "./confirm.js";
|
|
7
15
|
import { I18n } from "./intl.js";
|
|
16
|
+
import { Toast } from "./toast.js";
|
|
8
17
|
import { WithToast } from "./withToast.js";
|
|
9
18
|
type IntlRecord = Record<string, PrimitiveType | FormatXMLElementFn<string, string>>;
|
|
19
|
+
/**
|
|
20
|
+
* Progress information surfaced by a stream command. Either a plain text label
|
|
21
|
+
* or a `{ text, percentage }` pair when concrete progress is known.
|
|
22
|
+
*/
|
|
23
|
+
export type Progress = string | {
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly percentage: number;
|
|
26
|
+
};
|
|
10
27
|
type FnOptions<Id extends string, I18nCustomKey extends string, State extends IntlRecord | undefined> = {
|
|
11
28
|
i18nCustomKey?: I18nCustomKey;
|
|
12
29
|
/**
|
|
@@ -63,6 +80,34 @@ declare const CommandContext_base: Context.ServiceClass<CommandContext, "Command
|
|
|
63
80
|
}>;
|
|
64
81
|
export declare class CommandContext extends CommandContext_base {
|
|
65
82
|
}
|
|
83
|
+
declare const CommandProgress_base: Context.Reference<{
|
|
84
|
+
readonly update: (progress: Progress | undefined) => Effect.Effect<void>;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Service available inside `streamFn` stream handlers that lets you imperatively push
|
|
88
|
+
* progress updates to the command's reactive `progress` ref.
|
|
89
|
+
*
|
|
90
|
+
* Use `Command.mapProgress(fn)` or `Command.updateProgress(progress)` to interact with this service.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* // Using mapProgress (recommended) — applied as a stream pipe operator:
|
|
95
|
+
* const exportCmd = Command.streamFn("exportData")(
|
|
96
|
+
* function*(arg, ctx) {
|
|
97
|
+
* return makeExportStream(arg.id).pipe(
|
|
98
|
+
* Command.mapProgress((r) =>
|
|
99
|
+
* AsyncResult.isSuccess(r) && r.value._tag === "OperationProgress"
|
|
100
|
+
* ? { text: `${r.value.completed}/${r.value.total}`, percentage: r.value.completed / r.value.total * 100 }
|
|
101
|
+
* : undefined
|
|
102
|
+
* )
|
|
103
|
+
* )
|
|
104
|
+
* }
|
|
105
|
+
* )
|
|
106
|
+
* // exportCmd.progress is updated for every OperationProgress event
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare class CommandProgress extends CommandProgress_base {
|
|
110
|
+
}
|
|
66
111
|
export type EmitWithCallback<A, Event extends string> = (event: Event, value: A, onDone: () => void) => void;
|
|
67
112
|
/**
|
|
68
113
|
* Use to wrap emit calls with a callback to signal completion.
|
|
@@ -70,6 +115,14 @@ export type EmitWithCallback<A, Event extends string> = (event: Event, value: A,
|
|
|
70
115
|
*/
|
|
71
116
|
export declare const wrapEmit: <A, Event extends string>(emit: EmitWithCallback<A, NoInfer<Event>>, event: Event) => (value: A) => Promise<void>;
|
|
72
117
|
export declare namespace Commander {
|
|
118
|
+
type IntlRecord = Record<string, PrimitiveType | FormatXMLElementFn<string, string>>;
|
|
119
|
+
type FnOptions<Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = {
|
|
120
|
+
i18nCustomKey?: I18nKey;
|
|
121
|
+
state?: ComputedRef<State> | (() => State);
|
|
122
|
+
blockKey?: (id: Id) => string | undefined;
|
|
123
|
+
waitKey?: (id: Id) => string | undefined;
|
|
124
|
+
allowed?: (id: Id, state: ComputedRef<State>) => boolean;
|
|
125
|
+
};
|
|
73
126
|
type CommanderBase<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = Gen<RT, Id, I18nKey, State> & NonGen<RT, Id, I18nKey, State> & CommandContextLocal<Id, I18nKey> & {
|
|
74
127
|
state: Context.Service<`Commander.Command.${Id}.state`, State>;
|
|
75
128
|
};
|
|
@@ -89,7 +142,12 @@ export declare namespace Commander {
|
|
|
89
142
|
/** reactive */
|
|
90
143
|
label: string;
|
|
91
144
|
/** reactive */
|
|
92
|
-
result: AsyncResult<A, E>;
|
|
145
|
+
result: AsyncResult.AsyncResult<A, E>;
|
|
146
|
+
/**
|
|
147
|
+
* reactive – formatted progress info driven by `Command.mapProgress` or `Command.updateProgress`
|
|
148
|
+
* inside a `streamFn` handler. Undefined for non-stream commands.
|
|
149
|
+
*/
|
|
150
|
+
progress: Progress | undefined;
|
|
93
151
|
/** reactive */
|
|
94
152
|
waiting: boolean;
|
|
95
153
|
/** reactive */
|
|
@@ -102,7 +160,7 @@ export declare namespace Commander {
|
|
|
102
160
|
interface CommandOut<Arg, A, E, R, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> extends CommandProps<A, E, Id, I18nKey, State> {
|
|
103
161
|
new (): {};
|
|
104
162
|
/** click handlers */
|
|
105
|
-
handle: ((arg: Arg) => Fiber.Fiber<Exit.Exit<A, E
|
|
163
|
+
handle: ((arg: Arg) => Fiber.Fiber<Exit.Exit<A, E>>) & {
|
|
106
164
|
/** @deprecated don't exist */
|
|
107
165
|
effect: (arg: Arg) => Effect.Effect<A, E, R>;
|
|
108
166
|
};
|
|
@@ -113,56 +171,56 @@ export declare namespace Commander {
|
|
|
113
171
|
type ArgForCombinator<Arg> = [Arg] extends [void] ? undefined : NoInfer<Arg>;
|
|
114
172
|
type CommandOutHelper<Arg, Eff extends Effect.Effect<any, any, any>, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = CommandOut<Arg, Effect.Success<Eff>, Effect.Error<Eff>, Effect.Services<Eff>, Id, I18nKey, State>;
|
|
115
173
|
type Gen<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = {
|
|
116
|
-
<Eff extends Effect.
|
|
174
|
+
<Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, AEff, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>): CommandOut<Arg, AEff, [
|
|
117
175
|
Eff
|
|
118
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
176
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
119
177
|
Eff
|
|
120
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
121
|
-
<Eff extends Effect.
|
|
178
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never, Id, I18nKey, State>;
|
|
179
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
122
180
|
Eff
|
|
123
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
181
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
124
182
|
Eff
|
|
125
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
126
|
-
<Eff extends Effect.
|
|
183
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A): CommandOutHelper<Arg, A, Id, I18nKey, State>;
|
|
184
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A, B extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
127
185
|
Eff
|
|
128
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
186
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
129
187
|
Eff
|
|
130
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
131
|
-
<Eff extends Effect.
|
|
188
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A, b: (_: A, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B): CommandOutHelper<Arg, B, Id, I18nKey, State>;
|
|
189
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A, B, C extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
132
190
|
Eff
|
|
133
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
191
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
134
192
|
Eff
|
|
135
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
136
|
-
<Eff extends Effect.
|
|
193
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A, b: (_: A, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, c: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C): CommandOutHelper<Arg, C, Id, I18nKey, State>;
|
|
194
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A, B, C, D extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
137
195
|
Eff
|
|
138
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
196
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
139
197
|
Eff
|
|
140
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
141
|
-
<Eff extends Effect.
|
|
198
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A, b: (_: A, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, c: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, d: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D): CommandOutHelper<Arg, D, Id, I18nKey, State>;
|
|
199
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A, B, C, D, E extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
142
200
|
Eff
|
|
143
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
201
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
144
202
|
Eff
|
|
145
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
146
|
-
<Eff extends Effect.
|
|
203
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A, b: (_: A, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, c: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, d: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D, e: (_: D, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E): CommandOutHelper<Arg, E, Id, I18nKey, State>;
|
|
204
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A, B, C, D, E, F extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
147
205
|
Eff
|
|
148
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
206
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
149
207
|
Eff
|
|
150
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
151
|
-
<Eff extends Effect.
|
|
208
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A, b: (_: A, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, c: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, d: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D, e: (_: D, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E, f: (_: E, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F): CommandOutHelper<Arg, F, Id, I18nKey, State>;
|
|
209
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A, B, C, D, E, F, G extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
152
210
|
Eff
|
|
153
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
211
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
154
212
|
Eff
|
|
155
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
156
|
-
<Eff extends Effect.
|
|
213
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A, b: (_: A, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, c: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, d: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D, e: (_: D, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E, f: (_: E, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F, g: (_: F, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G): CommandOutHelper<Arg, G, Id, I18nKey, State>;
|
|
214
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A, B, C, D, E, F, G, H extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
157
215
|
Eff
|
|
158
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
216
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
159
217
|
Eff
|
|
160
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
161
|
-
<Eff extends Effect.
|
|
218
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A, b: (_: A, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, c: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, d: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D, e: (_: D, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E, f: (_: E, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F, g: (_: F, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G, h: (_: G, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H): CommandOutHelper<Arg, H, Id, I18nKey, State>;
|
|
219
|
+
<Eff extends Effect.Effect<any, any, any>, AEff, A, B, C, D, E, F, G, H, I extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, AEff, never>, a: (_: Effect.Effect<AEff, [
|
|
162
220
|
Eff
|
|
163
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
221
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [
|
|
164
222
|
Eff
|
|
165
|
-
] extends [never] ? never : [Eff] extends [Effect.
|
|
223
|
+
] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A, b: (_: A, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, c: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, d: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D, e: (_: D, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E, f: (_: E, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F, g: (_: F, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G, h: (_: G, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H, i: (_: H, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => I): CommandOutHelper<Arg, I, Id, I18nKey, State>;
|
|
166
224
|
};
|
|
167
225
|
type NonGen<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = {
|
|
168
226
|
<Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Eff): CommandOutHelper<Arg, Eff, Id, I18nKey, State>;
|
|
@@ -200,20 +258,109 @@ export declare namespace Commander {
|
|
|
200
258
|
<Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, B, C, D, E, F, G, H, Arg>(a: (_: Effect.Effect<AEff, EEff, REff>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, b: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, c: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D, d: (_: D, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E, e: (_: E, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F, f: (_: F, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G, g: (_: G, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H, h: (_: H, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff): CommandOutHelper<Arg, Eff, Id, I18nKey, State>;
|
|
201
259
|
<Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, B, C, D, E, F, G, H, I, Arg>(a: (_: Effect.Effect<AEff, EEff, REff>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, b: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, c: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D, d: (_: D, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E, e: (_: E, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F, f: (_: F, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G, g: (_: G, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H, h: (_: H, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => I, i: (_: H, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => Eff): CommandOutHelper<Arg, Eff, Id, I18nKey, State>;
|
|
202
260
|
};
|
|
261
|
+
/**
|
|
262
|
+
* Type for `streamFn` — generator overload where the body yields Effects and returns a `Stream`.
|
|
263
|
+
* `waiting` stays `true` while the stream is running, and updates the `result` ref per emitted value.
|
|
264
|
+
*/
|
|
265
|
+
type StreamGen<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = {
|
|
266
|
+
<Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, SA, SE, SR, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, Stream.Stream<SA, SE, SR>, never>): CommandOut<Arg, SA, SE | ([Eff] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never), SR | ([Eff] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never), Id, I18nKey, State>;
|
|
267
|
+
<Eff extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, SA, SE, SR, B, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Generator<Eff, Stream.Stream<SA, SE, SR>, never>, a: (_: Effect.Effect<Stream.Stream<SA, SE, SR>, ([Eff] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never), ([Eff] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never)>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B): B extends Stream.Stream<infer SA2, infer SE2, infer SR2> ? CommandOut<Arg, SA2, SE2, SR2, Id, I18nKey, State> : B extends Effect.Effect<Stream.Stream<infer SA2, infer SE2, infer SR2>, infer EE2, infer ER2> ? CommandOut<Arg, SA2, SE2 | EE2, SR2 | ER2, Id, I18nKey, State> : never;
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Type for `streamFn` — non-generator overload accepting a function that returns a `Stream` directly,
|
|
271
|
+
* or an `Effect` that resolves to a `Stream`.
|
|
272
|
+
*/
|
|
273
|
+
type NonGenStream<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = {
|
|
274
|
+
<SA, SE, SR extends RT | CommandContext | `Commander.Command.${Id}.state`, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Stream.Stream<SA, SE, SR>): CommandOut<Arg, SA, SE, SR, Id, I18nKey, State>;
|
|
275
|
+
<SA, SE, SR, A extends Stream.Stream<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Stream.Stream<SA, SE, SR>, a: (_: Stream.Stream<SA, SE, SR>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A): CommandOut<Arg, Stream.Success<A>, Stream.Error<A>, Stream.Services<A>, Id, I18nKey, State>;
|
|
276
|
+
<SA, SE, SR, EE, ER extends RT | CommandContext | `Commander.Command.${Id}.state`, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Effect.Effect<Stream.Stream<SA, SE, SR>, EE, ER>): CommandOut<Arg, SA, SE | EE, SR | ER, Id, I18nKey, State>;
|
|
277
|
+
<SA, SE, SR, EE, ER, B, Arg = void>(body: (arg: Arg, ctx: CommandContextLocal2<Id, I18nKey, State>) => Effect.Effect<Stream.Stream<SA, SE, SR>, EE, ER>, a: (_: Effect.Effect<Stream.Stream<SA, SE, SR>, EE, ER>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B): B extends Stream.Stream<infer SA2, infer SE2, infer SR2> ? CommandOut<Arg, SA2, SE2, SR2, Id, I18nKey, State> : B extends Effect.Effect<Stream.Stream<infer SA2, infer SE2, infer SR2>, infer EE2, infer ER2> ? CommandOut<Arg, SA2, SE2 | EE2, SR2 | ER2, Id, I18nKey, State> : never;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Type returned by `mutate.wrap` on a stream handler — analogous to `CommanderWrap` but for streams.
|
|
281
|
+
* The handler is pre-baked (from the stream mutation), so this is called with only optional combinators.
|
|
282
|
+
*/
|
|
283
|
+
type StreamerWrap<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined, Arg, SA, SE, SR> = CommandContextLocal<Id, I18nKey> & {
|
|
284
|
+
readonly state: Context.Service<`Commander.Command.${Id}.state`, State>;
|
|
285
|
+
} & {
|
|
286
|
+
(): Exclude<SR, RT> extends never ? CommandOut<Arg, SA, SE, SR, Id, I18nKey, State> : MissingDependencies<RT, SR> & {};
|
|
287
|
+
<A extends Stream.Stream<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(a: (_: Stream.Stream<SA, SE, SR>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A): CommandOut<Arg, Stream.Success<A>, Stream.Error<A>, Stream.Services<A>, Id, I18nKey, State>;
|
|
288
|
+
<B, A extends Stream.Stream<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(a: (_: Stream.Stream<SA, SE, SR>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, b: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A): CommandOut<Arg, Stream.Success<A>, Stream.Error<A>, Stream.Services<A>, Id, I18nKey, State>;
|
|
289
|
+
<B, C, A extends Stream.Stream<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(a: (_: Stream.Stream<SA, SE, SR>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, b: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, c: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A): CommandOut<Arg, Stream.Success<A>, Stream.Error<A>, Stream.Services<A>, Id, I18nKey, State>;
|
|
290
|
+
<B, C, D, A extends Stream.Stream<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>(a: (_: Stream.Stream<SA, SE, SR>, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B, b: (_: B, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C, c: (_: C, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D, d: (_: D, arg: ArgForCombinator<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => A): CommandOut<Arg, Stream.Success<A>, Stream.Error<A>, Stream.Services<A>, Id, I18nKey, State>;
|
|
291
|
+
};
|
|
203
292
|
}
|
|
204
293
|
type ErrorRenderer<E, Args extends readonly any[]> = (e: E, action: string, ...args: Args) => string | undefined;
|
|
294
|
+
type RegisteredErrorRenderer<A> = {
|
|
295
|
+
guard: Refinement<unknown, A>;
|
|
296
|
+
render: (guarded: A) => string | undefined;
|
|
297
|
+
};
|
|
298
|
+
declare const CommanderErrorRenderers_base: Context.Reference<RegisteredErrorRenderer<any>[]>;
|
|
299
|
+
export declare class CommanderErrorRenderers extends CommanderErrorRenderers_base {
|
|
300
|
+
}
|
|
301
|
+
export declare const makeRegisteredErrorRenderer: <A>(guard: Predicate.Refinement<unknown, A>, render: (guarded: A) => string | undefined) => RegisteredErrorRenderer<A>;
|
|
205
302
|
export declare const CommanderStatic: {
|
|
206
303
|
accessArgs: <In, Out, Arg2, Arg = void>(cb: (a: NoInfer<Arg>, b: NoInfer<Arg2>) => (self: NoInfer<In>) => Out) => (self: In, arg: Arg, arg2: Arg2) => Out;
|
|
304
|
+
/**
|
|
305
|
+
* Stream pipe operator that maps each emitted value to a `Progress` entry and updates the
|
|
306
|
+
* command's reactive `progress` ref via the `CommandProgress` service.
|
|
307
|
+
*
|
|
308
|
+
* The mapper receives an `AsyncResult<A, E>` (each emitted value wrapped as
|
|
309
|
+
* `AsyncResult.success(value, { waiting: true })`), matching the same shape used by
|
|
310
|
+
* `CommandButton`'s `:progress-map` prop.
|
|
311
|
+
*
|
|
312
|
+
* Designed to be used inside a `streamFn` handler (either directly with `.pipe()`, or as
|
|
313
|
+
* a combinator argument):
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* // Inside the handler body:
|
|
318
|
+
* Command.streamFn("exportData")(function*(arg, ctx) {
|
|
319
|
+
* return makeExportStream(arg.id).pipe(
|
|
320
|
+
* Command.mapProgress((r) =>
|
|
321
|
+
* AsyncResult.isSuccess(r) && r.value._tag === "OperationProgress"
|
|
322
|
+
* ? { text: `${r.value.completed}/${r.value.total}`, percentage: r.value.completed / r.value.total * 100 }
|
|
323
|
+
* : undefined
|
|
324
|
+
* )
|
|
325
|
+
* )
|
|
326
|
+
* })
|
|
327
|
+
*
|
|
328
|
+
* // Or as a stream combinator argument:
|
|
329
|
+
* Command.streamFn("exportData")(
|
|
330
|
+
* function*(arg, ctx) { return makeExportStream(arg.id) },
|
|
331
|
+
* (s) => s.pipe(Command.mapProgress((r) => AsyncResult.isSuccess(r) && r.value._tag === "OperationProgress" ? { text: `${r.value.completed}/${r.value.total}` } : undefined))
|
|
332
|
+
* )
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
mapProgress: <A, E>(fn: (result: AsyncResult.AsyncResult<A, E>) => Progress | undefined) => <R>(stream: Stream.Stream<A, E, R>) => Stream.Stream<A, E, R>;
|
|
336
|
+
/**
|
|
337
|
+
* Imperatively push a progress update from inside a `streamFn` handler.
|
|
338
|
+
* Requires `CommandProgress` to be in context — provided automatically for all `streamFn` streams.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* // In a streamFn handler:
|
|
343
|
+
* stream.pipe(
|
|
344
|
+
* Stream.tap((event) =>
|
|
345
|
+
* event._tag === "OperationProgress"
|
|
346
|
+
* ? Command.updateProgress({ text: `${event.completed}/${event.total}`, percentage: event.completed / event.total * 100 })
|
|
347
|
+
* : Effect.void
|
|
348
|
+
* )
|
|
349
|
+
* )
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
updateProgress: (progress: Progress | undefined) => Effect.Effect<void>;
|
|
207
353
|
/** Version of @see confirmOrInterrupt that automatically includes the action name in the default messages */
|
|
208
|
-
confirmOrInterrupt: (message?: string | undefined) => Effect.Effect<void, never,
|
|
354
|
+
confirmOrInterrupt: (message?: string | undefined) => Effect.Effect<void, never, CommandContext | Confirm | I18n>;
|
|
209
355
|
/** Version of @see confirm that automatically includes the action name in the default messages */
|
|
210
|
-
confirm: (message?: string | undefined) => Effect.Effect<boolean, never,
|
|
211
|
-
updateAction: <Args extends Array<unknown>>(update: (currentActionId: string, ...args: Args) => string) => <A, E, R>(_: Effect.Effect<A, E, R>, ...input: Args) => Effect.Effect<A, E,
|
|
356
|
+
confirm: (message?: string | undefined) => Effect.Effect<boolean, never, CommandContext | Confirm | I18n>;
|
|
357
|
+
updateAction: <Args extends Array<unknown>>(update: (currentActionId: string, ...args: Args) => string) => <A, E, R>(_: Effect.Effect<A, E, R>, ...input: Args) => Effect.Effect<A, E, R | CommandContext>;
|
|
358
|
+
registerErrorRenderer: <A>(guard: Predicate.Refinement<unknown, A>, render: (guarded: A) => string | undefined) => Layer.Layer<never, never, never>;
|
|
212
359
|
defaultFailureMessageHandler: <E, Args extends Array<unknown>, AME, AMR>(actionMaker: string | ((o: Option.Option<E>, ...args: Args) => string) | ((o: Option.Option<E>, ...args: Args) => Effect.Effect<string, AME, AMR>), errorRenderer?: ErrorRenderer<E, Args>) => (o: Option.Option<E>, ...args: Args) => Effect.Effect<string | {
|
|
213
360
|
level: "warn";
|
|
214
361
|
message: string;
|
|
215
|
-
}, AME,
|
|
216
|
-
renderError: Effect.Effect
|
|
362
|
+
}, AME, AMR | I18n>;
|
|
363
|
+
renderError: Effect.Effect<<E, Args extends readonly any[]>(action: string, errorRenderer?: ErrorRenderer<E, Args>) => (e: E, ...args: Args) => string, never, I18n>;
|
|
217
364
|
/**
|
|
218
365
|
* Version of withDefaultToast that automatically includes the action name in the default messages and uses intl.
|
|
219
366
|
* uses the Command id as i18n namespace. `action.{id}` is the main action name,
|
|
@@ -231,9 +378,45 @@ export declare const CommanderStatic: {
|
|
|
231
378
|
*/
|
|
232
379
|
stableToastId?: undefined | true | string | ((id: string, arg: NoInfer<Args>[0], ctx: NoInfer<Args>[1]) => true | string | undefined);
|
|
233
380
|
errorRenderer?: (e: E, action: string, arg: NoInfer<Args>[0], ctx: NoInfer<Args>[1]) => string | undefined;
|
|
381
|
+
showSpanInfo?: false;
|
|
382
|
+
onWaiting?: null | undefined | string | ((id: string, arg: NoInfer<Args>[0], ctx: NoInfer<Args>[1]) => string | null | undefined);
|
|
383
|
+
onSuccess?: null | undefined | string | ((a: A, action: string, arg: NoInfer<Args>[0], ctx: NoInfer<Args>[1]) => string | null | undefined);
|
|
384
|
+
}) => (self: Effect.Effect<A, E, R>, ...args: Args) => Effect.Effect<A, E, R | CommandContext | I18n | WithToast>;
|
|
385
|
+
/**
|
|
386
|
+
* Stream-aware version of `withDefaultToast`. Use this as a combinator inside `streamFn`
|
|
387
|
+
* (or anywhere a `Stream` needs toast lifecycle handling) instead of `withDefaultToast`.
|
|
388
|
+
*
|
|
389
|
+
* Unlike `withDefaultToast` (which only wraps the initial `Effect`), this combinator:
|
|
390
|
+
* - Shows the "waiting" toast **before** the stream starts
|
|
391
|
+
* - Updates the waiting toast with progress text when `progress` is set and a new element arrives
|
|
392
|
+
* - Shows the "success" toast only **after** the stream drains fully without error
|
|
393
|
+
* - Shows the "failure" toast if the stream errors or fails
|
|
394
|
+
*
|
|
395
|
+
* Accepts either a `Stream<A, E, R>` or an `Effect<Stream<A, E, R>, EE, ER>` as input,
|
|
396
|
+
* so it works in both the `NonGenStream` and `StreamGen` overloads of `streamFn`.
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* ```ts
|
|
400
|
+
* Command.streamFn("exportData")(
|
|
401
|
+
* function*(arg, ctx) { return makeExportStream(arg.id) },
|
|
402
|
+
* Command.withDefaultToastStream({
|
|
403
|
+
* progress: (r) =>
|
|
404
|
+
* AsyncResult.isSuccess(r) && r.value._tag === "OperationProgress"
|
|
405
|
+
* ? { text: `${r.value.completed}/${r.value.total}`, percentage: r.value.completed / r.value.total * 100 }
|
|
406
|
+
* : undefined
|
|
407
|
+
* })
|
|
408
|
+
* )
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
withDefaultToastStream: <A, E, R, Args extends Array<unknown>>(options?: {
|
|
412
|
+
stableToastId?: undefined | true | string | ((id: string, arg: NoInfer<Args>[0], ctx: NoInfer<Args>[1]) => true | string | undefined);
|
|
413
|
+
errorRenderer?: (e: E, action: string, arg: NoInfer<Args>[0], ctx: NoInfer<Args>[1]) => string | undefined;
|
|
414
|
+
showSpanInfo?: false;
|
|
234
415
|
onWaiting?: null | undefined | string | ((id: string, arg: NoInfer<Args>[0], ctx: NoInfer<Args>[1]) => string | null | undefined);
|
|
235
416
|
onSuccess?: null | undefined | string | ((a: A, action: string, arg: NoInfer<Args>[0], ctx: NoInfer<Args>[1]) => string | null | undefined);
|
|
236
|
-
|
|
417
|
+
/** Map each stream element to a progress label. When non-`undefined`, updates both the active waiting toast and the `CommandProgress` service (for CommandButton progress display). */
|
|
418
|
+
progress?: (result: AsyncResult.AsyncResult<A, E>) => Progress | undefined;
|
|
419
|
+
}) => (self: Stream.Stream<A, E, R> | Effect.Effect<Stream.Stream<A, E, R>, any, any>, ...args: Args) => Stream.Stream<A, E, R | I18n | Toast | CommandContext>;
|
|
237
420
|
/** borrowing the idea from Families in Effect Atom */
|
|
238
421
|
family: <T extends object, Arg, ArgIn = Arg>(maker: (arg: Arg) => T, keyMaker?: (arg: ArgIn) => Arg) => (arg: ArgIn) => T;
|
|
239
422
|
};
|
|
@@ -258,7 +441,8 @@ export declare class CommanderImpl<RT, RTHooks> {
|
|
|
258
441
|
i18nKey: string;
|
|
259
442
|
namespace: string;
|
|
260
443
|
namespaced: (key: string) => string;
|
|
261
|
-
result: AsyncResult<A, E>;
|
|
444
|
+
result: AsyncResult.AsyncResult<A, E>;
|
|
445
|
+
progress: undefined;
|
|
262
446
|
waiting: boolean;
|
|
263
447
|
blocked: boolean;
|
|
264
448
|
allowed: boolean;
|
|
@@ -304,6 +488,96 @@ export declare class CommanderImpl<RT, RTHooks> {
|
|
|
304
488
|
}, options?: FnOptions<Id, I18nKey, State>) => Commander.Gen<RT | RTHooks, Id, I18nKey, State> & Commander.NonGen<RT | RTHooks, Id, I18nKey, State> & {
|
|
305
489
|
state: Context.Service<`Commander.Command.${Id}.state`, State>;
|
|
306
490
|
};
|
|
491
|
+
/**
|
|
492
|
+
* Internal factory for stream-backed commands. Accepts a handler that returns a `Stream` directly.
|
|
493
|
+
* Services (`CommandContext`, `stateTag`) are provided to the stream via `Stream.provideServiceEffect`.
|
|
494
|
+
*/
|
|
495
|
+
readonly makeStreamCommand: <const Id extends string, const State extends IntlRecord | undefined, const I18nKey extends string = Id>(id_: Id | {
|
|
496
|
+
id: Id;
|
|
497
|
+
}, options?: FnOptions<Id, I18nKey, State>, errorDef?: Error) => (<Arg, SA, SE, SR>(handler: (arg: Arg, ctx: Commander.CommandContextLocal2<Id, I18nKey, State>) => Stream.Stream<SA, SE, SR>) => {
|
|
498
|
+
id: import("vue").UnwrapRef<Id>;
|
|
499
|
+
i18nKey: string;
|
|
500
|
+
namespace: string;
|
|
501
|
+
namespaced: (key: string) => string;
|
|
502
|
+
result: AsyncResult.AsyncResult<SA, SE>;
|
|
503
|
+
progress: string | {
|
|
504
|
+
readonly text: string;
|
|
505
|
+
readonly percentage: number;
|
|
506
|
+
} | undefined;
|
|
507
|
+
waiting: boolean;
|
|
508
|
+
blocked: boolean;
|
|
509
|
+
allowed: boolean;
|
|
510
|
+
action: string;
|
|
511
|
+
label: string;
|
|
512
|
+
state: State;
|
|
513
|
+
handle: ((arg: Arg) => Fiber.Fiber<unknown, unknown>) & {
|
|
514
|
+
action: ComputedRef<string>;
|
|
515
|
+
label: ComputedRef<string>;
|
|
516
|
+
};
|
|
517
|
+
}) & {
|
|
518
|
+
id: Id;
|
|
519
|
+
};
|
|
520
|
+
/**
|
|
521
|
+
* Define a stream-backed Command for handling user actions.
|
|
522
|
+
*
|
|
523
|
+
* Like `fn`, but the body generator (or function) must **return** a `Stream` rather than
|
|
524
|
+
* an `Effect`. The command's `waiting` state stays `true` while the stream is running and
|
|
525
|
+
* is set to `false` once it terminates. The reactive `result` ref is updated for every
|
|
526
|
+
* value emitted by the stream.
|
|
527
|
+
*
|
|
528
|
+
* Three handler shapes are accepted:
|
|
529
|
+
* 1. **Generator returning a Stream** (primary) — may yield Effects freely before returning the stream:
|
|
530
|
+
* ```ts
|
|
531
|
+
* Command.streamFn("exportData")(
|
|
532
|
+
* function*(arg, ctx) {
|
|
533
|
+
* const token = yield* getAuthToken
|
|
534
|
+
* return Stream.fromEffect(startExport(token, arg.id)).pipe(
|
|
535
|
+
* Stream.flatMap((job) => pollProgress(job.id))
|
|
536
|
+
* )
|
|
537
|
+
* }
|
|
538
|
+
* )
|
|
539
|
+
* ```
|
|
540
|
+
* 2. **Function returning a Stream directly**: `(arg, ctx) => Stream.make(1, 2, 3)`
|
|
541
|
+
* 3. **Function returning `Effect<Stream>`**: `(arg, ctx) => Effect.map(setup, (s) => s.stream)`
|
|
542
|
+
*
|
|
543
|
+
* @param id The internal identifier for the action (used for tracing and i18n lookup).
|
|
544
|
+
* @param options Same options as `fn` (`state`, `blockKey`, `waitKey`, `allowed`, `i18nCustomKey`).
|
|
545
|
+
*
|
|
546
|
+
* **Progress** — use `Command.mapProgress(fn)` as a stream pipe operator; the mapper receives
|
|
547
|
+
* `AsyncResult<A, E>` (each value wrapped as `AsyncResult.success(v, { waiting: true })`),
|
|
548
|
+
* matching the same shape as CommandButton’s `:progress-map` prop. Or call
|
|
549
|
+
* `Command.updateProgress(p)` for imperative control:
|
|
550
|
+
*
|
|
551
|
+
* ```ts
|
|
552
|
+
* // mapProgress as a combinator arg (outside the handler):
|
|
553
|
+
* Command.streamFn("exportData")(
|
|
554
|
+
* function*(arg, ctx) { return makeExportStream(arg.id) },
|
|
555
|
+
* (s) => s.pipe(Command.mapProgress((r) => AsyncResult.isSuccess(r) && r.value._tag === "OperationProgress" ? { text: `${r.value.completed}/${r.value.total}` } : undefined))
|
|
556
|
+
* )
|
|
557
|
+
*
|
|
558
|
+
* // Or inline inside the handler body:
|
|
559
|
+
* Command.streamFn("exportData")(function*(arg, ctx) {
|
|
560
|
+
* return makeExportStream(arg.id).pipe(Command.mapProgress((r) => AsyncResult.isSuccess(r) ? ... : undefined))
|
|
561
|
+
* })
|
|
562
|
+
* ```
|
|
563
|
+
*
|
|
564
|
+
* **Pipeable combinators** — the 2nd–Nth args follow the same pattern as `fn`: each combinator
|
|
565
|
+
* receives `(stream, arg, ctx)` and returns a transformed stream:
|
|
566
|
+
* ```ts
|
|
567
|
+
* Command.streamFn("exportData")(
|
|
568
|
+
* handler,
|
|
569
|
+
* (s, arg, ctx) => s.pipe(Command.mapProgress(fn), Stream.take(100))
|
|
570
|
+
* )
|
|
571
|
+
* ```
|
|
572
|
+
*
|
|
573
|
+
* **Returned Properties**: `action`, `label`, `result`, `progress`, `waiting`, `blocked`,
|
|
574
|
+
* `allowed`, `handle`, `i18nKey`, `namespace`, `namespaced`.
|
|
575
|
+
*/
|
|
576
|
+
streamFn: <const Id extends string, const State extends IntlRecord = IntlRecord, const I18nKey extends string = Id>(id: Id | {
|
|
577
|
+
id: Id;
|
|
578
|
+
}, options?: FnOptions<Id, I18nKey, State>) => Commander.StreamGen<RT | RTHooks, Id, I18nKey, State> & Commander.NonGenStream<RT | RTHooks, Id, I18nKey, State> & {
|
|
579
|
+
state: Context.Service<`Commander.Command.${Id}.state`, State>;
|
|
580
|
+
};
|
|
307
581
|
/** @deprecated */
|
|
308
582
|
alt2: <const Id extends string, MutArg, MutA, MutE, MutR, const I18nKey extends string = Id, State extends IntlRecord | undefined = undefined>(id: Id | {
|
|
309
583
|
id: Id;
|
|
@@ -341,6 +615,7 @@ export declare class CommanderImpl<RT, RTHooks> {
|
|
|
341
615
|
* **User Feedback**: Use the `withDefaultToast` helper for status notifications, or render
|
|
342
616
|
* the `result` inline for custom UI feedback.
|
|
343
617
|
*/
|
|
618
|
+
streamWrap: <const Id extends string, Arg, SA, SE, SR, const State extends IntlRecord = IntlRecord, I18nKey extends string = Id>(handler: (arg: Arg, ctx: Commander.CommandContextLocal2<Id, I18nKey, State>) => Stream.Stream<SA, SE, SR>, id: Id, options?: FnOptions<Id, I18nKey, State>) => Commander.StreamerWrap<RT | RTHooks, Id, I18nKey, State, Arg, SA, SE, SR>;
|
|
344
619
|
wrap: <const Id extends string, Arg, A, E, R, const State extends IntlRecord = IntlRecord, I18nKey extends string = Id>(mutation: {
|
|
345
620
|
mutate: (arg: Arg) => Effect.Effect<A, E, R>;
|
|
346
621
|
id: Id;
|
|
@@ -349,7 +624,7 @@ export declare class CommanderImpl<RT, RTHooks> {
|
|
|
349
624
|
}), options?: FnOptions<Id, I18nKey, State>) => Commander.CommanderWrap<RT | RTHooks, Id, I18nKey, State, Arg, A, E, R>;
|
|
350
625
|
}
|
|
351
626
|
declare const Commander_base: Context.ServiceClass<Commander, "Commander", <RT, RTHooks>(rt: Context.Context<RT>, rtHooks: Layer.Layer<RTHooks, never, RT>) => CommanderImpl<RT, RTHooks>> & {
|
|
352
|
-
readonly make: Effect.Effect
|
|
627
|
+
readonly make: Effect.Effect<<RT, RTHooks>(rt: Context.Context<RT>, rtHooks: Layer.Layer<RTHooks, never, RT>) => CommanderImpl<RT, RTHooks>, never, I18n>;
|
|
353
628
|
};
|
|
354
629
|
export declare class Commander extends Commander_base {
|
|
355
630
|
static readonly DefaultWithoutDependencies: Layer.Layer<Commander, never, I18n>;
|