Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changesets/2879.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- fix(jobs): Stop importing all of type-fest for the priority type by @Tobbe

The type for a job's `priority` option is defined inside `@cedarjs/jobs`, so
`type-fest` is not a dependency of the package. Apps that type-check with
`skipLibCheck: false` don't load type-fest's declaration files through
`@cedarjs/jobs`, which makes `yarn cedar type-check` noticeably faster on the
api side.

`priority` still accepts only the integers 1 to 100, and your editor still flags
values outside that range.
1 change: 0 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"msw": "2.15.0",
"publint": "0.3.24",
"react": "19.3.0",
"type-fest": "5.10.0",
"typescript": "5.9.3",
"vitest": "4.1.11"
},
Expand Down
1 change: 0 additions & 1 deletion packages/framework-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"fast-glob": "3.3.3"
},
"devDependencies": {
"type-fest": "5.10.0",
"typescript": "5.9.3"
},
"engines": {
Expand Down
3 changes: 1 addition & 2 deletions packages/jobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
"dependencies": {
"@cedarjs/cli-helpers": "workspace:*",
"@cedarjs/project-config": "workspace:*",
"cron-parser": "5.10.1",
"type-fest": "5.10.0"
"cron-parser": "5.10.1"
},
"devDependencies": {
"@cedarjs/framework-tools": "workspace:*",
Expand Down
30 changes: 30 additions & 0 deletions packages/jobs/src/core/__tests__/JobManager.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,36 @@ describe('JobManager Type Tests', () => {
expectTypeOf(createdJob).toHaveProperty('queue')
expectTypeOf(createdJob).toHaveProperty('perform')
})

it('should accept integer priorities from 1 to 100', () => {
manager.createJob({ queue: 'default', priority: 1, perform: () => {} })
manager.createJob({ queue: 'default', priority: 50, perform: () => {} })
manager.createJob({ queue: 'default', priority: 100, perform: () => {} })

// prettier-ignore
expectTypeOf<JobDefinition<['default']>['priority']>().toEqualTypeOf<
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30
| 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40
| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50
| 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60
| 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70
| 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80
| 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90
| 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100
| undefined
>()
})

it('should reject priorities outside of 1 to 100', () => {
// @ts-expect-error - priority must be at least 1
manager.createJob({ queue: 'default', priority: 0, perform: () => {} })
// @ts-expect-error - priority must be at most 100
manager.createJob({ queue: 'default', priority: 101, perform: () => {} })
// @ts-expect-error - priority must be an integer
manager.createJob({ queue: 'default', priority: 1.5, perform: () => {} })
})
})

describe('scheduler function type', () => {
Expand Down
18 changes: 14 additions & 4 deletions packages/jobs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// debug messages. CedarJS's Jobs will fallback to use `console` if no logger is
// passed in to CedarJS or any adapter.

import type { IntRange } from 'type-fest' with { 'resolution-mode': 'import' }

import type { BaseAdapter } from './adapters/BaseAdapter/BaseAdapter.js'

/** CedarJS's logger and the standard console logger conform to this shape. */
Expand Down Expand Up @@ -176,7 +174,7 @@ export interface JobDefinition<
queue: TQueues[number]

/**
* The priority of the job in the range of 0-100. The lower the number, the
* The priority of the job in the range of 1-100. The lower the number, the
* higher the priority. The default is 50.
* @default 50
*/
Expand Down Expand Up @@ -240,7 +238,19 @@ export type ScheduleJobOptions =
cron: string
}

type PriorityValue = IntRange<1, 101>
/**
* A union of the integers from 0 up to, but not including, `TEnd`. `TEnd` must
* be a non-negative integer literal.
*/
type NumbersBelow<
TEnd extends number,
TAcc extends number[] = [],
> = TAcc['length'] extends TEnd
? TAcc[number]
: NumbersBelow<TEnd, [...TAcc, TAcc['length']]>

/** An integer from 1 to 100, inclusive */
type PriorityValue = Exclude<NumbersBelow<101>, 0>

/**
* If the job has no arguments:
Expand Down
21 changes: 9 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,6 @@ __metadata:
msw: "npm:2.15.0"
publint: "npm:0.3.24"
react: "npm:19.3.0"
type-fest: "npm:5.10.0"
typescript: "npm:5.9.3"
vitest: "npm:4.1.11"
peerDependencies:
Expand Down Expand Up @@ -3225,7 +3224,6 @@ __metadata:
esbuild: "npm:0.28.2"
execa: "npm:5.1.1"
fast-glob: "npm:3.3.3"
type-fest: "npm:5.10.0"
typescript: "npm:5.9.3"
bin:
cedar-fwtools-attw: ./dist/bins/cedar-fwtools-attw.js
Expand Down Expand Up @@ -3380,7 +3378,6 @@ __metadata:
concurrently: "npm:9.2.4"
cron-parser: "npm:5.10.1"
publint: "npm:0.3.24"
type-fest: "npm:5.10.0"
typescript: "npm:5.9.3"
vitest: "npm:4.1.11"
bin:
Expand Down Expand Up @@ -29082,15 +29079,6 @@ __metadata:
languageName: node
linkType: hard

"type-fest@npm:5.10.0, type-fest@npm:^5.5.0":
version: 5.10.0
resolution: "type-fest@npm:5.10.0"
dependencies:
tagged-tag: "npm:^1.0.0"
checksum: 10c0/313c5d0e37a3f1cc82e942f3228f897623c8b54a63a8a95532d0c2c21ab200793caa70bd8904a83fd713eb28d87ba32468b09b345ef6efa25cecb345b467226f
languageName: node
linkType: hard

"type-fest@npm:^0.20.2":
version: 0.20.2
resolution: "type-fest@npm:0.20.2"
Expand All @@ -29112,6 +29100,15 @@ __metadata:
languageName: node
linkType: hard

"type-fest@npm:^5.5.0":
version: 5.10.0
resolution: "type-fest@npm:5.10.0"
dependencies:
tagged-tag: "npm:^1.0.0"
checksum: 10c0/313c5d0e37a3f1cc82e942f3228f897623c8b54a63a8a95532d0c2c21ab200793caa70bd8904a83fd713eb28d87ba32468b09b345ef6efa25cecb345b467226f
languageName: node
linkType: hard

"type-is@npm:^2.0.1, type-is@npm:^2.1.0":
version: 2.1.0
resolution: "type-is@npm:2.1.0"
Expand Down
Loading