Skip to content

Commit b609f16

Browse files
committed
feat!: Upgrade bun and refactor routing
1 parent e53264c commit b609f16

39 files changed

Lines changed: 680 additions & 417 deletions

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@jsr:registry=https://npm.jsr.io

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ COPY package.json package.json
44
COPY bun.lockb bun.lockb
55
RUN bun install --production --ignore-scripts
66
COPY . .
7-
ENTRYPOINT ["bun", "src/index.ts"]
7+
ENTRYPOINT ["bun", "src/main.ts"]

bun.lock

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bun.lockb

-30.7 KB
Binary file not shown.

package.json

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "wxt-queue",
2+
"name": "@wxt-dev/queue",
33
"version": "0.3.14",
4-
"module": "src/index.ts",
54
"type": "module",
6-
"packageManager": "bun@1.1.31",
5+
"packageManager": "bun@1.2.18",
76
"scripts": {
8-
"dev": "bun --hot run src/dev.ts",
9-
"generate:types": "bun run src/generate-types.ts",
7+
"dev": "bun run --watch scripts/dev.ts",
8+
"gen": "bun run gen:types",
9+
"gen:types": "bun run scripts/generate-types.ts",
1010
"docker:build": "docker build . -t aklinker1/store-api",
1111
"docker:run": "docker run -it aklinker1/store-api",
1212
"docker:build:amd": "bun docker:build --platform linux/amd64",
@@ -15,31 +15,28 @@
1515
"check": "check"
1616
},
1717
"dependencies": {
18+
"@aklinker1/zero-ioc": "^1.3.2",
1819
"consola": "^3.2.3",
1920
"dataloader": "^2.2.2",
2021
"graphql": "^16.8.0",
2122
"linkedom": "^0.15.3",
2223
"picocolors": "^1.0.0",
23-
"radix3": "^1.1.2"
24+
"zod": "^3.25.75"
2425
},
2526
"devDependencies": {
26-
"@aklinker1/check": "^1.2.0",
27-
"bun-types": "latest",
27+
"@aklinker1/check": "^2.1.0",
28+
"@types/bun": "latest",
2829
"code-block-writer": "^12.0.0",
2930
"lint-staged": "^15.2.2",
31+
"oxlint": "^1.6.0",
3032
"prettier": "^3.2.5",
3133
"simple-git-hooks": "^2.9.0",
32-
"typescript": "^5.3.3"
34+
"typescript": "^5.8.3"
3335
},
3436
"simple-git-hooks": {
3537
"pre-commit": "bun lint-staged"
3638
},
3739
"lint-staged": {
3840
"*": "prettier --ignore-unknown --write"
39-
},
40-
"changelog": {
41-
"excludeAuthors": [
42-
"aaronklinker1@gmail.com"
43-
]
4441
}
4542
}

scripts/dev.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bun
2+
import consola, { LogLevels } from "consola";
3+
import app from "../src/server";
4+
import { generateGqlTypes } from "./generate-gql-types";
5+
import pc from "picocolors";
6+
import { version } from "../package.json";
7+
8+
const fetch = app.build();
9+
await generateGqlTypes(fetch);
10+
11+
consola.level = LogLevels.debug;
12+
const port = Number(process.env.PORT ?? "3000");
13+
Bun.serve({ port, fetch });
14+
15+
consola.success(
16+
`${pc.cyan("@wxt-dev/queue v" + version)} ${pc.dim("server started")}`,
17+
);
18+
consola.log(` ${pc.bold(pc.green("➜"))} http://localhost:${port}`);
19+
console.log();

scripts/gen.ts

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

scripts/generate-gql-types.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import CodeBlockWriter from "code-block-writer";
2-
import type { Server } from "../src/server";
32
import { consola } from "consola";
3+
import type { ServerSideFetch } from "@aklinker1/zeta/types";
4+
import app from "../src/server";
45

56
const typesFile = Bun.file("src/@types/gql.d.ts");
67

@@ -11,12 +12,17 @@ const scalarNameToTs = {
1112
Float: "number",
1213
};
1314

14-
export async function generateGqlTypes(server: Server) {
15+
export async function generateGqlTypes(fetch: ServerSideFetch = app.build()) {
1516
consola.info("Generating GraphQL types...");
16-
const introspection = await server.introspect();
17+
const introspection = await introspect(fetch);
1718

18-
const { queryType, mutationType, subscriptionType, types, directives } =
19-
introspection.data.__schema;
19+
const {
20+
queryType,
21+
mutationType,
22+
subscriptionType,
23+
types,
24+
directives: _,
25+
} = introspection.data.__schema;
2026

2127
let argTypes: any[] = [];
2228

@@ -63,7 +69,7 @@ export async function generateGqlTypes(server: Server) {
6369

6470
function capitalizeFirstLetter(str: string): string {
6571
if (str.length === 0) return str;
66-
return str[0].toUpperCase() + str.substring(1);
72+
return str[0]!.toUpperCase() + str.substring(1);
6773
}
6874

6975
function getTsTypeString(gqlType: any): string {
@@ -120,3 +126,21 @@ function writeScalarType(code: CodeBlockWriter, type: any) {
120126
}
121127
code.writeLine(`type ${type.name} = ${typeStr || "unknown"};`);
122128
}
129+
130+
async function introspect(fetch: ServerSideFetch): Promise<any> {
131+
const request = new Request("http://localhost/api", {
132+
body: JSON.stringify({
133+
operationName: "IntrospectionQuery",
134+
query:
135+
"query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } } ",
136+
}),
137+
headers: {
138+
"Content-Type": "application/json",
139+
},
140+
method: "POST",
141+
});
142+
const res = await fetch(request);
143+
if (res.ok) return await res.json();
144+
145+
throw Error("Introspection request failed: " + (await res.text()));
146+
}

scripts/generate-types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { generateGqlTypes } from "./generate-gql-types";
2+
3+
await generateGqlTypes();

src/@types/ctx.d.ts

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

0 commit comments

Comments
 (0)