Comparing version 0.0.5 to 0.0.6
import { JSON } from './json'; | ||
declare type Base64String = string; | ||
declare type SubscriptionId = string; | ||
declare type MessageId = string; | ||
@@ -27,3 +26,3 @@ /** | ||
*/ | ||
export interface PubSubMessage<S extends string, T extends JSON> { | ||
export interface PubSubMessage<S extends string, T> { | ||
subscription: S; | ||
@@ -51,3 +50,3 @@ message: { | ||
status: EventStatus; | ||
subscription: SubscriptionId; | ||
subscription: string; | ||
base64_event_data: Base64String; | ||
@@ -57,3 +56,3 @@ } | ||
getPubSubEvent(messageId: MessageId): Promise<PubSubEvent | undefined>; | ||
recordMessageReceived(rawMessage: UnprocessedPubSubMessage, subscription: SubscriptionId, cachedEvent?: PubSubEvent): Promise<PubSubEvent>; | ||
recordMessageReceived(rawMessage: UnprocessedPubSubMessage, subscription: string, cachedEvent?: PubSubEvent): Promise<PubSubEvent>; | ||
recordMessageProcessingOutcome(cachedEvent: PubSubEvent, outcome: EventStatus): Promise<void>; | ||
@@ -65,17 +64,17 @@ } | ||
getPubSubEvent(messageId: MessageId): Promise<PubSubEvent | undefined>; | ||
recordMessageReceived(rawMessage: UnprocessedPubSubMessage, subscription: SubscriptionId, cachedEvent?: PubSubEvent): Promise<PubSubEvent>; | ||
recordMessageReceived(rawMessage: UnprocessedPubSubMessage, subscription: string, cachedEvent?: PubSubEvent): Promise<PubSubEvent>; | ||
recordMessageProcessingOutcome(cachedEvent: PubSubEvent, outcome: EventStatus): Promise<void>; | ||
} | ||
declare type Validator<T> = (json: JSON) => T | undefined; | ||
interface SubscriptionHandler<T> { | ||
interface SubscriptionHandler<S extends string, T> { | ||
validator: Validator<T>; | ||
handler: (data: T) => Promise<boolean>; | ||
handler: (data: PubSubMessage<S, T>) => Promise<boolean>; | ||
} | ||
export declare type DecodingTable<T> = Map<SubscriptionId, SubscriptionHandler<T>>; | ||
export declare const getSubscription: (rawSubscription: string) => string | null; | ||
export declare class PubSub<T> { | ||
export declare type DecodingTable<S extends string, T> = Map<S, SubscriptionHandler<S, T>>; | ||
export declare const getSubscription: <S extends string>(rawSubscription: string) => S | null; | ||
export declare class PubSub<S extends string, T> { | ||
private projectId; | ||
private stateManager; | ||
private decoders; | ||
constructor(projectId: string, decodingTable: DecodingTable<T>, customStateManager?: StateManager); | ||
constructor(projectId: string, decodingTable: DecodingTable<S, T>, customStateManager?: StateManager); | ||
publish<J extends {}>(topic: string, data: J): Promise<void>; | ||
@@ -82,0 +81,0 @@ handlePubSubMessage(rawMsg: UnprocessedPubSubMessage): Promise<SubscriptionError | undefined>; |
@@ -142,3 +142,10 @@ "use strict"; | ||
} | ||
const succeeded = yield handler(decodedMessage.data).catch(() => { | ||
const pubSubMessage = { | ||
subscription, | ||
message: { | ||
messageId: rawMsg.message.messageId, | ||
data: decodedMessage.data, | ||
}, | ||
}; | ||
const succeeded = yield handler(pubSubMessage).catch(() => { | ||
// catching in case handler didn't catch its own errors | ||
@@ -145,0 +152,0 @@ return false; |
{ | ||
"name": "a1pubsub", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "GCP PubSub wrapper to add idempotency", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
22764
256
7