0.0.2 • Published 5 months ago

palesi v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Pales - Prisma API Layer Scaffolding

šŸš€ Introduction

Pales is a CLI tool designed to automate the generation of modular API layers for Node.js applications using Prisma and Zod. It streamlines the creation of models, validation schemas, and API endpoints based on a Prisma schema, reducing development overhead and ensuring consistency.

šŸ“Œ Features

  • šŸ›  Automatic Module Generation: Generates route handlers, validation schemas, and controllers from your Prisma schema.
  • šŸ” Zod Integration: Automatically converts Prisma types to Zod validation schemas.
  • šŸ“‚ Modular Structure: Organizes your API into modular components within src/app/modules/.
  • ⚔ Efficient Development: Save time by scaffolding essential files in seconds.

šŸ“‹ Prerequisites

Ensure you have the following installed:

  • Node.js (v16+ recommended)
  • Prisma (installed in your project)
  • Zod (for validation handling)

šŸ“¦ Installation

You can install pales globally using npm:

npm install -g pales

Alternatively, you can install it locally within your project:

npm install --save-dev pales

šŸŽÆ Usage

Once installed, navigate to your project root (where schema.prisma exists) and run:

pales

This will:

  1. Parse your schema.prisma file.
  2. Extract all models.
  3. Generate corresponding API modules with routes and validation.

šŸ“ Project Structure

After running pales, your project structure will look like this:

šŸ“‚ src/
 ā”œā”€ā”€ šŸ“‚ app/
 │   ā”œā”€ā”€ šŸ“‚ modules/
 │   │   ā”œā”€ā”€ user/
 │   │   │   ā”œā”€ā”€ user.controller.ts
 │   │   │   ā”œā”€ā”€ user.routes.ts
 │   │   │   ā”œā”€ā”€ user.validation.ts
 │   │   │   └── user.service.ts
 │   │   ā”œā”€ā”€ post/
 │   │   │   ā”œā”€ā”€ post.controller.ts
 │   │   │   ā”œā”€ā”€ post.routes.ts
 │   │   │   ā”œā”€ā”€ post.validation.ts
 │   │   │   └── post.service.ts
 │   ā”œā”€ā”€ šŸ“‚ routes/
 │   │   ā”œā”€ā”€ index.ts
 │   ā”œā”€ā”€ šŸ“‚ lib/
 │   │   ā”œā”€ā”€ utils.ts
 │   │   ā”œā”€ā”€ generate-constants.sh
 │   │   ā”œā”€ā”€ process-model.sh
 │   │   ā”œā”€ā”€ zod-generator.sh
 │   │   ā”œā”€ā”€ update-routes.sh

šŸ”„ Example

If your schema.prisma contains:

model User {
  id        String  @id @default(uuid())
  name      String
  email     String  @unique
  createdAt DateTime @default(now())
}

Running pales will generate:

  • Routes (**user.routes.ts**): Defines API endpoints for the User model.
  • Controller (**user.controller.ts**): Handles incoming requests.
  • Validation (**user.validation.ts**): Ensures request data matches the model schema.
  • Service (**user.service.ts**): Business logic layer for the User model.

šŸ›  Commands

CommandDescription
pales-generateGenerates API modules from Prisma schema.
pales-create `| Creates Application Starter.
pales --cleanDeletes previously generated modules.
pales --debugRuns in debug mode to log errors.

šŸž Troubleshooting

  • If you see schema.prisma not found, ensure you are running pales in the correct directory.
  • If schema.pi is missing, try manually copying schema.prisma to schema.pi.
  • If TYPE_MAP errors occur, ensure you're using bash with associative array support.

šŸ“œ License

MIT License

šŸ¤ Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.


šŸš€ Happy coding!