Skip to content

Commit 5b7f4c5

Browse files
committed
build server types
1 parent 1229c67 commit 5b7f4c5

File tree

8 files changed

+165
-14
lines changed

8 files changed

+165
-14
lines changed

client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"build": "tsc -b && vite build",
7+
"build": "pnpm run build:server-types && tsc -b && vite build",
8+
"build:server-types": "tsc -p ../server/tsconfig.shared.json --declaration --emitDeclarationOnly --outFile ./src/server-types.d.ts",
89
"build:test": "tsc -b && E2E=true vite build",
910
"deploy:stage": "pnpm wrangler pages deploy ./dist --project-name simon --branch \"stage\" --commit-hash \"$GITHUB_SHA\" --commit-message \"stage deployment\"",
1011
"deploy:prod": "pnpm wrangler pages deploy ./dist --project-name simon",
@@ -25,7 +26,6 @@
2526
"tone": "^15.0.4"
2627
},
2728
"devDependencies": {
28-
"@simon/server": "workspace:*",
2929
"@testing-library/jest-dom": "^6.4.6",
3030
"@testing-library/react": "^16.0.0",
3131
"@types/react": "^18.3.3",

client/src/components/use-game-machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { gameLogic, NEW_GAME_STATE } from './use-game-machine.logic';
55
import { useOnEntry } from './use-game-machine.use-on-entry';
66
import { melodyPlayer } from '../services/melody-player';
77
import type { PadId } from '../types';
8-
import type { HighScoreEntry } from '@simon/server/src/types';
8+
import type { HighScoreEntry } from 'types.shared';
99

1010
export type GameMachine = ReturnType<typeof useGameMachine>;
1111

client/src/server-types.d.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
declare module "types" {
2+
import type { KVNamespace } from '@cloudflare/workers-types';
3+
import type { Context as HonoContext } from 'hono';
4+
export interface Env {
5+
ALLOWED_HOST: string;
6+
DB: KVNamespace;
7+
LOCAL_DB: KVNamespace;
8+
TEST_DB: KVNamespace;
9+
ENV: 'dev' | 'prod' | 'stage' | 'test';
10+
GITHUB_REF_NAME: string;
11+
GITHUB_SHA: string;
12+
}
13+
export type Context = HonoContext<{
14+
Bindings: Env;
15+
}>;
16+
}
17+
declare module "test" {
18+
import type { Env } from "types";
19+
export const testRoute: import("hono/hono-base").HonoBase<{
20+
Bindings: Env;
21+
}, {
22+
"/reset": {
23+
$post: {
24+
input: {};
25+
output: {};
26+
outputFormat: string;
27+
status: import("hono/utils/http-status").StatusCode;
28+
};
29+
};
30+
}, "/">;
31+
}
32+
declare module "utils" {
33+
import type { KVNamespace } from '@cloudflare/workers-types';
34+
import type { Context } from "types";
35+
export const getDb: (c: Context) => KVNamespace;
36+
}
37+
declare module "high-score" {
38+
import type { Env } from "types";
39+
export const highScoreRoute: import("hono/hono-base").HonoBase<{
40+
Bindings: Env;
41+
}, {
42+
"/": {
43+
$get: {
44+
input: {};
45+
output: {
46+
highScore: any;
47+
};
48+
outputFormat: "json";
49+
status: 200;
50+
};
51+
};
52+
} & {
53+
"/": {
54+
$post: {
55+
input: {
56+
json: {
57+
name: string;
58+
score: number;
59+
};
60+
};
61+
output: {
62+
newHighScore: {
63+
score: number;
64+
name: string;
65+
timestamp: number;
66+
};
67+
};
68+
outputFormat: "json";
69+
status: 200;
70+
};
71+
};
72+
}, "/">;
73+
}
74+
declare module "index" {
75+
import type { Env } from "types";
76+
const app: import("hono/hono-base").HonoBase<{
77+
Bindings: Env;
78+
}, {
79+
"/high-score": {
80+
$get: {
81+
input: {};
82+
output: {
83+
highScore: any;
84+
};
85+
outputFormat: "json";
86+
status: 200;
87+
};
88+
$post: {
89+
input: {
90+
json: {
91+
name: string;
92+
score: number;
93+
};
94+
};
95+
output: {
96+
newHighScore: {
97+
score: number;
98+
name: string;
99+
timestamp: number;
100+
};
101+
};
102+
outputFormat: "json";
103+
status: 200;
104+
};
105+
};
106+
} & {
107+
"/test/reset": {
108+
$post: {
109+
input: {};
110+
output: {};
111+
outputFormat: string;
112+
status: import("hono/utils/http-status").StatusCode;
113+
};
114+
};
115+
} & {
116+
"*": {};
117+
} & {
118+
"/": {
119+
$get: {
120+
input: {};
121+
output: "ok";
122+
outputFormat: "text";
123+
status: 200;
124+
};
125+
};
126+
}, "/">;
127+
export default app;
128+
}
129+
declare module "types.shared" {
130+
import type app from "index";
131+
export type ServerApi = typeof app;
132+
export interface HighScoreEntry {
133+
name: string;
134+
score: number;
135+
timestamp: number;
136+
}
137+
}

client/src/services/api.high-score.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { ServerApi } from '@simon/server/src/types';
21
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
32
import type { InferRequestType, InferResponseType } from 'hono/client';
43
import { hc } from 'hono/client';
54
import { useMonitor } from './monitor.use-monitor';
65
import { getServerUrl } from '../config';
6+
import type { ServerApi } from 'types.shared';
77

88
const serverUrl = getServerUrl();
99

server/src/high-score.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Hono } from 'hono';
22
import { HTTPException } from 'hono/http-exception';
33
import { zValidator } from '@hono/zod-validator';
44
import type { Context, Env } from './types';
5-
import type { HighScoreEntry } from './types';
5+
import type { HighScoreEntry } from './types.shared';
66
import { z } from 'zod';
77
import { getDb } from './utils';
88

server/src/types.shared.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type app from './index';
2+
3+
export type ServerApi = typeof app;
4+
5+
export interface HighScoreEntry {
6+
name: string;
7+
score: number;
8+
timestamp: number;
9+
}

server/src/types.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { KVNamespace } from '@cloudflare/workers-types';
22
import type { Context as HonoContext } from 'hono';
3-
import type app from './index';
43

54
export interface Env {
65
ALLOWED_HOST: string;
@@ -15,11 +14,3 @@ export interface Env {
1514
export type Context = HonoContext<{
1615
Bindings: Env;
1716
}>;
18-
19-
export type ServerApi = typeof app;
20-
21-
export interface HighScoreEntry {
22-
name: string;
23-
score: number;
24-
timestamp: number;
25-
}

server/tsconfig.shared.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": false,
5+
"types": [
6+
"@cloudflare/workers-types",
7+
"@cloudflare/workers-types/experimental",
8+
"@cloudflare/vitest-pool-workers"
9+
],
10+
"noUnusedLocals": true,
11+
"noUnusedParameters": true
12+
},
13+
"include": ["src/types.shared.ts"]
14+
}

0 commit comments

Comments
 (0)