Skip to content

Commit d755bab

Browse files
committed
feat: split HandlePackageOutput types
1 parent b1b868a commit d755bab

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

lib/handlers/package/handle-package.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ import { parsePackageSlug } from "./parse-package-slug";
2222
const bun = new Bun(serverEnv.BUN_PATH);
2323
const db = serverEnv.CF_BUCKET_NAME ? new PackageApiR2Bucket() : new PackageApiMemDb();
2424

25+
export type HandlePackageOutput = HandlePackageError | HandlePackageRedirect | HandlePackageData;
26+
27+
export type HandlePackageError =
28+
| { status: "bad-request" }
29+
| { status: "not-found" }
30+
| { status: "error" };
31+
32+
export type HandlePackageRedirect = { status: "found"; path: string };
33+
34+
export type HandlePackageData =
35+
| { status: "pkg-has-invalid-license"; pkgInfo: PackageInfo }
36+
| { status: "pkg-is-deprecated-dt-pkg"; pkgInfo: PackageInfo }
37+
| { status: "pkg-has-no-types"; pkgInfo: PackageInfo }
38+
| { status: "pkg-has-dt-pkg"; pkgInfo: PackageInfoWithDtPackage }
39+
| { status: "pkg-has-api"; pkgInfo: PackageInfoWithApi }
40+
| { status: "pkg-has-no-api"; pkgInfo: PackageInfo };
41+
2542
export interface PackageInfo {
2643
pkgId: string;
2744
subpath: string;
@@ -38,18 +55,6 @@ export interface PackageInfoWithApi extends PackageInfo {
3855
pkgApi: PackageApi;
3956
}
4057

41-
export type HandlePackageOutput =
42-
| { status: "bad-request" }
43-
| { status: "not-found" }
44-
| { status: "found"; path: string }
45-
| { status: "error" }
46-
| { status: "pkg-has-invalid-license"; pkgInfo: PackageInfo }
47-
| { status: "pkg-is-deprecated-dt-pkg"; pkgInfo: PackageInfo }
48-
| { status: "pkg-has-no-types"; pkgInfo: PackageInfo }
49-
| { status: "pkg-has-dt-pkg"; pkgInfo: PackageInfoWithDtPackage }
50-
| { status: "pkg-has-api"; pkgInfo: PackageInfoWithApi }
51-
| { status: "pkg-has-no-api"; pkgInfo: PackageInfo };
52-
5358
export async function handlePackage(slug: string): Promise<HandlePackageOutput> {
5459
const log = getLogger("handlePackage");
5560
log.info({ path: `/package/${slug}` });

0 commit comments

Comments
 (0)