Socket
Book a DemoInstallSign in
Socket

@arabesque/core

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arabesque/core

Functional micro-framework

0.3.0
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Arabesque

NPM version Coverage Status

Functional micro-framework

Arabesque is a lightweight, modular and functional micro-framework.

Getting started

Arabesque provides a minimal foundation to create applications and micro-services, consisting of three types and a function.

Listener

declare type Listener<Channel, Context> = (channel: Channel, handler: (context: Context) => Promise<Context>) => Promise<() => Promise<void>>;

The fundamental part of an Arabesque application, the Listener is passed by the application a channel, that the Listener is expected to subscribe to, and a handler, that the Listener must call whenever it receives something from the channel. The Listener must return a promise that resolves to an argument-less function that, when executed, stop the Listener.

A channel can take any imaginable form, for example:

  • a number in the context of a TCP service, representing a port
  • a structured object in the context of a Kafka consumer, representing a broker, a group ID and a topic
  • a string in the context of a file watcher, representing a pattern of files to watch

Middleware

declare type Middleware<Context> = (context: Context, next: (context: Context) => Promise<Context>) => Promise<Context>;

The operational part of an Arabesque application, the Middleware is passed by the application a context, coming from either the Listener or a previous Middleware, and a next function, that the Middleware may call with a Context to execute the next Middleware, if any.

Application

declare type Application<Channel> = (channel: Channel) => Promise<() => Promise<void>>;

The Arabesque Application itself that, when executed, returns a Promise that resolves to an argument-less function that, when executed, stop the Application.

createApplication

import {Middleware} from "./index";

declare const createApplication: <Channel, Context>(
    listen: Listener<Channel, Context>,
    middleware: Middleware<Context>
) => Application<Channel, Context>;

The factory that creates an Arabesque Application from a Listener and a Middleware.

Code sample

import type {Listener} from "@arabesque/core";
import {createApplication} from "@arabesque/core";

const listener: Listener<string, string> = (channel, handler) => {
    return handler(channel).then(() => {
        return () => Promise.resolve();
    });
};

const start = createApplication(listener, (context, next) => {
    console.log(`I am the middleware and I received ${context}`);

    return next(context);
});

return start('foo').then((stop) => {
    return stop();
});

Contributing

  • Fork this repository
  • Code
  • Implement tests using tape
  • Issue a merge request keeping in mind that all pull requests must reference an issue in the issue queue

Keywords

application

FAQs

Package last updated on 26 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.