Skip to content

Migrate all examples to Effect v4 syntax - #324

Open
valkalon wants to merge 2 commits into
PaulJPhilp:mainfrom
valkalon:effect-v4-migration
Open

valkalon wants to merge 2 commits into
PaulJPhilp:mainfrom
valkalon:effect-v4-migration

Conversation

@valkalon

Copy link
Copy Markdown

Summary

Migrates every TypeScript example under content/ (211 published pattern files + roadmap + drafts, ~600 code blocks) from Effect v3 to Effect v4 syntax, following the official v3→v4 migration guides (MIGRATION.md + migration/* in Effect-TS/effect).

Branch: valkalon:effect-v4-migration (256 files, +2269/−2309).

What changed (examples only)

  • Services: Context.GenericTag/Tag, Effect.Tag/Service → Context.Service with make + explicit static layer; .Default → .layer
  • Errors: catchAll → catch, catchAllCause → catchCause, catchAllDefect → catchDefect
  • Either → Result: constructors, guards, getters, match handlers, _tag checks, Effect.either → Effect.result
  • Concurrency: Effect.fork → forkChild, forkDaemon → forkDetach
  • Constructors: Effect.async → Effect.callback, Scope.extend → Scope.provide, fromNullable/fromEither → fromNullishOr/fromResult
  • Schema: decode/encode → decodeEffect/encodeEffect family, variadic Literal/Union/Tuple → array form, Record({k,v\}), transform → decodeTo + SchemaTransformation.transform, struct spread / Struct.pick/omit/map instead of extend/pick/omit/partial, filters → check(is*), filter() → check(makeFilter()), Date → DateFromString (kept for Date-typed targets)
  • Time: DurationInput → Input, decode → fromInputUnsafe, comparison predicates gain is prefix
  • Schedule: intersect/union/compose → max/min, tap*/while*/until*/recurWhile/delayed/filter/upTo/jittered moved to v4 signatures
  • Platform: Command → ChildProcess + ChildProcessSpawner, Stream.fromChunk → fromArray, Http.* namespace → HttpRouter/HttpServerRequest/HttpServerResponse from effect/http, NodeContext → NodeServices, NodeHttpServer.layer takes the server factory, HttpClientResponse.json(x) → x.json
  • Data: Data.struct/array/tuple/case lessons rewritten for v4 structural equality on plain values
  • Deps: effect + @effect/* bumped to 4.0.0-rc.117; folded packages (@effect/platform, @effect/schema, @effect/rpc, @effect/cli) removed

Verification

  • Zero remaining v3 identifiers (swept for ~150 removed/renamed APIs)
  • Representative snippets (services, retry policies, Result, Schema transforms, HttpRouter serve, spawner, filters) typecheck cleanly against effect@4.0.0-rc.117 + @effect/platform-node@4.0.0-rc.117

Notes / follow-ups (not in scope)

  • Import paths use the final v4 layout (effect/http, effect/process, …) per MIGRATION.md; the npm rc.117 build still exposes them under effect/unstable/* (main branch already uses final paths) — a one-line sed flips back if you want to pin the rc exactly
  • packages/*/src application code is not migrated (blocked on @effect/cli v4); bun install needed to refresh the lockfile
  • Data.TaggedError kept intentionally (still valid v4)

Mechanical migration of every TypeScript example (content/**/*.mdx)
from Effect v3 to Effect v4, following the official v3-to-v4 migration
guides (Effect-TS/effect MIGRATION.md + migration/*).

Highlights:
- Services: Context.GenericTag/Tag, Effect.Tag/Service -> Context.Service
  with make + explicit static layer; .Default -> .layer
- Errors: catchAll -> catch, catchAllCause -> catchCause,
  catchAllDefect -> catchDefect, catchSome -> catchFilter
- Either -> Result (succeed/fail, isSuccess/isFailure, getSuccess/
  getFailure, mapError, fromNullishOr, match onFailure/onSuccess,
  _tag Success/Failure); Effect.either -> Effect.result
- Concurrency: Effect.fork -> forkChild, forkDaemon -> forkDetach
- Constructors: Effect.async -> Effect.callback; Scope.extend -> Scope.provide
- Schema: decode/encode -> decodeEffect/encodeEffect (+Unknown variants),
  Either decoders -> Exit/Result variants, Literal/Union/Tuple ->
  array form, Record({k,v}) shape, Transform -> decodeTo +
  SchemaTransformation.transform, Struct spread/Struct.pick/omit/map
  instead of extend/pick/omit/partial, filters -> check(is*),
  filter() -> check(makeFilter()), Date -> DateFromString (Date kept
  for Date-typed targets), TaggedError/Data APIs kept where valid
- Time: DurationInput -> Input, decode -> fromInputUnsafe,
  lessThanOrEqualTo/greaterThan -> is* predicates
- Schedule: intersect/union/compose -> max/min, tap/while/delayed/
  until/recurWhile/filter/upTo/jittered moved to v4 signatures,
  Command -> ChildProcess + ChildProcessSpawner, Stream.fromChunk ->
  fromArray, Http.* namespace -> HttpRouter/HttpServerRequest/
  HttpServerResponse from effect/http, platform HttpClient.* ->
  effect/http, FileSystem/Terminal stay in effect barrel,
  KeyValueStore -> effect/persistence
- Deps: effect + @effect/* bumped to 4.0.0-rc.117; folded packages
  (@effect/platform, @effect/schema, @effect/rpc, @effect/cli)
  removed (now part of effect core)

Notes / follow-ups:
- import paths use final v4 layout (effect/http, effect/process,
  effect/sql, ...) per MIGRATION.md; the npm rc.117 build still
  exposes them under effect/unstable/*, main branch already uses
  the final paths
- packages/*/src application code is NOT migrated yet (blocked on
  @effect/cli v4); run bun install to refresh the lockfile
- Data.TaggedError kept intentionally (still valid v4)
…Is, add missing v4 courses

- Remove 5 Schema.filterEffect courses (API removed in v4, no drop-in):
  schema/async-validation/basic-async, batched-async, database-checks,
  external-api-validation, schema/form-validation/async-validation
- Add schema/async-validation/async-validation-with-effects (decode + Effect,
  transformEffect inline alternative, verified vs 4.0.0-rc.117)
- Fix Schema.optionalWith -> withDecodingDefaultKey in 6 files
  (optional-fields, with-defaults, multiple-files, database-columns,
  postgres-jsonb, schema-evolution)
- Fix Cause.failures/defects -> reasons filter in
  error-management-extract-cause; FiberRef/Effect.runtime ->
  References/Effect.context in tooling-devtools
- Fix schema-vs-zod filterEffect placeholder -> transformEffect
- Update Result prose Left/Right -> Success/Failure (3 files)
- Add missing v4 courses: Context.Reference, Effect.fn,
  context-not-runtime, cause reasons array, Scope.provide

Verified with bun vs effect@4.0.0-rc.117. Yieldable/.asEffect
intentionally omitted: documented but not functional in rc.117.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant