From 0d388af4a46badb7f0b8f621a1775537cb2cd7d2 Mon Sep 17 00:00:00 2001 From: Dave Druska Date: Thu, 24 Aug 2017 14:25:45 -0400 Subject: [PATCH] Add TypeScript type definitions --- package.json | 3 +- src/types.d.ts | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/types.d.ts diff --git a/package.json b/package.json index 2a66b8e1..894c7cf6 100644 --- a/package.json +++ b/package.json @@ -52,5 +52,6 @@ "bugs": { "url": "https://github.com/timgit/pg-boss/issues" }, - "homepage": "https://github.com/timgit/pg-boss#readme" + "homepage": "https://github.com/timgit/pg-boss#readme", + "types": "./src/types.d.ts" } diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 00000000..1c9614f4 --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,92 @@ +// Type definitions for pg-boss + +declare namespace PgBoss { + export interface ConnectionOptions { + database: string + user: string + password: string + host?: string + port?: number + schema?: string + uuid?: string + poolSize?: number + } + + interface PublishOptions { + startIn?: number | string + singletonKey?: string + singletonSeconds?: number + singletonMinutes?: number + singletonHours?: number + singletonDays?: number + retryLimit?: number + expireIn?: string + } + + interface SubscribeOptions { + teamSize?: number + batchSize?: number + newJobCheckInterval?: number + newJobCheckIntervalSeconds?: number + } + + interface Request { + name: string + data?: object + options?: PublishOptions + } + + interface Job { + id: number + name: string + data: object + done: (err?: Error, data?: object) => void + } +} + +interface PgBoss { + on(event: string, handler: Function): void + start(): Promise + stop(): Promise + connect(): Promise + disconnect(): Promise + publish(request: Request): Promise + publish(name: string, data: object): Promise + publish(name: string, data: object, options: PgBoss.PublishOptions): Promise + subscribe(name: string, handler: Function): Promise + subscribe(name: string, options: PgBoss.SubscribeOptions, handler: Function): Promise + onComplete(name: string, handler: Function): Promise + onComplete(name: string, options: PgBoss.SubscribeOptions, handler: Function): Promise + onFail(name: string, handler: Function): Promise + onFail(name: string, options: PgBoss.SubscribeOptions, handler: Function): Promise + unsubscribe(name: string): Promise + offComplete(name: string): Promise + offExpire(name: string): Promise + offFail(name: string): Promise + fetch(name: string): Promise + fetch(name: string, batchSize: number): Promise + fetchCompleted(name: string): Promise + fetchCompleted(name: string, batchSize: number): Promise + fetchExpired(name: string): Promise + fetchExpired(name: string, batchSize: number): Promise + fetchFailed(name: string): Promise + fetchFailed(name: string, batchSize: number): Promise + cancel(id: string): Promise + cancel(ids: string[]): Promise + complete(id: string): Promise + complete(id: string, data: object): Promise + complete(ids: string[]): Promise + fail(id: string): Promise + fail(id: string, data: object): Promise + fail(ids: string[]): Promise +} + +interface PgBossConstructor { + new(connectionString: string): PgBoss + new(options: PgBoss.ConnectionOptions): PgBoss +} + +declare module 'pg-boss' { + const PgBoss: PgBossConstructor + export = PgBoss +}