@@ -9,12 +9,27 @@ import { delay } from './tools.ts'
99import type * as types from './types.ts'
1010import DbDefault from './db.ts'
1111
12- const events = {
12+ export const states : types . JobStates = plans . JOB_STATES
13+ export const policies : types . QueuePolicies = plans . QUEUE_POLICIES
14+ export const events : types . Events = {
1315 error : 'error' ,
16+ warning : 'warning' ,
17+ wip : 'wip' ,
1418 stopped : 'stopped'
1519} as const
1620
17- class PgBoss extends EventEmitter < types . PgBossEventMap > {
21+ export function getConstructionPlans ( schema ?: string ) {
22+ return Contractor . constructionPlans ( schema )
23+ }
24+
25+ export function getMigrationPlans ( schema ?: string , version ?: number ) {
26+ return Contractor . migrationPlans ( schema , version )
27+ }
28+
29+ export function getRollbackPlans ( schema ?: string , version ?: number ) {
30+ return Contractor . rollbackPlans ( schema , version )
31+ }
32+ export class PgBoss extends EventEmitter < types . PgBossEventMap > {
1833 #stoppingOn: number | null
1934 #stopped: boolean
2035 #starting: boolean | undefined
@@ -25,6 +40,7 @@ class PgBoss extends EventEmitter<types.PgBossEventMap> {
2540 #contractor: Contractor
2641 #manager: Manager
2742 #timekeeper: Timekeeper
43+ #events: { readonly error : 'error' ; readonly stopped : 'stopped' }
2844
2945 constructor ( connectionString : string )
3046 constructor ( options : types . ConstructorOptions )
@@ -60,6 +76,11 @@ class PgBoss extends EventEmitter<types.PgBossEventMap> {
6076 this . #contractor = contractor
6177 this . #manager = manager
6278 this . #timekeeper = timekeeper
79+
80+ this . #events = {
81+ error : 'error' ,
82+ stopped : 'stopped'
83+ } as const
6384 }
6485
6586 #promoteEvents ( emitter : types . EventsMixin ) {
@@ -68,8 +89,6 @@ class PgBoss extends EventEmitter<types.PgBossEventMap> {
6889 }
6990 }
7091
71- // Public API
72-
7392 static getConstructionPlans ( schema ?: string ) {
7493 return Contractor . constructionPlans ( schema )
7594 }
@@ -151,10 +170,10 @@ class PgBoss extends EventEmitter<types.PgBossEventMap> {
151170 this . #stoppingOn = null
152171 this . #started = false
153172
154- this . emit ( events . stopped )
173+ this . emit ( this . # events. stopped )
155174 resolve ( )
156175 } catch ( err : any ) {
157- this . emit ( events . error , err )
176+ this . emit ( this . # events. error , err )
158177 reject ( err )
159178 }
160179 }
@@ -182,7 +201,7 @@ class PgBoss extends EventEmitter<types.PgBossEventMap> {
182201 await shutdown ( )
183202 } catch ( err : any ) {
184203 reject ( err )
185- this . emit ( events . error , err )
204+ this . emit ( this . # events. error , err )
186205 }
187206 } )
188207 } )
@@ -349,11 +368,6 @@ class PgBoss extends EventEmitter<types.PgBossEventMap> {
349368 }
350369}
351370
352- export default PgBoss
353-
354- export const states = PgBoss . states
355- export const policies = PgBoss . policies
356-
357371export type {
358372 ConnectionOptions ,
359373 ConstructorOptions ,
@@ -364,6 +378,7 @@ export type {
364378 JobInsert ,
365379 JobPollingOptions ,
366380 JobStates ,
381+ Events ,
367382 JobWithMetadata ,
368383 MaintenanceOptions ,
369384 OffWorkOptions ,
0 commit comments