Skip to content

Add experimental in-process observation for Drizzle read models - #89

Merged
woksin merged 13 commits into
mainfrom
feature/drizzle-observation
Sep 26, 2026
Merged

woksin merged 13 commits into
mainfrom
feature/drizzle-observation

Conversation

@woksin

@woksin woksin commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Arc for TypeScript 0.38.0 adds experimental live observation for Drizzle SQL read models, the counterpart of Observe() on Entity Framework Core read models in Arc for .NET, limited to changes announced in the same process. npm publication remains disabled.

Added

  • Opt-in, tenant-scoped observation for Drizzle read models: withDrizzle({ observation: DrizzleObservation.InProcess }).
    • DrizzleReadModels.observe(filter?) and observeById(key) return a live RxJS observable with current(), which model-bound observable queries can return and serve over SSE and WebSocket like any observable query.
    • observePage(filter, options) emits QueryPage results for low-level defineObservableQuery definitions; generated proxies don't support observable pages yet.
  • DrizzleHandle.notifyChanged(tableOrReadModelType) announces a write. Inside an Arc command, notifications from the command and its nested commands are published once, when the outermost command finishes (also when it fails). Outside a command they are published immediately.
  • The proxy generator recognizes query results whose class derives from an RxJS Observable or Subject, such as the observables returned by MongoDB and Drizzle read models, and asks for an Observable<...> annotation when it can't resolve the item type.

Changed

  • rxjs is now a required peer dependency of @cratis/arc.drizzle.

Observation is experimental and deliberately narrow: only writes announced with notifyChanged in the same process and tenant are observed, pages are eventually consistent, a transaction the host holds around the whole Arc call must notify after it commits, and starting an observation without the opt-in fails instead of returning a stream that never updates. Cross-process change detection, such as PostgreSQL LISTEN/NOTIFY, is not included.

Refs #53

Resolve RxJS observable base types and typed service-token query bindings so Drizzle observe() generates an observable array proxy. Refs #53
Reject disabled observation; buffer by tenant, schedule re-reads outside the publisher context and release failed primes. Split and extend behavioral specs for HTTP, SSE, hub and lifecycle cases. Refs #53
Use small-array model-bound queries, restrict SQL page streams to low-level definitions, explain runner order and list rxjs as a required peer. Refs #53
Move shared race setup into a given context and assert outcomes after each scenario action. Refs #53
@woksin woksin added the minor New backward-compatible capabilities label Sep 26, 2026
@woksin woksin self-assigned this Sep 26, 2026
@woksin
woksin merged commit 673c7ba into main Sep 26, 2026
3 checks passed
@cratis-direct
cratis-direct Bot deleted the feature/drizzle-observation branch September 26, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New backward-compatible capabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant