OpenSource-Hub

effect

ライブラリ

Effect-TS/effect

型安全なプロダクションレベルの TypeScript アプリケーションを構築するためのライブラリ。

概要

Effect は、堅牢で保守しやすく型安全な本番グレードの TypeScript アプリケーションを構築するためのライブラリです。型付きエラーハンドリング、依存性注入、構造化並行性、スケジューリング、トレーシング、統一されたデータスキーマバリデーションを提供します。この monorepo には、Node.js、Bun、Deno、ブラウザ向けのプラットフォームパッケージ、および多数の SQL や AI との統合も含まれています。

README プレビュー

\n\n[](https://pkg.pr.new/~/Effect-TS/effect)\n\n# Effect\n\nEffect is a library for building robust, maintainable, type-safe, and production grade applications in TypeScript. It helps you handle the hard problems at scale: typed errors, dependency injection, structured concurrency, scheduling, tracing, and unified schema validation.\n\n> **Effect 4.x is a long-term support (LTS) release.** If you are upgrading from Effect 3.x, follow the [migration guide](MIGRATION.md).\n\n## Installation\n\n```sh\nnpm install effect\n```\n\n## Requirements\n\n- **TypeScript 5.9 or newer.** TypeScript 7 is recommended for the best performance and compatibility with [Effect's TypeScript tooling](https://github.com/Effect-TS/tsgo#installation).\n- **Node.js 18 or newer** is the general minimum for running Effect on Node.js. Some integration packages require newer runtimes; for example, `@effect/sql-sqlite-node` requires Node.js 22.16 or newer.\n- **Strict type-checking:** the `strict` flag must be enabled in your `tsconfig.json`.\n\n## Links\n\n- [Website](https://effect.website): documentation, guides, and news\n- [Discord](https://discord.gg/effect-ts): ask questions, share what you're building, and talk to the core team\n- [Community](https://effect.website/community-hub): meetups and events, or bring Effect to your own\n- [Issues](https://github.com/Effect-TS/effect/issues): bug reports and feature requests\n- [Jobs](https://effect.website/effect-jobs): companies hiring Effect developers\n- Follow us on [X](https://x.com/EffectTS_), [Bluesky](https://bsky.app/profile/effect-ts.bsky.social), and [LinkedIn](https://www.linkedin.com/company/effect-ts)\n\n## Let's talk\n\nWhether your team is considering Effect, rolling it out, or already running it in production, we'd love to hear from you: what you're building, what works, and what you need from Effect next.\n\n- **Talk to the maintainers.** Introduce your team on [Discord](https://discord.gg/effect-ts) or email [contact@effectful.

FAQ (2)

トラブル対応
なぜ Effect の RequestResolver.persisted は、staleWhileRevalidate のリフレッシュが失敗した後も、TTL が更新された古いデータを提供し続けるのですか?

これは Effect 4.0.5 のバグです(main でも依然として存在します)。staleWhileRevalidate を使用している場合、バックグラウンドリフレッシュの runAll がバッチ全体として失敗したとき(またはエントリを完了せずに成功したとき)、persisted は失敗を永続化する代わりに、古い保存値を新しい TTL で書き戻します。その結果、stale なエントリが復活し、無期限に延長され続けます。エントリごとの失敗は正しく保存されます。回避策:エフェクト全体を失敗させるのではなく、リゾルバーが各リクエストを個別に完了させるようにしてください。リゾルバー内でエラーをキャッチし、すべてのエントリを自分で失敗させます:

const resolver = RequestResolver.make<GetValue>((entries) =>
  Effect.catchAll(backendCall(entries), (err) =>
    Effect.sync(() => {
      for (const entry of entries) entry.completeUnsafe(Exit.fail(err))
    })
  )
)

エントリごとに完了させることで、失敗は PersistenceStore.setMany を介して永続化され、stale な値が書き戻されることはありません。上流での修正は effect-ts の issue #9583 で追跡してください。

参照 Issue #9583
トラブル対応
なぜ Effect の FiberMap.run / FiberHandle.run は、スコープが閉じられたときに置き換えられたファイバーのクリーンアップを待機しないのですか?

effect@4.0.5では、占有済みのキー/ハンドルに対してFiberMap.run(またはFiberHandle.run、set、runtime)を呼び出すと、以前のファイバーを待機せずに中断し、コンテナから切り離します。スコープのファイナライザーはコンテナ内に残っているファイバーのみを待機するため、置き換えられたファイバーの中断クリーンアップ(例:Effect.onInterrupt)がまだ実行中であっても、スコープは閉じられてリソースが解放されます。NodeRuntime.runMainでは、SIGTERMの後にそのクリーンアップが完了する前にプロセスが終了してしまうことさえあります。

回避策:remove/clearは中断の完了を待機するため、置き換える前に古いファイバーを明示的に削除して待機してください:

// FiberMap: 先にremoveしてからrun
yield* FiberMap.remove(map, "k")
yield* FiberMap.run(map, "k", newEffect)

// FiberHandle: 先にclearしてからrun
yield* FiberHandle.clear(handle)
yield* FiberHandle.run(handle, newEffect)

これにより、古いファイバーのクリーンアップが置き換えの開始前およびスコープのクローズ前に完了することが保証され、期待される解放順序(クリーンアップが外部リソースの解放より先に実行される)が復元されます。

参照 Issue #9588