Skip to content

Commit

Permalink
Merge pull request #34 from druska/master
Browse files Browse the repository at this point in the history
Add TypeScript type definitions
  • Loading branch information
timgit committed Aug 28, 2017
2 parents e602c0f + 0d388af commit af2cc1f
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
92 changes: 92 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -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<PgBoss>
stop(): Promise<void>
connect(): Promise<PgBoss>
disconnect(): Promise<void>
publish(request: Request): Promise<string | null>
publish(name: string, data: object): Promise<string | null>
publish(name: string, data: object, options: PgBoss.PublishOptions): Promise<string | null>
subscribe(name: string, handler: Function): Promise<void>
subscribe(name: string, options: PgBoss.SubscribeOptions, handler: Function): Promise<void>
onComplete(name: string, handler: Function): Promise<void>
onComplete(name: string, options: PgBoss.SubscribeOptions, handler: Function): Promise<void>
onFail(name: string, handler: Function): Promise<void>
onFail(name: string, options: PgBoss.SubscribeOptions, handler: Function): Promise<void>
unsubscribe(name: string): Promise<boolean>
offComplete(name: string): Promise<boolean>
offExpire(name: string): Promise<boolean>
offFail(name: string): Promise<boolean>
fetch(name: string): Promise<PgBoss.Job | null>
fetch(name: string, batchSize: number): Promise<PgBoss.Job | null>
fetchCompleted(name: string): Promise<PgBoss.Job | null>
fetchCompleted(name: string, batchSize: number): Promise<PgBoss.Job | null>
fetchExpired(name: string): Promise<PgBoss.Job | null>
fetchExpired(name: string, batchSize: number): Promise<PgBoss.Job | null>
fetchFailed(name: string): Promise<PgBoss.Job | null>
fetchFailed(name: string, batchSize: number): Promise<PgBoss.Job | null>
cancel(id: string): Promise<void>
cancel(ids: string[]): Promise<void>
complete(id: string): Promise<void>
complete(id: string, data: object): Promise<void>
complete(ids: string[]): Promise<void>
fail(id: string): Promise<void>
fail(id: string, data: object): Promise<void>
fail(ids: string[]): Promise<void>
}

interface PgBossConstructor {
new(connectionString: string): PgBoss
new(options: PgBoss.ConnectionOptions): PgBoss
}

declare module 'pg-boss' {
const PgBoss: PgBossConstructor
export = PgBoss
}

0 comments on commit af2cc1f

Please sign in to comment.