Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tramvai/module-common

Package Overview
Dependencies
Maintainers
0
Versions
666
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tramvai/module-common

Base module consisted of the architectural blocks for typical tramvai app. This module is required at most cases and is used a lot by the other modules.

  • 3.41.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-40.4%
Maintainers
0
Weekly downloads
 
Created
Source

Common

Base module consisted of the architectural blocks for typical tramvai app. This module is required at most cases and is used a lot by the other modules.

Installation

First install @tramvai/module-common

npm i @tramvai/module-common

Add CommonModule to the modules list

import { createApp } from '@tramvai/core';
import { CommonModule } from '@tramvai/module-common';

createApp({
  modules: [CommonModule],
});

Explanation

Submodules

CommandModule

Module that adds implementation for the commandLineRunner and defines default command lines

This module logs with id command:command-line-runner

StateModule

Adds state-manager

ActionModule

Implements action system

This module logs with id action:action-page-runner

CookieModule

Add providers that works with cookie. See docs

EnvironmentModule

Implements work with environment variables both on server and client. See docs

PubSub

Provides PubSub interface to implement communication between components. See docs

This modules logs with id pubsub

LogModule

Module for logging. Uses @tramvai/module-log

CacheModule

Module that implements caches.

It provides next functionality:

  • create new cache instance (currently it will be instance of lru-cache)
  • clear all of the previously create caches
  • subscribe on cache clearance event to execute own cache clearance actions
  • adds papi-route /clear-cache that will trigger caches clear event

This modules logs wit id cache:papi-clear-cache

RequestManagerModule

Wrapper for the client request

ResponseManagerModule

Wrapper for the client response

How to

Create cache

import { provide } from '@tramvai/core';

export const providers = [
  provide({
    provide: MY_MODULE_PROVIDER_FACTORY,
    scope: Scope.SINGLETON,
    useFactory: ({ createCache }) => {
      const cache = createCache('memory', ...args); // type of the cache and any additional options that will be passed to the cache constructor

      return someFactory({ cache });
    },
    deps: {
      createCache: CREATE_CACHE_TOKEN,
    },
  }),

  provide({
    provide: REGISTER_CLEAR_CACHE_TOKEN,
    scope: Scope.SINGLETON,
    useFactory: ({ cache }) => {
      return async () => {
        await cache.reset();
        console.log('my module cache cleared');
      };
    },
    deps: {
      cache: MY_MODULE_CACHE,
    },
  }),

  provide({
    provide: commandLineListTokens.clear,
    useFactory: ({ clearCache }) => {
      return function clear() {
        clearCache(); // clear caches explicitly
      };
    },
    deps: {
      clearCache: CLEAR_CACHE_TOKEN,
    },
  }),
];

Exported tokens

FAQs

Package last updated on 23 Aug 2024

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