|
| 1 | +// CHANGE: Define Effect-channel client types over openapi-fetch-compatible inputs |
| 2 | +// WHY: Method inputs stay derived from openapi-fetch helpers while output is inferred from operation responses |
| 3 | +// QUOTE(ТЗ): "output должен отличаться тем что он стаёт Effect ... input должен быть 1 в 1" |
| 4 | +// REF: user-msg-openapi-effect-input-compat |
| 5 | +// SOURCE: n/a |
| 6 | +// PURITY: CORE - compile-time types only |
| 7 | +// EFFECT: Effect<ApiSuccess<Responses>, ApiFailure<Responses>, never> |
| 8 | +// INVARIANT: ∀ call: Path ∧ Method select exactly one OpenAPI operation response set |
| 9 | +// COMPLEXITY: O(1) runtime / compile-time only |
| 10 | + |
| 11 | +import type { Effect } from "effect" |
| 12 | +import type { HttpMethod, PathsWithMethod } from "openapi-typescript-helpers" |
| 13 | + |
| 14 | +import type { ApiFailure, ApiSuccess, ResponsesFor } from "../../core/api-client/strict-types.js" |
| 15 | +import type { |
| 16 | + MaybeOptionalInit, |
| 17 | + MethodArgs, |
| 18 | + Middleware, |
| 19 | + OperationFor, |
| 20 | + RequestMethodArgs |
| 21 | +} from "./create-client-types.js" |
| 22 | + |
| 23 | +type EffectMethodResult< |
| 24 | + Paths extends object, |
| 25 | + Path extends PathsWithMethod<Paths, Method>, |
| 26 | + Method extends HttpMethod |
| 27 | +> = Effect.Effect< |
| 28 | + ApiSuccess<ResponsesFor<OperationFor<Paths, Path & keyof Paths, Method>>>, |
| 29 | + ApiFailure<ResponsesFor<OperationFor<Paths, Path & keyof Paths, Method>>> |
| 30 | +> |
| 31 | + |
| 32 | +type EffectPath<Paths extends object, Method extends HttpMethod> = PathsWithMethod<Paths, Method> |
| 33 | + |
| 34 | +type EffectInit< |
| 35 | + Paths extends object, |
| 36 | + Method extends HttpMethod, |
| 37 | + Path extends EffectPath<Paths, Method> |
| 38 | +> = MaybeOptionalInit<Paths[Path], Extract<Method, keyof Paths[Path]>> |
| 39 | + |
| 40 | +export interface EffectClientMethod< |
| 41 | + Paths extends object, |
| 42 | + Method extends HttpMethod |
| 43 | +> { |
| 44 | + < |
| 45 | + Path extends EffectPath<Paths, Method>, |
| 46 | + Init extends EffectInit<Paths, Method, Path> |
| 47 | + >( |
| 48 | + ...args: MethodArgs<Paths, Method, Path, Init> |
| 49 | + ): EffectMethodResult<Paths, Path, Method> |
| 50 | +} |
| 51 | + |
| 52 | +export interface EffectClientRequestMethod<Paths extends object> { |
| 53 | + < |
| 54 | + Method extends HttpMethod, |
| 55 | + Path extends EffectPath<Paths, Method>, |
| 56 | + Init extends EffectInit<Paths, Method, Path> |
| 57 | + >( |
| 58 | + ...args: RequestMethodArgs<Method, MethodArgs<Paths, Method, Path, Init>> |
| 59 | + ): EffectMethodResult<Paths, Path, Method> |
| 60 | +} |
| 61 | + |
| 62 | +export interface EffectClient<Paths extends object> { |
| 63 | + request: EffectClientRequestMethod<Paths> |
| 64 | + GET: EffectClientMethod<Paths, "get"> |
| 65 | + PUT: EffectClientMethod<Paths, "put"> |
| 66 | + POST: EffectClientMethod<Paths, "post"> |
| 67 | + DELETE: EffectClientMethod<Paths, "delete"> |
| 68 | + OPTIONS: EffectClientMethod<Paths, "options"> |
| 69 | + HEAD: EffectClientMethod<Paths, "head"> |
| 70 | + PATCH: EffectClientMethod<Paths, "patch"> |
| 71 | + TRACE: EffectClientMethod<Paths, "trace"> |
| 72 | + use(...middleware: Array<Middleware>): void |
| 73 | + eject(...middleware: Array<Middleware>): void |
| 74 | +} |
| 75 | + |
| 76 | +export type ClientEffect<Paths extends object> = EffectClient<Paths> |
0 commit comments