Skip to content

feat(routes): add registered route lifecycle observer - #16

Open
Upd4ting wants to merge 5 commits into
mainfrom
fix/observable-registered-routes
Open

feat(routes): add registered route lifecycle observer#16
Upd4ting wants to merge 5 commits into
mainfrom
fix/observable-registered-routes

Conversation

@Upd4ting

@Upd4ting Upd4ting commented Aug 21, 2026

Copy link
Copy Markdown
Member

Summary

  • expose RegisteredRoutesObserver and ObserveRegisteredRoutes(observer): () => void
  • synchronously replay complete RouteHandler objects, then multicast registrations and removals
  • emit removals for explicit unregister and module unload while keeping the existing registering provider untouched
  • isolate and log observer callback failures so route lifecycle and other observers continue
  • validate the integration suite against @antelopejs/api@1.2.4

Motivation

cms-api needs complete route handlers to maintain its route cache. It currently relies on the internal routesProxy.onRegister and onUnregister methods. Under Core 1.5, that registering proxy is a provider-routing slot rather than a multicast event source, so a direct subscriber can fail with MissingProviderError, compete with the real API provider, or remain inert. getRegisteredRoutes() cannot replace this usage because it omits handler mode, callback, and prototype.

The new public observer is owned by interface-api and uses its existing routesList source of truth without exposing proxy internals.

Validation

  • pnpm lint
  • pnpm build
  • generated declaration inspection for both public exports
  • pnpm test — 92 passing with Core 1.4.7 / interface-core 0.0.8 and @antelopejs/api@1.2.4
  • candidate package manifest and tarball inspection
  • pnpm publish --dry-run --no-git-checks

The planned release is 0.0.13; this PR intentionally does not bump the package version.

Greptile Summary

The PR adds a public registered-route lifecycle observer that synchronously replays complete handlers and multicasts subsequent registrations and removals while isolating callback failures.

  • Adds observer subscription, replay, unsubscription, and reentrancy handling.
  • Emits removal events for explicit unregister and module unload.
  • Adds lifecycle coverage and validates integration against @antelopejs/api@1.2.4.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/index.ts Adds the public route lifecycle observer and resolves the previously reported replay, live-iteration, unsubscribe, and repeated-subscription defects.
src/tests/route-lifecycle.test.ts Adds comprehensive tests for replay, multicast lifecycle events, reentrant mutation, unsubscribe behavior, and callback isolation.
src/antelope.test.ts Updates the integration fixture to validate against @antelopejs/api@1.2.4.

Sequence Diagram

sequenceDiagram
  participant Consumer
  participant ObserverAPI as ObserveRegisteredRoutes
  participant Routes as routesList
  participant Proxy as routesProxy

  Consumer->>ObserverAPI: Subscribe(observer)
  ObserverAPI->>Routes: Snapshot existing handlers
  loop Existing registered routes
    ObserverAPI-->>Consumer: onRegister(id, handler)
  end
  Proxy->>Routes: Add registered handler
  Proxy->>ObserverAPI: Notify registration
  ObserverAPI-->>Consumer: onRegister(id, handler)
  Proxy->>Routes: Remove handler
  Proxy->>ObserverAPI: Notify removal
  ObserverAPI-->>Consumer: onUnregister(id)
Loading

Reviews (5): Last reviewed commit: "fix(routes): deduplicate repeated observ..." | Re-trigger Greptile

Expose a replayable multicast lifecycle API for complete route handlers without attaching another provider to the internal registering proxy. Keep explicit removals and module unloads synchronized with the public observer.
Comment thread src/index.ts Outdated
Comment thread src/index.ts
Snapshot live subscribers so nested subscriptions do not receive duplicate events. Skip stale replay entries removed by earlier observer callbacks.

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread src/index.ts
Track observer subscription generations so callbacks removed during an emission are skipped, including remove-and-resubscribe sequences.

Copy link
Copy Markdown
Member Author

@greptile review

Revalidate the route before each live registration callback so reentrant removal cannot leave later observer caches stale.

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread src/index.ts
Reuse one active subscription per observer identity so either unsubscribe handle stops future notifications without weakening reentrant generation checks.

Copy link
Copy Markdown
Member Author

@greptile review

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