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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@woen4/higher

v0.0.82

Published

<p align="center"> <img src="https://i.imgur.com/a2Agwqa.jpeg" height="300" /> </p> &nbsp; &nbsp;

Downloads

20

Readme

Higher is a framework it was built thinking in some requirements

  • The minimum of code lines to create an endpoint
  • Files with a unique responsibilty, representing a unique endpoint
  • Easy to test
  • Performance
  • Good developer experience
  • And that it works well in a serverless environment

 

has support to:

  • 🔄 Middlewares (per folder level)
  • ✅ Body and query params validation (using Zod)
  • ⤵ Dependency injection (Test is very easy)

 

and was built-in using:

  • Fastify
  • Zod
  • Typescript
  • Tsup (Dev server and build process is very fast)

 

How to install:

  npx create-higher-app

 

Initial guide:

Higher follow a well defined structure, let's start with a route to retrieve users

get.ts :

  export handle = () => {
    return ["Kaio", "Woen"]
  }

index.ts :

  import { bootstrap } from "@woen4/higher";

  const server = bootstrap();

  server.listen(3000)

On run dev script, this will run your server exposing a route /users of method GET

so you need create a folder providers in src directory and exports a object from there

prisma.ts :

  import { PrismaClient } from '@prisma/client'

  export const prisma = new PrismaClient()

index.ts :

  export type Providers = typeof import("./index");

  export * from './prisma'

And then, use this in your route handler

get.ts :

  import { Providers } from '../../providers'

  export handle = (ctx: Providers) => {
    return ctx.prisma.users.findMany()
  }

But... how to acess request in handler? Simple modules/users/post.ts

  import { Providers } from '../../providers'

  export handle = (ctx: Providers, { body }: HigherRequest) => {
    return ctx.prisma.users.create({ data: body })
  }

But... how to validate the body data? Also is simple

  import { Providers } from '../../providers'
  import { z } from "zod";

  export const schema = z.object({
    name: z.string(),
    email: z.string(),
  });

  export handle = (ctx: Providers, { body }: HigherRequest<void, typeof schema>) => {
    return ctx.prisma.users.create({ data: body })
  }

The generic type <void, typeof schema> will offer the intellisense in your editor when using body object

Ok, but I need of a middleware to authenticate my routes, how do it?. Also is very simple

Create a file named middleware.ts inside the modules folder and it will be apply to all routes, otherwise if you put your middleware file inside the users folder, it will only apply to users routes

middleware.ts

  import { HigherRequest, HigherResponse } from "@woen4/higher";
  import { Providers } from '../providers'

  export type WithAuth = {
    user: {
      id: string;
    };
  };

  export const handle = (ctx: Providers, request: HigherRequest<WithAuth>) => {
    /* 
    
    Some lines of code to implementate authorization

    */

    request.user = {
      id: '123',
    }
  };

One more question, how to create routes with parameters? Simple and plain

[userId]/get.ts

  import { Providers } from '../../providers'
  import { WithAuth } from '../../../middleware.ts'

  export handle = (ctx: Providers, { user }: HigherRequest<WithAuth>) => {
    
    return ctx.prisma.users.findFirst({ where: { id: user.id } })
  }

 

Full documention:

is coming...