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

middlifier

v1.0.187

Published

Middlifier provides a command where you can give instructions to build a general backend and middleware template.

Downloads

43

Readme

Middlifier

Middlifier provides an interactive tool to build a server and middleware with type and value validation and hot reload. It checks the types and values, which are provided from the app in the middleware and which arrive at the server. As developer you can build a server and middleware very fast and save.

Installation

  • npm install middlifier

Commands

  • npx middlifier-init
  • npx middlifier-end

Type Validation

Type Validation takes place with Zod.

Example of generated Code from middlifier:

import { Request, Response, NextFunction } from "express";
import { z } from "zod";

export async function getUser(req: Request, res: Response, next: NextFunction) {
  const schema = z.object({ name: z.array(z.string()) });
  const body: z.infer<typeof schema> = req.body;
  schema.parse(body);
  const { name } = body;
}

Corresponding configuration from the mid.config.ts

{
  user:
    {
      getUser:
        { req: { body: { name: { type: ["string"], required: true } } } },
    },
}

Value Validation

| Type | Options | | ------ | ------------ | | String | Regex, Enums | | Number | Min, Max |

Hot Reload

For hot reload is nodemon used. Nodemon checks if changes in the "mid.config.ts" appear.

Features

  • [x] TypeScript support
  • [ ] JavaScript support
  • [x] Value Validation
  • [x] Type Validation
  • [x] Docker build
  • [x] Drizzle build
  • [x] Environment variables config
  • [x] Server entrypoint build
  • [x] Funcs build
  • [ ] Urlencoded support params - will be finished at 20.05.2024
  • [ ] Prebuild server-functions Logger, OAuth2 - will be finished at 20.05.2024
  • [x] Route build
  • [ ] Automatic generation of documentation
  • [ ] Middleware build
  • [ ] Strapi integration
  • [ ] Support for bun and npm
  • [ ] Test build
  • [ ] Automatic execution of tests
  • [ ] Doku build
  • Add an Issue type enhancement for more feature ideas!

Getting Started

  1. Navigate to your project folder: cd 'project-folder'
  2. Set up Node: npm init -y
  3. Install Middlifier: npm i middlifier
  4. Set up builder: npx middlifier-init
  5. Navigate to the "gen" folder: cd gen
  6. Start builder: npm run dev
  7. Edit "mid.config.ts" in the "gen/src" folder
  8. Navigate to your project folder: cd ..
  9. Delete unnecessary files with: npx middlifier-end
import { MidConfig } from "middlifier";
export const config: MidConfig = {
  server: {
    port: 3000,
    funcs: {},
  },
  app: {},
};

Structure of MidConfig

type MidConfig = {
  language?: "ts" | "js"; // language in which the server and middleware is builded Typescript or JavaScript
  server: {
    port: number | string; // string if you want to use an environment variable
    host?: string; // url of server
    ssl?: boolean; // secure connection
    set?: {
      [key: string]: any;
    };
    cors?: CorsOptions; // cors options for the server app.use(cors(MidConfig.server.cors))
    funcs: {
      [path: string]: {
        [fileName: string]: {
          [funcName: string]: {
            method?:
              | "GET"
              | "POST"
              | "PUT"
              | "DELETE"
              | "PATCH"
              | "OPTIONS"
              | "HEAD"
              | "CONNECT"
              | "TRACE";
            req?:
              | {
                  body?: {
                    [key: string]: { type: ParamType; required?: boolean };
                  };
                  params?: {
                    [key: string]: {
                      type: ParamType;
                      required?: boolean;
                      urlencoded?: boolean;
                    };
                  };
                  dynamicRoute?: never;
                }
              | {
                  body?: {
                    [key: string]: { type: ParamType; required?: boolean };
                  };
                  params?: never;
                  dynamicRoute?: string;
                };
            res?: {};
          };
        };
      };
    };
    indexFuncNames?: string[];
    routes?: {
      [key: string]:
        | Routes
        | [
            {
              [key: string]: Routes;
            },
            [string] | [string, string] // [path] or [path, funcName]
          ];
    };
    json?: OptionsJson; // json options for the server app.use(cors(MidConfig.server.json))
    urlencoded?: OptionsUrlencoded; // urlencoded options for the server app.use(cors(MidConfig.server.urlencoded))
    drizzle?: {
      config: Config;
      dbConfig: PoolConfig;
      schemas?: {
        [key: string]: {
          [key: string]: {
            type: "serial" | "text" | "integer" | "real";
            name: string;
            primaryKey?: boolean;
          };
        };
      };
    };
    secrets?: {
      // environment variables you yould like to set in a ".env" file
      [key: string]: string;
    };
    docker?: [
      (
        | "FROM"
        | "RUN"
        | "CMD"
        | "LABEL"
        | "EXPOSE"
        | "ENV"
        | "ADD"
        | "COPY"
        | "ENTRYPOINT"
        | "VOLUME"
        | "USER"
        | "WORKDIR"
        | "ARG"
        | "ONBUILD"
        | "STOPSIGNAL"
        | "HEALTHCHECK"
        | "SHELL"
      ),
      string
    ][];
  };
  app: {};
};

I am looking for open source non-profit-oriented developers. If you are interested contact me: [email protected]! 🚀