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: ExpressRequest, 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"
}
}
}
- provider: The storage-provider plugin that implements the actual storage (Default: Mashroom Storage Filestore Provider)
Services
MashroomStorageService
The exposed service is accessible through pluginContext.services.storage.service
Interface:
export interface MashroomStorageService {
getCollection<T: {}>(name: string): Promise<MashroomStorageCollection<T>>;
}
export interface MashroomStorageCollection<T: Object> {
find(filter?: StorageObjectFilter<T>, limit?: number): Promise<Array<StorageObject<T>>>;
findOne(filter: StorageObjectFilter<T>): Promise<?StorageObject<T>>;
insertOne(item: T): Promise<StorageObject<T>>;
updateOne(filter: StorageObjectFilter<T>, propertiesToUpdate: $Shape<StorageObject<T>>): Promise<StorageUpdateResult>;
replaceOne(filter: StorageObjectFilter<T>, newItem: T): Promise<StorageUpdateResult>;
deleteOne(filter: StorageObjectFilter<T>): Promise<StorageUpdateResult>;
deleteMany(filter: StorageObjectFilter<T>): Promise<StorageUpdateResult>;
}
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 {
getCollection<T: {}>(name: string): Promise<MashroomStorageCollection<T>>;
}
export interface MashroomStorageCollection<T: {}> {
find(filter?: StorageObjectFilter<T>, limit?: number): Promise<Array<StorageObject<T>>>;
findOne(filter: StorageObjectFilter<T>): Promise<?StorageObject<T>>;
insertOne(item: T): Promise<StorageObject<T>>;
updateOne(filter: StorageObjectFilter<T>, propertiesToUpdate: $Shape<StorageObject<T>>): Promise<StorageUpdateResult>;
replaceOne(filter: StorageObjectFilter<T>, newItem: T): Promise<StorageUpdateResult>;
deleteOne(filter: StorageObjectFilter<T>): Promise<StorageDeleteResult>;
deleteMany(filter: StorageObjectFilter<T>): Promise<StorageDeleteResult>;
}