From f9da0fe2aa3cb7087df09e9a895f07605d7d958c Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 13 Feb 2025 13:09:38 -0700 Subject: [PATCH] add rules for the request directory --- .../rules/api_buster_request_interfaces.mdc | 70 +++++++++++++++++ web/.cursor/rules/api_structure_rules.mdc | 75 ------------------- .../collection/collectionQueryKeys.ts | 3 +- .../collections/collectionRequests.ts | 20 ++--- .../request_interfaces/collections/index.ts | 1 + .../collections/interfaces.ts | 15 ++++ .../useCollectionCreate.ts | 16 +--- 7 files changed, 98 insertions(+), 102 deletions(-) create mode 100644 web/.cursor/rules/api_buster_request_interfaces.mdc delete mode 100644 web/.cursor/rules/api_structure_rules.mdc create mode 100644 web/src/api/request_interfaces/collections/index.ts create mode 100644 web/src/api/request_interfaces/collections/interfaces.ts diff --git a/web/.cursor/rules/api_buster_request_interfaces.mdc b/web/.cursor/rules/api_buster_request_interfaces.mdc new file mode 100644 index 000000000..6a3553e78 --- /dev/null +++ b/web/.cursor/rules/api_buster_request_interfaces.mdc @@ -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. + diff --git a/web/.cursor/rules/api_structure_rules.mdc b/web/.cursor/rules/api_structure_rules.mdc deleted file mode 100644 index f6e5d3bb3..000000000 --- a/web/.cursor/rules/api_structure_rules.mdc +++ /dev/null @@ -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 \ No newline at end of file diff --git a/web/src/api/asset_interfaces/collection/collectionQueryKeys.ts b/web/src/api/asset_interfaces/collection/collectionQueryKeys.ts index 7df89b359..0d40ed800 100644 --- a/web/src/api/asset_interfaces/collection/collectionQueryKeys.ts +++ b/web/src/api/asset_interfaces/collection/collectionQueryKeys.ts @@ -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({ diff --git a/web/src/api/buster_socket/collections/collectionRequests.ts b/web/src/api/buster_socket/collections/collectionRequests.ts index bc92d3df8..124f9628e 100644 --- a/web/src/api/buster_socket/collections/collectionRequests.ts +++ b/web/src/api/buster_socket/collections/collectionRequests.ts @@ -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 >; /** diff --git a/web/src/api/request_interfaces/collections/index.ts b/web/src/api/request_interfaces/collections/index.ts new file mode 100644 index 000000000..957860982 --- /dev/null +++ b/web/src/api/request_interfaces/collections/index.ts @@ -0,0 +1 @@ +export * from './interfaces'; diff --git a/web/src/api/request_interfaces/collections/interfaces.ts b/web/src/api/request_interfaces/collections/interfaces.ts new file mode 100644 index 000000000..22655d2ba --- /dev/null +++ b/web/src/api/request_interfaces/collections/interfaces.ts @@ -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; +} diff --git a/web/src/context/Collections/CollectionIndividualProvider/useCollectionCreate.ts b/web/src/context/Collections/CollectionIndividualProvider/useCollectionCreate.ts index ad5e7f8e6..6237ff286 100644 --- a/web/src/context/Collections/CollectionIndividualProvider/useCollectionCreate.ts +++ b/web/src/context/Collections/CollectionIndividualProvider/useCollectionCreate.ts @@ -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) => {