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

@pratiko-framework/pratiko

v1.1.5

Published

Pratiko is a microservices framework derived from [Byron Framework](https://byron.netlify.com), from where it inherited the **event-driven microservices framework**. Pratiko is also **tangible** by adopting an interface inspired by Google's [Flutter](http

Downloads

22

Readme

Pratiko Framework

Pratiko is a microservices framework derived from Byron Framework, from where it inherited the event-driven microservices framework. Pratiko is also tangible by adopting an interface inspired by Google's Flutter framework for mobile development.

Installation

Pratiko is hosted at NPM and can easily be install with your package manager:

# using YARN
yarn add @pratiko-framework/pratiko

# using NPM
npm install --save @pratiko-framework/pratiko

Hello, outter World

"It's a pleasure to meet you!" you hear from the Diplomat, Pratiko's component responsible for handling with communication with external world. Let's dive into the code:

import { Diplomat, Resolver } from '@pratiko-framework/pratiko';

import { CreateUser } from 'path/to/CreateUser.ts';

export const app: Diplomat = new Diplomat({
  resolvers: [
    new Resolver({
      route: 'POST /users',
      callback: CreateUser,
    }),
  ],
});

app.run();

The Diplomat handles communication with external world by defining a set of Resolvers. Each resolver implements an exposed action thru Diplomat's API. That means, Diplomat exposes an RESTful API and each endpoint is implemented with a Resolver.

Resolvers are a simple set of two or three informations: a route and a callback, which are both mandatory, and a name, which is opcional. The route is defined by a HTTP verb and a URI. The callback is the implementation for that endpoint and it follows this structure:

// CreateUser.ts
export const CreateUser = async (ctx: any): Promise<void> => {
  const { db }: any = ctx;
  const { email, password, confirmation }: any = ctx.args;

  // validate the data given, using rules and database, for instance

  if (isValid) {
    ctx.body = { user };
  } else {
    ctx.status = 400;
    ctx.body = { error: validationError };
  }
};

Notice some design decisions that might be unusual:

  1. the successful case -- when isValid === true -- doesn't change the database directly, instead it publishes an event
  2. the response is sent as soon as possible, without further due -- like updating the DB or receiving an ack back

Hello, inner World

Since the external communication is well handled by the Diplomat, meet now the component responsible for watching every internal event and dispatching actions accordingly: the Meerkat. Let's dive into the code:

import { Meerkat, Broker, Handler } from '@pratiko-framework/pratiko';

import { CreateUser } from '/path/to/CreateUser.ts';

export const app: Meerkat = new Meerkat({
  broker: new Broker({
    clientID: 'module-meerkat',
  }),
  handlers: [
    new Handler({
      topic: 'new.user',
      callback: CreateUser,
    }),
  ],
});

app.run();

You might noticed that the Meerkat requires a broker. The Broker is an object that wraps a connection to the NATS Streaming broker. That makes sense because Meerkat is responsible for the internal communication, i.e., it listens to events published all across the system and react accordingly.

Each event the Meerkat listens is declared in a Handler object, along-side with the reaction implementation, which is presented following:

export const CreateUser = async (msg: any, ctx: any): Promise<void> => {
  const { db }: any = ctx;
  const user = JSON.parse(msg.getData());

  await db.collection('users').insertOne(user);
};

The tipical behavior a Handler has is to extract data from messages -- representation of an event in the broker -- and update the database with that. But nothing stops you from doing other validations, transformations and even emitting events back to the broker as part of a choreography, a Saga for instance.