import SubscriptionQueue from './subscription-queue'; import type { ITransport } from '../transport/transport-base'; import type { StreamingMessage } from './types'; declare const updateTypes: { readonly UPDATE_TYPE_SNAPSHOT: 1; readonly UPDATE_TYPE_DELTA: 2; }; declare type SubscriptionUpdateTypes = typeof updateTypes[keyof typeof updateTypes]; declare const stateFlags: { readonly SUBSCRIBE_REQUESTED: 1; readonly SUBSCRIBED: 2; readonly UNSUBSCRIBE_REQUESTED: 4; readonly UNSUBSCRIBED: 8; readonly PATCH_REQUESTED: 16; readonly REPLACE_REQUESTED: 32; readonly READY_FOR_UNSUBSCRIBE_BY_TAG: 64; }; export declare type SubscriptionState = typeof stateFlags[keyof typeof stateFlags]; export interface StreamingOptions { /** * headers to add to the subscription request */ headers?: Record; /** * A callback function that is invoked when an initial snapshot or update is received. * @param data - data received * @param updateType - either be subscription.UPDATE_TYPE_DELTA or subscription.UPDATE_TYPE_SNAPSHOT * @param subscription - the subscription where the update originated from */ onUpdate?: (data: unknown, updateType: SubscriptionUpdateTypes, subscription: Subscription) => void; /** * A callback function that is invoked when an error occurs. * @param data - error data * @param subscription - the subscription the error occurred on */ onError?: (data: unknown, subscription: Subscription) => void; /** * A callback function that is invoked after the last action is dequeued. * @param subscription - the subscription whose queue became empty */ onQueueEmpty?: (subscription: Subscription) => void; /** * A callback function that is invoked on network error. * @param subscription - the subscription getting a network error */ onNetworkError?: (subscription: Subscription) => void; /** * A callback function that is invoked when the subscription is created. * @param subscription - the subscription created */ onSubscriptionCreated?: (subscription: Subscription) => void; /** * A callback function that is invoked when the subscription is ready to be removed. * @param subscription - the subscription ready to remove */ onSubscriptionReadyToRemove?: (subscription: Subscription) => void; } export interface SubscriptionArgs { /** * The format for the subscription (passed to OpenAPI). */ Format?: string | null; /** * The subscription arguments (passed to OpenAPI). */ Arguments?: Record; /** * The data refresh rate (passed to OpenAPI). */ RefreshRate?: number; Top?: number; /** * The tag for the subscription (passed to OpenAPI). */ Tag?: string; } interface SubscriptionSuccessResult { /** * The current state */ State: 'active' | 'suspended'; /** * The media type (RFC 2046), of the serialized data updates that are streamed to the client. */ Format: string; /** * The streaming context id that this response is associated with. */ ContextId: string; /** * The time (in seconds) that the client should accept the subscription to be inactive before considering it invalid. */ InactivityTimeout: number; /** * Actual refresh rate assigned to the subscription according to the customers SLA. */ RefreshRate: number; /** * Snapshot of the current data available */ Snapshot: Record; Schema?: string; SchemaName?: string; } export declare function __forTestingOnlyResetReferenceId(): void; declare type LogDiagnostic = { queue: ReadonlyArray; type: string; [otherKey: string]: unknown; }; /** * A subscription to a resource, which streams updates. * * This class should not be constructed directly, it should instead be created via the * Streaming.createSubscription factory method. */ declare class Subscription { UPDATE_TYPE_SNAPSHOT: 1; UPDATE_TYPE_DELTA: 2; STATE_SUBSCRIBE_REQUESTED: 1; STATE_SUBSCRIBED: 2; STATE_UNSUBSCRIBE_REQUESTED: 4; STATE_UNSUBSCRIBED: 8; STATE_PATCH_REQUESTED: 16; STATE_REPLACE_REQUESTED: 32; STATE_READY_FOR_UNSUBSCRIBE_BY_TAG: 64; TRANSITIONING_STATES: number; SUBSCRIBED_OR_SUBSCRIBING_STATES: number; /** * Defines the name of the property on data used to indicate that the data item is a deletion, rather than a * insertion / update. */ OPENAPI_DELETE_PROPERTY: string; /** * The streaming context id identifies the particular streaming connection that this subscription will use to subscribe. * It is updated while reconnecting with new connection or switching between on-premise and cloud streaming */ streamingContextId: string; /** * Context id will be set when subscribed and will be used to unsubscribe */ currentStreamingContextId: string | null; /** * The reference id is used to identify this subscription. */ referenceId: string | null; /** * The last reference id a reset was called on, if we are throttling resets due to a publisher being down */ publisherDownReferenceId: string | null; /** * The action queue. */ queue: SubscriptionQueue; onSubscriptionReadyToRemove?: (subscription: Subscription) => void; parser: import("./parser/parser-base").default; onStateChangedCallbacks: Array<(state: SubscriptionState) => void>; transport: ITransport; servicePath: string; url: string; onSubscriptionCreated: ((subscription: Subscription) => void) | undefined; subscriptionData: SubscriptionArgs; onUpdate: ((data: unknown, updateType: SubscriptionUpdateTypes, subscription: Subscription) => void) | undefined; onError: ((data: unknown, subscription: Subscription) => void) | undefined; onQueueEmpty: ((subscription: Subscription) => void) | undefined; headers: Record | undefined; onNetworkError: ((subscription: Subscription) => void) | undefined; connectionAvailable: boolean; currentState: SubscriptionState; updatesBeforeSubscribed: null | StreamingMessage[]; networkErrorSubscribingTimer: null | number; inactivityTimeout: number | undefined; latestActivity: number | undefined; SchemaName: string | undefined | null; isDisposed: boolean; resetTimeStamps: Array; waitForPublisherToRespondTimer: null | number; logDiagnostics: Array; constructor(streamingContextId: string, transport: ITransport, servicePath: string, url: string, subscriptionArgs: SubscriptionArgs, options?: StreamingOptions); /** * If we get 3 resets within 1 minute then we wait for 1 minute * since it may indicate some problem with publishers or the frontend */ private checkIfPublisherDown; /** * Returns url used in subscribe post request. * Supports pagination (includes Top property in url request). */ private getSubscribeUrl; /** * Normalize subscription data, by removing * unsupported properties. */ private normalizeSubscribeData; /** * Call to actually do a subscribe. */ private subscribe; /** * Does an actual unsubscribe. */ private unsubscribe; /** * Does subscription modification through PATCH request * Only works for endpoints that support PATCH. */ private modifyPatch; /** * Does subscription modification through delete & resubscribe in one HTTP call. * Works for all endpoints. */ private modifyReplace; private unsubscribeByTagPending; /** * Queues or performs an action based on the current state. * Supports queue for more then one action, to support consecutive modify requests, * which invoke unsubscribe and subscribe one after another. * @param action - action * @param args - args */ private tryPerformAction; /** * Callback for when the subscription is ready to perform the next action. */ private onReadyToPerformNextAction; private addLogDiagnostic; /** * Performs an action to a subscription based on the current state. * @param queuedAction - queuedAction * @param isLastQueuedAction - isLastQueuedAction */ private performAction; /** * Handles the response to the initial REST request that creates the subscription. * @param referenceId - referenceId * @param result - Result object */ private onSubscribeSuccess; private cleanUpLeftOverSubscription; /** * Called when a subscribe errors * @param response - response */ private onSubscribeError; /** * Called after subscribe is successful */ private onUnsubscribeSuccess; /** * Called when a unsubscribe errors * @param response - response */ private onUnsubscribeError; /** * Called after modify patch is successful * @param referenceId - referenceId * @param response - response */ private onModifyPatchSuccess; /** * Called when a unsubscribe errors * @param response - response */ private onModifyPatchError; private setState; /** * Resets the subscription activity */ onActivity(): void; /** * Add a callback to be invoked when the subscription state changes. */ addStateChangedCallback(callback: (state: SubscriptionState) => void): void; /** * Remove a callback which was invoked when the subscription state changes. */ removeStateChangedCallback(callback: (...args: unknown[]) => void): void; processUpdate(message: StreamingMessage, type: SubscriptionUpdateTypes): void; private fallbackToJSON; processSnapshot(response: SubscriptionSuccessResult): void; /** * Reset happens when the server notices that a publisher is dead or when * it misses some messages so it doesn't know who is dead (reset all) * This may be called with a burst of messages. The intent is that we queue * an operation to unsubscribe, wait for that to finish and then subscribe * This waiting means that if we get further resets whilst unsubscribing, we * can ignore them. It also ensures that we don't hit the subscription limit * because the subscribe manages to get to the server before the unsubscribe. */ reset(isServerInitiated: boolean): void; /** * Does a unsubscribe and then schedules a subscribe for when it is finished unsubscribing * Call this only if this is not a error scenario. Normally you should use reset * So that we track the reset */ unsubscribeAndSubscribe(): void; /** * Try to subscribe. */ onSubscribe({ replace }?: { replace?: boolean | undefined; }): void; /** * Remove the subscription once it has finished processing previous actions */ onRemove(): void; /** * Try to modify. * @param newArgs - Updated arguments of modified subscription. */ onModify(newArgs?: Record, options?: { isPatch?: false; isReplace: true; } | { isPatch: true; patchArgsDelta: Record; isReplace?: false; } | { isPatch?: false; isReplace?: false; }): void; /** * Try to unsubscribe. */ onUnsubscribe(forceUnsubscribe?: boolean): void; /** * Tells us we are now disposed */ dispose(): void; /** * Tell the subscription that the connection is unavailable. */ onConnectionUnavailable(): void; /** * Tell the subscription that the connection is available and it can perform any queued action. */ onConnectionAvailable(): void; /** * Handles the 'data' event raised by Streaming. * @returns false if the update is not for this subscription */ onStreamingData(message: StreamingMessage): false | void; /** * Handles a heartbeat from the server. */ onHeartbeat(): void; /** * Handle a subscription pending unsubscribe by tag. */ onUnsubscribeByTagPending(): void; /** * Handled a subscription having been unsubscribed by tag. */ onUnsubscribeByTagComplete(): void; /** * Returns whether this subscription is ready to be unsubscribed by tag after it has been requested. */ isReadyForUnsubscribeByTag(): boolean; /** * Returns the time in ms till the subscription would be orphaned. * @param now - The current time as a reference (e.g. Date.now()). */ timeTillOrphaned(now: number): number; } export default Subscription;