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

jetpath

v1.4.10

Published

JetPath - A fast, seamless and minimalist framework for Node, Deno and Bun.js. Embrace the speed and elegance of the next-gen server-side experience.

Downloads

139

Readme

Contributors npm Version Forks Stargazers

--

Latest version info

In this version, we added/tested these features on all runtimes.

  1. auto-generated api documentation UI (JethPath UI).
  2. streaming via ctx.pipe(stream||filename).
  3. file uploads check this example
  4. support for websockets check this example.
  5. Logger usage - (we tested pino/winston).

In this version (not this latest), multi-runtime support is no-longer based on compartiblity but pure engine api(s).

We Added Examples in the examples folder!

  • running Node index.js starts a Node instance for your app.
  • running Deno run index.ts starts a Deno instance for your app.
  • running Bun index.ts starts a Bun instance for your app.
  • looking into serverless

this version we fixed issues with the inbuilt cors hook.

  • more speed, same size, more power.

Rationale

JetPath is a Small Server-side framework that is Fast and Easy to use.

benchmark repo

  • JetPath now runs one the runtime you are using, bun or node or deno.
  • Function names as routing patterns (newest innovation you haven't seen before).
  • Pre, Post and Error request hooks.
  • Inbuilt Cors handlers.
  • Fast and small and easy as peasy.
  • A strong backup community moved with passion for making the web better.
  • Now supports file streaming.
  • Inbuilt swagger functionality.

In JetPath, unlike express, fastify or other Javascript base server-side framworks, JetPath is designed as a light, simple and but powerful, using the an intuitive route as function name system. you can be able to design and manage your api(s) with the smallest granularity possible.

This benefits are very lovely and delighting, but trust me you have never written javascript app in this manner before and you should definitely check this out for a new taste beyound what the mainstream offers, an eciting DX.

--

How JetPath works

JetPath works by search through the source forder and join up any defined paths and hooks that follows it's formart.

Requirements to use JetPath.

JetPath support all server-side Javascript runtimes:

  • Nodejs.
  • Denojs.
  • Bunjs.
  • and deno deploy (testing)
  • Edge support for runtimes like cloudflare workers(in view).

Installation

Install JetPath Right away on your project using npm or Javascript other package managers.

npm i jetpath --save

Usage

JetPath is very simple, it allows you to create the most actions in app in a very simple intuitive way.

A Basic App setup

// in your src/app.js
import JetPath from "jetpath";

const app = new JetPath({
  source: "./src", // optional
  port: 3000, // optional
  cors: true, // optional
});
//? listening for requests
app.listen();

Example routes

// in your ./src/routes/PathShop.js

import { AppCTX, Schema } from "../dist/index.js";

//? Body validators

export const BODY_pets: Schema = {
  name: { err: "please provide dog name", type: "string" },
  image: { type: "string", nullable: true, inputType: "file" },
  age: { type: "number" },
};
export const BODY_petBy$id: Schema = {
  name: { err: "please provide dog name", type: "string" },
  image: { type: "string", nullable: true, inputType: "file" },
  age: { type: "number" },
};
export const BODY_petImage$id: Schema = {
  image: { type: "string", inputType: "file" },
};

// ? Routes

// ? PETshop temperaly Database
const pets: { id: string; imageUrl: string; name: string }[] = [];

// ? /
export async function GET_(ctx: AppCTX) {
  ctx.send("Welcome to Petshop!");
}

// List Pets: Retrieve a list of pets available in the shop
// ? /pets
export function GET_pets(ctx: AppCTX) {
  ctx.send(pets);
}

// ? /petBy/19388
// Get a Pet by ID: Retrieve detailed information about a specific pet by its unique identifier
export function GET_petBy$id(ctx: AppCTX) {
  const petId = ctx.params?.id;
  const pet = pets.find((p) => p.id === petId);
  if (pet) {
    ctx.send(pet);
  } else {
    ctx.code = 404;
    ctx.send({ message: "Pet not found" });
  }
}

// ? /pets
// Add a New Pet: Add a new pet to the inventory
export async function POST_pets(ctx: AppCTX) {
  ctx.validate(await ctx.json());
  const newPet: { id: string; imageUrl: string; name: string } = ctx.body;
  // Generate a unique ID for the new pet (in a real scenario, consider using a UUID or another robust method)
  newPet.id = String(Date.now());
  pets.push(newPet);
  ctx.send({ message: "Pet added successfully", pet: newPet });
}

// Update a Pet: Modify the details of an existing pet
// ? /petBy/8766
export async function PUT_petBy$id(ctx: AppCTX) {
  ctx.validate(await ctx.json());
  const petId = ctx.params.id;
  const updatedPetData = await ctx.json();
  const index = pets.findIndex((p) => p.id === petId);
  if (index !== -1) {
    // Update the existing pet's data
    pets[index] = { ...pets[index], ...updatedPetData };
    ctx.send({ message: "Pet updated successfully", pet: pets[index] });
  } else {
    ctx.code = 404;
    ctx.send({ message: "Pet not found" });
  }
}

// ? /petBy/8766
// Delete a Pet: Remove a pet from the inventory
export function DELETE_petBy$id(ctx: AppCTX) {
  const petId = ctx.params.id;
  const index = pets.findIndex((p) => p.id === petId);
  if (index !== -1) {
    const deletedPet = pets.splice(index, 1)[0];
    ctx.send({ message: "Pet deleted successfully", pet: deletedPet });
  } else {
    ctx.code = 404;
    ctx.send({ message: "Pet not found" });
  }
}

// ? /petImage/76554
// Upload a Pet's Image: Add an image to a pet's profile
export async function POST_petImage$id(ctx: AppCTX) {
  const petId = ctx.params.id;
  // @ts-ignore
  console.log(ctx.request);
  const formdata = await ctx.request.formData();
  console.log(formdata);
  const profilePicture = formdata.get("image");
  if (!profilePicture) throw new Error("Must upload a profile picture.");
  console.log({ formdata, profilePicture });

  const index = pets.findIndex((p) => p.id === petId);
  if (index !== -1) {
    // Attach the image URL to the pet's profile (in a real scenario, consider storing images externally)
    pets[index].imageUrl = `/images/${petId}.png`;
    // write profilePicture to disk
    // @ts-ignore
    await Bun.write(pets[index].imageUrl, profilePicture);
    ctx.send({
      message: "Image uploaded successfully",
      imageUrl: pets[index].imageUrl,
    });
  } else {
    ctx.code = 404;
    ctx.send({ message: "Pet not found" });
  }
}

// ? error hook
export function hook__ERROR(ctx: AppCTX, err: unknown) {
  ctx.code = 400;
  console.log(err);
  ctx.send(String(err));
}

//? hooks
export function hook__POST(ctx, data) {
  ctx.throw("no handlers for this request");
}

export function hook__PRE(ctx) {
  console.log(ctx.method);
}

ctx Overview at current

ctx is th JetPath parameter your route functions are called with.

export type AppCTX = {
  json(): Promise<Record<string, any>> | undefined;
  validate(data: any): Record<string, any>;
  body?: any;
  code: number;
  search: Record<string, string>;
  params: Record<string, string>;
  request: IncomingMessage | Request;
  method: string;
  reply(data: unknown, ContentType?: string): void;
  throw(
    code?: number | string | Record<string, any> | unknown,
    message?: string | Record<string, any>
  ): void;
  redirect(url: string): void;
  get(field: string): string | undefined;
  set(field: string, value: string): void;
  pipe(stream: Stream | string, ContentType: string): void;
  app: Record<string, any>;
};

When improvements and changes rolls out, we will quickly update this page and the currently prepared web documentation.

Where's JetPath future gonna be like?

We have exhausted our Roadmap, let's me what your suggestions are!

Apache 2.0 Lincenced

Opensourced And Free.

Uiedbook is an open source team of web focused engineers, their vision is to make the web better, improving and innovating infrastructures for a better web experience.

You can Join the Uiedbook group on telegram. Ask your questions and become a team-member/contributor by becoming an insider.

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work.

Support

Your contribution(s) is a good force for change anytime you do it, you can ensure JetPath's growth and improvement by contributing a re-occuring or fixed donations to:

https://www.buymeacoffee.com/fridaycandour

Or Click.