05f8e2e3b6
- Create reusable components: auth, api-client, shared-types - ModeTemplate with Hono backend and SvelteKit frontend - Auth store refactored to class-based Svelte 5 pattern - SSR-safe hydrate() pattern for localStorage access - Frontend builds successfully with Svelte 5 runes
Shared Types
Common types used by both frontend and backend. Keeps API contracts in sync.
Usage
import type { User, ApiResult, PaginatedResponse } from './components/shared-types';
// Backend endpoint
app.get('/api/users', async (c): Promise<ApiResult<PaginatedResponse<User>>> => {
const users = await getUsers();
return c.json({ success: true, data: users });
});
// Frontend call
const result = await api.get<ApiResult<PaginatedResponse<User>>>('/users');
if (result.ok && result.data?.success) {
const users = result.data.data.items;
}
Types Included
User/Auth:
User- User recordAuthState- Frontend auth state
API Responses:
SuccessResponse<T>-{ success: true, data: T }ErrorResponse-{ success: false, error: string }ApiResult<T>- Either success or errorPaginatedResponse<T>- List with pagination metadata
Request Params:
PaginationParams-{ page?, perPage? }SortParams-{ sort?, order? }ListParams- Combined pagination + sort
Utility Types:
CreateInput<T>- Omits id and timestamps for creatingUpdateInput<T>- Partial without id/timestamps for updating
Copying to a Mode
- Copy
components/shared-types/to your mode root astypes/ - Import from
./typesin both frontend and backend
Dependencies
None - pure TypeScript types.