@nathapp/nestjs-storage 1.0.0-rc.1 → 1.0.0-rc.2

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
@@ -2,3 +2,11 @@
2
2
 
3
3
  # inspire by https://github.com/Eleven-am/nest-storage
4
4
 
5
+ # Supported Provider
6
+
7
+ 1. LOCAL
8
+ 2. NFS
9
+ 3. ALIBABA OSS
10
+ 4. AWS s3
11
+ 5. GDRIVE
12
+ 6. DROPBOX
package/bun.lockb CHANGED
Binary file
@@ -1,9 +1,25 @@
1
- import { StorageOption, AsyncStorageOptions } from '../types/options';
2
- import { DynamicModule } from '@nestjs/common';
3
- export declare class StorageModule {
4
- private static providerFactory;
5
- private static createService;
6
- static forRoot(options: StorageOption): DynamicModule;
7
- static forRootAsync(options: AsyncStorageOptions): Promise<DynamicModule>;
1
+ import { StorageOption } from '../types/options';
2
+ import { DynamicModule, ModuleMetadata, Type } from '@nestjs/common';
3
+ export declare const STORAGE_MODULE_OPTIONS = "STORAGE_MODULE_OPTIONS";
4
+ declare const StorageModule_base: import("@nathapp/nestjs-common").ConfigurableModuleCls<StorageOption, "register", "createOptions", {}>;
5
+ export declare class StorageModule extends StorageModule_base {
6
+ static register(options: StorageModuleOptions): DynamicModule;
7
+ static registerAsync(options: StorageModuleAsyncOptions): DynamicModule;
8
8
  private static createAsyncProviders;
9
9
  }
10
+ export type StorageModuleOptions = StorageOption & {
11
+ name?: string;
12
+ isGlobal?: boolean;
13
+ };
14
+ export interface StorageModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
15
+ name?: string;
16
+ isGlobal?: boolean;
17
+ useExisting?: Type<StorageModuleOptionsFactory>;
18
+ useClass?: Type<StorageModuleOptionsFactory>;
19
+ useFactory?: (...args: any[]) => Promise<StorageModuleOptions> | StorageModuleOptions;
20
+ inject?: any[];
21
+ }
22
+ export interface StorageModuleOptionsFactory {
23
+ createOptions(): Promise<StorageModuleOptions> | StorageModuleOptions;
24
+ }
25
+ export {};
@@ -1,62 +1,65 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var StorageModule_1;
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.StorageModule = void 0;
3
+ exports.StorageModule = exports.STORAGE_MODULE_OPTIONS = void 0;
11
4
  const providers_1 = require("../providers");
12
5
  const storage_service_1 = require("../service/storage-service");
13
- const common_1 = require("@nestjs/common");
14
- let StorageModule = StorageModule_1 = class StorageModule {
15
- static providerFactory(options) {
16
- return providers_1.ProviderFactory.createProvider(options);
17
- }
18
- static createService(options) {
19
- const provider = this.providerFactory(options);
20
- const nestProvider = {
21
- provide: storage_service_1.StorageService,
22
- useValue: new storage_service_1.StorageService(provider),
23
- };
24
- return {
25
- providers: [nestProvider],
26
- exports: [nestProvider],
27
- };
28
- }
29
- static forRoot(options) {
6
+ const nestjs_common_1 = require("@nathapp/nestjs-common");
7
+ exports.STORAGE_MODULE_OPTIONS = "STORAGE_MODULE_OPTIONS";
8
+ class StorageModule extends (0, nestjs_common_1.ConfigurableModuleClass)(exports.STORAGE_MODULE_OPTIONS) {
9
+ static register(options) {
10
+ const providers = [];
11
+ providers.push(this.createAsyncProviders(options));
30
12
  return {
31
- global: true,
32
- module: StorageModule_1,
33
- ...this.createService(options),
13
+ global: options.isGlobal,
14
+ module: StorageModule,
15
+ imports: [],
16
+ ...super.register(options),
17
+ providers: [...providers],
18
+ exports: [...providers],
34
19
  };
35
20
  }
36
- static async forRootAsync(options) {
21
+ static registerAsync(options) {
22
+ const providers = [];
23
+ providers.push(this.createAsyncProviders(options));
37
24
  return {
38
25
  global: options.isGlobal,
39
- module: StorageModule_1,
26
+ module: StorageModule,
40
27
  imports: options.imports || [],
41
- ...this.createAsyncProviders(options),
28
+ ...super.registerAsync(options),
29
+ providers: [...providers],
30
+ exports: [...providers],
42
31
  };
43
32
  }
44
33
  static createAsyncProviders(options) {
45
- const provider = {
34
+ if ('useExisting' in options) {
35
+ return {
36
+ provide: storage_service_1.StorageService,
37
+ useExisting: options.useExisting,
38
+ };
39
+ }
40
+ if ('useClass' in options) {
41
+ return {
42
+ provide: storage_service_1.StorageService,
43
+ useClass: options.useClass,
44
+ };
45
+ }
46
+ if ('useFactory' in options) {
47
+ return {
48
+ provide: storage_service_1.StorageService,
49
+ useFactory: async (...args) => {
50
+ const storageOption = await options.useFactory(...args);
51
+ return new storage_service_1.StorageService(providers_1.ProviderFactory.createProvider(storageOption));
52
+ },
53
+ inject: options.inject || [],
54
+ };
55
+ }
56
+ return {
46
57
  provide: storage_service_1.StorageService,
47
- useFactory: async (...args) => {
48
- const storageOption = await options.useFactory(...args);
49
- return new storage_service_1.StorageService(this.providerFactory(storageOption));
58
+ useFactory: async (moduleOptions) => {
59
+ return new storage_service_1.StorageService(providers_1.ProviderFactory.createProvider(moduleOptions));
50
60
  },
51
- inject: options.inject || [],
52
- };
53
- return {
54
- providers: [provider],
55
- exports: [provider],
61
+ inject: [exports.STORAGE_MODULE_OPTIONS],
56
62
  };
57
63
  }
58
- };
64
+ }
59
65
  exports.StorageModule = StorageModule;
60
- exports.StorageModule = StorageModule = StorageModule_1 = __decorate([
61
- (0, common_1.Module)({})
62
- ], StorageModule);
@@ -69,9 +69,3 @@ export type DropboxStorageOption = {
69
69
  refreshToken: string;
70
70
  };
71
71
  };
72
- export interface AsyncStorageOptions {
73
- isGlobal?: boolean;
74
- inject?: any[];
75
- imports?: any[];
76
- useFactory: (...args: any[]) => Promise<StorageOption> | StorageOption;
77
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-storage",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.0.0-rc.2",
4
4
  "description": "Nestjs Storage Implementation",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && tsc -p tsconfig.json",
@@ -45,10 +45,11 @@
45
45
  "lib": "lib"
46
46
  },
47
47
  "dependencies": {
48
- "@nathapp/auth": "^1.0.2",
49
48
  "zod": "^3.23.8"
50
49
  },
51
50
  "peerDependencies": {
51
+ "@nathapp/auth": "^1.0.2",
52
+ "@nathapp/nestjs-common": "^1.0.1-rc.39",
52
53
  "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
53
54
  "@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0",
54
55
  "@azure/storage-blob": "^12.23.0",