add rules for the request directory

This commit is contained in:
Nate Kelley 2025-02-13 13:09:38 -07:00
parent ba80aaf41d
commit f9da0fe2aa
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
7 changed files with 98 additions and 102 deletions

View File

@ -0,0 +1,70 @@
---
description: This will be used whenever we need a type for a request either from rest or web socket
globs: src/api/request_interfaces/**/*
---
# Cursor Rules
## Directory Structure
This directory contains all the namespaces, each organized into separate folders. Every namespace follows this structure:
```
/namespaces/
├── namespace1/
│ ├── index.ts
│ ├── interfaces.ts
├── namespace2/
│ ├── index.ts
│ ├── interfaces.ts
...
```
### File Descriptions
#### `index.ts`
- This file serves as the entry point for the namespace, exporting all relevant types and utilities.
#### `interfaces.ts`
- This file defines the TypeScript interfaces for the namespace.
- All interfaces must be documented using **TSDoc** to ensure clarity and maintainability.
Example:
```ts
/**
* Represents a user profile in the system.
*/
export interface UserProfile {
/** The unique identifier for the user */
id: string;
/** The user's display name */
name: string;
}
/**
* Parameters for fetching a collection list.
*/
export interface GetCollectionListParams {
/** Current page number (1-based indexing) */
page: number;
/** Number of items to display per page */
page_size: number;
/** When true, returns only collections shared with the current user */
shared_with_me?: boolean;
/** When true, returns only collections owned by the current user */
owned_by_me?: boolean;
}
```
## Usage
These namespace types will be imported into the following locations:
- `/src/api/buster_rest/*`
- `/src/api/buster_socket/*`
- `/src/api/buster_socket_query/*`
Ensure that all types are properly imported and used to maintain consistency across the codebase.

View File

@ -1,75 +0,0 @@
# API Structure Rules
## Directory Structure
Each API namespace should follow this specific structure:
```
src/api/{namespace}/
├── {namespace}Requests.ts # Contains all request interfaces and types
├── {namespace}Responses.ts # Contains all response interfaces and types
└── index.ts # Exports all public interfaces and functions
```
## File Requirements
### {namespace}Requests.ts
- Must contain all request interfaces and types for the namespace
- Each request interface should be prefixed with the namespace
- Example: `interface UserCreateRequest { ... }`
- Must include proper TypeScript types and documentation
### {namespace}Responses.ts
- Must contain all response interfaces and types for the namespace
- Each response interface should be prefixed with the namespace
- Example: `interface UserCreateResponse { ... }`
- Must include proper TypeScript types and documentation
### index.ts
- Must export all public interfaces, types, and functions
- Should re-export from both requests and responses files
- Should contain any namespace-specific utility functions
- Must use named exports (no default exports)
## Naming Conventions
- All file names must use PascalCase for namespace names
- All interface names must be prefixed with the namespace
- All type names must be prefixed with the namespace
- Use descriptive names that clearly indicate purpose
## Documentation Requirements
- Each interface must have JSDoc comments explaining its purpose
- Each property in interfaces must be documented
- Include examples where appropriate
- Document any validation requirements or constraints
## Type Safety
- Avoid using `any` type
- Use strict TypeScript configurations
- Define proper type guards when necessary
- Use generics appropriately for reusable types
## Example Structure
```typescript
// {namespace}Requests.ts
export interface {Namespace}CreateRequest {
// properties
}
// {namespace}Responses.ts
export interface {Namespace}CreateResponse {
// properties
}
// index.ts
export * from './{namespace}Requests';
export * from './{namespace}Responses';
```
## Additional Guidelines
1. Keep files focused and single-responsibility
2. Use TypeScript's strict mode
3. Implement proper error handling types
4. Follow consistent formatting
5. Include proper type exports
6. Maintain backward compatibility
7. Use enums for fixed sets of values

View File

@ -1,5 +1,6 @@
import { queryOptions, useQuery, useQueryClient } from '@tanstack/react-query';
import { queryOptions } from '@tanstack/react-query';
import { BusterCollectionListItem } from './interfaces';
import type { GetCollectionListParams } from '../../request_interfaces/collections';
const collectionsGetList = (filters?: GetCollectionListParams) =>
queryOptions<BusterCollectionListItem[]>({

View File

@ -1,22 +1,17 @@
import { ShareAssetType } from '../../asset_interfaces';
import { BusterSocketRequestBase } from '../base_interfaces';
import { ShareRequest } from '../shared_interfaces';
import type {
GetCollectionListParams,
GetCollectionParams
} from '../../request_interfaces/collections';
/**
* WebSocket request for listing collections with pagination support.
*/
export type CollectionsListEmit = BusterSocketRequestBase<
'/collections/list',
{
/** Current page number (1-based indexing) */
page: number;
/** Number of items to display per page */
page_size: number;
/** When true, returns only collections shared with the current user */
shared_with_me?: boolean;
/** When true, returns only collections owned by the current user */
owned_by_me?: boolean;
}
GetCollectionListParams
>;
/**
@ -24,10 +19,7 @@ export type CollectionsListEmit = BusterSocketRequestBase<
*/
export type CollectionGetIndividual = BusterSocketRequestBase<
'/collections/get',
{
/** Unique identifier of the collection to retrieve */
id: string;
}
GetCollectionParams
>;
/**

View File

@ -0,0 +1 @@
export * from './interfaces';

View File

@ -0,0 +1,15 @@
export interface GetCollectionListParams {
/** Current page number (1-based indexing) */
page: number;
/** Number of items to display per page */
page_size: number;
/** When true, returns only collections shared with the current user */
shared_with_me?: boolean;
/** When true, returns only collections owned by the current user */
owned_by_me?: boolean;
}
export interface GetCollectionParams {
/** Unique identifier of the collection to retrieve */
id: string;
}

View File

@ -31,18 +31,10 @@ export const useCollectionCreate = () => {
useSocketQueryMutation(
{ route: '/collections/delete' },
{ route: '/collections/delete:deleteCollections' },
queryKeys
// {
// preSetQueryData: [
// {
// responseRoute: '/collections/list:listCollections',
// callback: (data, variables) => {
// return data?.filter((collection) => !variables.ids.includes(collection.id)) || [];
// }
// }
// ]
// }
queryKeys['/collections/list:getCollectionsList'](),
(data, variables) => {
return data?.filter((collection) => !variables.ids.includes(collection.id)) || [];
}
);
const deleteCollection = useMemoizedFn(async (id: string | string[], useConfirmModal = true) => {