events.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Change-event vocabulary of the domain data form. Every durable write emits
  3. * one event after the backend resolves durability, carrying the new snapshot
  4. * and an operation discriminant — never the old value (a diffing consumer
  5. * keeps its own previous snapshot). This is the event source for cross-process
  6. * change push (RPC frames) in a later phase.
  7. * @module @deepseek-ai/dsh-storage-domain/src/events
  8. */
  9. /** Shared location fields of one durable domain change. */
  10. export interface DomainChangedBase {
  11. /** Owning domain name. */
  12. readonly domain: string
  13. /** Table name; `''` for a global-singleton write. */
  14. readonly table: string
  15. /** Record key; `''` for a global-singleton write. */
  16. readonly key: string
  17. }
  18. /** A record (or the global singleton) was inserted or overwritten. */
  19. export interface DomainChangedPut extends DomainChangedBase {
  20. readonly operation: 'put'
  21. /** The new snapshot. */
  22. readonly value: unknown
  23. }
  24. /** A record was deleted; tombstones carry no value. */
  25. export interface DomainChangedDeleted extends DomainChangedBase {
  26. readonly operation: 'deleted'
  27. readonly value?: never
  28. }
  29. /** One durable domain change; a closed union — switch on `operation`. */
  30. export type DomainChanged = DomainChangedPut | DomainChangedDeleted
  31. declare module '@deepseek-ai/cordis' {
  32. interface Events {
  33. /**
  34. * A domain record or the global singleton changed, emitted once per write
  35. * strictly after the backend acknowledged durability. Events of one
  36. * domain arrive in its write-chain order.
  37. * @param change - domain, table (`''` for global), key (`''` for global),
  38. * operation discriminant, and on `put` the new snapshot.
  39. * @mode emit
  40. */
  41. 'domain/changed'(change: DomainChanged): void
  42. }
  43. }