/** * @module ObservableBase_V1 witness class * */ import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs'; import { MetaspaceService } from '../../../witness/space/metaspace/metaspace-types.mjs'; import { ObservableData_V1, ObservableRel8ns_V1, ObservableIbGib_V1, ObservableResultData, ObservableResultIbGib, ObservableWitness } from './observable-types.mjs'; import { LightWitnessBase_V1 } from '../../../witness/light-witness-base-v1.mjs'; import { WitnessAny } from '../../../witness/witness-types.mjs'; import { SubscriptionIbGib_V1, SubscriptionWitness } from '../subscription/subscription-types.mjs'; import { ObserverWitness } from '../observer/observer-types.mjs'; import { WitnessCmdData, WitnessCmdIbGib, WitnessCmdRel8ns } from '../../../witness/witness-cmd/witness-cmd-types.mjs'; import { ObservableEventType } from './observable-event/observable-event-types.mjs'; import { ErrorIbGib_V1 } from '../../error/error-types.mjs'; /** * sketching... * under construction... */ export declare abstract class ObservableBase_V1 = WitnessCmdData, TCmdRel8ns extends WitnessCmdRel8ns = WitnessCmdRel8ns, TCmdIbGib extends WitnessCmdIbGib = WitnessCmdIbGib, TData extends ObservableData_V1 = ObservableData_V1, TRel8ns extends ObservableRel8ns_V1 = ObservableRel8ns_V1> extends LightWitnessBase_V1 implements ObservableIbGib_V1, ObservableWitness { /** * Log context for convenience with logging. (Ignore if you don't want to use this.) */ protected lc: string; /** * Reference to the local ibgibs service, which is one way at getting at the * local user space. */ metaspace: MetaspaceService | undefined; protected _subscribers: { [subscriptionId: string]: [SubscriptionWitness, ObserverWitness | WitnessAny]; }; protected _isComplete: boolean; /** * this is used for {@link SubjectData_V1.replay} */ protected _pastPayloads: TIbGibIn_ie_Payload[]; /** * if observable errors out, this should be the stored error. */ protected _pastError: ErrorIbGib_V1 | Error | string | undefined; get isCompleteOrErrored(): boolean; get isComplete(): boolean; get isErrored(): boolean; constructor(initialData?: TData, initialRel8ns?: TRel8ns); /** * The observable's primary function is to accept subscribers * who wish to observe the stream of ibgibs this observable creates. * * So there are two ways to subscribe: * * ## 1. Use an ObservableCmd (via this.argy(...) for convenience) * * @see {@link subscribe} * * ## 2. Use any ol' Witness IbGib * @see {@link witness_otherWitness} * * @param arg * @returns * * @see {@link argy} */ witness(arg: IbGib_V1): Promise; /** * default implementation here subscribes the witness. * * override this for custom handling cmds. * * @returns idk, an ibgib */ protected witness_cmd({ arg, }: { arg: TCmdIbGib; }): Promise; protected witness_otherWitness({ arg, }: { arg: WitnessAny; }): Promise; protected witness_subscriptionIbGib({ arg, }: { arg: SubscriptionIbGib_V1; }): Promise; protected replayPastPayloads({ observer, subscription, }: { observer: ObserverWitness; subscription: SubscriptionWitness; }): Promise; protected witness_subscribe_cmd({ ibGib, }: { ibGib: TCmdIbGib; }): Promise; /** * we have been given a witness ibGib that is not a command. by default, an * observable will subscribe a witness, and when a value comes down the pipe * the witness will have its `witness` fn called a la a visitor pattern. If * an error occurs, it will be propagated. I'm not sure how to do the * `observer.complete` analog. * @param arg ibgib object with `witness` function */ protected witness_subscribe_nonCmdWitness({ arg }: { arg: WitnessAny; }): Promise; /** * subscribes the given `observer` to this observable's stream. * * ## notes * * * The `observer` can be any ibgib witness (not specifically expose the * {@link ObserverWitness} contract), but that witness will have to be * able to deal with this observable's outputs via that witness ibGib's * `witness` function (visitor pattern). * * this is a wrapper that internally produces an ObservableCmd * * @param observer * * @returns subscription used for unsubscribing */ subscribe(observer: WitnessAny | ObserverWitness): Promise; private getSubscriberKey; protected dispatchToEachSubscriber({ payload, fnForObserver, observableEventType, }: { /** * payload to dispatch */ payload: TIbGibIn_ie_Payload | undefined; /** * fn to execute dispatch for each observer subscriber. * * each subscriber is either an observer or a plain jane witness. if * it's a plain witness, then it's easy - we just dispatch the payload * to the `subscriber.witness` function. If it's an observer though, * we need to decide which function to do: `next`, `error`, `complete`. */ fnForObserver: (observer: ObserverWitness, payload: TIbGibIn_ie_Payload | undefined) => Promise; /** * this type is used for dispatching to bare witness subscribers (i.e. * non-observer interface witnesses). */ observableEventType: ObservableEventType; }): Promise; /** * validates against common witness qualities. * * Override this with a call to `super.validateThis` for custom validation * for descending witness classes. * * @returns validation errors common to all observable witnesses, if any errors exist. */ protected validateThis(): Promise; /** * builds an arg ibGib. * * wrapper convenience to avoid long generic calls. */ argy({ argData, ibMetadata, noTimestamp, ibGibs, }: { argData: TCmdData; ibMetadata?: string; noTimestamp?: boolean; ibGibs?: IbGib_V1[]; }): Promise; /** * builds a result ibGib, if indeed a result ibgib is required. * * This is only useful in witnesses that have more structured * inputs/outputs. For those that simply accept any ibgib incoming and * return a primitive like ib^gib or whatever, then this is unnecessary. * * wrapper convenience to avoid long generic calls. */ resulty({ resultData, ibGibs, }: { resultData: ObservableResultData; ibGibs?: IbGib_V1[]; }): Promise; } //# sourceMappingURL=observable-base-v1.d.mts.map