Skip to content

Refactor Giant index.ts into Modular Files Using Mixins #24

@teles

Description

@teles

We currently have a monolithic index.ts file containing the entire HolySheets class with all operations (find, insert, clear, etc.). This makes the file hard to maintain and extend. The goal of this task is to refactor this giant file into a modular structure by splitting it into several files, using mixins to compose the final API.

Objectives:

  1. Modularization:
  • Extract the common functionality into a base class (e.g., HolySheetsBase.ts).
  • Separate the various operations into individual mixin files, such as:
  • WithFindOperations.ts
  • WithInsertOperations.ts
  • WithClearOperations.ts
  • Compose the final HolySheets class using a mixin composition function (e.g., composeMixins.ts).

API Consistency:

  • Ensure that the final API remains “flat” (e.g., instance.findMany(), instance.insert(), etc.)—similar to how Prisma exposes its API.
    Improved Typing:

  • Avoid the use of this as any by defining a shared interface (e.g., IHolySheets) that outlines the properties and methods needed by the mixins.
    Tests Update:

  • Update and, if necessary, split existing tests (currently in index.spec.ts) into multiple test files to reflect the new modular structure (e.g., tests for base, find operations, insert operations, clear operations, etc.).
    Documentation:

Update any relevant documentation or comments within the code to reflect the new modular structure and guide future developers.
Acceptance Criteria:

  • The index.ts file is refactored into multiple files:
  • A base file containing shared functionality.
  • Separate mixin files for each set of operations.
  • A composition file to build the final class.
  • The final HolySheets class must expose all original methods (including orThrow variants) with the same behavior.
  • All existing tests pass, and tests are organized into separate files based on functionality.
  • Code should use proper TypeScript typing and avoid any usage of this as any.

By completing this task, we will improve code maintainability, scalability, and readability, making it easier to add new operations (like update or delete) in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions