@xnestjs/storage 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/providers/s3-storage-connection.js +3 -3
- package/cjs/storage-core.module.js +13 -13
- package/cjs/storage.module.js +2 -2
- package/cjs/storage.utils.js +3 -3
- package/esm/providers/s3-storage-connection.js +3 -3
- package/esm/storage-core.module.js +13 -13
- package/esm/storage.module.js +2 -2
- package/esm/storage.utils.js +1 -0
- package/package.json +6 -4
- package/types/interfaces/storage.interfaces.d.ts +1 -1
- package/types/providers/s3-storage-connection.d.ts +0 -2
- package/types/services/storage-bucket.d.ts +0 -2
- package/types/services/storage-connection.d.ts +0 -2
|
@@ -15,8 +15,8 @@ class S3StorageConnection extends storage_connection_js_1.StorageConnection {
|
|
|
15
15
|
const meta = options ? updateMetadata(options?.metadata, options) : {};
|
|
16
16
|
if (typeof source === 'string')
|
|
17
17
|
await this._client.fPutObject(bucketName, objectName, source, meta);
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
18
19
|
else
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
20
20
|
await this._client.putObject(bucketName, objectName, source, undefined, meta);
|
|
21
21
|
}
|
|
22
22
|
async getObjectInfo(bucketName, objectName) {
|
|
@@ -25,7 +25,7 @@ class S3StorageConnection extends storage_connection_js_1.StorageConnection {
|
|
|
25
25
|
size: o.size,
|
|
26
26
|
etag: o.etag,
|
|
27
27
|
lastModified: o.lastModified,
|
|
28
|
-
metadata: o.metaData
|
|
28
|
+
metadata: o.metaData,
|
|
29
29
|
};
|
|
30
30
|
if (inf.metadata) {
|
|
31
31
|
const meta = inf.metadata;
|
|
@@ -60,7 +60,7 @@ class S3StorageConnection extends storage_connection_js_1.StorageConnection {
|
|
|
60
60
|
return this._client.getObject(bucketName, objectName);
|
|
61
61
|
}
|
|
62
62
|
presignedGetObject(bucketName, objectName, options) {
|
|
63
|
-
const expires = options?.expires ||
|
|
63
|
+
const expires = options?.expires || 5 * 60 * 60; // 5 minutes
|
|
64
64
|
return this._client.presignedGetObject(bucketName, objectName, expires);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -9,50 +9,50 @@ let StorageCoreModule = StorageCoreModule_1 = class StorageCoreModule {
|
|
|
9
9
|
static register(options) {
|
|
10
10
|
const connectionProvider = {
|
|
11
11
|
provide: (0, storage_utils_js_1.getStorageConnectionToken)(options.name),
|
|
12
|
-
useValue: (0, storage_utils_js_1.createConnection)(options)
|
|
12
|
+
useValue: (0, storage_utils_js_1.createConnection)(options),
|
|
13
13
|
};
|
|
14
14
|
return {
|
|
15
15
|
module: StorageCoreModule_1,
|
|
16
16
|
providers: [connectionProvider],
|
|
17
|
-
exports: [connectionProvider]
|
|
17
|
+
exports: [connectionProvider],
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
static forRootAsync(asyncOptions) {
|
|
21
|
-
const providers = [
|
|
22
|
-
...this.createAsyncProviders(asyncOptions),
|
|
23
|
-
...(asyncOptions.extraProviders || [])
|
|
24
|
-
];
|
|
21
|
+
const providers = [...this.createAsyncProviders(asyncOptions), ...(asyncOptions.extraProviders || [])];
|
|
25
22
|
return {
|
|
26
23
|
module: StorageCoreModule_1,
|
|
27
24
|
imports: asyncOptions.imports || [],
|
|
28
25
|
providers,
|
|
29
|
-
exports: providers
|
|
26
|
+
exports: providers,
|
|
30
27
|
};
|
|
31
28
|
}
|
|
32
29
|
static createAsyncProviders(asyncOptions) {
|
|
33
30
|
if (asyncOptions.useFactory || asyncOptions.useExisting)
|
|
34
31
|
return [this.createAsyncOptionsProvider(asyncOptions)];
|
|
35
|
-
if (asyncOptions.useClass)
|
|
32
|
+
if (asyncOptions.useClass) {
|
|
36
33
|
return [
|
|
37
34
|
this.createAsyncOptionsProvider(asyncOptions),
|
|
38
|
-
{ provide: asyncOptions.useClass, useClass: asyncOptions.useClass }
|
|
35
|
+
{ provide: asyncOptions.useClass, useClass: asyncOptions.useClass },
|
|
39
36
|
];
|
|
37
|
+
}
|
|
40
38
|
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
41
39
|
}
|
|
42
40
|
static createAsyncOptionsProvider(asyncOptions) {
|
|
43
|
-
if (asyncOptions.useFactory)
|
|
41
|
+
if (asyncOptions.useFactory) {
|
|
44
42
|
return {
|
|
45
43
|
provide: (0, storage_utils_js_1.getStorageConnectionToken)(asyncOptions.name),
|
|
46
44
|
useFactory: this.createFactoryWrapper(asyncOptions.useFactory),
|
|
47
|
-
inject: asyncOptions.inject || []
|
|
45
|
+
inject: asyncOptions.inject || [],
|
|
48
46
|
};
|
|
47
|
+
}
|
|
49
48
|
const useClass = asyncOptions.useClass || asyncOptions.useExisting;
|
|
50
|
-
if (useClass)
|
|
49
|
+
if (useClass) {
|
|
51
50
|
return {
|
|
52
51
|
provide: (0, storage_utils_js_1.getStorageConnectionToken)(asyncOptions.name),
|
|
53
52
|
useFactory: this.createFactoryWrapper((optionsFactory) => optionsFactory.getOptions()),
|
|
54
|
-
inject: [useClass]
|
|
53
|
+
inject: [useClass],
|
|
55
54
|
};
|
|
55
|
+
}
|
|
56
56
|
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
57
57
|
}
|
|
58
58
|
static createFactoryWrapper(useFactory) {
|
package/cjs/storage.module.js
CHANGED
|
@@ -9,13 +9,13 @@ let StorageModule = StorageModule_1 = class StorageModule {
|
|
|
9
9
|
static register(options) {
|
|
10
10
|
return {
|
|
11
11
|
module: StorageModule_1,
|
|
12
|
-
imports: [storage_core_module_js_1.StorageCoreModule.register(options)]
|
|
12
|
+
imports: [storage_core_module_js_1.StorageCoreModule.register(options)],
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
static registerAsync(options) {
|
|
16
16
|
return {
|
|
17
17
|
module: StorageModule_1,
|
|
18
|
-
imports: [storage_core_module_js_1.StorageCoreModule.forRootAsync(options)]
|
|
18
|
+
imports: [storage_core_module_js_1.StorageCoreModule.forRootAsync(options)],
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
};
|
package/cjs/storage.utils.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getStorageConnectionToken = getStorageConnectionToken;
|
|
4
|
+
exports.createConnection = createConnection;
|
|
4
5
|
const s3_storage_connection_js_1 = require("./providers/s3-storage-connection.js");
|
|
5
6
|
const storage_connection_js_1 = require("./services/storage-connection.js");
|
|
6
7
|
function getStorageConnectionToken(name) {
|
|
7
8
|
if (!name)
|
|
8
9
|
return storage_connection_js_1.StorageConnection;
|
|
10
|
+
// noinspection SuspiciousTypeOfGuard
|
|
9
11
|
if (typeof name === 'symbol' || typeof name === 'function')
|
|
10
12
|
return name;
|
|
11
13
|
return `${name}_StorageConnection`;
|
|
12
14
|
}
|
|
13
|
-
exports.getStorageConnectionToken = getStorageConnectionToken;
|
|
14
15
|
function createConnection(options) {
|
|
15
16
|
if (!options.config)
|
|
16
17
|
throw new Error('You must provide storage config');
|
|
@@ -21,4 +22,3 @@ function createConnection(options) {
|
|
|
21
22
|
throw new Error(`Unknown Storage provider type ${options.type}`);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
exports.createConnection = createConnection;
|
|
@@ -11,8 +11,8 @@ export class S3StorageConnection extends StorageConnection {
|
|
|
11
11
|
const meta = options ? updateMetadata(options?.metadata, options) : {};
|
|
12
12
|
if (typeof source === 'string')
|
|
13
13
|
await this._client.fPutObject(bucketName, objectName, source, meta);
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
14
15
|
else
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
16
16
|
await this._client.putObject(bucketName, objectName, source, undefined, meta);
|
|
17
17
|
}
|
|
18
18
|
async getObjectInfo(bucketName, objectName) {
|
|
@@ -21,7 +21,7 @@ export class S3StorageConnection extends StorageConnection {
|
|
|
21
21
|
size: o.size,
|
|
22
22
|
etag: o.etag,
|
|
23
23
|
lastModified: o.lastModified,
|
|
24
|
-
metadata: o.metaData
|
|
24
|
+
metadata: o.metaData,
|
|
25
25
|
};
|
|
26
26
|
if (inf.metadata) {
|
|
27
27
|
const meta = inf.metadata;
|
|
@@ -56,7 +56,7 @@ export class S3StorageConnection extends StorageConnection {
|
|
|
56
56
|
return this._client.getObject(bucketName, objectName);
|
|
57
57
|
}
|
|
58
58
|
presignedGetObject(bucketName, objectName, options) {
|
|
59
|
-
const expires = options?.expires ||
|
|
59
|
+
const expires = options?.expires || 5 * 60 * 60; // 5 minutes
|
|
60
60
|
return this._client.presignedGetObject(bucketName, objectName, expires);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -6,50 +6,50 @@ let StorageCoreModule = StorageCoreModule_1 = class StorageCoreModule {
|
|
|
6
6
|
static register(options) {
|
|
7
7
|
const connectionProvider = {
|
|
8
8
|
provide: getStorageConnectionToken(options.name),
|
|
9
|
-
useValue: createConnection(options)
|
|
9
|
+
useValue: createConnection(options),
|
|
10
10
|
};
|
|
11
11
|
return {
|
|
12
12
|
module: StorageCoreModule_1,
|
|
13
13
|
providers: [connectionProvider],
|
|
14
|
-
exports: [connectionProvider]
|
|
14
|
+
exports: [connectionProvider],
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
static forRootAsync(asyncOptions) {
|
|
18
|
-
const providers = [
|
|
19
|
-
...this.createAsyncProviders(asyncOptions),
|
|
20
|
-
...(asyncOptions.extraProviders || [])
|
|
21
|
-
];
|
|
18
|
+
const providers = [...this.createAsyncProviders(asyncOptions), ...(asyncOptions.extraProviders || [])];
|
|
22
19
|
return {
|
|
23
20
|
module: StorageCoreModule_1,
|
|
24
21
|
imports: asyncOptions.imports || [],
|
|
25
22
|
providers,
|
|
26
|
-
exports: providers
|
|
23
|
+
exports: providers,
|
|
27
24
|
};
|
|
28
25
|
}
|
|
29
26
|
static createAsyncProviders(asyncOptions) {
|
|
30
27
|
if (asyncOptions.useFactory || asyncOptions.useExisting)
|
|
31
28
|
return [this.createAsyncOptionsProvider(asyncOptions)];
|
|
32
|
-
if (asyncOptions.useClass)
|
|
29
|
+
if (asyncOptions.useClass) {
|
|
33
30
|
return [
|
|
34
31
|
this.createAsyncOptionsProvider(asyncOptions),
|
|
35
|
-
{ provide: asyncOptions.useClass, useClass: asyncOptions.useClass }
|
|
32
|
+
{ provide: asyncOptions.useClass, useClass: asyncOptions.useClass },
|
|
36
33
|
];
|
|
34
|
+
}
|
|
37
35
|
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
38
36
|
}
|
|
39
37
|
static createAsyncOptionsProvider(asyncOptions) {
|
|
40
|
-
if (asyncOptions.useFactory)
|
|
38
|
+
if (asyncOptions.useFactory) {
|
|
41
39
|
return {
|
|
42
40
|
provide: getStorageConnectionToken(asyncOptions.name),
|
|
43
41
|
useFactory: this.createFactoryWrapper(asyncOptions.useFactory),
|
|
44
|
-
inject: asyncOptions.inject || []
|
|
42
|
+
inject: asyncOptions.inject || [],
|
|
45
43
|
};
|
|
44
|
+
}
|
|
46
45
|
const useClass = asyncOptions.useClass || asyncOptions.useExisting;
|
|
47
|
-
if (useClass)
|
|
46
|
+
if (useClass) {
|
|
48
47
|
return {
|
|
49
48
|
provide: getStorageConnectionToken(asyncOptions.name),
|
|
50
49
|
useFactory: this.createFactoryWrapper((optionsFactory) => optionsFactory.getOptions()),
|
|
51
|
-
inject: [useClass]
|
|
50
|
+
inject: [useClass],
|
|
52
51
|
};
|
|
52
|
+
}
|
|
53
53
|
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
54
54
|
}
|
|
55
55
|
static createFactoryWrapper(useFactory) {
|
package/esm/storage.module.js
CHANGED
|
@@ -6,13 +6,13 @@ let StorageModule = StorageModule_1 = class StorageModule {
|
|
|
6
6
|
static register(options) {
|
|
7
7
|
return {
|
|
8
8
|
module: StorageModule_1,
|
|
9
|
-
imports: [StorageCoreModule.register(options)]
|
|
9
|
+
imports: [StorageCoreModule.register(options)],
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
static registerAsync(options) {
|
|
13
13
|
return {
|
|
14
14
|
module: StorageModule_1,
|
|
15
|
-
imports: [StorageCoreModule.forRootAsync(options)]
|
|
15
|
+
imports: [StorageCoreModule.forRootAsync(options)],
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
};
|
package/esm/storage.utils.js
CHANGED
|
@@ -3,6 +3,7 @@ import { StorageConnection } from './services/storage-connection.js';
|
|
|
3
3
|
export function getStorageConnectionToken(name) {
|
|
4
4
|
if (!name)
|
|
5
5
|
return StorageConnection;
|
|
6
|
+
// noinspection SuspiciousTypeOfGuard
|
|
6
7
|
if (typeof name === 'symbol' || typeof name === 'function')
|
|
7
8
|
return name;
|
|
8
9
|
return `${name}_StorageConnection`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xnestjs/storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "NestJS extension library for Storage solutions (S3,GS)",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
21
21
|
"postbuild": "cp package.json README.md ../../LICENSE ../../build/storage && cp ../../package.cjs.json ../../build/storage/cjs/package.json",
|
|
22
22
|
"lint": "eslint . --max-warnings=0",
|
|
23
|
+
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
24
|
+
"format": "prettier . --write --log-level=warn",
|
|
23
25
|
"check": "madge --circular src/**",
|
|
24
26
|
"test": "jest",
|
|
25
27
|
"cover": "jest --collect-coverage",
|
|
@@ -29,10 +31,10 @@
|
|
|
29
31
|
"clean:cover": "rimraf ../../coverage/storage"
|
|
30
32
|
},
|
|
31
33
|
"peerDependencies": {
|
|
32
|
-
"@nestjs/common": "^10.
|
|
34
|
+
"@nestjs/common": "^10.3.10"
|
|
33
35
|
},
|
|
34
36
|
"optionalDependencies": {
|
|
35
|
-
"minio": "^
|
|
37
|
+
"minio": "^8.0.1"
|
|
36
38
|
},
|
|
37
39
|
"engines": {
|
|
38
40
|
"node": ">=16.0",
|
|
@@ -51,4 +53,4 @@
|
|
|
51
53
|
"storage",
|
|
52
54
|
"s3"
|
|
53
55
|
]
|
|
54
|
-
}
|
|
56
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as minio from 'minio';
|
|
2
1
|
import { Provider } from '@nestjs/common';
|
|
3
2
|
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
|
|
3
|
+
import * as minio from 'minio';
|
|
4
4
|
export type S3StorageOptions = minio.ClientOptions & {
|
|
5
5
|
rejectUnauthorized: boolean;
|
|
6
6
|
};
|