Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
declaration file for Google Cloud PubSub
declare module '@google-cloud/pubsub' {
import stream from 'stream'
import events from 'events'
interface ConfigurationObject extends Object {
projectId?: string
keyFilename?: string
email?: string
credentials?: CredentialsObject
autoRetry?: boolean
maxRetries?: number
promise?: Function
}
interface CredentialsObject extends Object {
client_email?: string
private_key?: string
}
interface QueryOptions extends Object {
autoPaginate?: boolean
maxApiCalls?: number
maxResults?: number
pageSize?: number
pageToken?: string
}
interface SnapshotQueryOptions extends QueryOptions { }
interface TopicsQueryOptions extends Object { }
interface SubscriptionQueryOptions extends Object {
topic?: string
}
interface SubscribeOptions extends Object {
ackDeadlineSeconds: number
autoAck: boolean
encoding: string
interval: number
maxInProgress: number
pushEndpoint: string
timeout: number
}
interface SubscriptionOptions extends Object {
autoAck?: boolean
encoding?: string
interval?: number
maxInProgress?: number
timeout?: number
}
interface SubscriptionObject extends Object {
name: string
topic: string
pushConfig: PushConfigObject
ackDeadlineSeconds: number
}
interface PushConfigObject extends Object {
pushEndpoint: string
attributes: {
[key: string]: string
}
}
interface TopicObject extends Object {
name: string
}
interface SnapshotObject extends Object {
name: string
}
interface Message {
id: string
ackId: string
data: any
attributes: any
timestamp: number
ack(callback: Function): void
skip(): void
}
type ApiCallbackFunction<T> = (err: Error | null, data: T, apiResponse: any) => void
type CallbackFunction<T> = (err: Error | null, data: T) => void
type ApiPromiseResult<T> = [T, any]
class Subscription extends events.EventEmitter {
ack(
ackIds: string | string[],
options?: {
timeout: number
},
callback?: () => void
): Promise<void> | void
create(
options?: SubscribeOptions,
callback?: ApiCallbackFunction<SubscriptionObject>
): Promise<ApiPromiseResult<SubscriptionObject>> | void
createSnapshot(
name: string,
callback?: ApiCallbackFunction<SnapshotObject>
): Promise<ApiPromiseResult<SnapshotObject>> | void
}
class PubSub {
constructor(
config: ConfigurationObject
)
createTopic(
name: string,
callback?: ApiCallbackFunction<TopicObject>
): Promise<ApiPromiseResult<TopicObject>> | void
getSnapshots(
options?: SnapshotQueryOptions,
callback?: CallbackFunction<SnapshotObject[]>
): Promise<any[]> | void
getSnapshotsStream(
options?: SnapshotQueryOptions
): stream.Readable
getSubscriptions(
options?: SubscriptionQueryOptions,
callback?: ApiCallbackFunction<SubscriptionObject[]>
): Promise<ApiPromiseResult<SubscriptionObject[]>> | void
getSubscriptionsStream(
options?: SubscriptionQueryOptions
): stream.Readable
getTopics(
options?: TopicsQueryOptions,
callback?: ApiCallbackFunction<TopicObject[]>
): Promise<ApiPromiseResult<TopicObject[]>> | void
getTopicsStream(
options?: TopicsQueryOptions
): stream.Readable
snapshot(
name: string
): any
subscribe(
topic: TopicObject | string,
subName?: stream,
options?: SubscribeOptions,
callback?: ApiCallbackFunction<SubscriptionObject>
): Promise<ApiPromiseResult<SubscriptionObject>> | void
subscription(
name?: string,
options?: SubscriptionOptions
): void
topic(
name: string
): TopicObject
}
function PubSubFn(config: ConfigurationObject): PubSub
export = PubSubFn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment