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

@maeum/schema-controller

v1.5.2

Published

maeum framework schema-controller

Downloads

181

Readme

@maeum/schema-controller

ts Download Status Github Star Github Issues NPM version @maeum/schema-controller License codecov code style: prettier

The @maeum/schema-controller is a package that helps developer to integreate schema-nozzle and fastify.js. Developer can generate a json-schema via schema-nozzle and then use as a schema in fastify.js request/response.

Why use @maeum/schema-controller?

  • You can decouple the schema-controller from fastify.js
  • Less effort to set up route configuration in fastify.js
  • You can add json-schema validation to messages received from MQ (RabbitMQ, ActiveMQ, SQS, etc), server configurations, and anywhere else you want.

Table of Contents

Getting Started

installation

npm install @maeum/schema-controller --save

Configuration

import fastify from 'fastify';
import { SchemaController } from '@maeum/schema-controller';

const listen = () => {
  // step 01. bootstrap your json-schema database
  SchemaController.bootstrap(false, {
    // set your json-schema database file-path
    filePath: path.join(getCwd(process.env), 'resources', 'configs', 'store.json'),
  });

  const server = fastify()

  // step 02. your schema controller pass to fastify.js
  server.setSchemaController(SchemaController.it.getFastifyController(server));
}

listen();

How to work?

The schema-nozzle generate as json-schema database file that is available in @maeum/schema-controller. This generated json-schema database file is read from @ameum/schema-controller and then use to set up the schema in fastify.js routing.

server.post('/pet', { schema: { querystring: { $ref: 'ICreatePetDto' } } }, (req: FastifyRequest<{ Querystring: ICreatePetDto }>, reply) => {
  // ...your code
  // You can use auto-complete and intellisence Request Object like that,
  // `req.query.name`
})
flowchart LR
    SN[schema-nozzle]
    DB[store.json]
    SC[schema-controller]
    RC[fastify.js<br /> route configuration<br /> swagger document]

    SN-->|TypeScript interface<br />convert to json-schema|DB
    DB-->SC
    SC-->|fastify.js schema-controller|RC

Custom ajv Options

fastify.js uses ajv for request data validation. If you want to change the options of the ajv instance, you can pass custom options as shown below.

SchemaController.bootstrap(false, {
  filePath: path.join(getCwd(process.env), 'resources', 'configs', 'store.json'),
  ajv: {
    // custom option of ajv instance
    options: {
      coerceTypes: 'array',
      keywords: ['collectionFormat', 'example', 'binary'],
      formats: {
        binary: { type: 'string', validate: () => true },
        byte: { type: 'string', validate: () => true },
      },
    },
    // extension apply on ajv
    extension: (ajv) => { 
      ajvFormat(ajv);
    },
});

Relate To

License

This software is licensed under the MIT.