Uh oh!
There was an error while loading. Please reload this page.
♻️ Refactor context-api to use @effectionx/middleware with min/max priority - #187
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
e04434e to
b77977cCompareee1be5d to
7fdf6fcCompare7fdf6fc to
0016614Compare…iority
Replace hand-rolled middleware composition in context-api with the shared
@effectionx/middleware package. Internal state changes from a single composed
function per field to immutable {max, min, composed} arrays that support
priority ordering while preserving scope isolation.
- Import Middleware type and combine() from @effectionx/middleware
- Add { at: "min" | "max" } option to around() (defaults to "max")
- Store per-field max/min arrays in context; recompute on each around() call
- Add 5 new tests covering min/max ordering, scope isolation, implementation
replacement, mixed insertion order, and default behavior
- Rewrite README with Quick Start, Min/Max Priority, Instrumentation,
Test Mocking, Scope Isolation, and API reference sections
- Bump version to 0.4.0 (new feature, non-breaking)0016614 to
a819973Compare| (api, field) => { | ||
| let handle = handler[field]; | ||
| if (typeof handle === "function") { | ||
| // biome-ignore lint/suspicious/noExplicitAny: Handler is dynamically typed per field |
There was a problem hiding this comment.
to many of these. let's fix or disable on the file
There was a problem hiding this comment.
Fixed — disabled noExplicitAny for this file via biome.json override instead of inline comments.
| max: [], | ||
| min: [], | ||
| // biome-ignore lint/suspicious/noExplicitAny: Passthrough middleware for initial state | ||
| composed: (args: any, next: any) => next(...args), |
There was a problem hiding this comment.
Does this create an extra wrap of the core in all cases?
There was a problem hiding this comment.
Yes it did. Changed composed to undefined initially — handlers are now called directly when no middleware is registered.
| type FieldState = { | ||
| // biome-ignore lint/suspicious/noExplicitAny: Middleware arrays store heterogeneous field types | ||
| max: Middleware<any[], any>[]; | ||
| // biome-ignore lint/suspicious/noExplicitAny: Middleware arrays store heterogeneous field types | ||
| min: Middleware<any[], any>[]; | ||
| // biome-ignore lint/suspicious/noExplicitAny: Pre-composed middleware for dynamic dispatch | ||
| composed: Middleware<any[], any>; | ||
| }; | ||
| /** | ||
| * The context stores a FieldState for each field in the API. | ||
| */ | ||
| type ContextState<A> = Record<keyof Operations<A>, FieldState>; |
There was a problem hiding this comment.
Field state and context state are too vague
There was a problem hiding this comment.
Renamed to FieldMiddleware and MiddlewareRegistry.
…ove passthrough wrap - Disable noExplicitAny for context-api/mod.ts via biome.json override instead of 7 scattered inline biome-ignore comments - Rename FieldState → FieldMiddleware, ContextState → MiddlewareRegistry for clarity - Skip middleware wrapping when no middleware is registered — call handlers directly instead of going through an identity passthrough
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Motivation
The
@effectionx/context-apipackage hand-rolls its own middleware compositionlogic, duplicating the
Middlewaretype andcombinesemantics already providedby
@effectionx/middleware. It also lacks min/max priority ordering — every callto
around()always wraps outermost, with no way to register implementationproviders at a different priority level.
This PR refactors context-api to depend on the shared middleware package and adds
min/max support to
around().Approach
Middlewaretype andcombine()now come from@effectionx/middleware, eliminating the local duplicate definitioncomposed function per field to
{ max: Middleware[], min: Middleware[], composed: Middleware }.Each
around()call clones arrays and recomputes the composite, preservingscope isolation (child scope changes never leak to parent)
around()accepts{ at: "min" | "max" }— defaults to"max"(outermost),so existing callers are unaffected.
"min"registers middleware closest to thecore handler, enabling the implementation-provider pattern
insertion order, scope isolation with priority, and default behavior
Instrumentation, Test Mocking, Scope Isolation, and API reference sections