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

@wrserver/core

v1.2.3

Published

wrserver - core module

Downloads

1

Readme

WRServer/Core

License Email Donate Donate

@wrserver core module that define the basic concepts of the WRS.

Installing

Install this library is easy by cloning the repo. You can install trhought npm too:

Local installation

npm install @wrserver/core

Global installation

npm install -g @wrserver/core

We recomend to use the entire base package (core, crypt, data, auth, mail)

WRServer Concepts

Elements

The WRServer is built up on this elements:

  • Module - is a container usefull to pack everything a part of your server needs
  • Controller - enstabilish the reachable paths and the sort of responses the server builds
  • Model - represent the object on the server, that could be sent as response to the clients
  • Service - an intermodule process that allow internal server comunication
  • Component - everything the server need to process particular information or run tasks
  • Connection - the client representation on the server side
  • Message - the client message representation on the server side
Incoming Message Format
//Incoming Message - from Core > Connection
interface IConnectionIncomingParsed {
    target: string,
    section: string,
    page: string,
    option: string,
    id: number,
    data: any
}
Outcoming Message Format
//Outcoming Message - from Core > Connection
interface IConnectionOutcome {
    id?: number,
    bad: boolean
    code: string,
    class: string,
    data: any,
    message: string,
}
WRServer usual procedures

Start-up The Server instanciate once every module disposed at the creation time and search for needs of every module. Then it instanciate every service once and inject them on modules that needs them. The Server is now ready to communicate. Connection A Client want to connect to the server, it make handshacke and the connection is approved. When Server and Client are connected the Server send a lookup table of codes to enstabilish the correct communication. Message Client send a message on the websocket connection. The Server try to parse the message as a well-formatted Message, if it fails reply with a bad-formatted CODE. After the formattation success Server route the Message to the instanciated Module that match name with the message target, check if module can create a Controller named as the message section. If success it create a Controller and try to call the message page method with the Message as argument to generate a response. If not page found try to check if default method is provided else generate a bad response. Anyway if no response is generated the Server provide a bad response as fallback. Broadcast The Server can send a message to every connection that satisfy a filter clause.

How To

Create a custom Module

import { Module, Controller, Service, ModelBase, ControllerType } from "<core>";

//This are just suggested for typing your controller
export type MyControllerServices = { <ServiceName>: <ServiceType> };
export type MyControllerModels = { <ModelName>: <ModelType> };

export class MyModule extends Module {
    protected controllers: ControllerType[] = [ ... Controllers needed ... ];
    protected models: ModelType[] = [ ... Models needed ... ];
    public services: ServiceType[] = [ ... Services needed ... ];
    public dependencies: ModuleType[] = [ ... Other Modules needed ... ];
    public codes: string[] = [ ... Response Codes needed ... ];
}

Create a custom Controller

import { Controller, Connection, IConnectionIncomingParsed, IConnectionOutcome } from "<core>";
import { MyControllerServices, MyControllerModels } from "<my.module>";

export class MyController extends Controller {
    protected services: MyControllerServices;
    protected models: MyControllerModels;

    //optional
    constructor(connection: Connection, services: { [name: string]: any }, models: { [name: string]: any }){
        super(connection, services, models);
        //... code ...
    }

    // PAGES
    protected <PageName>(message: IConnectionIncomingParsed): IConnectionOutcome {
        //... code...
        if(BAD){
            return this.bad(<code>);
        }
        if(GOOD){
            return this.ok(<class>, <response>)
        }
    }
    public static section: string = <SectionName>;
}

Create a custom Model

NOTE: @wrserver/data gives a new model representation for db-like usage.

import { Model, ModelBase } from '<core>';

@Model
export class MyModel extends ModelBase {
   // PROPERTIES

    public sendable(): any{ return <object cleaned for response>; }
}

Create a custom Service

import { Service, Emitter, Connection } from "<core>";

/** Auth Service for simple manage of User Account with WS Connections */
export class MyService extends Service {
    constructor(eventEmitter: Emitter){
        super(eventEmitter);
        //... code ...
        //REMEBRE to call ready method after the service has started up
        this.ready();
    }
}

Usage

TS

import { WRServer } from '@wrserver/core';

let options = {
    path: <path>,
    port: <port>,
    modules: [ ... Modules ... ],
    root: <static root>
}

let wrserver = new WRServer(options.path, options.port, options.modules).withRoot(options.root);

###JS

const { WRServer } = require('@wrserver/core');
let options = {
    path: <path>,
    port: <port>,
    modules: [ ... Modules ... ],
    root: <static root>
};

let wrserver = new WRServer(options.path, options.port, options.modules).withRoot(options.root);

Contacts

If you like the project feel free to contact me on my Email.

Something gone wrong? Feel free to rise an issue!

Did you like this project and it was usefull? Help me improve my work:

Donate Donate