H3ravel Framework

website·Indexed 32 days ago

https://h3ravel.toneflix.net

A TypeScript framework featuring Arquebus ORM for active record CRUD and relationship management, Musket CLI for application tooling, and a comprehensive suite of guides covering routing, controllers, middleware, and service providers.

Tokens
53.1K
Snippets
377
Records
410
Agent score
52%

What's inside H3ravel

  1. Overview of Musket CLI

    Musket CLI is a lightweight, framework-agnostic toolkit inspired by Laravel’s Artisan, designed for building expressive command-line interfaces. It is powered by Commander.js and serves as the console layer for the H3ravel framework. By default, Musket automatically handles configuration loading, command registration, and parsing. For advanced control, the skipParsing option can be enabled to access the underlying Commander instance for manual command registration or lifecycle hooks.
  2. Overview of H3ravel Framework

    H3ravel is a modern, runtime-agnostic TypeScript web framework built on top of H3. It is designed to provide a developer experience similar to Laravel, featuring a TypeScript-first approach with strong type safety and IntelliSense. Because it is runtime-agnostic, it can be deployed on Node.js, Bun, Deno, or other JavaScript runtimes.
  3. Overview of the H3ravel Request class

    The Request class is a unified HTTP request abstraction that wraps the native H3Event. It normalizes data from query strings, JSON payloads, form data, and file uploads into consistent, strongly typed input sources. It can be injected into controllers and middleware or accessed via a global helper.
    // Injected into a controller
    export class UserController extends Controller {
      @Injectable()
      async store(request: Request, response: Response) {
        return response
          .setStatusCode(202)
          .json({ message: `User ${request.input('name')} created` });
      }
    }
    
    // Using the global helper
    const name = request().input('name');
  4. Overview of H3ravel Encryption

    H3ravel provides an API for encrypting and decrypting data using OpenSSL. It supports AES-256 and AES-128 encryption algorithms. To ensure data integrity and prevent tampering or modification after encryption, all encrypted values are automatically signed with a message authentication code (MAC).
  5. H3ravel Framework Overview

    H3ravel is a modern, runtime-agnostic TypeScript web framework built on top of H3. It is designed to bring Laravel's architecture and developer experience (DX) to the JavaScript ecosystem, featuring a Service Container, Service Providers, Middleware, and Facades. It is fully type-safe and compatible with Node.js, Bun, and Deno.
  6. Required skillset for H3ravel contributors

    Contributors should have a working knowledge of server-side programming and JavaScript. Recommended expertise includes:

    • TypeScript, Node.js, and the H3 framework.
    • Laravel's architecture and patterns (or a willingness to learn the Laravel-inspired approach used in H3ravel).
    • Understanding of dependency injection, middleware pipelines, and modern service container patterns.
  7. Use Arquebus ORM in browser environments

    Arquebus ORM supports running in browser environments in addition to server-side usage. The browser version supports core functionalities including Models, Attributes, and Relations. Note that database-related features, such as the Query Builder, are not available in the browser version.
  8. Understand Arquebus ORM Collections

    In Arquebus ORM, any method that returns multiple model results (such as .get() or relationship accessors) returns an instance of the Collection class. This class extends @h3ravel/collect.js, meaning it supports fluent map/reduce operations and is iterable like a standard array.
    import { User } from './models';
    
    // Retrieve a collection of users
    const users = await User.query().where('active', 1).get();
    
    // Use as an iterator
    for (let user of users) {
      console.log(user.name);
    }
    
    // Use fluent chaining (inherited from collect.js)
    const names = (await User.query().all())
      .reject((user) => user.active === false)
      .map((user) => user.name);
  9. Handle transactions within model hooks

    When a model operation is performed within a transaction, the transaction client is passed to the hook. To ensure related operations (like deleting related records) stay within the same transaction, use the .transacting(client) method on the query.
    User.deleted(async (user, { client }) => {
      const query = user.related('posts');
    
      if (client) {
        query.transacting(client);
      }
    
      await query.delete();
    });
    
    // Usage with a transaction
    const trx = await arquebus.beginTransaction();
    
    await user.delete({
      client: trx,
    });
    
    await trx.commit();
  10. Use the Advanced Logger for complex layouts

    For advanced layouts, multi-column details, or specific color arrays, use the Logger class from @h3ravel/shared.
    import { Logger } from '@h3ravel/shared';
    
    Logger.info('Processing...');
    Logger.twoColumnDetail('Task', 'DONE');
    Logger.success('Operation completed');
    
    // Log with specific colors for parts of the string
    Logger.log([
      ['Processed', 'white'],
      ['100 items', ['green', 'bold']],
      ['successfully', 'white'],
    ]);
    
    Logger.log('Job completed successfully', 'green');
  11. Create an H3ravel HTTP test client

    H3ravel provides a test client via @h3ravel/foundation that boots the application without starting a network server. By default, calling testApp() loads src/bootstrap/providers, configures web and API routes, and boots the application. The client uses Parasito for fluent requests and assertions and can be used with any test runner (e.g., Vitest).
    import { testApp, type TestClient } from '@h3ravel/foundation'
    import { beforeAll, describe, it } from 'vitest'
    
    describe('home page', () => {
      let client: TestClient
    
      beforeAll(async () => {
        client = await testApp()
      })
    
      it('returns a successful response', async () => {
        await client
          .get('/')
          .expect(200)
      })
    })