1.0.0 • Published 4 months ago
devpulse-common v1.0.0
devpulse-common
Shared types and validation schemas for the DevPulse application.
Installation
npm install devpulse-common
Features
- Type-safe request and response types
- Zod validation schemas for API requests
- Shared types between client and server
Usage
Authentication
import { loginSchema, LoginRequest, LoginResponse } from 'devpulse-common';
// Validate request body
const result = loginSchema.safeParse(requestBody);
if (!result.success) {
console.error(result.error);
return;
}
// Use typed request data
const data: LoginRequest = result.data;
Posts
import {
createPostSchema,
CreatePostRequest,
PostResponse
} from 'devpulse-common';
// Create a new post with type safety
const createPost = async (data: CreatePostRequest): Promise<PostResponse> => {
// Validate request
const result = createPostSchema.safeParse(data);
if (!result.success) {
throw new Error(result.error.message);
}
// Make API call...
};
Comments
import {
createCommentSchema,
CommentResponse
} from 'devpulse-common';
// Validate comment data
const validateComment = (data: unknown) => {
return createCommentSchema.safeParse(data);
};
Available Schemas
- Auth:
loginSchema
,registerSchema
- Posts:
createPostSchema
,updatePostSchema
,addReactionSchema
- Comments:
createCommentSchema
,updateCommentSchema
- Topics:
createTopicSchema
- Playlists:
createPlaylistSchema
,updatePlaylistSchema
- Users:
updateProfileSchema
Available Types
- Auth:
LoginRequest
,LoginResponse
,RegisterRequest
,RegisterResponse
- Posts:
PostResponse
,PostsListResponse
,CreatePostRequest
- Comments:
CommentResponse
,CreateCommentRequest
- Topics:
TopicResponse
,TopicListResponse
- Playlists:
PlaylistResponse
,PlaylistListResponse
- Users:
UserProfileResponse
,UserPublicProfileResponse
License
MIT
1.0.0
4 months ago