← All packages

API reference

@searsuite/sear-foundation-subscription

Idempotent subscription ownership and reverse-order disposal utilities.

14 exportsderived from source

classObservationErrorsource ↗
class ObservationError extends SearError

Public error raised when an observation definition or registry lifecycle contract is violated.

constructorconstructor
ObservationError(code: ObservationErrorCode, message: string, details?: SearErrorDetails): ObservationError

Creates an observation contract error with structured diagnostic details.

code: ObservationErrorCode
message: string
details: SearErrorDetails
propertycode
readonly code: ObservationErrorCode

Stable observation-specific error code.

Inherited members 9

Inherited from SearError.

classObservationRegistrysource ↗
class ObservationRegistry

Editor-local typed observation registry exposed to plugins and third-party hosts.

constructorconstructor
ObservationRegistry(platform?: Platform): ObservationRegistry

Creates a registry that reports isolated host listener failures through the platform.

platform: Platform
propertysymbolstatic
readonly symbol: typeof symbol

DI token for resolving the registry owned by one editor instance.

methoddestroy
destroy(): void

Disposes every active host subscription and removes all registered sources.

methodenforceWriteBoundary
enforceWriteBoundary(assertWrite: (): void, runListener?: ObservationListenerScope, detachValue?: (value: unknown, definition: ObservationDefinition<unknown>): unknown): void

Requires editor command dispatch for source registration changes after assembly.

assertWrite: (): void
runListener: ObservationListenerScope
detachValue: (value: unknown, definition: ObservationDefinition<unknown>): unknown
methodgetRegisteredObservations
getRegisteredObservations(): readonly ObservationDefinition<unknown>[]

Returns a stable snapshot of registered observation definitions sorted by id.

methodgetSnapshot
getSnapshot<Value>(definition: StateObservationDefinition<Value>): Value

Returns the current snapshot for a state observation without subscribing.

definition: StateObservationDefinition<Value>
methodhas
has(definition: string | ObservationDefinition<unknown>): boolean

Returns whether an observation id is registered in this editor instance.

definition: string | ObservationDefinition<unknown>
methodregister
register<Value>(definition: EventObservationDefinition<Value>, source: ObservationSource<Value>): (): void register<Value>(definition: StateObservationDefinition<Value>, source: StateObservationSource<Value>): (): void

Registers an event-only source and returns an idempotent registration disposer.

definition: EventObservationDefinition<Value>
source: ObservationSource<Value>
methodsubscribe
subscribe<Value>(definition: ObservationDefinition<Value>, listener: (value: Value): void): (): void

Subscribes to a typed observation and returns an idempotent disposer.

definition: ObservationDefinition<Value>
listener: (value: Value): void
classSubscriptionManagersource ↗
class SubscriptionManager

Owns cancellable subscriptions for one consumer instance.

It centralizes disposal so viewport, DPR, visibility, network, and other observers do not each need a dedicated cleanup field.

constructorconstructor
SubscriptionManager(platform: Platform): SubscriptionManager

Creates a SubscriptionManager instance.

platform: Platform
propertysymbolstatic
readonly symbol: typeof symbol

DI token for resolving SubscriptionManager.

methoddestroy
destroy(): void

Releases resources owned by SubscriptionManager.

methodobserveResize
observeResize(target: unknown, callback: (size: { height: number; width: number }): void): (): void

Observes host-view size changes and returns an idempotent disposer.

target: unknown
callback: (size: { height: number; width: number }): void
methodtrack
track(dispose: (): void): (): void

Tracks an arbitrary subscription cleanup function and returns an idempotent disposer.

dispose: (): void
interfaceEventObservationDefinitionsource ↗
interface EventObservationDefinition<Value> extends ObservationDefinition<Value>

Definition for an event-only observation stream.

propertykind
readonly kind: "event"

Event observations have no current snapshot.

Inherited members 2

Inherited from ObservationDefinition.

interfaceObservationDefinitionsource ↗
interface ObservationDefinition<Value>

Typed identity imported by publishers and consumers of one observation.

propertyid
readonly id: string

Stable globally unique id used for registration diagnostics.

propertykind
readonly kind: ObservationKind

Delivery model that determines whether a current snapshot is available.

propertyvalueType
readonly valueType?: Value

Compile-time value carrier; never populated at runtime.

interfaceObservationSourcesource ↗
interface ObservationSource<Value>

Produces future values for an event or state observation.

methodsubscribe
subscribe(listener: (value: Value): void): (): void

Registers a listener for future values and returns an idempotent disposer.

listener: (value: Value): void
interfaceStateObservationDefinitionsource ↗
interface StateObservationDefinition<Value> extends ObservationDefinition<Value>

Definition for an observation stream backed by a current state snapshot.

propertykind
readonly kind: "state"

State observations expose a current snapshot.

Inherited members 2

Inherited from ObservationDefinition.

interfaceStateObservationSourcesource ↗
interface StateObservationSource<Value> extends ObservationSource<Value>

Produces a current snapshot plus future values for a state observation.

methodgetSnapshot
getSnapshot(): Value

Returns the current immutable state snapshot.

Inherited members 1

Inherited from ObservationSource.

typeObservationErrorCodesource ↗
type ObservationErrorCode = typeof ObservationErrorCode[keyof typeof ObservationErrorCode]

Machine-readable observation error code.

typeObservationKindsource ↗
type ObservationKind = typeof ObservationKind[keyof typeof ObservationKind]

Supported observation delivery models.

variableObservationErrorCodesource ↗
ObservationErrorCode: { AlreadyRegistered: "SEAR_OBSERVATION_ALREADY_REGISTERED"; DefinitionMismatch: "SEAR_OBSERVATION_DEFINITION_MISMATCH"; InvalidDefinition: "SEAR_OBSERVATION_INVALID_DEFINITION"; NotRegistered: "SEAR_OBSERVATION_NOT_REGISTERED"; RegistryDestroyed: "SEAR_OBSERVATION_REGISTRY_DESTROYED"; SnapshotUnavailable: "SEAR_OBSERVATION_SNAPSHOT_UNAVAILABLE" }

Stable machine-readable error codes for the observation extension surface.

variableObservationKindsource ↗
ObservationKind: { Event: "event"; State: "state" }

Distinguishes snapshot-backed state observations from event-only streams.

functiondefineEventObservationsource ↗
defineEventObservation<Value>(id: string): EventObservationDefinition<Value>

Creates a typed identity for an event-only observation stream.

id: string
functiondefineStateObservationsource ↗
defineStateObservation<Value>(id: string): StateObservationDefinition<Value>

Creates a typed identity for a snapshot-backed state observation stream.

id: string