npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gravito/orbit-request

v0.1.0-alpha.0

Published

Form Request validation for Gravito - Laravel-style request validation with Zod

Downloads

76

Readme


title: Orbit Request

Orbit Request

Form Request validation for Gravito with Zod integration.

Orbit Request provides Laravel-style request validation for Gravito applications. Define your validation rules as classes and get type-safe validated data in your controllers.

Features

  • Type-Safe Validation: Zod schemas with full TypeScript inference
  • Class-Based Requests: Organize validation logic into reusable classes
  • Authorization: Built-in authorize() hook for access control
  • Multiple Data Sources: Validate JSON, form data, query params, or route params
  • Structured Errors: Consistent error response format

Installation

bun add @gravito/orbit-request

Usage

1. Define a FormRequest

// src/requests/StoreUserRequest.ts
import { FormRequest, z } from '@gravito/orbit-request'

export class StoreUserRequest extends FormRequest {
  schema = z.object({
    name: z.string().min(2, 'Name must be at least 2 characters'),
    email: z.string().email('Invalid email format'),
    age: z.number().min(18).optional(),
  })
}

2. Apply to Routes

import { validateRequest } from '@gravito/orbit-request'
import { StoreUserRequest } from './requests/StoreUserRequest'

core.router.post(
  '/users',
  validateRequest(StoreUserRequest),
  [UserController, 'store']
)

3. Access Validated Data

// src/controllers/UserController.ts
export class UserController {
  store(ctx: Context) {
    // Type-safe validated data
    const data = ctx.get('validated') as {
      name: string
      email: string
      age?: number
    }

    return ctx.json({ user: data })
  }
}

Data Sources

By default, FormRequest validates JSON body. Change the source:

class SearchRequest extends FormRequest {
  source = 'query' // Validate query parameters

  schema = z.object({
    q: z.string().min(1),
    page: z.coerce.number().default(1),
  })
}

| Source | Description | |--------|-------------| | json | Request body (default) | | form | Form data (multipart/form-data) | | query | URL query parameters | | param | Route parameters |

Authorization

Add authorization logic to requests:

class AdminRequest extends FormRequest {
  schema = z.object({
    action: z.string(),
  })

  authorize(ctx: Context) {
    const user = ctx.get('user')
    return user?.role === 'admin'
  }
}

Failed authorization returns 403 with:

{
  "success": false,
  "error": {
    "code": "AUTHORIZATION_ERROR",
    "message": "Unauthorized",
    "details": []
  }
}

Validation Error Format

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": [
      { "field": "email", "message": "Invalid email format", "code": "invalid_string" },
      { "field": "name", "message": "Name must be at least 2 characters", "code": "too_small" }
    ]
  }
}

Transform Data

Pre-process data before validation:

class UppercaseRequest extends FormRequest {
  schema = z.object({
    code: z.string().length(6),
  })

  transform(data: any) {
    return {
      ...data,
      code: data.code?.toUpperCase(),
    }
  }
}

License

MIT