Skip to content

[codex] Add scoped resource helpers#64

Merged
samlaycock merged 2 commits into
mainfrom
codex/scoped-resource-helpers
May 19, 2026
Merged

[codex] Add scoped resource helpers#64
samlaycock merged 2 commits into
mainfrom
codex/scoped-resource-helpers

Conversation

@samlaycock

Copy link
Copy Markdown
Owner

Summary

Closes #53.

This adds focused scoped resource helpers to the public fx API:

  • fx.acquireRelease for acquiring a scoped resource and registering its finalizer
  • fx.scoped for opening and closing a scope around a task
  • fx.layerScoped for scoped dependency layers that release resources when the runtime boundary is disposed

Why

fluent-effect already exposed fx.acquireUseRelease / fx.bracket, but scoped-resource workflows still required importing native Effect helpers from fluent-effect/effect. Resource safety is central enough to warrant a small ergonomic surface without wrapping the full Effect resource API.

Validation

  • bun fmt
  • bun lint:fix
  • bun test
  • bun typecheck

Notes

The docs now clarify when to use direct acquire/use/release versus scoped resources and when to fall back to native Effect APIs for advanced finalizer composition.

Expose ergonomic wrappers for Effect scoped resources through fx.acquireRelease and fx.scoped, plus fx.layerScoped for scoped dependency layers.

Add runtime coverage for success, failure, interruption, and app disposal finalization, along with type-level assertions for success, failure, and dependency inference.

Update resource and API docs, and include the required changeset for the public API addition.
Dispose the reusable fx.app in the dependencies example after the exported main promise settles.

CI timed out while running the example smoke test because the child Bun process could stay alive until the 5s test timeout on the runner.
@samlaycock samlaycock marked this pull request as ready for review May 19, 2026 19:50
@greptile-apps

greptile-apps Bot commented May 19, 2026

Copy link
Copy Markdown

Greptile Summary

This PR exposes three scoped-resource helpers — fx.acquireRelease, fx.scoped, and fx.layerScoped — as thin wrappers over Effect.acquireRelease, Effect.scoped, and Layer.scoped, closing the gap that previously forced users to reach into fluent-effect/effect for scope-based resource workflows.

  • src/builders.ts and src/dependencies.ts add the three helpers as direct aliases; no custom logic is introduced.
  • test/runtime.test.ts covers all four relevant paths: success, typed failure, fiber interruption, and layerScoped disposal via app.dispose().
  • Type tests verify that Scope.Scope appears in the dependency type of a bare acquireRelease effect and is correctly eliminated after fx.scoped / fx.layerScoped.

Confidence Score: 5/5

Safe to merge — all new helpers are direct aliases over well-tested Effect primitives with no custom logic, and the added tests cover every documented failure mode.

The implementation is three one-liner aliases, the tests exercise success, failure, interruption, and disposal, and the type-level assertions confirm the Scope.Scope dependency flows correctly through the new surface. No existing behaviour is modified.

No files require special attention.

Important Files Changed

Filename Overview
src/builders.ts Adds acquireRelease and scoped as thin pass-throughs to Effect.acquireRelease and Effect.scoped; no logic added.
src/dependencies.ts Adds layerScoped as a direct alias for Layer.scoped; consistent with existing layerSync/layer patterns.
src/index.ts Exports the three new helpers in the fx object; placement is consistent with existing layout.
test/runtime.test.ts Adds four runtime tests covering success, typed failure, fiber interruption, and layerScoped disposal; all paths are exercised.
test/types.test.ts Adds compile-time assertions confirming Scope.Scope appears in deps of a bare acquireRelease task and is eliminated after fx.scoped / fx.layerScoped.
examples/dependencies.ts Updates the example to call app.dispose() in a .finally() handler, demonstrating proper cleanup practice for apps that use scoped layers.
docs/resources.md Adds a "Scoped Resources" section with concrete usage examples for acquireRelease, scoped, and layerScoped; updates the native escape-hatch guidance.
docs/api-reference.md Adds table rows for fx.acquireRelease, fx.scoped, and fx.layerScoped in the correct sections.
.changeset/scoped-resource-helpers.md Minor changeset correctly classifying the new public API additions.

Reviews (1): Last reviewed commit: "test: dispose dependency smoke app" | Re-trigger Greptile

@samlaycock samlaycock merged commit c7776a3 into main May 19, 2026
2 checks passed
@samlaycock samlaycock deleted the codex/scoped-resource-helpers branch May 19, 2026 19:55
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.

P2: Add ergonomic scoped resource helpers

1 participant