Socket
Socket
Sign inDemoInstall

@nodebrick/nodebrick-core

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodebrick/nodebrick-core

Core of Nodebrick


Version published
Weekly downloads
3
decreased by-89.29%
Maintainers
1
Weekly downloads
 
Created
Source

nodebrick-core

Core of the Nodebrick framework

Description

This is the core of the framework and works as a glue between all the modules and is required by all application you will create

  • cls hooked and Contexts
  • Inversify DI
  • Configuration (node-config)
  • class validation formater
  • default logger
  • Options (filtering, sorting, couting, field p)

Module Structure

Have a look at the existing modules, it's self explenatory.

Few things to note:

  • index.ts
    The entrypoint, exporting all the classes/interfaces accessible by other modules (think public api)
  • I<ModuleNameModule>.ts
    The module 'interface' - note we are using the following notation export abstract class I<ModuleName> to define interface so they exists in the JS realm and are accessible by InversifyJS
  • <ModuleNameModule>.ts The module class implementing and extending the 'interface'
  • <ModuleNameBindings>.ts
    Defines the Inversify bindings for this module are done
  • models Folder storing all our models, i.e our business logic data
    Models can also define and validates DTO (data transfer object) fields using class-transformer and class-validator libraries eg
    @Exclude()
    export abstract class IAPIResponse<TData>
    {
    
        @Expose({name: `request_id`, toClassOnly: true})
        @IsOptional()
        public abstract requestId?: string;
    
        @Expose({name: `client_request_id`, toPlainOnly: true})
        @IsString()
        @IsOptional()
        public abstract clientRequestId?: string;
    
        @Expose({name: `start_time`, toPlainOnly: true})
        @IsDate()
        public abstract startTime?: Date;
    
        @Expose({name: `end_time`, toPlainOnly: true})
        @IsDate()
        public abstract endTime: Date;
    
        @Expose({toPlainOnly: true})
        @IsInt()
        @IsOptional()
        // In milliseconds
        public abstract duration?: number;
    }
    
    For instance a REST API returning the above will automatically create a JSON like
    {
      "client_request_id": "933ca46c-25a5-4166-903e-a437700ae4ef",
      "startTime": "933ca46c-25a5-4166-903e-a437700ae4ef",
      "end_time": "933ca46c-25a5-4166-903e-a437700ae4ef",
      "duration": 50
    }
    
    I invite you to read the class-transformer and class-validator documentations.
    Note that table column can also be created and validated with nodebrick-database and the help TypeORM

Dependency Injection

NodebrickCore provides dependency injection by using internally InversifyJS

All the bindings will be defined in the <ModuleNameBindings>.ts as for instance

    //  bind the module to its interface using transitive binding, i.e we are reusing the singleton.
    bind(INodebrickApiModule).toService(NodebrickApiModule);

    //  middlewares - transient
    bind(IGlobalApiMiddleware).to(GlobalApiMiddleware).inTransientScope();
    bind(IGlobalOptionsMiddleware).to(GlobalOptionsMiddleware).inTransientScope();
    bind(IGlobalRequestMiddleware).to(GlobalRequestMiddleware).inTransientScope();

    //  services - singletons
    bind(INodebrickApiService).to(NodebrickApiService).inSingletonScope();

As you can see you have multiple scope for those

Context

A context can be defined as all the relevant information that a developer needs to complete a task.

NodebrickCore with the help of cls-hooked provides you with tools to create a context and attach any

  • create a context

Keywords

FAQs

Package last updated on 12 Feb 2020

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc