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
3 changes: 2 additions & 1 deletion client/.eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.eslintrc.cjs
.eslintrc.cjs
src/server-types.d.ts
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"build": "tsc -b && vite build",
"build": "pnpm run build:server-types && tsc -b && vite build",
"build:server-types": "tsc -p ../server/tsconfig.shared.json --declaration --emitDeclarationOnly --outFile ./src/server-types.d.ts",
"build:test": "tsc -b && E2E=true vite build",
"deploy:stage": "pnpm wrangler pages deploy ./dist --project-name simon --branch \"stage\" --commit-hash \"$GITHUB_SHA\" --commit-message \"stage deployment\"",
"deploy:prod": "pnpm wrangler pages deploy ./dist --project-name simon",
Expand All @@ -25,7 +26,6 @@
"tone": "^15.0.4"
},
"devDependencies": {
"@simon/server": "workspace:*",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@types/react": "^18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/use-game-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { gameLogic, NEW_GAME_STATE } from './use-game-machine.logic';
import { useOnEntry } from './use-game-machine.use-on-entry';
import { melodyPlayer } from '../services/melody-player';
import type { PadId } from '../types';
import type { HighScoreEntry } from '@simon/server/src/types';
import type { HighScoreEntry } from 'types.shared';

export type GameMachine = ReturnType<typeof useGameMachine>;

Expand Down
137 changes: 137 additions & 0 deletions client/src/server-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
declare module "types" {
import type { KVNamespace } from '@cloudflare/workers-types';
import type { Context as HonoContext } from 'hono';
export interface Env {
ALLOWED_HOST: string;
DB: KVNamespace;
LOCAL_DB: KVNamespace;
TEST_DB: KVNamespace;
ENV: 'dev' | 'prod' | 'stage' | 'test';
GITHUB_REF_NAME: string;
GITHUB_SHA: string;
}
export type Context = HonoContext<{
Bindings: Env;
}>;
}
declare module "test" {
import type { Env } from "types";
export const testRoute: import("hono/hono-base").HonoBase<{
Bindings: Env;
}, {
"/reset": {
$post: {
input: {};
output: {};
outputFormat: string;
status: import("hono/utils/http-status").StatusCode;
};
};
}, "/">;
}
declare module "utils" {
import type { KVNamespace } from '@cloudflare/workers-types';
import type { Context } from "types";
export const getDb: (c: Context) => KVNamespace;
}
declare module "high-score" {
import type { Env } from "types";
export const highScoreRoute: import("hono/hono-base").HonoBase<{
Bindings: Env;
}, {
"/": {
$get: {
input: {};
output: {
highScore: any;
};
outputFormat: "json";
status: 200;
};
};
} & {
"/": {
$post: {
input: {
json: {
name: string;
score: number;
};
};
output: {
newHighScore: {
score: number;
name: string;
timestamp: number;
};
};
outputFormat: "json";
status: 200;
};
};
}, "/">;
}
declare module "index" {
import type { Env } from "types";
const app: import("hono/hono-base").HonoBase<{
Bindings: Env;
}, {
"/high-score": {
$get: {
input: {};
output: {
highScore: any;
};
outputFormat: "json";
status: 200;
};
$post: {
input: {
json: {
name: string;
score: number;
};
};
output: {
newHighScore: {
score: number;
name: string;
timestamp: number;
};
};
outputFormat: "json";
status: 200;
};
};
} & {
"/test/reset": {
$post: {
input: {};
output: {};
outputFormat: string;
status: import("hono/utils/http-status").StatusCode;
};
};
} & {
"*": {};
} & {
"/": {
$get: {
input: {};
output: "ok";
outputFormat: "text";
status: 200;
};
};
}, "/">;
export default app;
}
declare module "types.shared" {
import type app from "index";
export type ServerApi = typeof app;
export interface HighScoreEntry {
name: string;
score: number;
timestamp: number;
}
}
2 changes: 1 addition & 1 deletion client/src/services/api.high-score.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ServerApi } from '@simon/server/src/types';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import type { InferRequestType, InferResponseType } from 'hono/client';
import { hc } from 'hono/client';
import { useMonitor } from './monitor.use-monitor';
import { getServerUrl } from '../config';
import type { ServerApi } from 'types.shared';

const serverUrl = getServerUrl();

Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/src/high-score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Hono } from 'hono';
import { HTTPException } from 'hono/http-exception';
import { zValidator } from '@hono/zod-validator';
import type { Context, Env } from './types';
import type { HighScoreEntry } from './types';
import type { HighScoreEntry } from './types.shared';
import { z } from 'zod';
import { getDb } from './utils';

Expand Down
9 changes: 9 additions & 0 deletions server/src/types.shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type app from './index';

export type ServerApi = typeof app;

export interface HighScoreEntry {
name: string;
score: number;
timestamp: number;
}
9 changes: 0 additions & 9 deletions server/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { KVNamespace } from '@cloudflare/workers-types';
import type { Context as HonoContext } from 'hono';
import type app from './index';

export interface Env {
ALLOWED_HOST: string;
Expand All @@ -15,11 +14,3 @@ export interface Env {
export type Context = HonoContext<{
Bindings: Env;
}>;

export type ServerApi = typeof app;

export interface HighScoreEntry {
name: string;
score: number;
timestamp: number;
}
14 changes: 14 additions & 0 deletions server/tsconfig.shared.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"types": [
"@cloudflare/workers-types",
"@cloudflare/workers-types/experimental",
"@cloudflare/vitest-pool-workers"
],
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": ["src/types.shared.ts"]
}