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

@alarife/core

v1.4.0

Published

This library provides a framework for creating applications with a decorator pattern.

Downloads

21

Readme

Alarife

Alarife is an Iberian term that referred to Mudejarian architects and master builders.

What is this library? This library provides a framework for creating applications with a decorator pattern.

Application example code alarife.

Decorators

@App

App is a class decorator.

The @App decorator injects the Logger module.

When using @App with other plugins @App should always be on top of them all.

This decorator instantiates the class to which it is applied to launch its constructor, so you can add additional configuration.

You can add the parameters belonging to Core to your instance with @Value.

core includes: environment, version configuration includes: traceLog

import { App, Value } from '@alarife/core/decorators';

@App()
class Main {

  @Value('Core.environment') environment;

  @Value('Core.version') coreVersion;

  @Value('Core.rootPath') rootPath;

  @Value('Core.traceLog') traceLog;

  @Value('configuration') configuration;

  constructor() {
    this.configuration.traceLog({ levels : ['info', 'debug', 'error', 'warn'] });
  }
}

@Service

Service is a class decorator.

The @Service decorator injects the Logger module.

The @Service decorator instantiates the class for further injection into other classes.

The @AutoWired decorator used on fields injects the value of the instantiated class.

import { App, Service, AutoWired } from '@alarife/core/decorators';

@Service()
class UserService {

  getAllUsers() {
    return [
      { id   : 1, name : 'Jhon' }
    ];
  }
}

@App()
class Main {

  @AutoWired(UserService) #userService;

  constructor() {
    this.configuration.traceLog({ levels : ['info', 'debug', 'error', 'warn'] });

    this.#userService.getAllUsers();
  }
}

@Value

Value is a field decorator.

@Value manages a store of data that you can inject into your classes.

import { App, Value } from '@alarife/core/decorators';
import { valueStore } from '@alarife/core/modules';

valueStore.set('app.ip', '0.0.0.0')

@App()
class Main {

  @Value('app.ip') ip;

  constructor() {
    this.log.info('server ip: ' this.ip);
  }
}

ValueStore

You can save your own values to reuse them in your app.

By default, the configuration object is added to store the configuration methods.

import { valueStore } from '@alarife/core/modules';

// Store options
valueStore.set('app.url', mongooseUrl)
valueStore.merge('app.configuration', { ... }) // Merge over existing objects
valueStore.get('app.url')
valueStore.delete('app.url')

@Logger

Logger is a class decorator. Insert the entire Logger module to the class.

import { Logger } from '@alarife/core/decorators';

@Logger()
class Service {
  constructor() {
    this.log.info('Message');
  }
}

@Worker

Worker is a method decorator. You can use it in any class.

You use the workerpool library, you work with the worker as you would work with promises.

The method does not have access to this. Worker parameters must be serializable.

Allows you to launch blocking functions within your code without blocking the main thread.

import { Worker, Service, App, AutoWired } from '@alarife/core/decorators';

@Service()
class TestService {

  @Worker()
  blockingMethod(range) {
    const start = new Date();

    let total = 0;
    for (let index = 0; index < range; index++) {
      total += index;
    }

    const end = new Date();

    console.log(`Delay: ${end - start} ms`);

    return total;
  }
}

@App()
class Main {

  @AutoWired(TestService) #testService;

  constructor() {
    this.#testService.blockingMethod(9000000000)
      .then(result => {
        this.log.info(result);
      })
      .catch(err => {
        this.log.error(err);
      });
  }
}

Addons

Some of the additional functionalities that the library contains are listed.

DeveloperError

Exception Management for Development

  throw new DeveloperError('The Service Document can only be applied to classes.');

Logger

The App, Controller, and Service decorators add this functionality.

Future plugin for server log and access log management

Morgan is used as a library for access log.

Configurations:

  • Allows different output levels ('info', 'debug', 'error', 'warn').
this.log.info('New message');
this.log.error('Error message', error);
this.log.warn('Warn message');

Lombok

Developing Proposal for a decorator based on Lombok to decorate classes in javascript.

Banner

The banner functionality is added at the beginning of the project.

If a banner.txt file does not exist in the root of the project, use the one with the default library.

Utils

Type validation capabilities

  /** return true or false */
  isDefined(value);
  isFunction(value);
  isClass(value);
  isObject(value);
  isString(value);
  isNumber(value);

Object functionalities

  defineProperty(prototype, key, value);
  merge(target, source);

Related