feat(sdk): Effect v4 + @effect/openapi-generator; typed pf.api & example ladder

Drop Orval for the first-party @effect/openapi-generator (OpenAPI 3.1 ->
Effect Schema + a typed HttpClient client) and bump effect 3.19 ->
4.0.0-beta.98. Port the hand-written surfaces to the v4 API (Result over
Either, Context.Service, Codec, Literals/Union arrays, Stream/Schedule/
Effect renames). Transport (CA-pinning fetch) and the reconnecting SSE
source are kept intact.

Make the SDK approachable for non-Effect users:
- Add pf.api.* on the Promise facade: the generated client surfaced as
  typed, Promise-native methods (await pf.api.listPairedClients()), so REST
  calls are autocompleted and checked instead of stringly-typed
  pf.request(method, path, body) + `as` casts. Zero-drift veneer over
  make(httpClient), backed by the same pinning fetch. pf.request stays as
  the untyped escape hatch.
- Re-tier examples into a 1-4 complexity ladder, rewritten onto pf.api.*
  (the typed payloads caught a wrong `launch` shape in provider-sync);
  the Effect example is labelled advanced. Add examples/ to tsconfig so
  they are typechecked (stops rot).

typecheck + 19 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-17 12:40:04 +02:00
parent 27a5d8daac
commit f012ebbcba
19 changed files with 1645 additions and 1974 deletions
+9 -7
View File
@@ -38,7 +38,7 @@ export interface RunnerOptions {
/** Connection overrides handed to every unit's client/layer. */
connect?: ConnectOptions;
/** Restart backoff base (test seam). Default 1 s, capped at 60 s, jittered. */
restartBase?: Duration.DurationInput;
restartBase?: Duration.Input;
/** Line sink. Default: stamped stdout. */
log?: (line: string) => void;
}
@@ -167,10 +167,12 @@ export const superviseUnit = (
options: RunnerOptions = {},
): Effect.Effect<void> => {
const log = options.log ?? defaultLog;
const restart = Schedule.exponential(options.restartBase ?? "1 second").pipe(
Schedule.union(Schedule.spaced("60 seconds")), // cap
Schedule.jittered,
);
// Exponential backoff, capped at 60 s (min-delay of the two schedules), then jittered.
// (v4 replaced `Schedule.union` with the array-form `Schedule.min`.)
const restart = Schedule.min([
Schedule.exponential(options.restartBase ?? "1 second"),
Schedule.spaced("60 seconds"),
]).pipe(Schedule.jittered);
let attempt = 0;
const once = Effect.suspend(() => {
attempt += 1;
@@ -187,13 +189,13 @@ export const superviseUnit = (
),
),
),
Effect.tapErrorCause((cause) =>
Effect.tapCause((cause) =>
Effect.sync(() =>
log(`[${unit.name}] failed: ${Cause.pretty(cause).split("\n")[0]}`),
),
),
Effect.retry(restart),
Effect.catchAllCause((cause) =>
Effect.catchCause((cause) =>
// A retry schedule that gives up (it doesn't, but stay total) — log and end.
Effect.sync(() => log(`[${unit.name}] gave up: ${Cause.pretty(cause)}`)),
),