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 - npm Package Compare versions

Comparing version 1.4.5 to 1.5.0

dist/memorycache/MashroomStorageCollectionMemoryCacheWrapper.js

16

dist/plugins/loader/MashroomStorageProviderLoader.js

@@ -10,4 +10,5 @@ "use strict";

constructor(storageRegistry, loggerFactory) {
this._storageRegistry = storageRegistry;
this._log = loggerFactory('mashroom.storage.loader');
this.storageRegistry = storageRegistry;
this.loggerFactory = loggerFactory;
this.logger = loggerFactory('mashroom.storage.loader');
}

@@ -22,12 +23,9 @@

const storageProvider = await bootstrap(plugin.name, config, contextHolder);
this._log.info(`Registering storage provider: ${plugin.name}`);
this._storageRegistry.registerStorage(plugin.name, storageProvider);
this.logger.info(`Registering storage provider: ${plugin.name}`);
this.storageRegistry.registerStorage(plugin.name, storageProvider);
}
async unload(plugin) {
this._log.info(`Unregistering storage provider: ${plugin.name}`);
this._storageRegistry.unregisterStorage(plugin.name);
this.logger.info(`Unregistering storage provider: ${plugin.name}`);
this.storageRegistry.unregisterStorage(plugin.name);
}

@@ -34,0 +32,0 @@

@@ -8,4 +8,2 @@ "use strict";

var _readonly_utils = require("@mashroom/mashroom-utils/lib/readonly_utils");
class MashroomStorageRegistry {

@@ -29,3 +27,4 @@ constructor() {

get storages() {
return (0, _readonly_utils.createReadonlyProxy)(this._storages);
return Object.freeze({ ...this._storages
});
}

@@ -32,0 +31,0 @@

@@ -15,5 +15,7 @@ "use strict";

const bootstrap = async (pluginName, pluginConfig, pluginContextHolder) => {
const providerName = pluginConfig.provider;
const pluginContext = pluginContextHolder.getPluginContext();
const service = new _MashroomStorageService.default(providerName, _global_context.default.pluginRegistry, pluginContext.loggerFactory);
const {
provider,
memoryCache
} = pluginConfig;
const service = new _MashroomStorageService.default(provider, memoryCache, _global_context.default.pluginRegistry, pluginContextHolder);
return {

@@ -20,0 +22,0 @@ service

@@ -7,16 +7,20 @@ "use strict";

exports.default = void 0;
const MAX_WAIT_FOR_STORAGE = 10000;
var _MashroomStorageMemoryCacheWrapper = _interopRequireDefault(require("../memorycache/MashroomStorageMemoryCacheWrapper"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const MAX_WAIT_FOR_STORAGE = 30000;
class MashroomStorageService {
constructor(providerName, storageRegistry, loggerFactory) {
this._logger = loggerFactory('mashroom.portal.service');
constructor(providerName, memoryCacheConfig, storageRegistry, pluginContextHolder) {
this.logger = pluginContextHolder.getPluginContext().loggerFactory('mashroom.storage.service');
this._getStorage = async () => {
this.getStorage = async () => {
let storage = storageRegistry.getStorage(providerName);
let waited = 0;
let storage = storageRegistry.getStorage(providerName);
while (!storage && waited < MAX_WAIT_FOR_STORAGE) {
this._logger.warn('Storage provider not available yet, waiting...');
await this._waitFor(500);
this.logger.warn('Storage provider not available yet, waiting...');
await this.waitFor(500);
waited += 500;

@@ -30,3 +34,9 @@ storage = storageRegistry.getStorage(providerName);

return storage;
if (storage !== this.currentStorage) {
this.currentStorage = storage;
this.currentWrappedStorage = new _MashroomStorageMemoryCacheWrapper.default(storage, memoryCacheConfig, pluginContextHolder);
} // @ts-ignore
return this.currentWrappedStorage;
};

@@ -36,7 +46,7 @@ }

async getCollection(name) {
const storage = await this._getStorage();
const storage = await this.getStorage();
return storage.getCollection(name);
}
async _waitFor(ms) {
async waitFor(ms) {
return new Promise(resolve => {

@@ -43,0 +53,0 @@ setTimeout(() => resolve(), ms);

@@ -7,3 +7,3 @@ {

"license": "MIT",
"version": "1.4.5",
"version": "1.5.0",
"files": [

@@ -14,9 +14,12 @@ "dist/**",

"dependencies": {
"@mashroom/mashroom-utils": "1.4.5"
"@mashroom/mashroom-utils": "1.5.0"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@mashroom/mashroom": "1.4.5",
"eslint": "^6.8.0",
"jest": "^25.1.0"
"@mashroom/mashroom": "1.5.0",
"@mashroom/mashroom-memory-cache": "1.5.0",
"@types/jest": "^25.2.2",
"eslint": "^7.0.0",
"jest": "^26.0.1",
"typescript": "^3.9.2"
},

@@ -29,7 +32,9 @@ "jest": {

],
"testRegex": "(\\.(test|spec))\\.js$"
"testRegex": "(\\.(test|spec))\\.ts"
},
"scripts": {
"lint": "eslint src --fix",
"build": "babel src -d dist"
"lint": "eslint src test --ext '.ts' --fix",
"type-check": "tsc --noEmit",
"test": "jest",
"build": "babel src -d dist --extensions '.ts'"
},

@@ -45,9 +50,15 @@ "mashroom": {

"defaultConfig": {
"provider": "Mashroom Storage Filestore Provider"
"provider": "Mashroom Storage Filestore Provider",
"memoryCache": {
"enabled": true,
"ttlSec": 120,
"invalidateOnUpdate": true,
"collections": {}
}
}
},
{
"name": "Mashroom Storage Provider Loader",
"name": "Mashroom Storage Provider Loadaer",
"type": "plugin-loader",
"bootstrap": "./dist/plugins/loader/mashroom-bootstrap-storage-provider-plugin-loader.js",
"bootstrap": "./dist/plugins/loader/mashroom-bootstrap-plugin-loader.js",
"loads": "storage-provider"

@@ -54,0 +65,0 @@ }

@@ -36,3 +36,13 @@

"Mashroom Storage Services": {
"provider": "Mashroom Storage Filestore Provider"
"provider": "Mashroom Storage Filestore Provider",
"memoryCache": {
"enabled": true,
"ttlSec": 120,
"invalidateOnUpdate": true,
"collections": {
"mashroom-portal-pages": {
"ttlSec": 300
}
}
}
}

@@ -44,2 +54,9 @@ }

* _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 the store. If you set this to false you can still enable caching on some collections (default: true)
* _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_.

@@ -46,0 +63,0 @@ ## Services

@@ -1,102 +0,2 @@

/* eslint-disable */
import {MashroomPluginConfig, MashroomPluginContextHolder} from "@mashroom/mashroom/type-definitions";
// -------- Converted from api.js via https://flow-to-ts.netlify.com ----------
export type StorageObject<T extends {}> = T & {
_id: any;
};
export type StorageObjectFilter<T extends {}> = {
[key in keyof StorageObject<T>]?: any
};
export type StorageUpdateResult = {
modifiedCount: number;
};
export type StorageDeleteResult = {
deletedCount: number;
};
/**
* Mashroom storage collection
*/
export interface MashroomStorageCollection<T extends {}> {
/**
* 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>;
}
/**
* Mashroom storage interface
*/
export interface MashroomStorage {
/**
* Get (or create) the MashroomStorageCollection with given name.
*/
getCollection<T extends {}>(
name: string,
): Promise<MashroomStorageCollection<T>>;
}
export interface MashroomStorageService {
/**
* Get (or create) the MashroomStorageCollection with given name.
*/
getCollection<T extends {}>(
name: string,
): Promise<MashroomStorageCollection<T>>;
}
/**
* Bootstrap method definition for storage plugins
*/
export type MashroomStoragePluginBootstrapFunction = (
pluginName: string,
pluginConfig: MashroomPluginConfig,
contextHolder: MashroomPluginContextHolder,
) => Promise<MashroomStorage>;
export * from './api';
// @flow
export type * from './api';
import type {MashroomPluginConfig, MashroomPluginContextHolder} from "@mashroom/mashroom/type-definitions";
export type StorageRecord = {};
export type StorageObject<T: StorageRecord> = T & {|
_id: any
|}
export type StorageObjectFilter<T: StorageRecord> = {[$Keys<StorageObject<T>>]: any};
export type StorageUpdateResult = {
modifiedCount: number,
};
export type StorageDeleteResult = {
deletedCount: number;
};
/**
* Mashroom storage collection
*/
export interface MashroomStorageCollection<T: 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>>;
/**
* Insert one item
*/
insertOne(item: T): Promise<StorageObject<T>>;
/**
* Update the first item that matches the given filter.
*/
updateOne(filter: StorageObjectFilter<T>, propertiesToUpdate: $Shape<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>;
}
/**
* Mashroom storage interface
*/
export interface MashroomStorage {
/**
* Get (or create) the MashroomStorageCollection with given name.
*/
getCollection<T: StorageRecord>(name: string): Promise<MashroomStorageCollection<T>>;
}
export interface MashroomStorageService {
/**
* Get (or create) the MashroomStorageCollection with given name.
*/
getCollection<T: StorageRecord>(name: string): Promise<MashroomStorageCollection<T>>;
}
/**
* Bootstrap method definition for storage plugins
*/
export type MashroomStoragePluginBootstrapFunction = (pluginName: string, pluginConfig: MashroomPluginConfig, contextHolder: MashroomPluginContextHolder) => Promise<MashroomStorage>;
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