diff --git a/.changesets/2879.md b/.changesets/2879.md new file mode 100644 index 0000000000..8d8395391a --- /dev/null +++ b/.changesets/2879.md @@ -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. diff --git a/packages/auth/package.json b/packages/auth/package.json index 88a022b9e1..869f009b88 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -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" }, diff --git a/packages/framework-tools/package.json b/packages/framework-tools/package.json index 64a77cdfe1..e198eddf47 100644 --- a/packages/framework-tools/package.json +++ b/packages/framework-tools/package.json @@ -37,7 +37,6 @@ "fast-glob": "3.3.3" }, "devDependencies": { - "type-fest": "5.10.0", "typescript": "5.9.3" }, "engines": { diff --git a/packages/jobs/package.json b/packages/jobs/package.json index ce45e28aaa..4bb4abe896 100644 --- a/packages/jobs/package.json +++ b/packages/jobs/package.json @@ -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:*", diff --git a/packages/jobs/src/core/__tests__/JobManager.test-d.ts b/packages/jobs/src/core/__tests__/JobManager.test-d.ts index a42342869c..09c3962d9d 100644 --- a/packages/jobs/src/core/__tests__/JobManager.test-d.ts +++ b/packages/jobs/src/core/__tests__/JobManager.test-d.ts @@ -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['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', () => { diff --git a/packages/jobs/src/types.ts b/packages/jobs/src/types.ts index ed2573bbeb..e801a4f474 100644 --- a/packages/jobs/src/types.ts +++ b/packages/jobs/src/types.ts @@ -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. */ @@ -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 */ @@ -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 + +/** An integer from 1 to 100, inclusive */ +type PriorityValue = Exclude, 0> /** * If the job has no arguments: diff --git a/yarn.lock b/yarn.lock index 515ce80250..f481fc9588 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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: @@ -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 @@ -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: @@ -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" @@ -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"