Skip to content

Commit ba24697

Browse files
authored
fix(knex)!: scope KnexQueueSchemaService to the driver module (#27)
* fix(knex)!: move QueueSchemaService to the driver module The root barrel re-exported QueueSchemaService, whose constructor takes a Knex instance. That single export made build/index.d.ts import 'knex', so every consumer type checking with skipLibCheck disabled had to install the optional peer, even when using the Kysely, Redis or Sync adapter. Export it from src/drivers/knex_adapter.ts instead, the way the Kysely module already exports KyselyQueueSchemaService, so the type stays reachable only from the subpath that owns the dependency. BREAKING CHANGE: QueueSchemaService is no longer exported from the package root. Import it from '@boringnode/queue/drivers/knex_adapter'. * refactor(knex)!: rename QueueSchemaService to KnexQueueSchemaService Now that the schema service is exported from the Knex driver module, the name mirrors KyselyQueueSchemaService and src/services/knex_queue_schema.ts mirrors src/services/kysely_queue_schema.ts, so neither module carries the unqualified name. BREAKING CHANGE: QueueSchemaService is now named KnexQueueSchemaService. --------- Co-authored-by: Gerardo PG <168353+gerardp@users.noreply.github.com>
1 parent 6008ed6 commit ba24697

7 files changed

Lines changed: 23 additions & 22 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,16 @@ const adapter = knex(config, 'custom_jobs_table')
389389
</details>
390390

391391
<details>
392-
<summary><strong>Database setup with QueueSchemaService</strong></summary>
392+
<summary><strong>Database setup with KnexQueueSchemaService</strong></summary>
393393

394-
The Knex adapter requires tables to be created before use. Use `QueueSchemaService` to create them:
394+
The Knex adapter requires tables to be created before use. Use `KnexQueueSchemaService` to create them:
395395

396396
```typescript
397-
import { QueueSchemaService } from '@boringnode/queue'
397+
import { KnexQueueSchemaService } from '@boringnode/queue/drivers/knex_adapter'
398398
import Knex from 'knex'
399399

400400
const connection = Knex({ client: 'pg', connection: '...' })
401-
const schemaService = new QueueSchemaService(connection)
401+
const schemaService = new KnexQueueSchemaService(connection)
402402

403403
// Create tables with default names
404404
await schemaService.createJobsTable()
@@ -414,17 +414,17 @@ await schemaService.createJobsTable('queue_jobs', (table) => {
414414

415415
```typescript
416416
import { BaseSchema } from '@adonisjs/lucid/schema'
417-
import { QueueSchemaService } from '@boringnode/queue'
417+
import { KnexQueueSchemaService } from '@boringnode/queue/drivers/knex_adapter'
418418

419419
export default class extends BaseSchema {
420420
async up() {
421-
const schemaService = new QueueSchemaService(this.db.connection().getWriteClient())
421+
const schemaService = new KnexQueueSchemaService(this.db.connection().getWriteClient())
422422
await schemaService.createJobsTable()
423423
await schemaService.createSchedulesTable()
424424
}
425425

426426
async down() {
427-
const schemaService = new QueueSchemaService(this.db.connection().getWriteClient())
427+
const schemaService = new KnexQueueSchemaService(this.db.connection().getWriteClient())
428428
await schemaService.dropSchedulesTable()
429429
await schemaService.dropJobsTable()
430430
}

‎index.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export { Locator } from './src/locator.js'
55
export { Schedule } from './src/schedule.js'
66
export { ScheduleBuilder } from './src/schedule_builder.js'
77
export { JobBatchDispatcher } from './src/job_batch_dispatcher.js'
8-
export { QueueSchemaService } from './src/services/queue_schema.js'
98
export {
109
customBackoff,
1110
linearBackoff,

‎src/drivers/knex_adapter.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import type {
1515
import { DEFAULT_PRIORITY } from '../constants.js'
1616
import { calculateScore, resolveRetention, resolveSchedulePayload } from '../utils.js'
1717

18+
export { KnexQueueSchemaService } from '../services/knex_queue_schema.js'
19+
1820
export interface KnexAdapterOptions {
1921
connection: Knex
2022
tableName?: string
@@ -419,7 +421,7 @@ export class KnexAdapter implements Adapter {
419421
} catch (err) {
420422
if (this.#isMissingDedupColumn(err)) {
421423
throw new Error(
422-
`Dedup columns missing on "${this.#jobsTable}". Run QueueSchemaService.addDedupColumns() on your jobs table before dispatching jobs with .dedup().`,
424+
`Dedup columns missing on "${this.#jobsTable}". Run KnexQueueSchemaService.addDedupColumns() on your jobs table before dispatching jobs with .dedup().`,
423425
{ cause: err }
424426
)
425427
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Knex } from 'knex'
22

3-
export class QueueSchemaService {
3+
export class KnexQueueSchemaService {
44
#connection: Knex
55

66
constructor(connection: Knex) {

‎tests/adapter.spec.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Redis } from 'ioredis'
44
import { MemoryAdapter } from './_mocks/memory_adapter.js'
55
import { redis, RedisAdapter } from '../src/drivers/redis_adapter.js'
66
import { KnexAdapter } from '../src/drivers/knex_adapter.js'
7-
import { QueueSchemaService } from '../src/services/queue_schema.js'
7+
import { KnexQueueSchemaService } from '../src/services/knex_queue_schema.js'
88
import { registerDriverTestSuite } from './_utils/register_driver_test_suite.js'
99
import { withRedisWriteSpy } from './_utils/with_redis_write_spy.js'
1010
import { withKnexQuerySpy } from './_utils/with_knex_query_spy.js'
@@ -1672,8 +1672,8 @@ test.group('Adapter | Knex (SQLite)', (group) => {
16721672
useNullAsDefault: true,
16731673
})
16741674

1675-
// Create tables via QueueSchemaService
1676-
const schemaService = new QueueSchemaService(connection)
1675+
// Create tables via KnexQueueSchemaService
1676+
const schemaService = new KnexQueueSchemaService(connection)
16771677
await schemaService.createJobsTable()
16781678
await schemaService.createSchedulesTable()
16791679

@@ -1756,7 +1756,7 @@ test.group('Adapter | Knex (SQLite)', (group) => {
17561756
test.group('Adapter | Knex (PostgreSQL)', (group) => {
17571757
let connection: ReturnType<typeof Knex>
17581758
let adapter: KnexAdapter
1759-
let schemaService: QueueSchemaService
1759+
let schemaService: KnexQueueSchemaService
17601760
const tableName = 'queue_jobs_test'
17611761
const schedulesTableName = 'queue_schedules_test'
17621762

@@ -1772,7 +1772,7 @@ test.group('Adapter | Knex (PostgreSQL)', (group) => {
17721772
},
17731773
})
17741774

1775-
schemaService = new QueueSchemaService(connection)
1775+
schemaService = new KnexQueueSchemaService(connection)
17761776

17771777
// Clean up tables before each test
17781778
await schemaService.dropJobsTable(tableName)

‎tests/worker_adapter.spec.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Redis } from 'ioredis'
44
import { MemoryAdapter } from './_mocks/memory_adapter.js'
55
import { RedisAdapter } from '../src/drivers/redis_adapter.js'
66
import { KnexAdapter } from '../src/drivers/knex_adapter.js'
7-
import { QueueSchemaService } from '../src/services/queue_schema.js'
7+
import { KnexQueueSchemaService } from '../src/services/knex_queue_schema.js'
88
import { registerWorkerRetryTestSuite } from './_utils/register_worker_retry_suite.js'
99

1010
const KEY_PREFIX = 'boringnode::queue::worker-test::'
@@ -62,7 +62,7 @@ test.group('Worker Adapter | Knex (SQLite)', (group) => {
6262
useNullAsDefault: true,
6363
})
6464

65-
const schemaService = new QueueSchemaService(connection)
65+
const schemaService = new KnexQueueSchemaService(connection)
6666
await schemaService.createJobsTable()
6767
await schemaService.createSchedulesTable()
6868

@@ -84,7 +84,7 @@ test.group('Worker Adapter | Knex (SQLite)', (group) => {
8484
test.group('Worker Adapter | Knex (PostgreSQL)', (group) => {
8585
let connection: ReturnType<typeof Knex>
8686
let adapter: KnexAdapter
87-
let schemaService: QueueSchemaService
87+
let schemaService: KnexQueueSchemaService
8888
const tableName = 'queue_jobs_worker_test'
8989
const schedulesTableName = 'queue_schedules_worker_test'
9090

@@ -100,7 +100,7 @@ test.group('Worker Adapter | Knex (PostgreSQL)', (group) => {
100100
},
101101
})
102102

103-
schemaService = new QueueSchemaService(connection)
103+
schemaService = new KnexQueueSchemaService(connection)
104104
await schemaService.dropJobsTable(tableName)
105105
await schemaService.dropSchedulesTable(schedulesTableName)
106106
await schemaService.createJobsTable(tableName)

‎tests/worker_concurrency.spec.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { test } from '@japa/runner'
33
import { Redis } from 'ioredis'
44
import { RedisAdapter } from '../src/drivers/redis_adapter.js'
55
import { KnexAdapter } from '../src/drivers/knex_adapter.js'
6-
import { QueueSchemaService } from '../src/services/queue_schema.js'
6+
import { KnexQueueSchemaService } from '../src/services/knex_queue_schema.js'
77
import { registerWorkerConcurrencyTestSuite } from './_utils/register_worker_concurrency_suite.js'
88

99
const KEY_PREFIX = 'boringnode::queue::concurrency-test::'
@@ -38,7 +38,7 @@ test.group('Worker Concurrency | Redis', (group) => {
3838
test.group('Worker Concurrency | Knex (PostgreSQL)', (group) => {
3939
let connection: ReturnType<typeof Knex>
4040
let adapter: KnexAdapter
41-
let schemaService: QueueSchemaService
41+
let schemaService: KnexQueueSchemaService
4242
const tableName = 'queue_jobs_concurrency_test'
4343
const schedulesTableName = 'queue_schedules_concurrency_test'
4444

@@ -54,7 +54,7 @@ test.group('Worker Concurrency | Knex (PostgreSQL)', (group) => {
5454
},
5555
})
5656

57-
schemaService = new QueueSchemaService(connection)
57+
schemaService = new KnexQueueSchemaService(connection)
5858

5959
// Drop both tables to ensure clean state
6060
await schemaService.dropJobsTable(tableName)

0 commit comments

Comments
 (0)