Skip to content

Commit 2c9009f

Browse files
committed
consolidate to named exports
1 parent 6111529 commit 2c9009f

31 files changed

Lines changed: 169 additions & 151 deletions

examples/load/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import PgBoss from '../../dist/index.mjs'
1+
import { PgBoss } from '../../dist/index.mjs'
22
import * as helper from '../../test/testHelper.js'
33
import { delay } from '../../src/tools.ts'
44

examples/readme.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const PgBoss = require('../')
1+
const { PgBoss } = require('../')
22

33
async function readme () {
44
const boss = new PgBoss('postgres://postgres:postgres@localhost/pgboss')

examples/readme.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import PgBoss from '../dist/index.mjs'
1+
import { PgBoss } from '../dist/index.mjs'
22

33
async function readme () {
44
const boss = new PgBoss('postgres://postgres:postgres@localhost/pgboss')

examples/schedule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import PgBoss from '../dist/index.mjs'
1+
import { PgBoss } from '../dist/index.mjs'
22
import * as helper from '../test/testHelper.js'
33

44
async function schedule () {

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "pg-boss",
3-
"version": "12.0.0-beta1",
3+
"version": "12.0.0-beta3",
44
"description": "Queueing jobs in Postgres from Node.js like a boss",
55
"type": "module",
6-
"main": "./dist/index.cjs",
6+
"main": "./dist/index.mjs",
77
"module": "./dist/index.mjs",
88
"types": "./dist/index.d.mts",
99
"engines": {
1010
"node": ">=22.12.0"
1111
},
1212
"exports": {
13-
"import": "./dist/index.mjs",
14-
"require": "./dist/index.cjs"
13+
".": "./dist/index.mjs",
14+
"./package.json": "./package.json"
1515
},
1616
"dependencies": {
1717
"cron-parser": "^5.4.0",
@@ -36,7 +36,6 @@
3636
},
3737
"scripts": {
3838
"build": "tsdown",
39-
"postbuild": "node scripts/cjs-shim.js",
4039
"prepublishOnly": "npm test && npm run build",
4140
"test": "eslint . && mocha test/**/*.ts",
4241
"cover": "nyc npm test",

scripts/cjs-shim.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/index.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,27 @@ import { delay } from './tools.ts'
99
import type * as types from './types.ts'
1010
import 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-
357371
export 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,

src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export type QueuePolicies = {
1414
stately: 'stately'
1515
}
1616

17+
export type Events = {
18+
error: 'error',
19+
warning: 'warning',
20+
wip: 'wip',
21+
stopped: 'stopped'
22+
}
23+
1724
export interface IDatabase {
1825
executeSql(text: string, values?: unknown[]): Promise<{ rows: any[] }>;
1926
}
@@ -86,7 +93,6 @@ export interface ConstructorOptions extends DatabaseOptions, SchedulingOptions,
8693

8794
export interface ResolvedConstructorOptions extends ConstructorOptions {
8895
schema: string;
89-
pollingInterval: number;
9096
monitorIntervalSeconds: number;
9197
cronMonitorIntervalSeconds: number;
9298
maintenanceIntervalSeconds: number;
@@ -215,6 +221,7 @@ export interface JobWithMetadata<T = object> extends Job<T> {
215221

216222
export interface JobInsert<T = object> {
217223
id?: string;
224+
name: string;
218225
data?: T;
219226
priority?: number;
220227
retryLimit?: number;

test/backgroundErrorTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert, { strictEqual } from 'node:assert'
2-
import PgBoss from '../src/index.ts'
2+
import { PgBoss } from '../src/index.ts'
33
import { delay } from '../src/tools.ts'
44

55
describe('background processing error handling', function () {
@@ -62,7 +62,7 @@ describe('background processing error handling', function () {
6262
await this.boss.start()
6363

6464
assert.rejects(async () => {
65-
await this.boss!.stop({ wait: false })
65+
await this.boss.stop({ wait: false })
6666
})
6767
})
6868
})

test/cancelTest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import assert from 'node:assert'
22
import * as helper from './testHelper.ts'
33
import type { TestContext } from './hooks.ts'
4+
import { type PgBoss } from '../src/index.ts'
45

56
describe('cancel', function () {
67
it('should reject missing arguments', async function (this: TestContext) {
7-
this.boss = await helper.start(this.bossConfig)
8+
this.boss = await helper.start(this.bossConfig) as PgBoss
89

910
assert.rejects(async () => {
1011
await this.boss.cancel(null as any, null as any)

0 commit comments

Comments
 (0)