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

@cosmoosjs/hono-openapi

v1.1.10

Published

Http server using hono zod for @cosmoosjs/core

Downloads

2

Readme

hono-openapi-adapter

This packages is intented to be injected to @cosmoosjs/core.
It aims to inject an http server and create an api with a simplified integration of Hono Zod OpenApi

Installation

$ bun i @cosmoosjs/hono-openapi

Api

Below you'll find the api for understanding some of the existing components

Decorators


@Guards

Guards can be used to create middleware using hono middleware.
Regarding the declaration of a guard, it must always be declared before the Get,Post... because of its typescript composition Typescript

const Guards = (...guard: GuardsType[]): void {}

Usage

@Guards(TestGuard, TestGuard2)
public ...

export class TestGuard extends GuardAbstract {
  public run(_ctx: any): void {
    console.log("Guard triggered");
  }
}

Types

type GuardsType<T extends GuardAbstract = any> = new (...args: any) => T;

abstract class GuardAbstract {
  public run(_ctx: Context): void {}
}

Http

@Get,Post,Put,Patch,Delete

All decorators work in the same way and have the same declaration.

const Get = (routeParameters: RouteParameters): void {}

Usage

@Get({
  path: '/user/me',
  tags: ['User'],
  security: [
    {
      Bearer: [],
    }
  ],
  responses: {},
})

Types

type RouteParameters = Omit<OperationObject, "responses"> & {
  path: string;
  request?: {
    body?: ZodRequestBody;
    params?: AnyZodObject;
    query?: AnyZodObject;
    cookies?: AnyZodObject;
    headers?: AnyZodObject | ZodType<unknown>[];
  };
  responses: {
    [statusCode: string]: ResponseConfig;
  };
};

Testing

$ bun test

To test the codebase you need to emulate the process of bootstraping the application. At the moment you can use the helper given below

/**
 * Setup environnement for tests
 */
export function setupTestsHelper(container: Container) {
  // Bind classes to container
  hono_openapi.bindToContainers(container);
  core.bindToContainers(container);
  bindToContainers(container);
  // Get app
  const app = container.get(hono_openapi.Server);
  // Set reflection for decorators
  hono_openapi.defineReflection(app);
  // Add custom error handler
  hono_openapi.HttpFactory.exceptionHandler(httpExceptionsHandler, container);
  // Setup routing
  const controllerRoot = container.get(ControllerRoot);
  controllerRoot.setup();
}

The helper full declaration is here

Example

This example is from the sample hono-openapi

import { describe, it, beforeAll, expect } from "bun:test";
import { Container } from "inversify";
import { setupTestsHelper } from "src/tests/helpers/setup.helper";
import { Server } from "@cosmoosjs/hono-openapi";

describe("User Controller", () => {
  const container = new Container();

  beforeAll(() => {
    setupTestsHelper(container);
  });

  it("Should test /", async () => {
    const server = container.get(Server);
    const res = await server.hono.request("/");
    expect(res.status).toEqual(500);
    expect(await res.text()).toEqual("Hello my name is error");
  });
});

You can have more examples here