@xnestjs/storage 1.2.4 → 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 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("./interfaces/connection.interfaces.js"), exports);
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 storage_constants_js_1 = require("./storage.constants.js");
9
- const storage_utils_js_1 = require("./storage.utils.js");
10
- let StorageCoreModule = StorageCoreModule_1 = class StorageCoreModule {
11
- static register(options) {
12
- const connectionProvider = {
13
- provide: options.token || storage_connection_js_1.StorageConnection,
14
- useValue: (0, storage_utils_js_1.createConnection)(options),
15
- };
16
- return {
17
- module: StorageCoreModule_1,
18
- providers: [connectionProvider],
19
- exports: [connectionProvider],
20
- global: options.global,
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
- static registerAsync(asyncOptions) {
24
- let optionsProvider;
25
- if (asyncOptions.useFactory) {
26
- optionsProvider = {
27
- provide: storage_constants_js_1.STORAGE_OPTIONS,
28
- inject: asyncOptions.inject || [],
29
- useFactory: asyncOptions.useFactory,
30
- };
31
- }
32
- else if (asyncOptions.useExisting) {
33
- optionsProvider = {
34
- provide: storage_constants_js_1.STORAGE_OPTIONS,
35
- useExisting: asyncOptions.useExisting,
36
- };
37
- }
38
- else if (asyncOptions.useClass) {
39
- optionsProvider = {
40
- provide: storage_constants_js_1.STORAGE_OPTIONS,
41
- useClass: asyncOptions.useClass,
42
- };
43
- }
44
- else {
45
- throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
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
- const storageToken = asyncOptions.token || storage_connection_js_1.StorageConnection;
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: storageToken,
52
- inject: [storage_constants_js_1.STORAGE_OPTIONS],
53
- useFactory: (options) => (0, storage_utils_js_1.createConnection)(options),
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: StorageCoreModule_1,
60
- imports: asyncOptions.imports || [],
61
- exports: [storageToken, ...(asyncOptions.exports || [])],
62
- providers,
63
- global: asyncOptions.global,
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);
@@ -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 register(options) {
9
+ static forRoot(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.forRoot(options)],
13
13
  global: options.global,
14
14
  };
15
15
  }
16
- static registerAsync(options) {
16
+ static forRootAsync(options) {
17
17
  return {
18
18
  module: StorageModule_1,
19
- imports: [storage_core_module_js_1.StorageCoreModule.registerAsync(options)],
19
+ imports: [storage_core_module_js_1.StorageCoreModule.forRootAsync(options)],
20
20
  global: options.global,
21
21
  };
22
22
  }
@@ -0,0 +1,2 @@
1
+ export const STORAGE_OPTIONS = Symbol('STORAGE_OPTIONS');
2
+ export const STORAGE_MODULE_ID = Symbol('STORAGE_MODULE_ID');
package/esm/index.js CHANGED
@@ -1,6 +1,5 @@
1
- export * from './interfaces/connection.interfaces.js';
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
- var StorageCoreModule_1;
2
- import { __decorate } from "tslib";
3
- import { Global, Module } from '@nestjs/common';
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
- import { STORAGE_OPTIONS } from './storage.constants.js';
6
- import { createConnection } from './storage.utils.js';
7
- let StorageCoreModule = StorageCoreModule_1 = class StorageCoreModule {
8
- static register(options) {
9
- const connectionProvider = {
10
- provide: options.token || StorageConnection,
11
- useValue: createConnection(options),
12
- };
13
- return {
14
- module: StorageCoreModule_1,
15
- providers: [connectionProvider],
16
- exports: [connectionProvider],
17
- global: options.global,
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
- static registerAsync(asyncOptions) {
21
- let optionsProvider;
22
- if (asyncOptions.useFactory) {
23
- optionsProvider = {
24
- provide: STORAGE_OPTIONS,
25
- inject: asyncOptions.inject || [],
26
- useFactory: asyncOptions.useFactory,
27
- };
28
- }
29
- else if (asyncOptions.useExisting) {
30
- optionsProvider = {
31
- provide: STORAGE_OPTIONS,
32
- useExisting: asyncOptions.useExisting,
33
- };
34
- }
35
- else if (asyncOptions.useClass) {
36
- optionsProvider = {
37
- provide: STORAGE_OPTIONS,
38
- useClass: asyncOptions.useClass,
39
- };
40
- }
41
- else {
42
- throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
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
- const storageToken = asyncOptions.token || StorageConnection;
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: storageToken,
68
+ provide: token,
49
69
  inject: [STORAGE_OPTIONS],
50
- useFactory: (options) => createConnection(options),
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: StorageCoreModule_1,
57
- imports: asyncOptions.imports || [],
58
- exports: [storageToken, ...(asyncOptions.exports || [])],
59
- providers,
60
- global: asyncOptions.global,
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
+ }
@@ -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 register(options) {
6
+ static forRoot(options) {
7
7
  return {
8
8
  module: StorageModule_1,
9
- imports: [StorageCoreModule.register(options)],
9
+ imports: [StorageCoreModule.forRoot(options)],
10
10
  global: options.global,
11
11
  };
12
12
  }
13
- static registerAsync(options) {
13
+ static forRootAsync(options) {
14
14
  return {
15
15
  module: StorageModule_1,
16
- imports: [StorageCoreModule.registerAsync(options)],
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.2.4",
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": {
@@ -0,0 +1,2 @@
1
+ export declare const STORAGE_OPTIONS: unique symbol;
2
+ export declare const STORAGE_MODULE_ID: unique symbol;
package/types/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- export * from './interfaces/connection.interfaces.js';
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 './interfaces/connection.interfaces.js';
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 '../interfaces/connection.interfaces.js';
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 { GetObjectSignedUrlOptions, ObjectInfo, PutObjectOptions } from '../interfaces/connection.interfaces.js';
4
- import type { StorageProvider } from '../interfaces/storage.interfaces.js';
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 './interfaces/storage.interfaces.js';
2
+ import type { StorageModuleAsyncOptions, StorageModuleOptions } from './types.js';
3
3
  export declare class StorageCoreModule {
4
- static register(options: StorageModuleOptions): DynamicModule;
5
- static registerAsync(asyncOptions: StorageModuleAsyncOptions): DynamicModule;
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 './interfaces/storage.interfaces.js';
2
+ import type { StorageModuleAsyncOptions, StorageModuleOptions } from './types.js';
3
3
  export declare class StorageModule {
4
- static register(options: StorageModuleOptions): DynamicModule;
5
- static registerAsync(options: StorageModuleAsyncOptions): DynamicModule;
4
+ static forRoot(options: StorageModuleOptions): DynamicModule;
5
+ static forRootAsync(options: StorageModuleAsyncOptions): DynamicModule;
6
6
  }
@@ -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 {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 {};
@@ -1 +0,0 @@
1
- export const STORAGE_OPTIONS = Symbol('STORAGE_OPTIONS');
@@ -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;
@@ -1,3 +0,0 @@
1
- import { StorageOptions } from './interfaces/storage.interfaces.js';
2
- import { StorageConnection } from './services/storage-connection.js';
3
- export declare function createConnection(options: StorageOptions): StorageConnection;