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

@chubbyts/chubbyts-api

v4.1.1

Published

[![CI](https://github.com/chubbyts/chubbyts-api/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyts/chubbyts-api/actions?query=workflow%3ACI) [![Coverage Status](https://coveralls.io/repos/github/chubbyts/chubbyts-api/badge.svg?branch=maste

Downloads

550

Readme

chubbyts-api

CI Coverage Status Mutation testing badge npm-version

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

Requirements

Installation

Through NPM as @chubbyts/chubbyts-api.

npm i @chubbyts/chubbyts-api@^4.1.1

Usage

Handler

createListHandler

import { createListHandler } from '@chubbyts/chubbyts-api/dist/handler/list';
import { createEncoder } from '@chubbyts/chubbyts-decode-encode/dist/encoder';
import { createJsonTypeEncoder } from '@chubbyts/chubbyts-decode-encode/dist/encoder/json-type-encoder';
import { z } from 'zod';
import { ResolveList } from '@chubbyts/chubbyts-api/dist/repository';
import { List, Model } from '@chubbyts/chubbyts-api/dist/model';
import {
  createResponseFactory,
  createServerRequestFactory,
} from '@chubbyts/chubbyts-http/dist/message-factory'; // any implementation can be used

const inputSchema = z.object({ name: z.string() }).strict();
const resolveList: ResolveList<MyModel> = (list: List<Model<MyModel>>): Promise<List<Model<MyModel>>> => {};
const responseFactory = createResponseFactory();
const outputSchema = z.object({ id: z.string(), createdAt: z.date(), name: z.string() }).strict();
const encoder = createEncoder([createJsonTypeEncoder()]);

const serverRequestFactory = createServerRequestFactory();

const listHandler = createListHandler<MyModel>(
  inputSchema,
  resolveList,
  responseFactory,
  outputSchema,
  encoder
);

(async () => {
  const request = serverRequestFactory('GET', 'http://localhost:8080/api/pets');
  const response = await listHandler(request);
})();

createCreateHandler

import { createCreateHandler } from '@chubbyts/chubbyts-api/dist/handler/create';
import { createDecoder } from '@chubbyts/chubbyts-decode-encode/dist/decoder';
import { createJsonTypeDecoder } from '@chubbyts/chubbyts-decode-encode/dist/decoder/json-type-decoder';
import { createEncoder } from '@chubbyts/chubbyts-decode-encode/dist/encoder';
import { createJsonTypeEncoder } from '@chubbyts/chubbyts-decode-encode/dist/encoder/json-type-encoder';
import { z } from 'zod';
import { Persist } from '@chubbyts/chubbyts-api/dist/repository';
import { Model } from '@chubbyts/chubbyts-api/dist/model';
import {
  createResponseFactory,
  createServerRequestFactory,
} from '@chubbyts/chubbyts-http/dist/message-factory'; // any implementation can be used

const decoder = createDecoder([createJsonTypeDecoder()]);
const inputSchema = z.object({ name: z.string() }).strict();
const persist: Persist<MyModel> = (model: Model<MyModel>): Promise<Model<MyModel>> => {};
const responseFactory = createResponseFactory();
const outputSchema = z.object({ id: z.string(), createdAt: z.date(), name: z.string() }).strict();
const encoder = createEncoder([createJsonTypeEncoder()]);

const serverRequestFactory = createServerRequestFactory();

const createHandler = createCreateHandler<Model>(
  decoder,
  inputSchema,
  persist,
  responseFactory,
  outputSchema,
  encoder
);

(async () => {
  const request = serverRequestFactory('POST', 'http://localhost:8080/api/pets');
  const response = await createHandler(request);
})();

createReadHandler

import { createReadHandler } from '@chubbyts/chubbyts-api/dist/handler/read';
import { createEncoder } from '@chubbyts/chubbyts-decode-encode/dist/encoder';
import { createJsonTypeEncoder } from '@chubbyts/chubbyts-decode-encode/dist/encoder/json-type-encoder';
import { z } from 'zod';
import { FindOneById } from '@chubbyts/chubbyts-api/dist/repository';
import { Model } from '@chubbyts/chubbyts-api/dist/model';
import {
  createResponseFactory,
  createServerRequestFactory,
} from '@chubbyts/chubbyts-http/dist/message-factory'; // any implementation can be used

const findOneById: FindOneById<MyModel> = async (id: string): Promise<Model<MyModel>|undefined> => {};
const responseFactory = createResponseFactory();
const outputSchema = z.object({ id: z.string(), createdAt: z.date(), name: z.string() }).strict();
const encoder = createEncoder([createJsonTypeEncoder()]);

const serverRequestFactory = createServerRequestFactory();

const readHandler = createReadHandler<Model>(
  findOneById,
  responseFactory,
  outputSchema,
  encoder
);

(async () => {
  const request = serverRequestFactory('GET', 'http://localhost:8080/api/pets/8ba9661b-ba7f-436b-bd25-c0606f911f7d');
  const response = await readHandler(request);
})();

createUpdateHandler

import { createUpdateHandler } from '@chubbyts/chubbyts-api/dist/handler/update';
import { createDecoder } from '@chubbyts/chubbyts-decode-encode/dist/decoder';
import { createJsonTypeDecoder } from '@chubbyts/chubbyts-decode-encode/dist/decoder/json-type-decoder';
import { createEncoder } from '@chubbyts/chubbyts-decode-encode/dist/encoder';
import { createJsonTypeEncoder } from '@chubbyts/chubbyts-decode-encode/dist/encoder/json-type-encoder';
import { z } from 'zod';
import { FindOneById, Persist } from '@chubbyts/chubbyts-api/dist/repository';
import { Model } from '@chubbyts/chubbyts-api/dist/model';
import {
  createResponseFactory,
  createServerRequestFactory,
} from '@chubbyts/chubbyts-http/dist/message-factory'; // any implementation can be used

const findOneById: FindOneById<MyModel> = async (id: string): Promise<Model<MyModel>|undefined> => {};
const decoder = createDecoder([createJsonTypeDecoder()]);
const inputSchema = z.object({ name: z.string() }).strict();
const persist: Persist<MyModel> = (model: Model<MyModel>): Promise<Model<MyModel>> => {};
const responseFactory = createResponseFactory();
const outputSchema = z.object({ id: z.string(), createdAt: z.date(), name: z.string() }).strict();
const encoder = createEncoder([createJsonTypeEncoder()]);

const serverRequestFactory = createServerRequestFactory();

const updateHandler = createUpdateHandler<Model>(
  findOneById,
  decoder,
  inputSchema,
  persist,
  responseFactory,
  outputSchema,
  encoder
);

(async () => {
  const request = serverRequestFactory('PUT', 'http://localhost:8080/api/pets/8ba9661b-ba7f-436b-bd25-c0606f911f7d');
  const response = await updateHandler(request);
})();

createDeleteHandler

import { createDeleteHandler } from '@chubbyts/chubbyts-api/dist/handler/delete';
import { FindOneById, Remove } from '@chubbyts/chubbyts-api/dist/repository';
import { Model } from '@chubbyts/chubbyts-api/dist/model';
import {
  createResponseFactory,
  createServerRequestFactory,
} from '@chubbyts/chubbyts-http/dist/message-factory'; // any implementation can be used

const findOneById: FindOneById<MyModel> = async (id: string): Promise<Model<MyModel>|undefined> => {};
const remove: Remove<MyModel> = (model: Model<MyModel>): Promise<void> => {};
const responseFactory = createResponseFactory();

const serverRequestFactory = createServerRequestFactory();

const deleteHandler = createDeleteHandler<Model>(
  findOneById,
  remove,
  responseFactory,
);

(async () => {
  const request = serverRequestFactory('DELETE', 'http://localhost:8080/api/pets/8ba9661b-ba7f-436b-bd25-c0606f911f7d');
  const response = await deleteHandler(request);
})();

Middleware

createAcceptLanguageNegotiationMiddleware

createAcceptNegotiationMiddleware

createContentTypeNegotiationMiddleware

createErrorMiddleware

Copyright

2024 Dominik Zogg