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

@mashroom/mashroom-storage

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mashroom/mashroom-storage

A storage service with a configurable provider

  • 1.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
Maintainers
1
Weekly downloads
 
Created
Source

Mashroom Storage

Plugin for Mashroom Server, a Integration Platform for Microfrontends.

This plugin adds a storage service.

Usage

If node_modules/@mashroom is configured as plugin path just add @mashroom/mashroom-storage as dependency.

Then use the security service like this:

import type {MashroomStorageService} from '@mashroom/mashroom-storage/type-definitions';

export default async (req: Request, res: ExpressResponse) => {
    const storageService: MashroomStorageService = req.pluginContext.services.storage.service;

    const pagesCollection = await storageService.getCollection('mashroom-portal-pages');

    const page = await pagesCollection.findOne({pageId});

    // ...
}

You can override the default config in your Mashroom config file like this:

{
  "plugins": {
       "Mashroom Storage Services": {
           "provider": "Mashroom Storage Filestore Provider",
           "memoryCache": {
               "enabled": false,
               "ttlSec": 120,
               "invalidateOnUpdate": true,
               "collections": {
                   "mashroom-portal-pages": {
                      "enabled": true,
                      "ttlSec": 300
                   }
               }
           }
       }
    }
}
  • provider: The storage-provider plugin that implements the actual storage (Default: Mashroom Storage Filestore Provider)
  • memoryCache: Use the memory cache to improve the performance. Requires @mashroom/mashroom-memory-cache to be installed.
    • enabled: Enable cache (of all) collections. The preferred way is to set this to false and enable caching per collection (Default: false)
    • ttlSec: The default TTL in seconds. Can be overwritten per collection (Default: 120)
    • invalidateOnUpdate: Clear the cache for the whole collection if an entry gets updated (Default: true). This might be an expensive operation on some memory cache implementations (e.g. based on Redis). So use this only if updates don't happen frequently.
    • collections: A map of collections specific settings. You can overwrite here enabled, ttlSec and invalidateOnUpdate.

Services

MashroomStorageService

The exposed service is accessible through pluginContext.services.storage.service

Interface:

export interface MashroomStorageService {
    /**
     * Get (or create) the MashroomStorageCollection with given name.
     */
    getCollection<T extends StorageRecord>(
        name: string,
    ): Promise<MashroomStorageCollection<T>>;
}

export interface MashroomStorageCollection<T extends StorageRecord> {
    /**
     * Find all items that match given filter (e.g. { name: 'foo' }).
     */
    find(
        filter?: StorageObjectFilter<T>,
        limit?: number,
    ): Promise<Array<StorageObject<T>>>;

    /**
     * Return the first item that matches the given filter or null otherwise.
     */
    findOne(
        filter: StorageObjectFilter<T>,
    ): Promise<StorageObject<T> | null | undefined>;

    /**
     * Insert one item
     */
    insertOne(item: T): Promise<StorageObject<T>>;

    /**
     * Update the first item that matches the given filter.
     */
    updateOne(
        filter: StorageObjectFilter<T>,
        propertiesToUpdate: Partial<StorageObject<T>>,
    ): Promise<StorageUpdateResult>;

    /**
     * Replace the first item that matches the given filter.
     */
    replaceOne(
        filter: StorageObjectFilter<T>,
        newItem: T,
    ): Promise<StorageUpdateResult>;

    /**
     * Delete the first item that matches the given filter.
     */
    deleteOne(filter: StorageObjectFilter<T>): Promise<StorageDeleteResult>;

    /**
     * Delete all items that matches the given filter.
     */
    deleteMany(filter: StorageObjectFilter<T>): Promise<StorageDeleteResult>;
}

Plugin type

storage-provider

This plugin type adds a a new storage implementation that can be used by this plugin.

To register a new storage-provider plugin add this to package.json:

{
    "mashroom": {
        "plugins": [
            {
                "name": "My Storage Provider",
                "type": "storage-provider",
                "bootstrap": "./dist/mashroom-bootstrap.js",
                "defaultConfig": {
                    "myProperty": "test"
                }
            }
        ]
    }
}

The bootstrap returns the provider:

import MyStorage from './MyStorage';

import type {MashroomStoragePluginBootstrapFunction} from '@mashroom/mashroom-storage/type-definitions';

const bootstrap: MashroomStoragePluginBootstrapFunction = async (pluginName, pluginConfig, pluginContextHolder) => {

    return new MyStorage(/* .... */);
};

export default bootstrap;

The plugin has to implement the following interfaces:

export interface MashroomStorage {
    /**
     * Get (or create) the MashroomStorageCollection with given name.
     */
    getCollection<T extends StorageRecord>(
        name: string,
    ): Promise<MashroomStorageCollection<T>>;
}

FAQs

Package last updated on 18 Oct 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

  • 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