@xnestjs/storage 1.2.6 → 1.3.1
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/README.md +88 -0
- package/cjs/{storage.constants.js → constants.js} +2 -1
- package/cjs/index.js +2 -3
- package/cjs/storage-core.module.js +91 -55
- package/cjs/storage.module.js +4 -4
- package/esm/constants.js +2 -0
- package/esm/index.js +2 -3
- package/esm/storage-core.module.js +91 -57
- package/esm/storage.module.js +4 -4
- package/package.json +4 -1
- package/types/constants.d.ts +2 -0
- package/types/index.d.cts +2 -3
- package/types/index.d.ts +2 -3
- package/types/providers/s3-storage-connection.d.ts +1 -2
- package/types/services/storage-bucket.d.ts +1 -1
- package/types/services/storage-connection.d.ts +2 -2
- package/types/storage-core.module.d.ts +11 -3
- package/types/storage.module.d.ts +3 -3
- package/types/types.d.ts +52 -0
- package/cjs/interfaces/storage.interfaces.js +0 -2
- package/cjs/storage.utils.js +0 -12
- package/esm/interfaces/storage.interfaces.js +0 -1
- package/esm/storage.constants.js +0 -1
- package/esm/storage.utils.js +0 -9
- package/types/interfaces/connection.interfaces.d.ts +0 -23
- package/types/interfaces/storage.interfaces.d.ts +0 -28
- package/types/storage.constants.d.ts +0 -1
- package/types/storage.utils.d.ts +0 -3
- /package/cjs/{interfaces/connection.interfaces.js → types.js} +0 -0
- /package/esm/{interfaces/connection.interfaces.js → types.js} +0 -0
package/README.md
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
1
|
# @xnestjs/storage
|
|
2
2
|
|
|
3
3
|
NestJS extension library for Storage solutions (S3,GS)
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @xnestjs/storage
|
|
9
|
+
# or using yarn
|
|
10
|
+
yarn add @xnestjs/storage
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Register sync
|
|
16
|
+
|
|
17
|
+
An example of nestjs module that import the @xnestjs/storage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// module.ts
|
|
21
|
+
import { Module } from '@nestjs/common';
|
|
22
|
+
import { StorageModule } from '@xnestjs/storage';
|
|
23
|
+
|
|
24
|
+
@Module({
|
|
25
|
+
imports: [
|
|
26
|
+
StorageModule.forRoot({
|
|
27
|
+
useValue: {
|
|
28
|
+
provider: 's3',
|
|
29
|
+
s3: {
|
|
30
|
+
endPoint: 'play.min.io',
|
|
31
|
+
port: 9000,
|
|
32
|
+
useSSL: true,
|
|
33
|
+
accessKey: 'accessKey',
|
|
34
|
+
secretKey: 'secretKey',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
export class MyModule {
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Register async
|
|
45
|
+
|
|
46
|
+
An example of nestjs module that import the @xnestjs/mongodb async
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
// module.ts
|
|
50
|
+
import { Module } from '@nestjs/common';
|
|
51
|
+
import { StorageModule } from '@xnestjs/storage';
|
|
52
|
+
|
|
53
|
+
@Module({
|
|
54
|
+
imports: [
|
|
55
|
+
StorageModule.forRootAsync({
|
|
56
|
+
inject: [ConfigModule],
|
|
57
|
+
useFactory: (config: ConfigService) => ({
|
|
58
|
+
provider: 's3',
|
|
59
|
+
s3: {
|
|
60
|
+
endPoint: config.get('S3_ENDPOINT'),
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
})
|
|
66
|
+
export class MyModule {
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Environment Variables
|
|
71
|
+
|
|
72
|
+
The library supports configuration through environment variables. Environment variables below is accepted.
|
|
73
|
+
All environment variables starts with prefix (STORAGE_). This can be configured while registering the module.
|
|
74
|
+
|
|
75
|
+
| Environment Variable | Type | Default | Description |
|
|
76
|
+
|----------------------|------|---------|-------------------------------------|
|
|
77
|
+
| STORAGE_PROVIDER | Enum | | Storage Provider `s3` for Amazon S3 |
|
|
78
|
+
|
|
79
|
+
## Amazon S3 Environment Variables
|
|
80
|
+
|
|
81
|
+
| Environment Variable | Type | Default | Description |
|
|
82
|
+
|--------------------------|---------|---------|-----------------|
|
|
83
|
+
| STORAGE_S3_ENDPOINT | String | | S3 Endpoint URL |
|
|
84
|
+
| STORAGE_S3_SECRET_KEY | String | | |
|
|
85
|
+
| STORAGE_S3_SSL | Boolean | | |
|
|
86
|
+
| STORAGE_S3_PORT | Number | | |
|
|
87
|
+
| STORAGE_S3_SESSION_TOKEN | String | | |
|
|
88
|
+
| STORAGE_S3_PART_SIZE | Number | | |
|
|
89
|
+
| STORAGE_S3_PATH_STYLE | Boolean | | |
|
|
90
|
+
| STORAGE_S3_SECRET_KEY | String | | |
|
|
91
|
+
| STORAGE_S3_ACC_ENDPOINT | String | | |
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STORAGE_OPTIONS = void 0;
|
|
3
|
+
exports.STORAGE_MODULE_ID = exports.STORAGE_OPTIONS = void 0;
|
|
4
4
|
exports.STORAGE_OPTIONS = Symbol('STORAGE_OPTIONS');
|
|
5
|
+
exports.STORAGE_MODULE_ID = Symbol('STORAGE_MODULE_ID');
|
package/cjs/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./
|
|
5
|
-
tslib_1.__exportStar(require("./interfaces/storage.interfaces.js"), exports);
|
|
4
|
+
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./services/storage-bucket.js"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./services/storage-connection.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./storage.constants.js"), exports);
|
|
9
7
|
tslib_1.__exportStar(require("./storage.module.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
@@ -1,71 +1,107 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var StorageCoreModule_1;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.StorageCoreModule = void 0;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
|
|
6
|
+
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
7
|
+
const objects_1 = require("@jsopen/objects");
|
|
6
8
|
const common_1 = require("@nestjs/common");
|
|
9
|
+
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
10
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
11
|
+
const constants_js_1 = require("./constants.js");
|
|
12
|
+
const s3_storage_connection_js_1 = require("./providers/s3-storage-connection.js");
|
|
7
13
|
const storage_connection_js_1 = require("./services/storage-connection.js");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
|
|
15
|
+
class StorageCoreModule {
|
|
16
|
+
/**
|
|
17
|
+
* Configures and returns a dynamic module
|
|
18
|
+
*/
|
|
19
|
+
static forRoot(moduleOptions) {
|
|
20
|
+
const connectionOptions = this._readConnectionOptions(moduleOptions.useValue || {}, moduleOptions.envPrefix);
|
|
21
|
+
return this._createDynamicModule(moduleOptions, {
|
|
22
|
+
global: moduleOptions.global,
|
|
23
|
+
providers: [
|
|
24
|
+
{
|
|
25
|
+
provide: constants_js_1.STORAGE_OPTIONS,
|
|
26
|
+
useValue: connectionOptions,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
});
|
|
22
30
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Configures and returns an async dynamic module
|
|
33
|
+
*/
|
|
34
|
+
static forRootAsync(asyncOptions) {
|
|
35
|
+
node_assert_1.default.ok(asyncOptions.useFactory, 'useFactory is required');
|
|
36
|
+
return this._createDynamicModule(asyncOptions, {
|
|
37
|
+
global: asyncOptions.global,
|
|
38
|
+
providers: [
|
|
39
|
+
{
|
|
40
|
+
provide: constants_js_1.STORAGE_OPTIONS,
|
|
41
|
+
inject: asyncOptions.inject,
|
|
42
|
+
useFactory: async (...args) => {
|
|
43
|
+
const opts = await asyncOptions.useFactory(...args);
|
|
44
|
+
return this._readConnectionOptions(opts, asyncOptions.envPrefix);
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
static _readConnectionOptions(moduleOptions, prefix = 'STORAGE_') {
|
|
51
|
+
const options = (0, objects_1.clone)(moduleOptions);
|
|
52
|
+
const env = node_process_1.default.env;
|
|
53
|
+
options.provider = options.provider || env[prefix + 'PROVIDER'];
|
|
54
|
+
if (options.provider === 's3') {
|
|
55
|
+
options.s3 = options.s3 || {};
|
|
56
|
+
options.s3.endPoint = options.s3.endPoint ?? env[prefix + 'S3_ENDPOINT'];
|
|
57
|
+
options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
|
|
58
|
+
options.s3.useSSL = options.s3.useSSL ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'S3_SSL']);
|
|
59
|
+
options.s3.port = options.s3.port ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'S3_PORT']);
|
|
60
|
+
options.s3.sessionToken = options.s3.sessionToken ?? env[prefix + 'S3_SESSION_TOKEN'];
|
|
61
|
+
options.s3.partSize = options.s3.partSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'S3_PART_SIZE']);
|
|
62
|
+
options.s3.pathStyle = options.s3.pathStyle ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'S3_PATH_STYLE']);
|
|
63
|
+
options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
|
|
64
|
+
options.s3.s3AccelerateEndpoint = options.s3.s3AccelerateEndpoint ?? env[prefix + 'S3_ACC_ENDPOINT'];
|
|
46
65
|
}
|
|
47
|
-
|
|
66
|
+
return options;
|
|
67
|
+
}
|
|
68
|
+
static _createDynamicModule(opts, metadata) {
|
|
69
|
+
const token = opts.token ?? storage_connection_js_1.StorageConnection;
|
|
48
70
|
const providers = [
|
|
49
|
-
optionsProvider,
|
|
50
71
|
{
|
|
51
|
-
provide:
|
|
52
|
-
inject: [
|
|
53
|
-
useFactory: (
|
|
72
|
+
provide: token,
|
|
73
|
+
inject: [constants_js_1.STORAGE_OPTIONS],
|
|
74
|
+
useFactory: async (storageOptions) => {
|
|
75
|
+
if (storageOptions.provider === 's3') {
|
|
76
|
+
if (!storageOptions.s3)
|
|
77
|
+
throw new Error('You must provide S3 config');
|
|
78
|
+
return new s3_storage_connection_js_1.S3StorageConnection(storageOptions.s3);
|
|
79
|
+
}
|
|
80
|
+
throw new Error(`Unknown Storage provider (${storageOptions.provider})`);
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
provide: CLIENT_TOKEN,
|
|
85
|
+
useExisting: token,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
provide: common_1.Logger,
|
|
89
|
+
useValue: typeof opts.logger === 'string' ? new common_1.Logger(opts.logger) : opts.logger,
|
|
54
90
|
},
|
|
55
91
|
];
|
|
56
|
-
if (asyncOptions.providers)
|
|
57
|
-
providers.push(...asyncOptions.providers);
|
|
58
92
|
return {
|
|
59
|
-
module:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
93
|
+
module: StorageCoreModule,
|
|
94
|
+
...metadata,
|
|
95
|
+
providers: [
|
|
96
|
+
...(metadata.providers ?? []),
|
|
97
|
+
...providers,
|
|
98
|
+
{
|
|
99
|
+
provide: constants_js_1.STORAGE_MODULE_ID,
|
|
100
|
+
useValue: crypto_1.default.randomUUID(),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
exports: [constants_js_1.STORAGE_OPTIONS, token, ...(metadata.exports ?? [])],
|
|
64
104
|
};
|
|
65
105
|
}
|
|
66
|
-
}
|
|
106
|
+
}
|
|
67
107
|
exports.StorageCoreModule = StorageCoreModule;
|
|
68
|
-
exports.StorageCoreModule = StorageCoreModule = StorageCoreModule_1 = tslib_1.__decorate([
|
|
69
|
-
(0, common_1.Global)(),
|
|
70
|
-
(0, common_1.Module)({})
|
|
71
|
-
], StorageCoreModule);
|
package/cjs/storage.module.js
CHANGED
|
@@ -6,17 +6,17 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
7
|
const storage_core_module_js_1 = require("./storage-core.module.js");
|
|
8
8
|
let StorageModule = StorageModule_1 = class StorageModule {
|
|
9
|
-
static
|
|
9
|
+
static forRoot(options) {
|
|
10
10
|
return {
|
|
11
11
|
module: StorageModule_1,
|
|
12
|
-
imports: [storage_core_module_js_1.StorageCoreModule.
|
|
12
|
+
imports: [storage_core_module_js_1.StorageCoreModule.forRoot(options)],
|
|
13
13
|
global: options.global,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
static
|
|
16
|
+
static forRootAsync(options) {
|
|
17
17
|
return {
|
|
18
18
|
module: StorageModule_1,
|
|
19
|
-
imports: [storage_core_module_js_1.StorageCoreModule.
|
|
19
|
+
imports: [storage_core_module_js_1.StorageCoreModule.forRootAsync(options)],
|
|
20
20
|
global: options.global,
|
|
21
21
|
};
|
|
22
22
|
}
|
package/esm/constants.js
ADDED
package/esm/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './interfaces/storage.interfaces.js';
|
|
1
|
+
export * from './constants.js';
|
|
3
2
|
export * from './services/storage-bucket.js';
|
|
4
3
|
export * from './services/storage-connection.js';
|
|
5
|
-
export * from './storage.constants.js';
|
|
6
4
|
export * from './storage.module.js';
|
|
5
|
+
export * from './types.js';
|
|
@@ -1,68 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { clone } from '@jsopen/objects';
|
|
4
|
+
import { Logger } from '@nestjs/common';
|
|
5
|
+
import crypto from 'crypto';
|
|
6
|
+
import { toBoolean, toInt } from 'putil-varhelpers';
|
|
7
|
+
import { STORAGE_MODULE_ID, STORAGE_OPTIONS } from './constants.js';
|
|
8
|
+
import { S3StorageConnection } from './providers/s3-storage-connection.js';
|
|
4
9
|
import { StorageConnection } from './services/storage-connection.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
|
|
11
|
+
export class StorageCoreModule {
|
|
12
|
+
/**
|
|
13
|
+
* Configures and returns a dynamic module
|
|
14
|
+
*/
|
|
15
|
+
static forRoot(moduleOptions) {
|
|
16
|
+
const connectionOptions = this._readConnectionOptions(moduleOptions.useValue || {}, moduleOptions.envPrefix);
|
|
17
|
+
return this._createDynamicModule(moduleOptions, {
|
|
18
|
+
global: moduleOptions.global,
|
|
19
|
+
providers: [
|
|
20
|
+
{
|
|
21
|
+
provide: STORAGE_OPTIONS,
|
|
22
|
+
useValue: connectionOptions,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
});
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Configures and returns an async dynamic module
|
|
29
|
+
*/
|
|
30
|
+
static forRootAsync(asyncOptions) {
|
|
31
|
+
assert.ok(asyncOptions.useFactory, 'useFactory is required');
|
|
32
|
+
return this._createDynamicModule(asyncOptions, {
|
|
33
|
+
global: asyncOptions.global,
|
|
34
|
+
providers: [
|
|
35
|
+
{
|
|
36
|
+
provide: STORAGE_OPTIONS,
|
|
37
|
+
inject: asyncOptions.inject,
|
|
38
|
+
useFactory: async (...args) => {
|
|
39
|
+
const opts = await asyncOptions.useFactory(...args);
|
|
40
|
+
return this._readConnectionOptions(opts, asyncOptions.envPrefix);
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
static _readConnectionOptions(moduleOptions, prefix = 'STORAGE_') {
|
|
47
|
+
const options = clone(moduleOptions);
|
|
48
|
+
const env = process.env;
|
|
49
|
+
options.provider = options.provider || env[prefix + 'PROVIDER'];
|
|
50
|
+
if (options.provider === 's3') {
|
|
51
|
+
options.s3 = options.s3 || {};
|
|
52
|
+
options.s3.endPoint = options.s3.endPoint ?? env[prefix + 'S3_ENDPOINT'];
|
|
53
|
+
options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
|
|
54
|
+
options.s3.useSSL = options.s3.useSSL ?? toBoolean(env[prefix + 'S3_SSL']);
|
|
55
|
+
options.s3.port = options.s3.port ?? toInt(env[prefix + 'S3_PORT']);
|
|
56
|
+
options.s3.sessionToken = options.s3.sessionToken ?? env[prefix + 'S3_SESSION_TOKEN'];
|
|
57
|
+
options.s3.partSize = options.s3.partSize ?? toInt(env[prefix + 'S3_PART_SIZE']);
|
|
58
|
+
options.s3.pathStyle = options.s3.pathStyle ?? toBoolean(env[prefix + 'S3_PATH_STYLE']);
|
|
59
|
+
options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
|
|
60
|
+
options.s3.s3AccelerateEndpoint = options.s3.s3AccelerateEndpoint ?? env[prefix + 'S3_ACC_ENDPOINT'];
|
|
43
61
|
}
|
|
44
|
-
|
|
62
|
+
return options;
|
|
63
|
+
}
|
|
64
|
+
static _createDynamicModule(opts, metadata) {
|
|
65
|
+
const token = opts.token ?? StorageConnection;
|
|
45
66
|
const providers = [
|
|
46
|
-
optionsProvider,
|
|
47
67
|
{
|
|
48
|
-
provide:
|
|
68
|
+
provide: token,
|
|
49
69
|
inject: [STORAGE_OPTIONS],
|
|
50
|
-
useFactory: (
|
|
70
|
+
useFactory: async (storageOptions) => {
|
|
71
|
+
if (storageOptions.provider === 's3') {
|
|
72
|
+
if (!storageOptions.s3)
|
|
73
|
+
throw new Error('You must provide S3 config');
|
|
74
|
+
return new S3StorageConnection(storageOptions.s3);
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`Unknown Storage provider (${storageOptions.provider})`);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
provide: CLIENT_TOKEN,
|
|
81
|
+
useExisting: token,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
provide: Logger,
|
|
85
|
+
useValue: typeof opts.logger === 'string' ? new Logger(opts.logger) : opts.logger,
|
|
51
86
|
},
|
|
52
87
|
];
|
|
53
|
-
if (asyncOptions.providers)
|
|
54
|
-
providers.push(...asyncOptions.providers);
|
|
55
88
|
return {
|
|
56
|
-
module:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
89
|
+
module: StorageCoreModule,
|
|
90
|
+
...metadata,
|
|
91
|
+
providers: [
|
|
92
|
+
...(metadata.providers ?? []),
|
|
93
|
+
...providers,
|
|
94
|
+
{
|
|
95
|
+
provide: STORAGE_MODULE_ID,
|
|
96
|
+
useValue: crypto.randomUUID(),
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
exports: [STORAGE_OPTIONS, token, ...(metadata.exports ?? [])],
|
|
61
100
|
};
|
|
62
101
|
}
|
|
63
|
-
}
|
|
64
|
-
StorageCoreModule = StorageCoreModule_1 = __decorate([
|
|
65
|
-
Global(),
|
|
66
|
-
Module({})
|
|
67
|
-
], StorageCoreModule);
|
|
68
|
-
export { StorageCoreModule };
|
|
102
|
+
}
|
package/esm/storage.module.js
CHANGED
|
@@ -3,17 +3,17 @@ import { __decorate } from "tslib";
|
|
|
3
3
|
import { Module } from '@nestjs/common';
|
|
4
4
|
import { StorageCoreModule } from './storage-core.module.js';
|
|
5
5
|
let StorageModule = StorageModule_1 = class StorageModule {
|
|
6
|
-
static
|
|
6
|
+
static forRoot(options) {
|
|
7
7
|
return {
|
|
8
8
|
module: StorageModule_1,
|
|
9
|
-
imports: [StorageCoreModule.
|
|
9
|
+
imports: [StorageCoreModule.forRoot(options)],
|
|
10
10
|
global: options.global,
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
static
|
|
13
|
+
static forRootAsync(options) {
|
|
14
14
|
return {
|
|
15
15
|
module: StorageModule_1,
|
|
16
|
-
imports: [StorageCoreModule.
|
|
16
|
+
imports: [StorageCoreModule.forRootAsync(options)],
|
|
17
17
|
global: options.global,
|
|
18
18
|
};
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xnestjs/storage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "NestJS extension library for Storage solutions (S3,GS)",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@jsopen/objects": "^1.5.2",
|
|
9
|
+
"ansi-colors": "^4.1.3",
|
|
10
|
+
"putil-varhelpers": "^1.6.5",
|
|
8
11
|
"tslib": "^2.8.1"
|
|
9
12
|
},
|
|
10
13
|
"peerDependencies": {
|
package/types/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './interfaces/storage.interfaces.js';
|
|
1
|
+
export * from './constants.js';
|
|
3
2
|
export * from './services/storage-bucket.js';
|
|
4
3
|
export * from './services/storage-connection.js';
|
|
5
|
-
export * from './storage.constants.js';
|
|
6
4
|
export * from './storage.module.js';
|
|
5
|
+
export * from './types.js';
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './interfaces/storage.interfaces.js';
|
|
1
|
+
export * from './constants.js';
|
|
3
2
|
export * from './services/storage-bucket.js';
|
|
4
3
|
export * from './services/storage-connection.js';
|
|
5
|
-
export * from './storage.constants.js';
|
|
6
4
|
export * from './storage.module.js';
|
|
5
|
+
export * from './types.js';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
|
-
import { GetObjectSignedUrlOptions, ObjectInfo, PutObjectOptions } from '../interfaces/connection.interfaces.js';
|
|
4
|
-
import { S3Config } from '../interfaces/storage.interfaces.js';
|
|
5
3
|
import { StorageConnection } from '../services/storage-connection.js';
|
|
4
|
+
import type { GetObjectSignedUrlOptions, ObjectInfo, PutObjectOptions, S3Config } from '../types.js';
|
|
6
5
|
export declare class S3StorageConnection extends StorageConnection {
|
|
7
6
|
readonly provider = "s3";
|
|
8
7
|
readonly config: S3Config;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Buffer } from 'buffer';
|
|
2
2
|
import type { Readable } from 'stream';
|
|
3
|
-
import type { GetObjectSignedUrlOptions, ObjectInfo, PutObjectOptions } from '../
|
|
3
|
+
import type { GetObjectSignedUrlOptions, ObjectInfo, PutObjectOptions } from '../types.js';
|
|
4
4
|
import type { StorageConnection } from './storage-connection';
|
|
5
5
|
export declare class StorageBucket {
|
|
6
6
|
private _connection;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Buffer } from 'buffer';
|
|
2
2
|
import type { Readable } from 'stream';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { StorageProvider } from '../types';
|
|
4
|
+
import type { GetObjectSignedUrlOptions, ObjectInfo, PutObjectOptions } from '../types.js';
|
|
5
5
|
import { StorageBucket } from './storage-bucket.js';
|
|
6
6
|
export declare abstract class StorageConnection {
|
|
7
7
|
abstract readonly provider: StorageProvider;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { StorageModuleAsyncOptions, StorageModuleOptions } from './
|
|
2
|
+
import type { StorageModuleAsyncOptions, StorageModuleOptions } from './types.js';
|
|
3
3
|
export declare class StorageCoreModule {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Configures and returns a dynamic module
|
|
6
|
+
*/
|
|
7
|
+
static forRoot(moduleOptions: StorageModuleOptions): DynamicModule;
|
|
8
|
+
/**
|
|
9
|
+
* Configures and returns an async dynamic module
|
|
10
|
+
*/
|
|
11
|
+
static forRootAsync(asyncOptions: StorageModuleAsyncOptions): DynamicModule;
|
|
12
|
+
private static _readConnectionOptions;
|
|
13
|
+
private static _createDynamicModule;
|
|
6
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { StorageModuleAsyncOptions, StorageModuleOptions } from './
|
|
2
|
+
import type { StorageModuleAsyncOptions, StorageModuleOptions } from './types.js';
|
|
3
3
|
export declare class StorageModule {
|
|
4
|
-
static
|
|
5
|
-
static
|
|
4
|
+
static forRoot(options: StorageModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: StorageModuleAsyncOptions): DynamicModule;
|
|
6
6
|
}
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { InjectionToken, Logger } from '@nestjs/common';
|
|
2
|
+
import type { ModuleMetadata } from '@nestjs/common/interfaces';
|
|
3
|
+
import type * as minio from 'minio';
|
|
4
|
+
export type S3Config = minio.ClientOptions & {
|
|
5
|
+
rejectUnauthorized?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type StorageProvider = 's3';
|
|
8
|
+
/**
|
|
9
|
+
* Amazon S3
|
|
10
|
+
*/
|
|
11
|
+
export interface S3StorageOptions {
|
|
12
|
+
provider: 's3';
|
|
13
|
+
s3: S3Config;
|
|
14
|
+
}
|
|
15
|
+
export type StorageOptions = S3StorageOptions;
|
|
16
|
+
export interface StorageModuleOptions extends BaseModuleOptions {
|
|
17
|
+
useValue: StorageOptions;
|
|
18
|
+
}
|
|
19
|
+
export interface StorageModuleAsyncOptions extends BaseModuleOptions, Pick<ModuleMetadata, 'imports'> {
|
|
20
|
+
useFactory?: (...args: any[]) => Promise<StorageOptions> | StorageOptions;
|
|
21
|
+
inject?: any[];
|
|
22
|
+
}
|
|
23
|
+
interface BaseModuleOptions {
|
|
24
|
+
token?: InjectionToken;
|
|
25
|
+
envPrefix?: string;
|
|
26
|
+
logger?: Logger | string;
|
|
27
|
+
global?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export type FileMetadata = Record<string, any>;
|
|
30
|
+
export interface ObjectInfo {
|
|
31
|
+
originalName?: string;
|
|
32
|
+
contentType?: string;
|
|
33
|
+
contentLanguage?: string;
|
|
34
|
+
contentEncoding?: string;
|
|
35
|
+
size: number;
|
|
36
|
+
etag: string;
|
|
37
|
+
lastModified: Date;
|
|
38
|
+
metadata: Record<string, any>;
|
|
39
|
+
}
|
|
40
|
+
export interface PutObjectOptions {
|
|
41
|
+
originalName?: string;
|
|
42
|
+
contentType?: string;
|
|
43
|
+
contentLanguage?: string;
|
|
44
|
+
contentEncoding?: string;
|
|
45
|
+
metadata?: FileMetadata;
|
|
46
|
+
}
|
|
47
|
+
export interface SignedUrlOptions {
|
|
48
|
+
expires?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface GetObjectSignedUrlOptions extends SignedUrlOptions {
|
|
51
|
+
}
|
|
52
|
+
export {};
|
package/cjs/storage.utils.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createConnection = createConnection;
|
|
4
|
-
const s3_storage_connection_js_1 = require("./providers/s3-storage-connection.js");
|
|
5
|
-
function createConnection(options) {
|
|
6
|
-
if (options.provider === 's3') {
|
|
7
|
-
if (!options.s3)
|
|
8
|
-
throw new Error('You must provide S3 config');
|
|
9
|
-
return new s3_storage_connection_js_1.S3StorageConnection(options.s3);
|
|
10
|
-
}
|
|
11
|
-
throw new Error(`Unknown Storage provider (${options.provider})`);
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/storage.constants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const STORAGE_OPTIONS = Symbol('STORAGE_OPTIONS');
|
package/esm/storage.utils.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { S3StorageConnection } from './providers/s3-storage-connection.js';
|
|
2
|
-
export function createConnection(options) {
|
|
3
|
-
if (options.provider === 's3') {
|
|
4
|
-
if (!options.s3)
|
|
5
|
-
throw new Error('You must provide S3 config');
|
|
6
|
-
return new S3StorageConnection(options.s3);
|
|
7
|
-
}
|
|
8
|
-
throw new Error(`Unknown Storage provider (${options.provider})`);
|
|
9
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type FileMetadata = Record<string, any>;
|
|
2
|
-
export interface ObjectInfo {
|
|
3
|
-
originalName?: string;
|
|
4
|
-
contentType?: string;
|
|
5
|
-
contentLanguage?: string;
|
|
6
|
-
contentEncoding?: string;
|
|
7
|
-
size: number;
|
|
8
|
-
etag: string;
|
|
9
|
-
lastModified: Date;
|
|
10
|
-
metadata: Record<string, any>;
|
|
11
|
-
}
|
|
12
|
-
export interface PutObjectOptions {
|
|
13
|
-
originalName?: string;
|
|
14
|
-
contentType?: string;
|
|
15
|
-
contentLanguage?: string;
|
|
16
|
-
contentEncoding?: string;
|
|
17
|
-
metadata?: FileMetadata;
|
|
18
|
-
}
|
|
19
|
-
export interface SignedUrlOptions {
|
|
20
|
-
expires?: number;
|
|
21
|
-
}
|
|
22
|
-
export interface GetObjectSignedUrlOptions extends SignedUrlOptions {
|
|
23
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { InjectionToken } from '@nestjs/common';
|
|
2
|
-
import type { ModuleMetadata, Type } from '@nestjs/common/interfaces';
|
|
3
|
-
import type * as minio from 'minio';
|
|
4
|
-
export type S3Config = minio.ClientOptions & {
|
|
5
|
-
rejectUnauthorized?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export type StorageProvider = 's3' | 'gs';
|
|
8
|
-
export interface S3StorageOptions {
|
|
9
|
-
provider: StorageProvider;
|
|
10
|
-
s3: S3Config;
|
|
11
|
-
}
|
|
12
|
-
export interface GSStorageOptions {
|
|
13
|
-
provider: StorageProvider;
|
|
14
|
-
gs: {};
|
|
15
|
-
}
|
|
16
|
-
export type StorageOptions = S3StorageOptions | GSStorageOptions;
|
|
17
|
-
export type StorageModuleOptions = StorageOptions & {
|
|
18
|
-
token?: InjectionToken;
|
|
19
|
-
global?: boolean;
|
|
20
|
-
};
|
|
21
|
-
export interface StorageModuleAsyncOptions extends Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
|
|
22
|
-
token?: InjectionToken;
|
|
23
|
-
inject?: any[];
|
|
24
|
-
global?: boolean;
|
|
25
|
-
useClass?: Type<StorageOptions>;
|
|
26
|
-
useExisting?: InjectionToken;
|
|
27
|
-
useFactory?: (...args: any[]) => Promise<StorageOptions> | StorageOptions;
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const STORAGE_OPTIONS: unique symbol;
|
package/types/storage.utils.d.ts
DELETED
|
File without changes
|
|
File without changes
|