Improve the HolySheets! library by introducing a withMetadata higher-order function to centralize metadata handling across all core operations (e.g., findFirst, findMany, updateFirst). This refactoring aims to enhance maintainability, readability, and consistency while adhering to SOLID principles.
Background
Currently, each core operation manages its own metadata logic, leading to code duplication and reduced clarity. Centralizing this functionality will streamline the codebase and ensure uniform metadata management.
Proposed Changes
-
Create withMetadata HOF:
- Location:
src/utils/operations/withMetadata.ts
- Functionality: Handles metadata tasks such as timing, status determination, error handling, and metadata creation.
- Parameters:
operationType: Type of operation (e.g., find, update).
params: Essential metadata parameters (spreadsheetId, sheetId, ranges, userId).
configs: Configuration options (e.g., includeMetadata).
callback: Core operation function.
-
Refactor Core Operations:
- Target Functions:
findFirst, findMany, updateFirst, etc.
- Changes:
- Extract core logic into separate functions.
- Wrap these functions with
withMetadata to handle metadata.
- Remove duplicated metadata handling from each operation.
-
Update Type Definitions:
- Ensure return types align with the new structure, returning single records or
null for findFirst and appropriate types for other operations.
-
Enhance Testing:
- Update existing tests to accommodate the refactored functions.
- Add tests for
withMetadata to verify proper metadata handling.
Benefits
- Single Responsibility: Each function handles one concern, improving code clarity.
- Reusability:
withMetadata can be used across all operations, reducing duplication.
- Consistency: Ensures uniform metadata handling throughout the library.
- Maintainability: Simplifies future updates and enhancements.
- Testability: Facilitates easier and more focused unit testing.
Acceptance Criteria
withMetadata is implemented and correctly handles metadata for all core operations.
- Core operations are successfully refactored to use
withMetadata.
- All existing functionalities remain intact and behave as expected.
- Unit tests are updated and pass successfully.
- Documentation is updated to reflect the changes in function signatures and usage patterns.
Tasks
-
Implement withMetadata:
- Develop the higher-order function with specified metadata handling capabilities.
-
Refactor Core Operations:
- Update each core operation to utilize
withMetadata, ensuring separation of concerns.
-
Update Types and Tests:
- Adjust TypeScript interfaces and add necessary tests for the new implementation.
-
Documentation:
- Update README and relevant docs to guide developers on the new usage patterns.
-
Code Review:
- Ensure all changes adhere to best practices and maintain code quality.
Improve the HolySheets! library by introducing a
withMetadatahigher-order function to centralize metadata handling across all core operations (e.g.,findFirst,findMany,updateFirst). This refactoring aims to enhance maintainability, readability, and consistency while adhering to SOLID principles.Background
Currently, each core operation manages its own metadata logic, leading to code duplication and reduced clarity. Centralizing this functionality will streamline the codebase and ensure uniform metadata management.
Proposed Changes
Create
withMetadataHOF:src/utils/operations/withMetadata.tsoperationType: Type of operation (e.g.,find,update).params: Essential metadata parameters (spreadsheetId,sheetId,ranges,userId).configs: Configuration options (e.g.,includeMetadata).callback: Core operation function.Refactor Core Operations:
findFirst,findMany,updateFirst, etc.withMetadatato handle metadata.Update Type Definitions:
nullforfindFirstand appropriate types for other operations.Enhance Testing:
withMetadatato verify proper metadata handling.Benefits
withMetadatacan be used across all operations, reducing duplication.Acceptance Criteria
withMetadatais implemented and correctly handles metadata for all core operations.withMetadata.Tasks
Implement
withMetadata:Refactor Core Operations:
withMetadata, ensuring separation of concerns.Update Types and Tests:
Documentation:
Code Review: