Socket
Socket
Sign inDemoInstall

@file-storage/core

Package Overview
Dependencies
70
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.4 to 1.1.0

9

dist/file-storage.d.ts
/// <reference types="node" />
import { Stream } from 'stream';
import { DiskConfig, Driver, Disk } from '@file-storage/common';
import { DiskConfig, Driver } from '@file-storage/common';
import { BuitInDiskConfig, StorageConfiguration } from './types';

@@ -8,9 +8,8 @@ /**

*/
declare class StorageClass implements Disk {
declare class StorageClass implements Driver {
/**
* Get default disk instance.
*/
defaultDisk: Disk;
defaultDisk: Driver;
get name(): string;
get driver(): Driver;
/**

@@ -23,3 +22,3 @@ * Config for storage methods supported in the application.

*/
disk<U extends Disk>(diskName?: string): U;
disk<U extends Driver>(diskName?: string): U;
url(path: string): string;

@@ -26,0 +25,0 @@ exists(path: string): Promise<boolean>;

@@ -5,8 +5,9 @@ "use strict";

const common_1 = require("@file-storage/common");
const S3Disk = common_1.requireDefaultModule('@file-storage/s3');
const LocalDisk = common_1.requireDefaultModule('@file-storage/local');
const SftpDisk = common_1.requireDefaultModule('@file-storage/sftp');
let configableDefaultDiskName = 'local';
// import S3Driver2 from '@file-storage/local';
const S3Driver = common_1.requireDefaultModule('@file-storage/s3');
const LocalDriver = common_1.requireDefaultModule('@file-storage/local');
const SftpDriver = common_1.requireDefaultModule('@file-storage/sftp');
let configableDefaultDriverName = 'local';
const defaultDiskConfig = {
driver: common_1.Driver.LOCAL,
driver: common_1.DriverName.LOCAL,
name: 'local',

@@ -17,16 +18,3 @@ root: 'storage',

let availableDisks = [defaultDiskConfig];
const driverDiskMaps = [
{
name: common_1.Driver.S3,
disk: S3Disk,
},
{
name: common_1.Driver.LOCAL,
disk: LocalDisk,
},
{
name: common_1.Driver.SFTP,
disk: SftpDisk,
},
];
const drivers = [S3Driver, LocalDriver, SftpDriver];
function handleDiskConfigs(diskConfigs) {

@@ -54,3 +42,3 @@ const seen = new Set();

if (diskConfig.isDefault) {
configableDefaultDiskName = diskConfig.name;
configableDefaultDriverName = diskConfig.name;
break;

@@ -62,6 +50,6 @@ }

if (map.length > 0) {
driverDiskMaps.push(...map);
drivers.push(...map);
}
}
function getDisk(diskName = configableDefaultDiskName) {
function getDisk(diskName = configableDefaultDriverName) {
const diskConfig = availableDisks.find((item) => item.name === diskName);

@@ -71,11 +59,11 @@ if (!diskConfig) {

}
const driverDiskMap = driverDiskMaps.find((item) => item.name === diskConfig.driver);
if (!driverDiskMap) {
throw new Error(`Driver '${diskConfig.driver}' is not declared.`);
}
try {
return new driverDiskMap.disk(diskConfig);
const driver = drivers.find((item) => item['driverName'] === diskConfig.driver);
return new driver(diskConfig);
}
catch (error) {
throw new Error(`Please install \`@file-storage/${diskConfig.driver}\` for ${diskConfig.driver} driver`);
if (Object.values(common_1.DriverName).includes(diskConfig.driver)) {
throw new Error(`Please install \`@file-storage/${diskConfig.driver}\` for ${diskConfig.driver} driver`);
}
throw new Error(`Driver '${diskConfig.driver}' is not declared.`);
}

@@ -91,3 +79,3 @@ }

*/
this.defaultDisk = getDisk(configableDefaultDiskName);
this.defaultDisk = getDisk(configableDefaultDriverName);
}

@@ -97,5 +85,5 @@ get name() {

}
get driver() {
return this.defaultDisk.driver;
}
// get driver() {
// return this.defaultDisk.driver;
// }
/**

@@ -108,3 +96,3 @@ * Config for storage methods supported in the application.

handleDiskConfigs(diskConfigs);
this.defaultDisk = getDisk(configableDefaultDiskName);
this.defaultDisk = getDisk(configableDefaultDriverName);
}

@@ -111,0 +99,0 @@ /**

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

import { DiskConfig, DriverDiskMap, LocalDiskConfig, S3DiskConfig, SftpDiskConfig } from '@file-storage/common';
import { Class, DiskConfig, Driver, LocalDiskConfig, S3DiskConfig, SftpDiskConfig } from '@file-storage/common';
export declare type BuitInDiskConfig = LocalDiskConfig | S3DiskConfig | SftpDiskConfig;

@@ -11,3 +11,3 @@ export interface StorageConfiguration<T extends DiskConfig> {

*/
customDrivers?: DriverDiskMap[];
customDrivers?: Class<Driver>[];
}
{
"name": "@file-storage/core",
"version": "1.0.4",
"version": "1.1.0",
"description": "> TODO: description",

@@ -13,2 +13,6 @@ "author": "Dang Nguyen <haidang009@gmail.com>",

],
"repository": {
"type": "git",
"url": "https://github.com/googlicius/file-storage.git"
},
"publishConfig": {

@@ -26,4 +30,4 @@ "registry": "https://registry.npmjs.org",

"dependencies": {
"@file-storage/common": "^1.0.3",
"@file-storage/local": "^1.0.4"
"@file-storage/common": "^1.1.0",
"@file-storage/local": "^1.1.0"
},

@@ -34,3 +38,3 @@ "devDependencies": {

},
"gitHead": "e5725a5b7bf2125b20388b1ff2451ce3f99e74a3"
"gitHead": "7f834776baac80f138fc283bff507a776c22ddad"
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc